mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
WAL
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/transsup.c,v 1.25 2000/01/26 05:56:04 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/transsup.c,v 1.26 2000/10/28 16:20:53 vadim Exp $
|
||||
*
|
||||
* NOTES
|
||||
* This file contains support functions for the high
|
||||
@@ -186,6 +186,10 @@ TransBlockGetXidStatus(Block tblock,
|
||||
bits8 bit2;
|
||||
BitIndex offset;
|
||||
|
||||
#ifdef XLOG
|
||||
tblock = (Block) ((char*) tblock + sizeof(XLogRecPtr));
|
||||
#endif
|
||||
|
||||
/* ----------------
|
||||
* calculate the index into the transaction data where
|
||||
* our transaction status is located
|
||||
@@ -227,6 +231,10 @@ TransBlockSetXidStatus(Block tblock,
|
||||
Index index;
|
||||
BitIndex offset;
|
||||
|
||||
#ifdef XLOG
|
||||
tblock = (Block) ((char*) tblock + sizeof(XLogRecPtr));
|
||||
#endif
|
||||
|
||||
/* ----------------
|
||||
* calculate the index into the transaction data where
|
||||
* we sould store our transaction status.
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.29 2000/07/25 20:18:19 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.30 2000/10/28 16:20:53 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -125,7 +125,11 @@ VariableRelationPutNextXid(TransactionId xid)
|
||||
|
||||
TransactionIdStore(xid, &(var->nextXidData));
|
||||
|
||||
#ifdef XLOG
|
||||
WriteBuffer(buf); /* temp */
|
||||
#else
|
||||
FlushBuffer(buf, TRUE);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* --------------------------------
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.77 2000/10/24 20:06:39 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.78 2000/10/28 16:20:53 vadim Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Transaction aborts can now occur two ways:
|
||||
@@ -176,6 +176,8 @@
|
||||
|
||||
extern bool SharedBufferChanged;
|
||||
|
||||
void RecordTransactionCommit(void);
|
||||
|
||||
static void AbortTransaction(void);
|
||||
static void AtAbort_Cache(void);
|
||||
static void AtAbort_Locks(void);
|
||||
@@ -191,7 +193,6 @@ static void AtStart_Memory(void);
|
||||
static void CleanupTransaction(void);
|
||||
static void CommitTransaction(void);
|
||||
static void RecordTransactionAbort(void);
|
||||
static void RecordTransactionCommit(void);
|
||||
static void StartTransaction(void);
|
||||
|
||||
/* ----------------
|
||||
@@ -220,7 +221,7 @@ int XactIsoLevel;
|
||||
#ifdef XLOG
|
||||
#include "access/xlogutils.h"
|
||||
|
||||
int CommitDelay = 100;
|
||||
int CommitDelay = 5; /* 1/200 sec */
|
||||
|
||||
void xact_redo(XLogRecPtr lsn, XLogRecord *record);
|
||||
void xact_undo(XLogRecPtr lsn, XLogRecord *record);
|
||||
@@ -658,8 +659,8 @@ AtStart_Memory(void)
|
||||
* -cim 3/18/90
|
||||
* --------------------------------
|
||||
*/
|
||||
static void
|
||||
RecordTransactionCommit(void)
|
||||
void
|
||||
RecordTransactionCommit()
|
||||
{
|
||||
TransactionId xid;
|
||||
int leak;
|
||||
@@ -683,6 +684,8 @@ RecordTransactionCommit(void)
|
||||
struct timeval delay;
|
||||
XLogRecPtr recptr;
|
||||
|
||||
BufmgrCommit();
|
||||
|
||||
xlrec.xtime = time(NULL);
|
||||
/*
|
||||
* MUST SAVE ARRAY OF RELFILENODE-s TO DROP
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.21 2000/10/24 09:56:09 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.22 2000/10/28 16:20:54 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -220,6 +220,8 @@ static uint32 readOff = 0;
|
||||
static char readBuf[BLCKSZ];
|
||||
static XLogRecord *nextRecord = NULL;
|
||||
|
||||
static bool InRedo = false;
|
||||
|
||||
XLogRecPtr
|
||||
XLogInsert(RmgrId rmid, uint8 info, char *hdr, uint32 hdrlen, char *buf, uint32 buflen)
|
||||
{
|
||||
@@ -481,6 +483,19 @@ XLogFlush(XLogRecPtr record)
|
||||
unsigned i = 0;
|
||||
bool force_lgwr = false;
|
||||
|
||||
if (XLOG_DEBUG)
|
||||
{
|
||||
fprintf(stderr, "XLogFlush%s%s: rqst %u/%u; wrt %u/%u; flsh %u/%u\n",
|
||||
(IsBootstrapProcessingMode()) ? "(bootstrap)" : "",
|
||||
(InRedo) ? "(redo)" : "",
|
||||
record.xlogid, record.xrecoff,
|
||||
LgwrResult.Write.xlogid, LgwrResult.Write.xrecoff,
|
||||
LgwrResult.Flush.xlogid, LgwrResult.Flush.xrecoff);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
if (IsBootstrapProcessingMode() || InRedo)
|
||||
return;
|
||||
if (XLByteLE(record, LgwrResult.Flush))
|
||||
return;
|
||||
WriteRqst = LgwrRqst.Write;
|
||||
@@ -894,7 +909,7 @@ ReadRecord(XLogRecPtr *RecPtr, char *buffer)
|
||||
record = (XLogRecord *) ((char *) readBuf + RecPtr->xrecoff % BLCKSZ);
|
||||
|
||||
got_record:;
|
||||
if (record->xl_len == 0 || record->xl_len >
|
||||
if (record->xl_len >
|
||||
(BLCKSZ - RecPtr->xrecoff % BLCKSZ - SizeOfXLogRecord))
|
||||
{
|
||||
elog(emode, "ReadRecord: invalid record len %u in (%u, %u)",
|
||||
@@ -1259,7 +1274,6 @@ StartupXLOG()
|
||||
LastRec;
|
||||
XLogRecord *record;
|
||||
char buffer[MAXLOGRECSZ + SizeOfXLogRecord];
|
||||
int recovery = 0;
|
||||
bool sie_saved = false;
|
||||
|
||||
#endif
|
||||
@@ -1380,16 +1394,15 @@ StartupXLOG()
|
||||
elog(STOP, "Invalid Redo/Undo record in shutdown checkpoint");
|
||||
if (ControlFile->state == DB_SHUTDOWNED)
|
||||
elog(STOP, "Invalid Redo/Undo record in Shutdowned state");
|
||||
recovery = 1;
|
||||
InRecovery = true;
|
||||
}
|
||||
else if (ControlFile->state != DB_SHUTDOWNED)
|
||||
{
|
||||
if (checkPoint.Shutdown)
|
||||
elog(STOP, "Invalid state in control file");
|
||||
recovery = 1;
|
||||
InRecovery = true;
|
||||
}
|
||||
|
||||
if (recovery)
|
||||
/* REDO */
|
||||
if (InRecovery)
|
||||
{
|
||||
elog(LOG, "The DataBase system was not properly shut down\n"
|
||||
"\tAutomatic recovery is in progress...");
|
||||
@@ -1401,6 +1414,7 @@ StartupXLOG()
|
||||
StopIfError = true;
|
||||
|
||||
XLogOpenLogRelation(); /* open pg_log */
|
||||
XLogInitRelationCache();
|
||||
|
||||
/* Is REDO required ? */
|
||||
if (XLByteLT(checkPoint.redo, RecPtr))
|
||||
@@ -1409,9 +1423,9 @@ StartupXLOG()
|
||||
/* read past CheckPoint record */
|
||||
record = ReadRecord(NULL, buffer);
|
||||
|
||||
/* REDO */
|
||||
if (record->xl_len != 0)
|
||||
{
|
||||
InRedo = true;
|
||||
elog(LOG, "Redo starts at (%u, %u)",
|
||||
ReadRecPtr.xlogid, ReadRecPtr.xrecoff);
|
||||
do
|
||||
@@ -1441,12 +1455,40 @@ StartupXLOG()
|
||||
elog(LOG, "Redo done at (%u, %u)",
|
||||
ReadRecPtr.xlogid, ReadRecPtr.xrecoff);
|
||||
LastRec = ReadRecPtr;
|
||||
InRedo = false;
|
||||
}
|
||||
else
|
||||
elog(LOG, "Redo is not required");
|
||||
}
|
||||
|
||||
/* Init xlog buffer cache */
|
||||
record = ReadRecord(&LastRec, buffer);
|
||||
logId = EndRecPtr.xlogid;
|
||||
logSeg = (EndRecPtr.xrecoff - 1) / XLogSegSize;
|
||||
logOff = 0;
|
||||
logFile = XLogFileOpen(logId, logSeg, false);
|
||||
XLogCtl->xlblocks[0].xlogid = logId;
|
||||
XLogCtl->xlblocks[0].xrecoff =
|
||||
((EndRecPtr.xrecoff - 1) / BLCKSZ + 1) * BLCKSZ;
|
||||
Insert = &XLogCtl->Insert;
|
||||
memcpy((char *) (Insert->currpage), readBuf, BLCKSZ);
|
||||
Insert->currpos = ((char *) Insert->currpage) +
|
||||
(EndRecPtr.xrecoff + BLCKSZ - XLogCtl->xlblocks[0].xrecoff);
|
||||
Insert->PrevRecord = LastRec;
|
||||
|
||||
LgwrRqst.Write = LgwrRqst.Flush =
|
||||
LgwrResult.Write = LgwrResult.Flush = EndRecPtr;
|
||||
|
||||
XLogCtl->Write.LgwrResult = LgwrResult;
|
||||
Insert->LgwrResult = LgwrResult;
|
||||
|
||||
XLogCtl->LgwrRqst = LgwrRqst;
|
||||
XLogCtl->LgwrResult = LgwrResult;
|
||||
|
||||
#ifdef NOT_USED
|
||||
/* UNDO */
|
||||
/* UNDO */
|
||||
if (InRecovery)
|
||||
{
|
||||
RecPtr = ReadRecPtr;
|
||||
if (XLByteLT(checkPoint.undo, RecPtr))
|
||||
{
|
||||
@@ -1465,29 +1507,16 @@ StartupXLOG()
|
||||
}
|
||||
else
|
||||
elog(LOG, "Undo is not required");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Init xlog buffer cache */
|
||||
record = ReadRecord(&LastRec, buffer);
|
||||
logId = EndRecPtr.xlogid;
|
||||
logSeg = (EndRecPtr.xrecoff - 1) / XLogSegSize;
|
||||
logOff = 0;
|
||||
logFile = XLogFileOpen(logId, logSeg, false);
|
||||
XLogCtl->xlblocks[0].xlogid = logId;
|
||||
XLogCtl->xlblocks[0].xrecoff =
|
||||
((EndRecPtr.xrecoff - 1) / BLCKSZ + 1) * BLCKSZ;
|
||||
Insert = &XLogCtl->Insert;
|
||||
memcpy((char *) (Insert->currpage), readBuf, BLCKSZ);
|
||||
Insert->currpos = ((char *) Insert->currpage) +
|
||||
(EndRecPtr.xrecoff + BLCKSZ - XLogCtl->xlblocks[0].xrecoff);
|
||||
Insert->PrevRecord = ControlFile->checkPoint;
|
||||
|
||||
if (recovery)
|
||||
if (InRecovery)
|
||||
{
|
||||
CreateCheckPoint(true);
|
||||
StopIfError = sie_saved;
|
||||
XLogCloseRelationCache();
|
||||
}
|
||||
InRecovery = false;
|
||||
|
||||
#endif /* XLOG */
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "access/htup.h"
|
||||
#include "access/xlogutils.h"
|
||||
#include "catalog/pg_database.h"
|
||||
#include "lib/hasht.h"
|
||||
|
||||
/*
|
||||
* ---------------------------------------------------------------
|
||||
@@ -240,32 +241,10 @@ static int _xlcnt = 0;
|
||||
#define _XLOG_INITRELCACHESIZE 32
|
||||
#define _XLOG_MAXRELCACHESIZE 512
|
||||
|
||||
void
|
||||
XLogCloseRelationCache(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!_xlrelarr)
|
||||
return;
|
||||
|
||||
for (i = 1; i < _xlast; i++)
|
||||
{
|
||||
Relation reln = &(_xlrelarr[i].reldata);
|
||||
if (reln->rd_fd >= 0)
|
||||
smgrclose(DEFAULT_SMGR, reln);
|
||||
}
|
||||
|
||||
free(_xlrelarr);
|
||||
free(_xlpgcarr);
|
||||
|
||||
hash_destroy(_xlrelcache);
|
||||
_xlrelarr = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
_xl_init_rel_cache(void)
|
||||
{
|
||||
HASHCTL ctl;
|
||||
HASHCTL ctl;
|
||||
|
||||
_xlcnt = _XLOG_INITRELCACHESIZE;
|
||||
_xlast = 0;
|
||||
@@ -286,6 +265,35 @@ _xl_init_rel_cache(void)
|
||||
HASH_ELEM | HASH_FUNCTION);
|
||||
}
|
||||
|
||||
static void
|
||||
_xl_remove_hash_entry(XLogRelDesc **edata, int dummy)
|
||||
{
|
||||
XLogRelCacheEntry *hentry;
|
||||
bool found;
|
||||
XLogRelDesc *rdesc = *edata;
|
||||
Form_pg_class tpgc = rdesc->reldata.rd_rel;
|
||||
|
||||
rdesc->lessRecently->moreRecently = rdesc->moreRecently;
|
||||
rdesc->moreRecently->lessRecently = rdesc->lessRecently;
|
||||
|
||||
hentry = (XLogRelCacheEntry*) hash_search(_xlrelcache,
|
||||
(char*)&(rdesc->reldata.rd_node), HASH_REMOVE, &found);
|
||||
|
||||
if (hentry == NULL)
|
||||
elog(STOP, "_xl_remove_hash_entry: can't delete from cache");
|
||||
if (!found)
|
||||
elog(STOP, "_xl_remove_hash_entry: file was not found in cache");
|
||||
|
||||
if (rdesc->reldata.rd_fd >= 0)
|
||||
smgrclose(DEFAULT_SMGR, &(rdesc->reldata));
|
||||
|
||||
memset(rdesc, 0, sizeof(XLogRelDesc));
|
||||
memset(tpgc, 0, sizeof(FormData_pg_class));
|
||||
rdesc->reldata.rd_rel = tpgc;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static XLogRelDesc*
|
||||
_xl_new_reldesc(void)
|
||||
{
|
||||
@@ -310,34 +318,43 @@ _xl_new_reldesc(void)
|
||||
}
|
||||
else /* reuse */
|
||||
{
|
||||
XLogRelCacheEntry *hentry;
|
||||
bool found;
|
||||
XLogRelDesc *res = _xlrelarr[0].moreRecently;
|
||||
Form_pg_class tpgc = res->reldata.rd_rel;
|
||||
XLogRelDesc *res = _xlrelarr[0].moreRecently;
|
||||
|
||||
res->lessRecently->moreRecently = res->moreRecently;
|
||||
res->moreRecently->lessRecently = res->lessRecently;
|
||||
|
||||
hentry = (XLogRelCacheEntry*) hash_search(_xlrelcache,
|
||||
(char*)&(res->reldata.rd_node), HASH_REMOVE, &found);
|
||||
|
||||
if (hentry == NULL)
|
||||
elog(STOP, "XLogOpenRelation: can't delete from cache");
|
||||
if (!found)
|
||||
elog(STOP, "XLogOpenRelation: file was not found in cache");
|
||||
|
||||
if (res->reldata.rd_fd >= 0)
|
||||
smgrclose(DEFAULT_SMGR, &(res->reldata));
|
||||
|
||||
memset(res, 0, sizeof(XLogRelDesc));
|
||||
memset(tpgc, 0, sizeof(FormData_pg_class));
|
||||
res->reldata.rd_rel = tpgc;
|
||||
_xl_remove_hash_entry(&res, 0);
|
||||
|
||||
_xlast--;
|
||||
return(res);
|
||||
}
|
||||
}
|
||||
|
||||
extern void CreateDummyCaches(void);
|
||||
extern void DestroyDummyCaches(void);
|
||||
|
||||
void
|
||||
XLogInitRelationCache(void)
|
||||
{
|
||||
CreateDummyCaches();
|
||||
_xl_init_rel_cache();
|
||||
}
|
||||
|
||||
void
|
||||
XLogCloseRelationCache(void)
|
||||
{
|
||||
|
||||
DestroyDummyCaches();
|
||||
|
||||
if (!_xlrelarr)
|
||||
return;
|
||||
|
||||
HashTableWalk(_xlrelcache, (HashtFunc)_xl_remove_hash_entry, 0);
|
||||
hash_destroy(_xlrelcache);
|
||||
|
||||
free(_xlrelarr);
|
||||
free(_xlpgcarr);
|
||||
|
||||
_xlrelarr = NULL;
|
||||
}
|
||||
|
||||
Relation
|
||||
XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
|
||||
{
|
||||
@@ -345,9 +362,6 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
|
||||
XLogRelCacheEntry *hentry;
|
||||
bool found;
|
||||
|
||||
if (!_xlrelarr)
|
||||
_xl_init_rel_cache();
|
||||
|
||||
hentry = (XLogRelCacheEntry*)
|
||||
hash_search(_xlrelcache, (char*)&rnode, HASH_FIND, &found);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user