mirror of
https://github.com/postgres/postgres.git
synced 2025-04-21 12:05:57 +03:00
WAL
This commit is contained in:
parent
2f4c9d39fe
commit
5b0740d3fc
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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
|
* NOTES
|
||||||
* This file contains support functions for the high
|
* This file contains support functions for the high
|
||||||
@ -186,6 +186,10 @@ TransBlockGetXidStatus(Block tblock,
|
|||||||
bits8 bit2;
|
bits8 bit2;
|
||||||
BitIndex offset;
|
BitIndex offset;
|
||||||
|
|
||||||
|
#ifdef XLOG
|
||||||
|
tblock = (Block) ((char*) tblock + sizeof(XLogRecPtr));
|
||||||
|
#endif
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
* calculate the index into the transaction data where
|
* calculate the index into the transaction data where
|
||||||
* our transaction status is located
|
* our transaction status is located
|
||||||
@ -227,6 +231,10 @@ TransBlockSetXidStatus(Block tblock,
|
|||||||
Index index;
|
Index index;
|
||||||
BitIndex offset;
|
BitIndex offset;
|
||||||
|
|
||||||
|
#ifdef XLOG
|
||||||
|
tblock = (Block) ((char*) tblock + sizeof(XLogRecPtr));
|
||||||
|
#endif
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
* calculate the index into the transaction data where
|
* calculate the index into the transaction data where
|
||||||
* we sould store our transaction status.
|
* we sould store our transaction status.
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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));
|
TransactionIdStore(xid, &(var->nextXidData));
|
||||||
|
|
||||||
|
#ifdef XLOG
|
||||||
|
WriteBuffer(buf); /* temp */
|
||||||
|
#else
|
||||||
FlushBuffer(buf, TRUE);
|
FlushBuffer(buf, TRUE);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------
|
/* --------------------------------
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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
|
* NOTES
|
||||||
* Transaction aborts can now occur two ways:
|
* Transaction aborts can now occur two ways:
|
||||||
@ -176,6 +176,8 @@
|
|||||||
|
|
||||||
extern bool SharedBufferChanged;
|
extern bool SharedBufferChanged;
|
||||||
|
|
||||||
|
void RecordTransactionCommit(void);
|
||||||
|
|
||||||
static void AbortTransaction(void);
|
static void AbortTransaction(void);
|
||||||
static void AtAbort_Cache(void);
|
static void AtAbort_Cache(void);
|
||||||
static void AtAbort_Locks(void);
|
static void AtAbort_Locks(void);
|
||||||
@ -191,7 +193,6 @@ static void AtStart_Memory(void);
|
|||||||
static void CleanupTransaction(void);
|
static void CleanupTransaction(void);
|
||||||
static void CommitTransaction(void);
|
static void CommitTransaction(void);
|
||||||
static void RecordTransactionAbort(void);
|
static void RecordTransactionAbort(void);
|
||||||
static void RecordTransactionCommit(void);
|
|
||||||
static void StartTransaction(void);
|
static void StartTransaction(void);
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
@ -220,7 +221,7 @@ int XactIsoLevel;
|
|||||||
#ifdef XLOG
|
#ifdef XLOG
|
||||||
#include "access/xlogutils.h"
|
#include "access/xlogutils.h"
|
||||||
|
|
||||||
int CommitDelay = 100;
|
int CommitDelay = 5; /* 1/200 sec */
|
||||||
|
|
||||||
void xact_redo(XLogRecPtr lsn, XLogRecord *record);
|
void xact_redo(XLogRecPtr lsn, XLogRecord *record);
|
||||||
void xact_undo(XLogRecPtr lsn, XLogRecord *record);
|
void xact_undo(XLogRecPtr lsn, XLogRecord *record);
|
||||||
@ -658,8 +659,8 @@ AtStart_Memory(void)
|
|||||||
* -cim 3/18/90
|
* -cim 3/18/90
|
||||||
* --------------------------------
|
* --------------------------------
|
||||||
*/
|
*/
|
||||||
static void
|
void
|
||||||
RecordTransactionCommit(void)
|
RecordTransactionCommit()
|
||||||
{
|
{
|
||||||
TransactionId xid;
|
TransactionId xid;
|
||||||
int leak;
|
int leak;
|
||||||
@ -683,6 +684,8 @@ RecordTransactionCommit(void)
|
|||||||
struct timeval delay;
|
struct timeval delay;
|
||||||
XLogRecPtr recptr;
|
XLogRecPtr recptr;
|
||||||
|
|
||||||
|
BufmgrCommit();
|
||||||
|
|
||||||
xlrec.xtime = time(NULL);
|
xlrec.xtime = time(NULL);
|
||||||
/*
|
/*
|
||||||
* MUST SAVE ARRAY OF RELFILENODE-s TO DROP
|
* MUST SAVE ARRAY OF RELFILENODE-s TO DROP
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* 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 char readBuf[BLCKSZ];
|
||||||
static XLogRecord *nextRecord = NULL;
|
static XLogRecord *nextRecord = NULL;
|
||||||
|
|
||||||
|
static bool InRedo = false;
|
||||||
|
|
||||||
XLogRecPtr
|
XLogRecPtr
|
||||||
XLogInsert(RmgrId rmid, uint8 info, char *hdr, uint32 hdrlen, char *buf, uint32 buflen)
|
XLogInsert(RmgrId rmid, uint8 info, char *hdr, uint32 hdrlen, char *buf, uint32 buflen)
|
||||||
{
|
{
|
||||||
@ -481,6 +483,19 @@ XLogFlush(XLogRecPtr record)
|
|||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
bool force_lgwr = false;
|
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))
|
if (XLByteLE(record, LgwrResult.Flush))
|
||||||
return;
|
return;
|
||||||
WriteRqst = LgwrRqst.Write;
|
WriteRqst = LgwrRqst.Write;
|
||||||
@ -894,7 +909,7 @@ ReadRecord(XLogRecPtr *RecPtr, char *buffer)
|
|||||||
record = (XLogRecord *) ((char *) readBuf + RecPtr->xrecoff % BLCKSZ);
|
record = (XLogRecord *) ((char *) readBuf + RecPtr->xrecoff % BLCKSZ);
|
||||||
|
|
||||||
got_record:;
|
got_record:;
|
||||||
if (record->xl_len == 0 || record->xl_len >
|
if (record->xl_len >
|
||||||
(BLCKSZ - RecPtr->xrecoff % BLCKSZ - SizeOfXLogRecord))
|
(BLCKSZ - RecPtr->xrecoff % BLCKSZ - SizeOfXLogRecord))
|
||||||
{
|
{
|
||||||
elog(emode, "ReadRecord: invalid record len %u in (%u, %u)",
|
elog(emode, "ReadRecord: invalid record len %u in (%u, %u)",
|
||||||
@ -1259,7 +1274,6 @@ StartupXLOG()
|
|||||||
LastRec;
|
LastRec;
|
||||||
XLogRecord *record;
|
XLogRecord *record;
|
||||||
char buffer[MAXLOGRECSZ + SizeOfXLogRecord];
|
char buffer[MAXLOGRECSZ + SizeOfXLogRecord];
|
||||||
int recovery = 0;
|
|
||||||
bool sie_saved = false;
|
bool sie_saved = false;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -1380,16 +1394,15 @@ StartupXLOG()
|
|||||||
elog(STOP, "Invalid Redo/Undo record in shutdown checkpoint");
|
elog(STOP, "Invalid Redo/Undo record in shutdown checkpoint");
|
||||||
if (ControlFile->state == DB_SHUTDOWNED)
|
if (ControlFile->state == DB_SHUTDOWNED)
|
||||||
elog(STOP, "Invalid Redo/Undo record in Shutdowned state");
|
elog(STOP, "Invalid Redo/Undo record in Shutdowned state");
|
||||||
recovery = 1;
|
InRecovery = true;
|
||||||
}
|
}
|
||||||
else if (ControlFile->state != DB_SHUTDOWNED)
|
else if (ControlFile->state != DB_SHUTDOWNED)
|
||||||
{
|
{
|
||||||
if (checkPoint.Shutdown)
|
InRecovery = true;
|
||||||
elog(STOP, "Invalid state in control file");
|
|
||||||
recovery = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recovery)
|
/* REDO */
|
||||||
|
if (InRecovery)
|
||||||
{
|
{
|
||||||
elog(LOG, "The DataBase system was not properly shut down\n"
|
elog(LOG, "The DataBase system was not properly shut down\n"
|
||||||
"\tAutomatic recovery is in progress...");
|
"\tAutomatic recovery is in progress...");
|
||||||
@ -1401,6 +1414,7 @@ StartupXLOG()
|
|||||||
StopIfError = true;
|
StopIfError = true;
|
||||||
|
|
||||||
XLogOpenLogRelation(); /* open pg_log */
|
XLogOpenLogRelation(); /* open pg_log */
|
||||||
|
XLogInitRelationCache();
|
||||||
|
|
||||||
/* Is REDO required ? */
|
/* Is REDO required ? */
|
||||||
if (XLByteLT(checkPoint.redo, RecPtr))
|
if (XLByteLT(checkPoint.redo, RecPtr))
|
||||||
@ -1409,9 +1423,9 @@ StartupXLOG()
|
|||||||
/* read past CheckPoint record */
|
/* read past CheckPoint record */
|
||||||
record = ReadRecord(NULL, buffer);
|
record = ReadRecord(NULL, buffer);
|
||||||
|
|
||||||
/* REDO */
|
|
||||||
if (record->xl_len != 0)
|
if (record->xl_len != 0)
|
||||||
{
|
{
|
||||||
|
InRedo = true;
|
||||||
elog(LOG, "Redo starts at (%u, %u)",
|
elog(LOG, "Redo starts at (%u, %u)",
|
||||||
ReadRecPtr.xlogid, ReadRecPtr.xrecoff);
|
ReadRecPtr.xlogid, ReadRecPtr.xrecoff);
|
||||||
do
|
do
|
||||||
@ -1441,12 +1455,40 @@ StartupXLOG()
|
|||||||
elog(LOG, "Redo done at (%u, %u)",
|
elog(LOG, "Redo done at (%u, %u)",
|
||||||
ReadRecPtr.xlogid, ReadRecPtr.xrecoff);
|
ReadRecPtr.xlogid, ReadRecPtr.xrecoff);
|
||||||
LastRec = ReadRecPtr;
|
LastRec = ReadRecPtr;
|
||||||
|
InRedo = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
elog(LOG, "Redo is not required");
|
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
|
#ifdef NOT_USED
|
||||||
/* UNDO */
|
/* UNDO */
|
||||||
|
if (InRecovery)
|
||||||
|
{
|
||||||
RecPtr = ReadRecPtr;
|
RecPtr = ReadRecPtr;
|
||||||
if (XLByteLT(checkPoint.undo, RecPtr))
|
if (XLByteLT(checkPoint.undo, RecPtr))
|
||||||
{
|
{
|
||||||
@ -1465,29 +1507,16 @@ StartupXLOG()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
elog(LOG, "Undo is not required");
|
elog(LOG, "Undo is not required");
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Init xlog buffer cache */
|
if (InRecovery)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
CreateCheckPoint(true);
|
CreateCheckPoint(true);
|
||||||
StopIfError = sie_saved;
|
StopIfError = sie_saved;
|
||||||
|
XLogCloseRelationCache();
|
||||||
}
|
}
|
||||||
|
InRecovery = false;
|
||||||
|
|
||||||
#endif /* XLOG */
|
#endif /* XLOG */
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "access/htup.h"
|
#include "access/htup.h"
|
||||||
#include "access/xlogutils.h"
|
#include "access/xlogutils.h"
|
||||||
#include "catalog/pg_database.h"
|
#include "catalog/pg_database.h"
|
||||||
|
#include "lib/hasht.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ---------------------------------------------------------------
|
* ---------------------------------------------------------------
|
||||||
@ -240,32 +241,10 @@ static int _xlcnt = 0;
|
|||||||
#define _XLOG_INITRELCACHESIZE 32
|
#define _XLOG_INITRELCACHESIZE 32
|
||||||
#define _XLOG_MAXRELCACHESIZE 512
|
#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
|
static void
|
||||||
_xl_init_rel_cache(void)
|
_xl_init_rel_cache(void)
|
||||||
{
|
{
|
||||||
HASHCTL ctl;
|
HASHCTL ctl;
|
||||||
|
|
||||||
_xlcnt = _XLOG_INITRELCACHESIZE;
|
_xlcnt = _XLOG_INITRELCACHESIZE;
|
||||||
_xlast = 0;
|
_xlast = 0;
|
||||||
@ -286,6 +265,35 @@ _xl_init_rel_cache(void)
|
|||||||
HASH_ELEM | HASH_FUNCTION);
|
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*
|
static XLogRelDesc*
|
||||||
_xl_new_reldesc(void)
|
_xl_new_reldesc(void)
|
||||||
{
|
{
|
||||||
@ -310,34 +318,43 @@ _xl_new_reldesc(void)
|
|||||||
}
|
}
|
||||||
else /* reuse */
|
else /* reuse */
|
||||||
{
|
{
|
||||||
XLogRelCacheEntry *hentry;
|
XLogRelDesc *res = _xlrelarr[0].moreRecently;
|
||||||
bool found;
|
|
||||||
XLogRelDesc *res = _xlrelarr[0].moreRecently;
|
|
||||||
Form_pg_class tpgc = res->reldata.rd_rel;
|
|
||||||
|
|
||||||
res->lessRecently->moreRecently = res->moreRecently;
|
_xl_remove_hash_entry(&res, 0);
|
||||||
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;
|
|
||||||
|
|
||||||
_xlast--;
|
_xlast--;
|
||||||
return(res);
|
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
|
Relation
|
||||||
XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
|
XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
|
||||||
{
|
{
|
||||||
@ -345,9 +362,6 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
|
|||||||
XLogRelCacheEntry *hentry;
|
XLogRelCacheEntry *hentry;
|
||||||
bool found;
|
bool found;
|
||||||
|
|
||||||
if (!_xlrelarr)
|
|
||||||
_xl_init_rel_cache();
|
|
||||||
|
|
||||||
hentry = (XLogRelCacheEntry*)
|
hentry = (XLogRelCacheEntry*)
|
||||||
hash_search(_xlrelcache, (char*)&rnode, HASH_FIND, &found);
|
hash_search(_xlrelcache, (char*)&rnode, HASH_FIND, &found);
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.62 2000/10/22 17:55:36 pjw Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.63 2000/10/28 16:20:54 vadim Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -193,6 +193,9 @@ createdb(const char *dbname, const char *dbpath, int encoding)
|
|||||||
elog(ERROR, "CREATE DATABASE: Could not initialize database directory. Delete failed as well");
|
elog(ERROR, "CREATE DATABASE: Could not initialize database directory. Delete failed as well");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef XLOG
|
||||||
|
BufferSync();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.170 2000/10/24 09:56:15 vadim Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.171 2000/10/28 16:20:54 vadim Exp $
|
||||||
*
|
*
|
||||||
|
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
@ -1787,7 +1787,9 @@ failed to add item with len = %u to page %u (free space %u, nusd %u, noff %u)",
|
|||||||
|
|
||||||
if (num_moved > 0)
|
if (num_moved > 0)
|
||||||
{
|
{
|
||||||
|
#ifdef XLOG
|
||||||
|
RecordTransactionCommit();
|
||||||
|
#else
|
||||||
/*
|
/*
|
||||||
* We have to commit our tuple' movings before we'll truncate
|
* We have to commit our tuple' movings before we'll truncate
|
||||||
* relation, but we shouldn't lose our locks. And so - quick hack:
|
* relation, but we shouldn't lose our locks. And so - quick hack:
|
||||||
@ -1797,6 +1799,7 @@ failed to add item with len = %u to page %u (free space %u, nusd %u, noff %u)",
|
|||||||
FlushBufferPool();
|
FlushBufferPool();
|
||||||
TransactionIdCommit(myXID);
|
TransactionIdCommit(myXID);
|
||||||
FlushBufferPool();
|
FlushBufferPool();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.91 2000/10/23 04:10:06 vadim Exp $
|
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.92 2000/10/28 16:20:55 vadim Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -42,6 +42,13 @@
|
|||||||
* freelist.c -- chooses victim for buffer replacement
|
* freelist.c -- chooses victim for buffer replacement
|
||||||
* buf_table.c -- manages the buffer lookup table
|
* buf_table.c -- manages the buffer lookup table
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef XLOG
|
||||||
|
|
||||||
|
#include "xlog_bufmgr.c"
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@ -2512,3 +2519,5 @@ MarkBufferForCleanup(Buffer buffer, void (*CleanupFunc)(Buffer))
|
|||||||
SpinRelease(BufMgrLock);
|
SpinRelease(BufMgrLock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* ! XLOG */
|
||||||
|
@ -16,10 +16,17 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.32 2000/10/23 04:10:06 vadim Exp $
|
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.33 2000/10/28 16:20:56 vadim Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef XLOG
|
||||||
|
|
||||||
|
#include "xlog_localbuf.c"
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@ -247,10 +254,11 @@ InitLocalBuffer(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* LocalBufferSync -
|
* LocalBufferSync
|
||||||
* flush all dirty buffers in the local buffer cache. Since the buffer
|
*
|
||||||
* cache is only used for keeping relations visible during a transaction,
|
* Flush all dirty buffers in the local buffer cache at commit time.
|
||||||
* we will not need these buffers again.
|
* Since the buffer cache is only used for keeping relations visible
|
||||||
|
* during a transaction, we will not need these buffers again.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
LocalBufferSync(void)
|
LocalBufferSync(void)
|
||||||
@ -303,3 +311,5 @@ ResetLocalBufferPool(void)
|
|||||||
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
|
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
|
||||||
nextFreeLocalBuf = 0;
|
nextFreeLocalBuf = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* XLOG */
|
||||||
|
2205
src/backend/storage/buffer/xlog_bufmgr.c
Normal file
2205
src/backend/storage/buffer/xlog_bufmgr.c
Normal file
File diff suppressed because it is too large
Load Diff
274
src/backend/storage/buffer/xlog_localbuf.c
Normal file
274
src/backend/storage/buffer/xlog_localbuf.c
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* localbuf.c
|
||||||
|
* local buffer manager. Fast buffer manager for temporary tables
|
||||||
|
* or special cases when the operation is not visible to other backends.
|
||||||
|
*
|
||||||
|
* When a relation is being created, the descriptor will have rd_islocal
|
||||||
|
* set to indicate that the local buffer manager should be used. During
|
||||||
|
* the same transaction the relation is being created, any inserts or
|
||||||
|
* selects from the newly created relation will use the local buffer
|
||||||
|
* pool. rd_islocal is reset at the end of a transaction (commit/abort).
|
||||||
|
* This is useful for queries like SELECT INTO TABLE and create index.
|
||||||
|
*
|
||||||
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||||
|
* Portions Copyright (c) 1994-5, Regents of the University of California
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* IDENTIFICATION
|
||||||
|
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/xlog_localbuf.c,v 1.1 2000/10/28 16:20:56 vadim Exp $
|
||||||
|
*
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/file.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "postgres.h"
|
||||||
|
|
||||||
|
#include "executor/execdebug.h"
|
||||||
|
#include "storage/smgr.h"
|
||||||
|
#include "utils/relcache.h"
|
||||||
|
|
||||||
|
extern long int LocalBufferFlushCount;
|
||||||
|
|
||||||
|
int NLocBuffer = 64;
|
||||||
|
BufferDesc *LocalBufferDescriptors = NULL;
|
||||||
|
long *LocalRefCount = NULL;
|
||||||
|
|
||||||
|
static int nextFreeLocalBuf = 0;
|
||||||
|
|
||||||
|
/*#define LBDEBUG*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* LocalBufferAlloc -
|
||||||
|
* allocate a local buffer. We do round robin allocation for now.
|
||||||
|
*/
|
||||||
|
BufferDesc *
|
||||||
|
LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
BufferDesc *bufHdr = (BufferDesc *) NULL;
|
||||||
|
|
||||||
|
if (blockNum == P_NEW)
|
||||||
|
{
|
||||||
|
blockNum = reln->rd_nblocks;
|
||||||
|
reln->rd_nblocks++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* a low tech search for now -- not optimized for scans */
|
||||||
|
for (i = 0; i < NLocBuffer; i++)
|
||||||
|
{
|
||||||
|
if (LocalBufferDescriptors[i].tag.rnode.relNode ==
|
||||||
|
reln->rd_node.relNode &&
|
||||||
|
LocalBufferDescriptors[i].tag.blockNum == blockNum)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef LBDEBUG
|
||||||
|
fprintf(stderr, "LB ALLOC (%u,%d) %d\n",
|
||||||
|
RelationGetRelid(reln), blockNum, -i - 1);
|
||||||
|
#endif
|
||||||
|
LocalRefCount[i]++;
|
||||||
|
*foundPtr = TRUE;
|
||||||
|
return &LocalBufferDescriptors[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef LBDEBUG
|
||||||
|
fprintf(stderr, "LB ALLOC (%u,%d) %d\n",
|
||||||
|
RelationGetRelid(reln), blockNum, -nextFreeLocalBuf - 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* need to get a new buffer (round robin for now) */
|
||||||
|
for (i = 0; i < NLocBuffer; i++)
|
||||||
|
{
|
||||||
|
int b = (nextFreeLocalBuf + i) % NLocBuffer;
|
||||||
|
|
||||||
|
if (LocalRefCount[b] == 0)
|
||||||
|
{
|
||||||
|
bufHdr = &LocalBufferDescriptors[b];
|
||||||
|
LocalRefCount[b]++;
|
||||||
|
nextFreeLocalBuf = (b + 1) % NLocBuffer;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bufHdr == NULL)
|
||||||
|
elog(ERROR, "no empty local buffer.");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* this buffer is not referenced but it might still be dirty (the last
|
||||||
|
* transaction to touch it doesn't need its contents but has not
|
||||||
|
* flushed it). if that's the case, write it out before reusing it!
|
||||||
|
*/
|
||||||
|
if (bufHdr->flags & BM_DIRTY || bufHdr->cntxDirty)
|
||||||
|
{
|
||||||
|
Relation bufrel = RelationNodeCacheGetRelation(bufHdr->tag.rnode);
|
||||||
|
|
||||||
|
Assert(bufrel != NULL);
|
||||||
|
|
||||||
|
/* flush this page */
|
||||||
|
smgrwrite(DEFAULT_SMGR, bufrel, bufHdr->tag.blockNum,
|
||||||
|
(char *) MAKE_PTR(bufHdr->data));
|
||||||
|
LocalBufferFlushCount++;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* drop relcache refcount incremented by
|
||||||
|
* RelationIdCacheGetRelation
|
||||||
|
*/
|
||||||
|
RelationDecrementReferenceCount(bufrel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it's all ours now.
|
||||||
|
*
|
||||||
|
* We need not in tblNode currently but will in future I think,
|
||||||
|
* when we'll give up rel->rd_fd to fmgr cache.
|
||||||
|
*/
|
||||||
|
bufHdr->tag.rnode = reln->rd_node;
|
||||||
|
bufHdr->tag.blockNum = blockNum;
|
||||||
|
bufHdr->flags &= ~BM_DIRTY;
|
||||||
|
bufHdr->cntxDirty = false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* lazy memory allocation. (see MAKE_PTR for why we need to do
|
||||||
|
* MAKE_OFFSET.)
|
||||||
|
*/
|
||||||
|
if (bufHdr->data == (SHMEM_OFFSET) 0)
|
||||||
|
{
|
||||||
|
char *data = (char *) malloc(BLCKSZ);
|
||||||
|
|
||||||
|
bufHdr->data = MAKE_OFFSET(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
*foundPtr = FALSE;
|
||||||
|
return bufHdr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WriteLocalBuffer -
|
||||||
|
* writes out a local buffer
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
WriteLocalBuffer(Buffer buffer, bool release)
|
||||||
|
{
|
||||||
|
int bufid;
|
||||||
|
|
||||||
|
Assert(BufferIsLocal(buffer));
|
||||||
|
|
||||||
|
#ifdef LBDEBUG
|
||||||
|
fprintf(stderr, "LB WRITE %d\n", buffer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bufid = -(buffer + 1);
|
||||||
|
LocalBufferDescriptors[bufid].flags |= BM_DIRTY;
|
||||||
|
|
||||||
|
if (release)
|
||||||
|
{
|
||||||
|
Assert(LocalRefCount[bufid] > 0);
|
||||||
|
LocalRefCount[bufid]--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* InitLocalBuffer -
|
||||||
|
* init the local buffer cache. Since most queries (esp. multi-user ones)
|
||||||
|
* don't involve local buffers, we delay allocating memory for actual the
|
||||||
|
* buffer until we need it.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
InitLocalBuffer(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* these aren't going away. I'm not gonna use palloc.
|
||||||
|
*/
|
||||||
|
LocalBufferDescriptors =
|
||||||
|
(BufferDesc *) malloc(sizeof(BufferDesc) * NLocBuffer);
|
||||||
|
MemSet(LocalBufferDescriptors, 0, sizeof(BufferDesc) * NLocBuffer);
|
||||||
|
nextFreeLocalBuf = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < NLocBuffer; i++)
|
||||||
|
{
|
||||||
|
BufferDesc *buf = &LocalBufferDescriptors[i];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* negative to indicate local buffer. This is tricky: shared
|
||||||
|
* buffers start with 0. We have to start with -2. (Note that the
|
||||||
|
* routine BufferDescriptorGetBuffer adds 1 to buf_id so our first
|
||||||
|
* buffer id is -1.)
|
||||||
|
*/
|
||||||
|
buf->buf_id = -i - 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalRefCount = (long *) malloc(sizeof(long) * NLocBuffer);
|
||||||
|
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* LocalBufferSync
|
||||||
|
*
|
||||||
|
* Flush all dirty buffers in the local buffer cache at commit time.
|
||||||
|
* Since the buffer cache is only used for keeping relations visible
|
||||||
|
* during a transaction, we will not need these buffers again.
|
||||||
|
*
|
||||||
|
* Note that we have to *flush* local buffers because of them are not
|
||||||
|
* visible to checkpoint makers. But we can skip XLOG flush check.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
LocalBufferSync(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < NLocBuffer; i++)
|
||||||
|
{
|
||||||
|
BufferDesc *buf = &LocalBufferDescriptors[i];
|
||||||
|
Relation bufrel;
|
||||||
|
|
||||||
|
if (buf->flags & BM_DIRTY || buf->cntxDirty)
|
||||||
|
{
|
||||||
|
#ifdef LBDEBUG
|
||||||
|
fprintf(stderr, "LB SYNC %d\n", -i - 1);
|
||||||
|
#endif
|
||||||
|
bufrel = RelationNodeCacheGetRelation(buf->tag.rnode);
|
||||||
|
|
||||||
|
Assert(bufrel != NULL);
|
||||||
|
|
||||||
|
smgrwrite(DEFAULT_SMGR, bufrel, buf->tag.blockNum,
|
||||||
|
(char *) MAKE_PTR(buf->data));
|
||||||
|
smgrmarkdirty(DEFAULT_SMGR, bufrel, buf->tag.blockNum);
|
||||||
|
LocalBufferFlushCount++;
|
||||||
|
|
||||||
|
/* drop relcache refcount from RelationIdCacheGetRelation */
|
||||||
|
RelationDecrementReferenceCount(bufrel);
|
||||||
|
|
||||||
|
buf->flags &= ~BM_DIRTY;
|
||||||
|
buf->cntxDirty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
|
||||||
|
nextFreeLocalBuf = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ResetLocalBufferPool(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < NLocBuffer; i++)
|
||||||
|
{
|
||||||
|
BufferDesc *buf = &LocalBufferDescriptors[i];
|
||||||
|
|
||||||
|
buf->tag.rnode.relNode = InvalidOid;
|
||||||
|
buf->flags &= ~BM_DIRTY;
|
||||||
|
buf->cntxDirty = false;
|
||||||
|
buf->buf_id = -i - 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
|
||||||
|
nextFreeLocalBuf = 0;
|
||||||
|
}
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.64 2000/10/02 19:42:47 petere Exp $
|
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.65 2000/10/28 16:20:56 vadim Exp $
|
||||||
*
|
*
|
||||||
* NOTES:
|
* NOTES:
|
||||||
*
|
*
|
||||||
@ -823,8 +823,10 @@ FileWrite(File file, char *buffer, int amount)
|
|||||||
if (returnCode > 0)
|
if (returnCode > 0)
|
||||||
{
|
{
|
||||||
VfdCache[file].seekPos += returnCode;
|
VfdCache[file].seekPos += returnCode;
|
||||||
|
#ifndef XLOG
|
||||||
/* mark the file as needing fsync */
|
/* mark the file as needing fsync */
|
||||||
VfdCache[file].fdstate |= FD_DIRTY;
|
VfdCache[file].fdstate |= FD_DIRTY;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
VfdCache[file].seekPos = FileUnknownPos;
|
VfdCache[file].seekPos = FileUnknownPos;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.76 2000/10/20 11:01:11 vadim Exp $
|
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.77 2000/10/28 16:20:57 vadim Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -76,12 +76,7 @@ static int _mdfd_getrelnfd(Relation reln);
|
|||||||
static MdfdVec *_mdfd_openseg(Relation reln, int segno, int oflags);
|
static MdfdVec *_mdfd_openseg(Relation reln, int segno, int oflags);
|
||||||
static MdfdVec *_mdfd_getseg(Relation reln, int blkno);
|
static MdfdVec *_mdfd_getseg(Relation reln, int blkno);
|
||||||
|
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
static int _mdfd_blind_getseg(char *dbname, char *relname,
|
|
||||||
Oid dbid, Oid relid, int blkno);
|
|
||||||
#else
|
|
||||||
static int _mdfd_blind_getseg(RelFileNode rnode, int blkno);
|
static int _mdfd_blind_getseg(RelFileNode rnode, int blkno);
|
||||||
#endif
|
|
||||||
|
|
||||||
static int _fdvec_alloc(void);
|
static int _fdvec_alloc(void);
|
||||||
static void _fdvec_free(int);
|
static void _fdvec_free(int);
|
||||||
@ -134,11 +129,7 @@ mdcreate(Relation reln)
|
|||||||
|
|
||||||
Assert(reln->rd_unlinked && reln->rd_fd < 0);
|
Assert(reln->rd_unlinked && reln->rd_fd < 0);
|
||||||
|
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
path = relpath(RelationGetPhysicalRelationName(reln));
|
|
||||||
#else
|
|
||||||
path = relpath(reln->rd_node);
|
path = relpath(reln->rd_node);
|
||||||
#endif
|
|
||||||
fd = FileNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600);
|
fd = FileNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -336,11 +327,7 @@ mdopen(Relation reln)
|
|||||||
int vfd;
|
int vfd;
|
||||||
|
|
||||||
Assert(reln->rd_fd < 0);
|
Assert(reln->rd_fd < 0);
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
path = relpath(RelationGetPhysicalRelationName(reln));
|
|
||||||
#else
|
|
||||||
path = relpath(reln->rd_node);
|
path = relpath(reln->rd_node);
|
||||||
#endif
|
|
||||||
|
|
||||||
fd = FileNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
|
fd = FileNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
@ -579,30 +566,16 @@ mdflush(Relation reln, BlockNumber blocknum, char *buffer)
|
|||||||
* the file, making it more like mdflush().
|
* the file, making it more like mdflush().
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
mdblindwrt(char *dbname,
|
|
||||||
char *relname,
|
|
||||||
Oid dbid,
|
|
||||||
Oid relid,
|
|
||||||
BlockNumber blkno,
|
|
||||||
char *buffer,
|
|
||||||
bool dofsync)
|
|
||||||
#else
|
|
||||||
mdblindwrt(RelFileNode rnode,
|
mdblindwrt(RelFileNode rnode,
|
||||||
BlockNumber blkno,
|
BlockNumber blkno,
|
||||||
char *buffer,
|
char *buffer,
|
||||||
bool dofsync)
|
bool dofsync)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
long seekpos;
|
long seekpos;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
fd = _mdfd_blind_getseg(dbname, relname, dbid, relid, blkno);
|
|
||||||
#else
|
|
||||||
fd = _mdfd_blind_getseg(rnode, blkno);
|
fd = _mdfd_blind_getseg(rnode, blkno);
|
||||||
#endif
|
|
||||||
|
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return SM_FAIL;
|
return SM_FAIL;
|
||||||
@ -676,25 +649,13 @@ mdmarkdirty(Relation reln, BlockNumber blkno)
|
|||||||
* rather than building md/fd datastructures to postpone it till later.
|
* rather than building md/fd datastructures to postpone it till later.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
mdblindmarkdirty(char *dbname,
|
|
||||||
char *relname,
|
|
||||||
Oid dbid,
|
|
||||||
Oid relid,
|
|
||||||
BlockNumber blkno)
|
|
||||||
#else
|
|
||||||
mdblindmarkdirty(RelFileNode rnode,
|
mdblindmarkdirty(RelFileNode rnode,
|
||||||
BlockNumber blkno)
|
BlockNumber blkno)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
fd = _mdfd_blind_getseg(dbname, relname, dbid, relid, blkno);
|
|
||||||
#else
|
|
||||||
fd = _mdfd_blind_getseg(rnode, blkno);
|
fd = _mdfd_blind_getseg(rnode, blkno);
|
||||||
#endif
|
|
||||||
|
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return SM_FAIL;
|
return SM_FAIL;
|
||||||
@ -915,6 +876,22 @@ mdabort()
|
|||||||
return SM_SUCCESS;
|
return SM_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef XLOG
|
||||||
|
/*
|
||||||
|
* mdsync() -- Sync storage.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
mdsync()
|
||||||
|
{
|
||||||
|
sync();
|
||||||
|
if (IsUnderPostmaster)
|
||||||
|
sleep(2);
|
||||||
|
sync();
|
||||||
|
return SM_SUCCESS;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* _fdvec_alloc () -- grab a free (or new) md file descriptor vector.
|
* _fdvec_alloc () -- grab a free (or new) md file descriptor vector.
|
||||||
*
|
*
|
||||||
@ -996,11 +973,7 @@ _mdfd_openseg(Relation reln, int segno, int oflags)
|
|||||||
*fullpath;
|
*fullpath;
|
||||||
|
|
||||||
/* be sure we have enough space for the '.segno', if any */
|
/* be sure we have enough space for the '.segno', if any */
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
path = relpath(RelationGetPhysicalRelationName(reln));
|
|
||||||
#else
|
|
||||||
path = relpath(reln->rd_node);
|
path = relpath(reln->rd_node);
|
||||||
#endif
|
|
||||||
|
|
||||||
if (segno > 0)
|
if (segno > 0)
|
||||||
{
|
{
|
||||||
@ -1115,12 +1088,7 @@ _mdfd_getseg(Relation reln, int blkno)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
_mdfd_blind_getseg(char *dbname, char *relname, Oid dbid, Oid relid,
|
|
||||||
int blkno)
|
|
||||||
#else
|
|
||||||
_mdfd_blind_getseg(RelFileNode rnode, int blkno)
|
_mdfd_blind_getseg(RelFileNode rnode, int blkno)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
int fd;
|
int fd;
|
||||||
@ -1130,12 +1098,7 @@ _mdfd_blind_getseg(RelFileNode rnode, int blkno)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
/* construct the path to the relation */
|
|
||||||
path = relpath_blind(dbname, relname, dbid, relid);
|
|
||||||
#else
|
|
||||||
path = relpath(rnode);
|
path = relpath(rnode);
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef LET_OS_MANAGE_FILESIZE
|
#ifndef LET_OS_MANAGE_FILESIZE
|
||||||
/* append the '.segno', if needed */
|
/* append the '.segno', if needed */
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/smgr.c,v 1.41 2000/10/21 15:43:31 vadim Exp $
|
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/smgr.c,v 1.42 2000/10/28 16:20:57 vadim Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -36,27 +36,17 @@ typedef struct f_smgr
|
|||||||
char *buffer);
|
char *buffer);
|
||||||
int (*smgr_flush) (Relation reln, BlockNumber blocknum,
|
int (*smgr_flush) (Relation reln, BlockNumber blocknum,
|
||||||
char *buffer);
|
char *buffer);
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
int (*smgr_blindwrt) (char *dbname, char *relname,
|
|
||||||
Oid dbid, Oid relid,
|
|
||||||
BlockNumber blkno, char *buffer,
|
|
||||||
bool dofsync);
|
|
||||||
#else
|
|
||||||
int (*smgr_blindwrt) (RelFileNode rnode, BlockNumber blkno,
|
int (*smgr_blindwrt) (RelFileNode rnode, BlockNumber blkno,
|
||||||
char *buffer, bool dofsync);
|
char *buffer, bool dofsync);
|
||||||
#endif
|
|
||||||
int (*smgr_markdirty) (Relation reln, BlockNumber blkno);
|
int (*smgr_markdirty) (Relation reln, BlockNumber blkno);
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
int (*smgr_blindmarkdirty) (char *dbname, char *relname,
|
|
||||||
Oid dbid, Oid relid,
|
|
||||||
BlockNumber blkno);
|
|
||||||
#else
|
|
||||||
int (*smgr_blindmarkdirty) (RelFileNode, BlockNumber blkno);
|
int (*smgr_blindmarkdirty) (RelFileNode, BlockNumber blkno);
|
||||||
#endif
|
|
||||||
int (*smgr_nblocks) (Relation reln);
|
int (*smgr_nblocks) (Relation reln);
|
||||||
int (*smgr_truncate) (Relation reln, int nblocks);
|
int (*smgr_truncate) (Relation reln, int nblocks);
|
||||||
int (*smgr_commit) (void); /* may be NULL */
|
int (*smgr_commit) (void); /* may be NULL */
|
||||||
int (*smgr_abort) (void); /* may be NULL */
|
int (*smgr_abort) (void); /* may be NULL */
|
||||||
|
#ifdef XLOG
|
||||||
|
int (*smgr_sync) (void);
|
||||||
|
#endif
|
||||||
} f_smgr;
|
} f_smgr;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -69,7 +59,11 @@ static f_smgr smgrsw[] = {
|
|||||||
/* magnetic disk */
|
/* magnetic disk */
|
||||||
{mdinit, NULL, mdcreate, mdunlink, mdextend, mdopen, mdclose,
|
{mdinit, NULL, mdcreate, mdunlink, mdextend, mdopen, mdclose,
|
||||||
mdread, mdwrite, mdflush, mdblindwrt, mdmarkdirty, mdblindmarkdirty,
|
mdread, mdwrite, mdflush, mdblindwrt, mdmarkdirty, mdblindmarkdirty,
|
||||||
|
#ifdef XLOG
|
||||||
|
mdnblocks, mdtruncate, mdcommit, mdabort, mdsync},
|
||||||
|
#else
|
||||||
mdnblocks, mdtruncate, mdcommit, mdabort},
|
mdnblocks, mdtruncate, mdcommit, mdabort},
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef STABLE_MEMORY_STORAGE
|
#ifdef STABLE_MEMORY_STORAGE
|
||||||
/* main memory */
|
/* main memory */
|
||||||
@ -310,40 +304,6 @@ smgrflush(int16 which, Relation reln, BlockNumber blocknum, char *buffer)
|
|||||||
* this page down to stable storage in this circumstance. The
|
* this page down to stable storage in this circumstance. The
|
||||||
* write should be synchronous if dofsync is true.
|
* write should be synchronous if dofsync is true.
|
||||||
*/
|
*/
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
int
|
|
||||||
smgrblindwrt(int16 which,
|
|
||||||
char *dbname,
|
|
||||||
char *relname,
|
|
||||||
Oid dbid,
|
|
||||||
Oid relid,
|
|
||||||
BlockNumber blkno,
|
|
||||||
char *buffer,
|
|
||||||
bool dofsync)
|
|
||||||
{
|
|
||||||
char *dbstr;
|
|
||||||
char *relstr;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/* strdup here is probably redundant */
|
|
||||||
dbstr = pstrdup(dbname);
|
|
||||||
relstr = pstrdup(relname);
|
|
||||||
|
|
||||||
status = (*(smgrsw[which].smgr_blindwrt)) (dbstr, relstr, dbid, relid,
|
|
||||||
blkno, buffer, dofsync);
|
|
||||||
|
|
||||||
if (status == SM_FAIL)
|
|
||||||
elog(ERROR, "cannot write block %d of %s [%s] blind: %m",
|
|
||||||
blkno, relstr, dbstr);
|
|
||||||
|
|
||||||
pfree(dbstr);
|
|
||||||
pfree(relstr);
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
int
|
int
|
||||||
smgrblindwrt(int16 which,
|
smgrblindwrt(int16 which,
|
||||||
RelFileNode rnode,
|
RelFileNode rnode,
|
||||||
@ -361,7 +321,6 @@ smgrblindwrt(int16 which,
|
|||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* smgrmarkdirty() -- Mark a page dirty (needs fsync).
|
* smgrmarkdirty() -- Mark a page dirty (needs fsync).
|
||||||
@ -394,39 +353,6 @@ smgrmarkdirty(int16 which,
|
|||||||
*
|
*
|
||||||
* Just like smgrmarkdirty, except we don't have a reldesc.
|
* Just like smgrmarkdirty, except we don't have a reldesc.
|
||||||
*/
|
*/
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
int
|
|
||||||
smgrblindmarkdirty(int16 which,
|
|
||||||
char *dbname,
|
|
||||||
char *relname,
|
|
||||||
Oid dbid,
|
|
||||||
Oid relid,
|
|
||||||
BlockNumber blkno)
|
|
||||||
{
|
|
||||||
char *dbstr;
|
|
||||||
char *relstr;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/* strdup here is probably redundant */
|
|
||||||
dbstr = pstrdup(dbname);
|
|
||||||
relstr = pstrdup(relname);
|
|
||||||
|
|
||||||
status = (*(smgrsw[which].smgr_blindmarkdirty)) (dbstr, relstr,
|
|
||||||
dbid, relid,
|
|
||||||
blkno);
|
|
||||||
|
|
||||||
if (status == SM_FAIL)
|
|
||||||
elog(ERROR, "cannot mark block %d of %s [%s] blind: %m",
|
|
||||||
blkno, relstr, dbstr);
|
|
||||||
|
|
||||||
pfree(dbstr);
|
|
||||||
pfree(relstr);
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
int
|
int
|
||||||
smgrblindmarkdirty(int16 which,
|
smgrblindmarkdirty(int16 which,
|
||||||
RelFileNode rnode,
|
RelFileNode rnode,
|
||||||
@ -442,7 +368,6 @@ smgrblindmarkdirty(int16 which,
|
|||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* smgrnblocks() -- Calculate the number of POSTGRES blocks in the
|
* smgrnblocks() -- Calculate the number of POSTGRES blocks in the
|
||||||
@ -528,6 +453,27 @@ smgrabort()
|
|||||||
return SM_SUCCESS;
|
return SM_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef XLOG
|
||||||
|
int
|
||||||
|
smgrsync()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < NSmgr; i++)
|
||||||
|
{
|
||||||
|
if (smgrsw[i].smgr_sync)
|
||||||
|
{
|
||||||
|
if ((*(smgrsw[i].smgr_sync)) () == SM_FAIL)
|
||||||
|
elog(STOP, "storage sync failed on %s: %m",
|
||||||
|
DatumGetCString(DirectFunctionCall1(smgrout,
|
||||||
|
Int16GetDatum(i))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SM_SUCCESS;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef NOT_USED
|
#ifdef NOT_USED
|
||||||
bool
|
bool
|
||||||
smgriswo(int16 smgrno)
|
smgriswo(int16 smgrno)
|
||||||
|
57
src/backend/utils/cache/relcache.c
vendored
57
src/backend/utils/cache/relcache.c
vendored
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.113 2000/10/23 04:10:08 vadim Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.114 2000/10/28 16:20:57 vadim Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -2064,7 +2064,62 @@ RelationCacheInitializePhase2(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef XLOG /* used by XLogInitCache */
|
||||||
|
|
||||||
|
void CreateDummyCaches(void);
|
||||||
|
void DestroyDummyCaches(void);
|
||||||
|
|
||||||
|
void
|
||||||
|
CreateDummyCaches(void)
|
||||||
|
{
|
||||||
|
MemoryContext oldcxt;
|
||||||
|
HASHCTL ctl;
|
||||||
|
|
||||||
|
if (!CacheMemoryContext)
|
||||||
|
CreateCacheMemoryContext();
|
||||||
|
|
||||||
|
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
|
||||||
|
|
||||||
|
MemSet(&ctl, 0, (int) sizeof(ctl));
|
||||||
|
ctl.keysize = sizeof(NameData);
|
||||||
|
ctl.datasize = sizeof(Relation);
|
||||||
|
RelationNameCache = hash_create(INITRELCACHESIZE, &ctl, HASH_ELEM);
|
||||||
|
|
||||||
|
ctl.keysize = sizeof(Oid);
|
||||||
|
ctl.hash = tag_hash;
|
||||||
|
RelationIdCache = hash_create(INITRELCACHESIZE, &ctl,
|
||||||
|
HASH_ELEM | HASH_FUNCTION);
|
||||||
|
|
||||||
|
ctl.keysize = sizeof(RelFileNode);
|
||||||
|
ctl.hash = tag_hash;
|
||||||
|
RelationNodeCache = hash_create(INITRELCACHESIZE, &ctl,
|
||||||
|
HASH_ELEM | HASH_FUNCTION);
|
||||||
|
MemoryContextSwitchTo(oldcxt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DestroyDummyCaches(void)
|
||||||
|
{
|
||||||
|
MemoryContext oldcxt;
|
||||||
|
|
||||||
|
if (!CacheMemoryContext)
|
||||||
|
return;
|
||||||
|
|
||||||
|
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
|
||||||
|
|
||||||
|
if (RelationNameCache)
|
||||||
|
hash_destroy(RelationNameCache);
|
||||||
|
if (RelationIdCache)
|
||||||
|
hash_destroy(RelationIdCache);
|
||||||
|
if (RelationNodeCache)
|
||||||
|
hash_destroy(RelationNodeCache);
|
||||||
|
|
||||||
|
RelationNameCache = RelationIdCache = RelationNodeCache = NULL;
|
||||||
|
|
||||||
|
MemoryContextSwitchTo(oldcxt);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* XLOG */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
AttrDefaultFetch(Relation relation)
|
AttrDefaultFetch(Relation relation)
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.68 2000/10/16 14:52:15 vadim Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.69 2000/10/28 16:20:58 vadim Exp $
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
@ -231,9 +231,6 @@ InitPostgres(const char *dbname, const char *username)
|
|||||||
{
|
{
|
||||||
bool bootstrap = IsBootstrapProcessingMode();
|
bool bootstrap = IsBootstrapProcessingMode();
|
||||||
|
|
||||||
/* initialize the local buffer manager */
|
|
||||||
InitLocalBuffer();
|
|
||||||
|
|
||||||
#ifndef XLOG
|
#ifndef XLOG
|
||||||
if (!TransactionFlushEnabled())
|
if (!TransactionFlushEnabled())
|
||||||
on_shmem_exit(FlushBufferPool, 0);
|
on_shmem_exit(FlushBufferPool, 0);
|
||||||
@ -414,4 +411,8 @@ BaseInit(void)
|
|||||||
smgrinit();
|
smgrinit();
|
||||||
|
|
||||||
EnablePortalManager(); /* memory for portal/transaction stuff */
|
EnablePortalManager(); /* memory for portal/transaction stuff */
|
||||||
|
|
||||||
|
/* initialize the local buffer manager */
|
||||||
|
InitLocalBuffer();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: transam.h,v 1.24 2000/01/26 05:57:51 momjian Exp $
|
* $Id: transam.h,v 1.25 2000/10/28 16:20:59 vadim Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* Transaction System Version 101 now support proper oid
|
* Transaction System Version 101 now support proper oid
|
||||||
@ -67,7 +67,11 @@ typedef unsigned char XidStatus;/* (2 bits) */
|
|||||||
* transaction page definitions
|
* transaction page definitions
|
||||||
* ----------------
|
* ----------------
|
||||||
*/
|
*/
|
||||||
|
#ifdef XLOG
|
||||||
|
#define TP_DataSize (BLCKSZ - sizeof(XLogRecPtr))
|
||||||
|
#else
|
||||||
#define TP_DataSize BLCKSZ
|
#define TP_DataSize BLCKSZ
|
||||||
|
#endif
|
||||||
#define TP_NumXidStatusPerBlock (TP_DataSize * 4)
|
#define TP_NumXidStatusPerBlock (TP_DataSize * 4)
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
@ -84,6 +88,10 @@ typedef unsigned char XidStatus;/* (2 bits) */
|
|||||||
*/
|
*/
|
||||||
typedef struct LogRelationContentsData
|
typedef struct LogRelationContentsData
|
||||||
{
|
{
|
||||||
|
#ifdef XLOG
|
||||||
|
XLogRecPtr LSN; /* temp hack: LSN is member of any block */
|
||||||
|
/* so should be described in bufmgr */
|
||||||
|
#endif
|
||||||
int TransSystemVersion;
|
int TransSystemVersion;
|
||||||
} LogRelationContentsData;
|
} LogRelationContentsData;
|
||||||
|
|
||||||
@ -107,6 +115,9 @@ typedef LogRelationContentsData *LogRelationContents;
|
|||||||
*/
|
*/
|
||||||
typedef struct VariableRelationContentsData
|
typedef struct VariableRelationContentsData
|
||||||
{
|
{
|
||||||
|
#ifdef XLOG
|
||||||
|
XLogRecPtr LSN;
|
||||||
|
#endif
|
||||||
int TransSystemVersion;
|
int TransSystemVersion;
|
||||||
TransactionId nextXidData;
|
TransactionId nextXidData;
|
||||||
TransactionId lastXidData; /* unused */
|
TransactionId lastXidData; /* unused */
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: xact.h,v 1.28 2000/10/20 11:01:14 vadim Exp $
|
* $Id: xact.h,v 1.29 2000/10/28 16:20:59 vadim Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -135,6 +135,8 @@ extern bool IsTransactionBlock(void);
|
|||||||
extern void UserAbortTransactionBlock(void);
|
extern void UserAbortTransactionBlock(void);
|
||||||
extern void AbortOutOfAnyTransaction(void);
|
extern void AbortOutOfAnyTransaction(void);
|
||||||
|
|
||||||
|
extern void RecordTransactionCommit(void);
|
||||||
|
|
||||||
extern TransactionId DisabledTransactionId;
|
extern TransactionId DisabledTransactionId;
|
||||||
|
|
||||||
extern void XactPushRollback(void (*func) (void *), void* data);
|
extern void XactPushRollback(void (*func) (void *), void* data);
|
||||||
|
@ -10,12 +10,7 @@
|
|||||||
|
|
||||||
#include "access/rmgr.h"
|
#include "access/rmgr.h"
|
||||||
#include "access/transam.h"
|
#include "access/transam.h"
|
||||||
|
#include "access/xlogdefs.h"
|
||||||
typedef struct XLogRecPtr
|
|
||||||
{
|
|
||||||
uint32 xlogid; /* log file #, 0 based */
|
|
||||||
uint32 xrecoff; /* offset of record in log file */
|
|
||||||
} XLogRecPtr;
|
|
||||||
|
|
||||||
typedef struct XLogRecord
|
typedef struct XLogRecord
|
||||||
{
|
{
|
||||||
@ -83,12 +78,7 @@ typedef XLogPageHeaderData *XLogPageHeader;
|
|||||||
#define XLByteEQ(left, right) \
|
#define XLByteEQ(left, right) \
|
||||||
(right.xlogid == left.xlogid && right.xrecoff == left.xrecoff)
|
(right.xlogid == left.xlogid && right.xrecoff == left.xrecoff)
|
||||||
|
|
||||||
/*
|
extern StartUpID ThisStartUpID; /* current SUI */
|
||||||
* StartUpID (SUI) - system startups counter.
|
|
||||||
* It's to allow removing pg_log after shutdown.
|
|
||||||
*/
|
|
||||||
typedef uint32 StartUpID;
|
|
||||||
extern StartUpID ThisStartUpID;
|
|
||||||
extern bool InRecovery;
|
extern bool InRecovery;
|
||||||
extern XLogRecPtr MyLastRecPtr;
|
extern XLogRecPtr MyLastRecPtr;
|
||||||
|
|
||||||
|
24
src/include/access/xlogdefs.h
Normal file
24
src/include/access/xlogdefs.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* xlogdefs.h
|
||||||
|
*
|
||||||
|
* Postgres transaction log manager record pointer and
|
||||||
|
* system stratup number definitions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef XLOG_DEFS_H
|
||||||
|
#define XLOG_DEFS_H
|
||||||
|
|
||||||
|
typedef struct XLogRecPtr
|
||||||
|
{
|
||||||
|
uint32 xlogid; /* log file #, 0 based */
|
||||||
|
uint32 xrecoff; /* offset of record in log file */
|
||||||
|
} XLogRecPtr;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* StartUpID (SUI) - system startups counter. It's to allow removing
|
||||||
|
* pg_log after shutdown, in future.
|
||||||
|
*/
|
||||||
|
typedef uint32 StartUpID;
|
||||||
|
|
||||||
|
#endif /* XLOG_DEFS_H */
|
@ -9,8 +9,10 @@ extern bool XLogIsValidTuple(RelFileNode hnode, ItemPointer iptr);
|
|||||||
|
|
||||||
extern void XLogOpenLogRelation(void);
|
extern void XLogOpenLogRelation(void);
|
||||||
|
|
||||||
extern Buffer XLogReadBuffer(bool extend, Relation reln, BlockNumber blkno);
|
extern void XLogInitRelationCache(void);
|
||||||
extern void XLogCloseRelationCache(void);
|
extern void XLogCloseRelationCache(void);
|
||||||
|
|
||||||
extern Relation XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode);
|
extern Relation XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode);
|
||||||
|
extern Buffer XLogReadBuffer(bool extend, Relation reln, BlockNumber blkno);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: buf_internals.h,v 1.41 2000/10/23 04:10:14 vadim Exp $
|
* $Id: buf_internals.h,v 1.42 2000/10/28 16:21:00 vadim Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -109,6 +109,10 @@ typedef struct sbufdesc
|
|||||||
bool ri_lock; /* read-intent lock */
|
bool ri_lock; /* read-intent lock */
|
||||||
bool w_lock; /* context exclusively locked */
|
bool w_lock; /* context exclusively locked */
|
||||||
|
|
||||||
|
#ifdef XLOG
|
||||||
|
bool cntxDirty; /* new way to mark block as dirty */
|
||||||
|
#endif
|
||||||
|
|
||||||
BufferBlindId blind; /* was used to support blind write */
|
BufferBlindId blind; /* was used to support blind write */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: bufmgr.h,v 1.41 2000/10/20 11:01:21 vadim Exp $
|
* $Id: bufmgr.h,v 1.42 2000/10/28 16:21:00 vadim Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -15,7 +15,7 @@
|
|||||||
#define BUFMGR_H
|
#define BUFMGR_H
|
||||||
|
|
||||||
#include "storage/buf_internals.h"
|
#include "storage/buf_internals.h"
|
||||||
|
#include "access/xlogdefs.h"
|
||||||
|
|
||||||
typedef void *Block;
|
typedef void *Block;
|
||||||
|
|
||||||
@ -177,4 +177,9 @@ extern void AbortBufferIO(void);
|
|||||||
extern bool BufferIsUpdatable(Buffer buffer);
|
extern bool BufferIsUpdatable(Buffer buffer);
|
||||||
extern void MarkBufferForCleanup(Buffer buffer, void (*CleanupFunc)(Buffer));
|
extern void MarkBufferForCleanup(Buffer buffer, void (*CleanupFunc)(Buffer));
|
||||||
|
|
||||||
|
#ifdef XLOG
|
||||||
|
extern void BufmgrCommit(void);
|
||||||
|
extern void BufferSync(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: bufpage.h,v 1.34 2000/10/21 15:43:36 vadim Exp $
|
* $Id: bufpage.h,v 1.35 2000/10/28 16:21:00 vadim Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -118,7 +118,8 @@ typedef OpaqueData *Opaque;
|
|||||||
*/
|
*/
|
||||||
typedef struct PageHeaderData
|
typedef struct PageHeaderData
|
||||||
{
|
{
|
||||||
#ifdef XLOG
|
#ifdef XLOG /* XXX LSN is member of *any* block, not */
|
||||||
|
/* only page-organized - 'll change later */
|
||||||
XLogRecPtr pd_lsn; /* LSN: next byte after last byte of xlog */
|
XLogRecPtr pd_lsn; /* LSN: next byte after last byte of xlog */
|
||||||
/* record for last change of this page */
|
/* record for last change of this page */
|
||||||
StartUpID pd_sui; /* SUI of last changes (currently it's */
|
StartUpID pd_sui; /* SUI of last changes (currently it's */
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: smgr.h,v 1.22 2000/10/16 14:52:28 vadim Exp $
|
* $Id: smgr.h,v 1.23 2000/10/28 16:21:00 vadim Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -36,26 +36,19 @@ extern int smgrwrite(int16 which, Relation reln, BlockNumber blocknum,
|
|||||||
char *buffer);
|
char *buffer);
|
||||||
extern int smgrflush(int16 which, Relation reln, BlockNumber blocknum,
|
extern int smgrflush(int16 which, Relation reln, BlockNumber blocknum,
|
||||||
char *buffer);
|
char *buffer);
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
extern int smgrblindwrt(int16 which, char *dbname, char *relname,
|
|
||||||
Oid dbid, Oid relid,
|
|
||||||
BlockNumber blkno, char *buffer,
|
|
||||||
bool dofsync);
|
|
||||||
extern int smgrblindmarkdirty(int16 which, char *dbname, char *relname,
|
|
||||||
Oid dbid, Oid relid,
|
|
||||||
BlockNumber blkno);
|
|
||||||
#else
|
|
||||||
extern int smgrblindwrt(int16 which, RelFileNode rnode,
|
extern int smgrblindwrt(int16 which, RelFileNode rnode,
|
||||||
BlockNumber blkno, char *buffer, bool dofsync);
|
BlockNumber blkno, char *buffer, bool dofsync);
|
||||||
extern int smgrblindmarkdirty(int16 which, RelFileNode rnode,
|
extern int smgrblindmarkdirty(int16 which, RelFileNode rnode,
|
||||||
BlockNumber blkno);
|
BlockNumber blkno);
|
||||||
#endif
|
|
||||||
extern int smgrmarkdirty(int16 which, Relation reln, BlockNumber blkno);
|
extern int smgrmarkdirty(int16 which, Relation reln, BlockNumber blkno);
|
||||||
extern int smgrnblocks(int16 which, Relation reln);
|
extern int smgrnblocks(int16 which, Relation reln);
|
||||||
extern int smgrtruncate(int16 which, Relation reln, int nblocks);
|
extern int smgrtruncate(int16 which, Relation reln, int nblocks);
|
||||||
extern int smgrcommit(void);
|
extern int smgrcommit(void);
|
||||||
extern int smgrabort(void);
|
extern int smgrabort(void);
|
||||||
|
|
||||||
|
#ifdef XLOG
|
||||||
|
extern int smgrsync(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* internals: move me elsewhere -- ay 7/94 */
|
/* internals: move me elsewhere -- ay 7/94 */
|
||||||
@ -71,22 +64,18 @@ extern int mdread(Relation reln, BlockNumber blocknum, char *buffer);
|
|||||||
extern int mdwrite(Relation reln, BlockNumber blocknum, char *buffer);
|
extern int mdwrite(Relation reln, BlockNumber blocknum, char *buffer);
|
||||||
extern int mdflush(Relation reln, BlockNumber blocknum, char *buffer);
|
extern int mdflush(Relation reln, BlockNumber blocknum, char *buffer);
|
||||||
extern int mdmarkdirty(Relation reln, BlockNumber blkno);
|
extern int mdmarkdirty(Relation reln, BlockNumber blkno);
|
||||||
#ifdef OLD_FILE_NAMING
|
|
||||||
extern int mdblindwrt(char *dbname, char *relname, Oid dbid, Oid relid,
|
|
||||||
BlockNumber blkno, char *buffer,
|
|
||||||
bool dofsync);
|
|
||||||
extern int mdblindmarkdirty(char *dbname, char *relname, Oid dbid, Oid relid,
|
|
||||||
BlockNumber blkno);
|
|
||||||
#else
|
|
||||||
extern int mdblindwrt(RelFileNode rnode, BlockNumber blkno,
|
extern int mdblindwrt(RelFileNode rnode, BlockNumber blkno,
|
||||||
char *buffer, bool dofsync);
|
char *buffer, bool dofsync);
|
||||||
extern int mdblindmarkdirty(RelFileNode rnode, BlockNumber blkno);
|
extern int mdblindmarkdirty(RelFileNode rnode, BlockNumber blkno);
|
||||||
#endif
|
|
||||||
extern int mdnblocks(Relation reln);
|
extern int mdnblocks(Relation reln);
|
||||||
extern int mdtruncate(Relation reln, int nblocks);
|
extern int mdtruncate(Relation reln, int nblocks);
|
||||||
extern int mdcommit(void);
|
extern int mdcommit(void);
|
||||||
extern int mdabort(void);
|
extern int mdabort(void);
|
||||||
|
|
||||||
|
#ifdef XLOG
|
||||||
|
extern int mdsync(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* mm.c */
|
/* mm.c */
|
||||||
extern SPINLOCK MMCacheLock;
|
extern SPINLOCK MMCacheLock;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user