mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Make btree index structure adjustments and WAL logging changes needed to
support btree compaction, as per proposal of a few days ago. btree index pages no longer store parent links, instead they have a level indicator (counting up from zero for leaf pages). The FixBTree recovery logic is removed, and replaced by code that detects missing parent-level insertions during WAL replay. Also, generate appropriate WAL entries when updating btree metapage and when building a btree index from scratch. I believe btree indexes are now completely WAL-legal for the first time. initdb forced due to index and WAL changes.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* Resource managers definition
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/rmgr.c,v 1.9 2001/08/25 18:52:41 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/rmgr.c,v 1.10 2003/02/21 00:06:22 tgl Exp $
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
@@ -19,21 +19,22 @@
|
||||
#include "commands/sequence.h"
|
||||
|
||||
|
||||
RmgrData RmgrTable[] = {
|
||||
{"XLOG", xlog_redo, xlog_undo, xlog_desc},
|
||||
{"Transaction", xact_redo, xact_undo, xact_desc},
|
||||
{"Storage", smgr_redo, smgr_undo, smgr_desc},
|
||||
{"CLOG", clog_redo, clog_undo, clog_desc},
|
||||
{"Reserved 4", NULL, NULL, NULL},
|
||||
{"Reserved 5", NULL, NULL, NULL},
|
||||
{"Reserved 6", NULL, NULL, NULL},
|
||||
{"Reserved 7", NULL, NULL, NULL},
|
||||
{"Reserved 8", NULL, NULL, NULL},
|
||||
{"Reserved 9", NULL, NULL, NULL},
|
||||
{"Heap", heap_redo, heap_undo, heap_desc},
|
||||
{"Btree", btree_redo, btree_undo, btree_desc},
|
||||
{"Hash", hash_redo, hash_undo, hash_desc},
|
||||
{"Rtree", rtree_redo, rtree_undo, rtree_desc},
|
||||
{"Gist", gist_redo, gist_undo, gist_desc},
|
||||
{"Sequence", seq_redo, seq_undo, seq_desc}
|
||||
RmgrData RmgrTable[RM_MAX_ID+1] = {
|
||||
{"XLOG", xlog_redo, xlog_undo, xlog_desc, NULL, NULL},
|
||||
{"Transaction", xact_redo, xact_undo, xact_desc, NULL, NULL},
|
||||
{"Storage", smgr_redo, smgr_undo, smgr_desc, NULL, NULL},
|
||||
{"CLOG", clog_redo, clog_undo, clog_desc, NULL, NULL},
|
||||
{"Reserved 4", NULL, NULL, NULL, NULL, NULL},
|
||||
{"Reserved 5", NULL, NULL, NULL, NULL, NULL},
|
||||
{"Reserved 6", NULL, NULL, NULL, NULL, NULL},
|
||||
{"Reserved 7", NULL, NULL, NULL, NULL, NULL},
|
||||
{"Reserved 8", NULL, NULL, NULL, NULL, NULL},
|
||||
{"Reserved 9", NULL, NULL, NULL, NULL, NULL},
|
||||
{"Heap", heap_redo, heap_undo, heap_desc, NULL, NULL},
|
||||
{"Btree", btree_redo, btree_undo, btree_desc,
|
||||
btree_xlog_startup, btree_xlog_cleanup},
|
||||
{"Hash", hash_redo, hash_undo, hash_desc, NULL, NULL},
|
||||
{"Rtree", rtree_redo, rtree_undo, rtree_desc, NULL, NULL},
|
||||
{"Gist", gist_redo, gist_undo, gist_desc, NULL, NULL},
|
||||
{"Sequence", seq_redo, seq_undo, seq_desc, NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.111 2003/01/25 03:06:04 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.112 2003/02/21 00:06:22 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1203,16 +1203,6 @@ XLogFlush(XLogRecPtr record)
|
||||
XLogRecPtr WriteRqstPtr;
|
||||
XLogwrtRqst WriteRqst;
|
||||
|
||||
if (XLOG_DEBUG)
|
||||
{
|
||||
elog(LOG, "XLogFlush%s%s: request %X/%X; write %X/%X; flush %X/%X",
|
||||
(IsBootstrapProcessingMode()) ? "(bootstrap)" : "",
|
||||
(InRedo) ? "(redo)" : "",
|
||||
record.xlogid, record.xrecoff,
|
||||
LogwrtResult.Write.xlogid, LogwrtResult.Write.xrecoff,
|
||||
LogwrtResult.Flush.xlogid, LogwrtResult.Flush.xrecoff);
|
||||
}
|
||||
|
||||
/* Disabled during REDO */
|
||||
if (InRedo)
|
||||
return;
|
||||
@@ -1221,6 +1211,15 @@ XLogFlush(XLogRecPtr record)
|
||||
if (XLByteLE(record, LogwrtResult.Flush))
|
||||
return;
|
||||
|
||||
if (XLOG_DEBUG)
|
||||
{
|
||||
elog(LOG, "XLogFlush%s: request %X/%X; write %X/%X; flush %X/%X",
|
||||
(IsBootstrapProcessingMode()) ? "(bootstrap)" : "",
|
||||
record.xlogid, record.xrecoff,
|
||||
LogwrtResult.Write.xlogid, LogwrtResult.Write.xrecoff,
|
||||
LogwrtResult.Flush.xlogid, LogwrtResult.Flush.xrecoff);
|
||||
}
|
||||
|
||||
START_CRIT_SECTION();
|
||||
|
||||
/*
|
||||
@@ -2515,6 +2514,12 @@ StartupXLOG(void)
|
||||
elog(LOG, "database system was interrupted at %s",
|
||||
str_time(ControlFile->time));
|
||||
|
||||
/* This is just to allow attaching to startup process with a debugger */
|
||||
#ifdef XLOG_REPLAY_DELAY
|
||||
if (XLOG_DEBUG && ControlFile->state != DB_SHUTDOWNED)
|
||||
sleep(60);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Get the last valid checkpoint record. If the latest one according
|
||||
* to pg_control is broken, try the next-to-last one.
|
||||
@@ -2578,14 +2583,23 @@ StartupXLOG(void)
|
||||
/* REDO */
|
||||
if (InRecovery)
|
||||
{
|
||||
int rmid;
|
||||
|
||||
elog(LOG, "database system was not properly shut down; "
|
||||
"automatic recovery in progress");
|
||||
ControlFile->state = DB_IN_RECOVERY;
|
||||
ControlFile->time = time(NULL);
|
||||
UpdateControlFile();
|
||||
|
||||
/* Start up the recovery environment */
|
||||
XLogInitRelationCache();
|
||||
|
||||
for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
|
||||
{
|
||||
if (RmgrTable[rmid].rm_startup != NULL)
|
||||
RmgrTable[rmid].rm_startup();
|
||||
}
|
||||
|
||||
/* Is REDO required ? */
|
||||
if (XLByteLT(checkPoint.redo, RecPtr))
|
||||
record = ReadRecord(&(checkPoint.redo), PANIC, buffer);
|
||||
@@ -2737,7 +2751,25 @@ StartupXLOG(void)
|
||||
|
||||
if (InRecovery)
|
||||
{
|
||||
int rmid;
|
||||
|
||||
/*
|
||||
* Allow resource managers to do any required cleanup.
|
||||
*/
|
||||
for (rmid = 0; rmid <= RM_MAX_ID; rmid++)
|
||||
{
|
||||
if (RmgrTable[rmid].rm_cleanup != NULL)
|
||||
RmgrTable[rmid].rm_cleanup();
|
||||
}
|
||||
|
||||
/* suppress in-transaction check in CreateCheckPoint */
|
||||
MyLastRecPtr.xrecoff = 0;
|
||||
MyXactMadeXLogEntry = false;
|
||||
MyXactMadeTempRelUpdate = false;
|
||||
|
||||
/*
|
||||
* Perform a new checkpoint to update our recovery activity to disk.
|
||||
*
|
||||
* In case we had to use the secondary checkpoint, make sure that
|
||||
* it will still be shown as the secondary checkpoint after this
|
||||
* CreateCheckPoint operation; we don't want the broken primary
|
||||
@@ -2745,6 +2777,10 @@ StartupXLOG(void)
|
||||
*/
|
||||
ControlFile->checkPoint = checkPointLoc;
|
||||
CreateCheckPoint(true, true);
|
||||
|
||||
/*
|
||||
* Close down recovery environment
|
||||
*/
|
||||
XLogCloseRelationCache();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user