Skip to content

Commit

Permalink
WAL
Browse files Browse the repository at this point in the history
  • Loading branch information
vadim4o committed Oct 28, 2000
1 parent 2f4c9d3 commit 5b0740d
Show file tree
Hide file tree
Showing 25 changed files with 2,828 additions and 271 deletions.
10 changes: 9 additions & 1 deletion src/backend/access/transam/transsup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion src/backend/access/transam/varsup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 $
*
*-------------------------------------------------------------------------
*/
Expand Down Expand Up @@ -125,7 +125,11 @@ VariableRelationPutNextXid(TransactionId xid)

TransactionIdStore(xid, &(var->nextXidData));

#ifdef XLOG
WriteBuffer(buf); /* temp */
#else
FlushBuffer(buf, TRUE);
#endif
}

/* --------------------------------
Expand Down
13 changes: 8 additions & 5 deletions src/backend/access/transam/xact.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -176,6 +176,8 @@

extern bool SharedBufferChanged;

void RecordTransactionCommit(void);

static void AbortTransaction(void);
static void AtAbort_Cache(void);
static void AtAbort_Locks(void);
Expand All @@ -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);

/* ----------------
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -658,8 +659,8 @@ AtStart_Memory(void)
* -cim 3/18/90
* --------------------------------
*/
static void
RecordTransactionCommit(void)
void
RecordTransactionCommit()
{
TransactionId xid;
int leak;
Expand All @@ -683,6 +684,8 @@ RecordTransactionCommit(void)
struct timeval delay;
XLogRecPtr recptr;

BufmgrCommit();

xlrec.xtime = time(NULL);
/*
* MUST SAVE ARRAY OF RELFILENODE-s TO DROP
Expand Down
83 changes: 56 additions & 27 deletions src/backend/access/transam/xlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 $
*
*-------------------------------------------------------------------------
*/
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)",
Expand Down Expand Up @@ -1259,7 +1274,6 @@ StartupXLOG()
LastRec;
XLogRecord *record;
char buffer[MAXLOGRECSZ + SizeOfXLogRecord];
int recovery = 0;
bool sie_saved = false;

#endif
Expand Down Expand Up @@ -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...");
Expand All @@ -1401,6 +1414,7 @@ StartupXLOG()
StopIfError = true;

XLogOpenLogRelation(); /* open pg_log */
XLogInitRelationCache();

/* Is REDO required ? */
if (XLByteLT(checkPoint.redo, RecPtr))
Expand All @@ -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
Expand Down Expand Up @@ -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))
{
Expand All @@ -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 */

Expand Down

0 comments on commit 5b0740d

Please sign in to comment.