mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
WAL misc
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.75 2000/10/23 04:10:05 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.76 2000/10/24 09:56:08 vadim Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Transaction aborts can now occur two ways:
|
||||
@@ -220,7 +220,7 @@ int XactIsoLevel;
|
||||
#ifdef XLOG
|
||||
#include "access/xlogutils.h"
|
||||
|
||||
int CommitDelay;
|
||||
int CommitDelay = 100;
|
||||
|
||||
void xact_redo(XLogRecPtr lsn, XLogRecord *record);
|
||||
void xact_undo(XLogRecPtr lsn, XLogRecord *record);
|
||||
@@ -676,7 +676,36 @@ RecordTransactionCommit()
|
||||
*/
|
||||
leak = BufferPoolCheckLeak();
|
||||
|
||||
#ifndef XLOG
|
||||
#ifdef XLOG
|
||||
if (MyLastRecPtr.xlogid != 0 || MyLastRecPtr.xrecoff != 0)
|
||||
{
|
||||
xl_xact_commit xlrec;
|
||||
struct timeval delay;
|
||||
XLogRecPtr recptr;
|
||||
|
||||
xlrec.xtime = time(NULL);
|
||||
/*
|
||||
* MUST SAVE ARRAY OF RELFILENODE-s TO DROP
|
||||
*/
|
||||
recptr = XLogInsert(RM_XACT_ID, XLOG_XACT_COMMIT,
|
||||
(char*) &xlrec, SizeOfXactCommit, NULL, 0);
|
||||
|
||||
/*
|
||||
* Sleep before commit! So we can flush more than one
|
||||
* commit records per single fsync.
|
||||
*/
|
||||
delay.tv_sec = 0;
|
||||
delay.tv_usec = CommitDelay;
|
||||
(void) select(0, NULL, NULL, NULL, &delay);
|
||||
XLogFlush(recptr);
|
||||
MyLastRecPtr.xlogid = 0;
|
||||
MyLastRecPtr.xrecoff = 0;
|
||||
|
||||
TransactionIdCommit(xid);
|
||||
|
||||
MyProc->logRec.xrecoff = 0;
|
||||
}
|
||||
#else
|
||||
/*
|
||||
* If no one shared buffer was changed by this transaction then we
|
||||
* don't flush shared buffers and don't record commit status.
|
||||
@@ -687,39 +716,12 @@ RecordTransactionCommit()
|
||||
if (leak)
|
||||
ResetBufferPool(true);
|
||||
|
||||
#endif
|
||||
/*
|
||||
* have the transaction access methods record the status of this
|
||||
* transaction id in the pg_log relation.
|
||||
*/
|
||||
TransactionIdCommit(xid);
|
||||
|
||||
#ifdef XLOG
|
||||
if (MyLastRecPtr.xlogid != 0 || MyLastRecPtr.xrecoff != 0)
|
||||
{
|
||||
xl_xact_commit xlrec;
|
||||
struct timeval delay;
|
||||
XLogRecPtr recptr;
|
||||
|
||||
xlrec.xtime = time(NULL);
|
||||
/*
|
||||
* MUST SAVE ARRAY OF RELFILENODE-s TO DROP
|
||||
*/
|
||||
recptr = XLogInsert(RM_XACT_ID, XLOG_XACT_COMMIT,
|
||||
(char*) &xlrec, SizeOfXactCommit, NULL, 0);
|
||||
|
||||
/*
|
||||
* Sleep before commit! So we can flush more than one
|
||||
* commit records per single fsync.
|
||||
*/
|
||||
delay.tv_sec = 0;
|
||||
delay.tv_usec = CommitDelay;
|
||||
(void) select(0, NULL, NULL, NULL, &delay);
|
||||
XLogFlush(recptr);
|
||||
MyLastRecPtr.xlogid = 0;
|
||||
MyLastRecPtr.xrecoff = 0;
|
||||
}
|
||||
#else
|
||||
/*
|
||||
* Now write the log info to the disk too.
|
||||
*/
|
||||
@@ -1737,12 +1739,12 @@ xact_redo(XLogRecPtr lsn, XLogRecord *record)
|
||||
{
|
||||
xl_xact_commit *xlrec = (xl_xact_commit*) XLogRecGetData(record);
|
||||
|
||||
XLogMarkCommitted(record->xl_xid);
|
||||
TransactionIdCommit(record->xl_xid);
|
||||
/* MUST REMOVE FILES OF ALL DROPPED RELATIONS */
|
||||
}
|
||||
else if (info == XLOG_XACT_ABORT)
|
||||
{
|
||||
XLogMarkAborted(record->xl_xid);
|
||||
TransactionIdAbort(record->xl_xid);
|
||||
}
|
||||
else
|
||||
elog(STOP, "xact_redo: unknown op code %u", info);
|
||||
|
||||
@@ -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.20 2000/10/23 04:10:05 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.21 2000/10/24 09:56:09 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -19,13 +19,14 @@
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "access/xlog.h"
|
||||
#include "access/xact.h"
|
||||
#include "catalog/catversion.h"
|
||||
#include "storage/sinval.h"
|
||||
#include "storage/proc.h"
|
||||
#include "storage/spin.h"
|
||||
#include "storage/s_lock.h"
|
||||
#include "access/xlog.h"
|
||||
#include "access/xlogutils.h"
|
||||
|
||||
#include "miscadmin.h"
|
||||
|
||||
@@ -1343,9 +1344,10 @@ StartupXLOG()
|
||||
elog(STOP, "Invalid length of checkPoint record");
|
||||
checkPoint = *((CheckPoint *) ((char *) record + SizeOfXLogRecord));
|
||||
|
||||
elog(LOG, "Redo record at (%u, %u); Undo record at (%u, %u)",
|
||||
elog(LOG, "Redo record at (%u, %u); Undo record at (%u, %u); Shutdown %s",
|
||||
checkPoint.redo.xlogid, checkPoint.redo.xrecoff,
|
||||
checkPoint.undo.xlogid, checkPoint.undo.xrecoff);
|
||||
checkPoint.undo.xlogid, checkPoint.undo.xrecoff,
|
||||
(checkPoint.Shutdown) ? "TRUE" : "FALSE");
|
||||
elog(LOG, "NextTransactionId: %u; NextOid: %u",
|
||||
checkPoint.nextXid, checkPoint.nextOid);
|
||||
if (checkPoint.nextXid < FirstTransactionId ||
|
||||
@@ -1371,16 +1373,23 @@ StartupXLOG()
|
||||
if (XLByteLT(RecPtr, checkPoint.undo))
|
||||
elog(STOP, "Invalid undo in checkPoint record");
|
||||
|
||||
if (XLByteLT(checkPoint.undo, RecPtr) || XLByteLT(checkPoint.redo, RecPtr))
|
||||
if (XLByteLT(checkPoint.undo, RecPtr) ||
|
||||
XLByteLT(checkPoint.redo, RecPtr))
|
||||
{
|
||||
if (checkPoint.Shutdown)
|
||||
elog(STOP, "Invalid Redo/Undo record in shutdown checkpoint");
|
||||
if (ControlFile->state == DB_SHUTDOWNED)
|
||||
elog(STOP, "Invalid Redo/Undo record in Shutdowned state");
|
||||
recovery = 2;
|
||||
recovery = 1;
|
||||
}
|
||||
else if (ControlFile->state != DB_SHUTDOWNED)
|
||||
recovery = 2;
|
||||
{
|
||||
if (checkPoint.Shutdown)
|
||||
elog(STOP, "Invalid state in control file");
|
||||
recovery = 1;
|
||||
}
|
||||
|
||||
if (recovery > 0)
|
||||
if (recovery)
|
||||
{
|
||||
elog(LOG, "The DataBase system was not properly shut down\n"
|
||||
"\tAutomatic recovery is in progress...");
|
||||
@@ -1391,6 +1400,8 @@ StartupXLOG()
|
||||
sie_saved = StopIfError;
|
||||
StopIfError = true;
|
||||
|
||||
XLogOpenLogRelation(); /* open pg_log */
|
||||
|
||||
/* Is REDO required ? */
|
||||
if (XLByteLT(checkPoint.redo, RecPtr))
|
||||
record = ReadRecord(&(checkPoint.redo), buffer);
|
||||
@@ -1432,11 +1443,9 @@ StartupXLOG()
|
||||
LastRec = ReadRecPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
elog(LOG, "Redo is not required");
|
||||
recovery--;
|
||||
}
|
||||
|
||||
#ifdef NOT_USED
|
||||
/* UNDO */
|
||||
RecPtr = ReadRecPtr;
|
||||
if (XLByteLT(checkPoint.undo, RecPtr))
|
||||
@@ -1455,10 +1464,8 @@ StartupXLOG()
|
||||
ReadRecPtr.xlogid, ReadRecPtr.xrecoff);
|
||||
}
|
||||
else
|
||||
{
|
||||
elog(LOG, "Undo is not required");
|
||||
recovery--;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Init xlog buffer cache */
|
||||
@@ -1476,17 +1483,8 @@ StartupXLOG()
|
||||
(EndRecPtr.xrecoff + BLCKSZ - XLogCtl->xlblocks[0].xrecoff);
|
||||
Insert->PrevRecord = ControlFile->checkPoint;
|
||||
|
||||
if (recovery > 0)
|
||||
if (recovery)
|
||||
{
|
||||
#ifdef NOT_USED
|
||||
int i;
|
||||
|
||||
/*
|
||||
* Let resource managers know that recovery is done
|
||||
*/
|
||||
for (i = 0; i <= RM_MAX_ID; i++)
|
||||
RmgrTable[record->xl_rmid].rm_redo(ReadRecPtr, NULL);
|
||||
#endif
|
||||
CreateCheckPoint(true);
|
||||
StopIfError = sie_saved;
|
||||
}
|
||||
@@ -1586,7 +1584,7 @@ CreateCheckPoint(bool shutdown)
|
||||
|
||||
FlushBufferPool();
|
||||
|
||||
/* Get UNDO record ptr */
|
||||
/* Get UNDO record ptr - should use oldest of PROC->logRec */
|
||||
checkPoint.undo.xrecoff = 0;
|
||||
|
||||
if (shutdown && checkPoint.undo.xrecoff != 0)
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "postgres.h"
|
||||
|
||||
#include "access/xlog.h"
|
||||
#include "access/transam.h"
|
||||
#include "access/xact.h"
|
||||
#include "storage/bufpage.h"
|
||||
#include "storage/bufmgr.h"
|
||||
@@ -134,10 +135,16 @@ XLogIsValidTuple(RelFileNode hnode, ItemPointer iptr)
|
||||
|
||||
/* MUST CHECK WASN'T TUPLE INSERTED IN PREV STARTUP */
|
||||
|
||||
if (XLogIsAborted(htup->t_xmin))
|
||||
if (!(htup->t_infomask & HEAP_XMIN_COMMITTED))
|
||||
{
|
||||
UnlockAndReleaseBuffer(buffer);
|
||||
return(false);
|
||||
if (htup->t_infomask & HEAP_XMIN_INVALID ||
|
||||
(htup->t_infomask & HEAP_MOVED_IN &&
|
||||
TransactionIdDidAbort((TransactionId)htup->t_cmin)) ||
|
||||
TransactionIdDidAbort(htup->t_xmin))
|
||||
{
|
||||
UnlockAndReleaseBuffer(buffer);
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
UnlockAndReleaseBuffer(buffer);
|
||||
@@ -145,40 +152,31 @@ XLogIsValidTuple(RelFileNode hnode, ItemPointer iptr)
|
||||
}
|
||||
|
||||
/*
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* Transaction support functions for recovery
|
||||
*
|
||||
* On recovery we create tmp file to know what xactions were
|
||||
* committed/aborted (2 bits per xaction).
|
||||
*
|
||||
*----------------------------------------------------------------
|
||||
* Open pg_log in recovery
|
||||
*/
|
||||
|
||||
bool
|
||||
XLogIsAborted(TransactionId xid)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
bool
|
||||
XLogIsCommitted(TransactionId xid)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
extern Relation LogRelation; /* pg_log relation */
|
||||
|
||||
void
|
||||
XLogMarkAborted(TransactionId xid)
|
||||
XLogOpenLogRelation(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Relation logRelation;
|
||||
|
||||
void
|
||||
XLogMarkCommitted(TransactionId xid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Assert(!LogRelation);
|
||||
logRelation = (Relation) malloc(sizeof(RelationData));
|
||||
memset(logRelation, 0, sizeof(RelationData));
|
||||
logRelation->rd_rel = (Form_pg_class) malloc(sizeof(FormData_pg_class));
|
||||
memset(logRelation->rd_rel, 0, sizeof(FormData_pg_class));
|
||||
|
||||
sprintf(RelationGetPhysicalRelationName(logRelation), "pg_log");
|
||||
logRelation->rd_node.tblNode = InvalidOid;
|
||||
logRelation->rd_node.relNode = RelOid_pg_log;
|
||||
logRelation->rd_unlinked = false; /* must exists */
|
||||
logRelation->rd_fd = -1;
|
||||
logRelation->rd_fd = smgropen(DEFAULT_SMGR, logRelation);
|
||||
if (logRelation->rd_fd < 0)
|
||||
elog(STOP, "XLogOpenLogRelation: failed to open pg_log");
|
||||
LogRelation = logRelation;
|
||||
}
|
||||
|
||||
/*
|
||||
* ---------------------------------------------------------------
|
||||
@@ -274,7 +272,7 @@ _xl_init_rel_cache(void)
|
||||
_xlrelarr = (XLogRelDesc*) malloc(sizeof(XLogRelDesc) * _xlcnt);
|
||||
memset(_xlrelarr, 0, sizeof(XLogRelDesc) * _xlcnt);
|
||||
_xlpgcarr = (Form_pg_class) malloc(sizeof(FormData_pg_class) * _xlcnt);
|
||||
memset(_xlpgcarr, 0, sizeof(XLogRelDesc) * _xlcnt);
|
||||
memset(_xlpgcarr, 0, sizeof(FormData_pg_class) * _xlcnt);
|
||||
|
||||
_xlrelarr[0].moreRecently = &(_xlrelarr[0]);
|
||||
_xlrelarr[0].lessRecently = &(_xlrelarr[0]);
|
||||
|
||||
Reference in New Issue
Block a user