Commit 94d4d240 authored by Tom Lane's avatar Tom Lane

Rename XLOG_BTREE_NEWPAGE xlog record type into XLOG_HEAP_NEWPAGE, and

shift support code into heapam.c accordingly.  This is in service of
soon-to-be-committed ALTER TABLE SET TABLESPACE code that will want to
use this same record type for both heaps and indexes.

Theoretically I should have forced initdb for this, but in practice there
is no change in xlog contents because CVS tip will never really emit this
record type anyhow...
parent 98e9775a
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.169 2004/06/18 06:13:09 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.170 2004/07/11 18:01:44 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -2189,6 +2189,39 @@ heap_xlog_clean(bool redo, XLogRecPtr lsn, XLogRecord *record) ...@@ -2189,6 +2189,39 @@ heap_xlog_clean(bool redo, XLogRecPtr lsn, XLogRecord *record)
WriteBuffer(buffer); WriteBuffer(buffer);
} }
static void
heap_xlog_newpage(bool redo, XLogRecPtr lsn, XLogRecord *record)
{
xl_heap_newpage *xlrec = (xl_heap_newpage *) XLogRecGetData(record);
Relation reln;
Buffer buffer;
Page page;
/*
* Note: the NEWPAGE log record is used for both heaps and indexes,
* so do not do anything that assumes we are touching a heap.
*/
if (!redo || (record->xl_info & XLR_BKP_BLOCK_1))
return;
reln = XLogOpenRelation(redo, RM_HEAP_ID, xlrec->node);
if (!RelationIsValid(reln))
return;
buffer = XLogReadBuffer(true, reln, xlrec->blkno);
if (!BufferIsValid(buffer))
elog(PANIC, "heap_newpage_redo: no block");
page = (Page) BufferGetPage(buffer);
Assert(record->xl_len == SizeOfHeapNewpage + BLCKSZ);
memcpy(page, (char *) xlrec + SizeOfHeapNewpage, BLCKSZ);
PageSetLSN(page, lsn);
PageSetSUI(page, ThisStartUpID);
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
WriteBuffer(buffer);
}
static void static void
heap_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record) heap_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
{ {
...@@ -2603,6 +2636,8 @@ heap_redo(XLogRecPtr lsn, XLogRecord *record) ...@@ -2603,6 +2636,8 @@ heap_redo(XLogRecPtr lsn, XLogRecord *record)
heap_xlog_update(true, lsn, record, true); heap_xlog_update(true, lsn, record, true);
else if (info == XLOG_HEAP_CLEAN) else if (info == XLOG_HEAP_CLEAN)
heap_xlog_clean(true, lsn, record); heap_xlog_clean(true, lsn, record);
else if (info == XLOG_HEAP_NEWPAGE)
heap_xlog_newpage(true, lsn, record);
else else
elog(PANIC, "heap_redo: unknown op code %u", info); elog(PANIC, "heap_redo: unknown op code %u", info);
} }
...@@ -2623,6 +2658,8 @@ heap_undo(XLogRecPtr lsn, XLogRecord *record) ...@@ -2623,6 +2658,8 @@ heap_undo(XLogRecPtr lsn, XLogRecord *record)
heap_xlog_update(false, lsn, record, true); heap_xlog_update(false, lsn, record, true);
else if (info == XLOG_HEAP_CLEAN) else if (info == XLOG_HEAP_CLEAN)
heap_xlog_clean(false, lsn, record); heap_xlog_clean(false, lsn, record);
else if (info == XLOG_HEAP_NEWPAGE)
heap_xlog_newpage(false, lsn, record);
else else
elog(PANIC, "heap_undo: unknown op code %u", info); elog(PANIC, "heap_undo: unknown op code %u", info);
} }
...@@ -2677,6 +2714,14 @@ heap_desc(char *buf, uint8 xl_info, char *rec) ...@@ -2677,6 +2714,14 @@ heap_desc(char *buf, uint8 xl_info, char *rec)
xlrec->node.spcNode, xlrec->node.dbNode, xlrec->node.spcNode, xlrec->node.dbNode,
xlrec->node.relNode, xlrec->block); xlrec->node.relNode, xlrec->block);
} }
else if (info == XLOG_HEAP_NEWPAGE)
{
xl_heap_newpage *xlrec = (xl_heap_newpage *) rec;
sprintf(buf + strlen(buf), "newpage: rel %u/%u/%u; blk %u",
xlrec->node.spcNode, xlrec->node.dbNode,
xlrec->node.relNode, xlrec->blkno);
}
else else
strcat(buf, "UNKNOWN"); strcat(buf, "UNKNOWN");
} }
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.82 2004/06/02 17:28:17 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.83 2004/07/11 18:01:45 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -280,7 +280,8 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno) ...@@ -280,7 +280,8 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno)
/* XLOG stuff */ /* XLOG stuff */
if (wstate->btws_use_wal) if (wstate->btws_use_wal)
{ {
xl_btree_newpage xlrec; /* We use the heap NEWPAGE record type for this */
xl_heap_newpage xlrec;
XLogRecPtr recptr; XLogRecPtr recptr;
XLogRecData rdata[2]; XLogRecData rdata[2];
...@@ -292,7 +293,7 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno) ...@@ -292,7 +293,7 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno)
rdata[0].buffer = InvalidBuffer; rdata[0].buffer = InvalidBuffer;
rdata[0].data = (char *) &xlrec; rdata[0].data = (char *) &xlrec;
rdata[0].len = SizeOfBtreeNewpage; rdata[0].len = SizeOfHeapNewpage;
rdata[0].next = &(rdata[1]); rdata[0].next = &(rdata[1]);
rdata[1].buffer = InvalidBuffer; rdata[1].buffer = InvalidBuffer;
...@@ -300,7 +301,7 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno) ...@@ -300,7 +301,7 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno)
rdata[1].len = BLCKSZ; rdata[1].len = BLCKSZ;
rdata[1].next = NULL; rdata[1].next = NULL;
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_NEWPAGE, rdata); recptr = XLogInsert(RM_HEAP_ID, XLOG_HEAP_NEWPAGE, rdata);
PageSetLSN(page, recptr); PageSetLSN(page, recptr);
PageSetSUI(page, ThisStartUpID); PageSetSUI(page, ThisStartUpID);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtxlog.c,v 1.14 2004/06/18 06:13:11 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtxlog.c,v 1.15 2004/07/11 18:01:45 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -669,34 +669,6 @@ btree_xlog_newmeta(bool redo, XLogRecPtr lsn, XLogRecord *record) ...@@ -669,34 +669,6 @@ btree_xlog_newmeta(bool redo, XLogRecPtr lsn, XLogRecord *record)
xlrec->meta.fastroot, xlrec->meta.fastlevel); xlrec->meta.fastroot, xlrec->meta.fastlevel);
} }
static void
btree_xlog_newpage(bool redo, XLogRecPtr lsn, XLogRecord *record)
{
xl_btree_newpage *xlrec = (xl_btree_newpage *) XLogRecGetData(record);
Relation reln;
Buffer buffer;
Page page;
if (!redo || (record->xl_info & XLR_BKP_BLOCK_1))
return;
reln = XLogOpenRelation(redo, RM_BTREE_ID, xlrec->node);
if (!RelationIsValid(reln))
return;
buffer = XLogReadBuffer(true, reln, xlrec->blkno);
if (!BufferIsValid(buffer))
elog(PANIC, "btree_newpage_redo: block unfound");
page = (Page) BufferGetPage(buffer);
Assert(record->xl_len == SizeOfBtreeNewpage + BLCKSZ);
memcpy(page, (char *) xlrec + SizeOfBtreeNewpage, BLCKSZ);
PageSetLSN(page, lsn);
PageSetSUI(page, ThisStartUpID);
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
WriteBuffer(buffer);
}
void void
btree_redo(XLogRecPtr lsn, XLogRecord *record) btree_redo(XLogRecPtr lsn, XLogRecord *record)
...@@ -741,9 +713,6 @@ btree_redo(XLogRecPtr lsn, XLogRecord *record) ...@@ -741,9 +713,6 @@ btree_redo(XLogRecPtr lsn, XLogRecord *record)
case XLOG_BTREE_NEWMETA: case XLOG_BTREE_NEWMETA:
btree_xlog_newmeta(true, lsn, record); btree_xlog_newmeta(true, lsn, record);
break; break;
case XLOG_BTREE_NEWPAGE:
btree_xlog_newpage(true, lsn, record);
break;
default: default:
elog(PANIC, "btree_redo: unknown op code %u", info); elog(PANIC, "btree_redo: unknown op code %u", info);
} }
...@@ -792,9 +761,6 @@ btree_undo(XLogRecPtr lsn, XLogRecord *record) ...@@ -792,9 +761,6 @@ btree_undo(XLogRecPtr lsn, XLogRecord *record)
case XLOG_BTREE_NEWMETA: case XLOG_BTREE_NEWMETA:
btree_xlog_newmeta(false, lsn, record); btree_xlog_newmeta(false, lsn, record);
break; break;
case XLOG_BTREE_NEWPAGE:
btree_xlog_newpage(false, lsn, record);
break;
default: default:
elog(PANIC, "btree_undo: unknown op code %u", info); elog(PANIC, "btree_undo: unknown op code %u", info);
} }
...@@ -921,15 +887,6 @@ btree_desc(char *buf, uint8 xl_info, char *rec) ...@@ -921,15 +887,6 @@ btree_desc(char *buf, uint8 xl_info, char *rec)
xlrec->meta.fastroot, xlrec->meta.fastlevel); xlrec->meta.fastroot, xlrec->meta.fastlevel);
break; break;
} }
case XLOG_BTREE_NEWPAGE:
{
xl_btree_newpage *xlrec = (xl_btree_newpage *) rec;
sprintf(buf + strlen(buf), "newpage: rel %u/%u/%u; page %u",
xlrec->node.spcNode, xlrec->node.dbNode,
xlrec->node.relNode, xlrec->blkno);
break;
}
default: default:
strcat(buf, "UNKNOWN"); strcat(buf, "UNKNOWN");
break; break;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/htup.h,v 1.66 2004/07/01 00:51:38 tgl Exp $ * $PostgreSQL: pgsql/src/include/access/htup.h,v 1.67 2004/07/11 18:01:45 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -423,6 +423,8 @@ typedef HeapTupleData *HeapTuple; ...@@ -423,6 +423,8 @@ typedef HeapTupleData *HeapTuple;
#define XLOG_HEAP_UPDATE 0x20 #define XLOG_HEAP_UPDATE 0x20
#define XLOG_HEAP_MOVE 0x30 #define XLOG_HEAP_MOVE 0x30
#define XLOG_HEAP_CLEAN 0x40 #define XLOG_HEAP_CLEAN 0x40
#define XLOG_HEAP_NEWPAGE 0x50
/* opcodes 0x60, 0x70 still free */
#define XLOG_HEAP_OPMASK 0x70 #define XLOG_HEAP_OPMASK 0x70
/* /*
* When we insert 1st item on new page in INSERT/UPDATE * When we insert 1st item on new page in INSERT/UPDATE
...@@ -491,7 +493,7 @@ typedef struct xl_heap_update ...@@ -491,7 +493,7 @@ typedef struct xl_heap_update
#define SizeOfHeapUpdate (offsetof(xl_heap_update, newtid) + SizeOfIptrData) #define SizeOfHeapUpdate (offsetof(xl_heap_update, newtid) + SizeOfIptrData)
/* This is what we need to know about page cleanup */ /* This is what we need to know about vacuum page cleanup */
typedef struct xl_heap_clean typedef struct xl_heap_clean
{ {
RelFileNode node; RelFileNode node;
...@@ -501,4 +503,15 @@ typedef struct xl_heap_clean ...@@ -501,4 +503,15 @@ typedef struct xl_heap_clean
#define SizeOfHeapClean (offsetof(xl_heap_clean, block) + sizeof(BlockNumber)) #define SizeOfHeapClean (offsetof(xl_heap_clean, block) + sizeof(BlockNumber))
/* This is for replacing a page's contents in toto */
/* NB: this is used for indexes as well as heaps */
typedef struct xl_heap_newpage
{
RelFileNode node;
BlockNumber blkno; /* location of new page */
/* entire page contents follow at end of record */
} xl_heap_newpage;
#define SizeOfHeapNewpage (offsetof(xl_heap_newpage, blkno) + sizeof(BlockNumber))
#endif /* HTUP_H */ #endif /* HTUP_H */
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/nbtree.h,v 1.78 2004/06/02 17:28:18 tgl Exp $ * $PostgreSQL: pgsql/src/include/access/nbtree.h,v 1.79 2004/07/11 18:01:45 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -197,7 +197,6 @@ typedef BTItemData *BTItem; ...@@ -197,7 +197,6 @@ typedef BTItemData *BTItem;
* metapage */ * metapage */
#define XLOG_BTREE_NEWROOT 0xA0 /* new root page */ #define XLOG_BTREE_NEWROOT 0xA0 /* new root page */
#define XLOG_BTREE_NEWMETA 0xB0 /* update metadata page */ #define XLOG_BTREE_NEWMETA 0xB0 /* update metadata page */
#define XLOG_BTREE_NEWPAGE 0xC0 /* new index page during build */
/* /*
* All that we need to find changed index tuple * All that we need to find changed index tuple
...@@ -324,18 +323,6 @@ typedef struct xl_btree_newmeta ...@@ -324,18 +323,6 @@ typedef struct xl_btree_newmeta
#define SizeOfBtreeNewmeta (sizeof(xl_btree_newmeta)) #define SizeOfBtreeNewmeta (sizeof(xl_btree_newmeta))
/*
* New index page log record. This is only used while building a new index.
*/
typedef struct xl_btree_newpage
{
RelFileNode node;
BlockNumber blkno; /* location of new page */
/* entire page contents follow at end of record */
} xl_btree_newpage;
#define SizeOfBtreeNewpage (offsetof(xl_btree_newpage, blkno) + sizeof(BlockNumber))
/* /*
* Operator strategy numbers for B-tree have been moved to access/skey.h, * Operator strategy numbers for B-tree have been moved to access/skey.h,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment