Commit 25a26a7a authored by Vadim B. Mikheev's avatar Vadim B. Mikheev

WAL

parent 0b33ace6
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.86 2000/10/04 00:04:41 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.87 2000/10/13 02:02:59 vadim Exp $
*
*
* INTERFACE ROUTINES
......@@ -2016,6 +2016,22 @@ void heap_redo(XLogRecPtr lsn, XLogRecord *record)
elog(STOP, "heap_redo: unknown op code %u", info);
}
void heap_undo(XLogRecPtr lsn, XLogRecord *record)
{
uint8 info = record->xl_info & ~XLR_INFO_MASK;
if (info == XLOG_HEAP_INSERT)
heap_xlog_insert(false, lsn, record);
else if (info == XLOG_HEAP_DELETE)
heap_xlog_delete(false, lsn, record);
else if (info == XLOG_HEAP_UPDATE)
heap_xlog_update(false, lsn, record);
else if (info == XLOG_HEAP_MOVE)
heap_xlog_move(false, lsn, record);
else
elog(STOP, "heap_undo: unknown op code %u", info);
}
void heap_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
{
xl_heap_delete *xlrec = (xl_heap_delete*) XLogRecGetData(record);
......@@ -2199,7 +2215,7 @@ void heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
else /* we can't delete tuple right now */
{
lp->lp_flags |= LP_DELETE; /* mark for deletion */
MarkBufferForCleanup(buffer, PageCleanup);
MarkBufferForCleanup(buffer, HeapPageCleanup);
}
}
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.64 2000/10/05 20:10:20 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.65 2000/10/13 02:03:00 vadim Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -61,6 +61,10 @@ static void _bt_pgaddtup(Relation rel, Page page,
static bool _bt_isequal(TupleDesc itupdesc, Page page, OffsetNumber offnum,
int keysz, ScanKey scankey);
#ifdef XLOG
static Relation _xlheapRel; /* temporary hack */
#endif
/*
* _bt_doinsert() -- Handle insertion of a single btitem in the tree.
*
......@@ -119,6 +123,10 @@ top:
}
}
#ifdef XLOG
_xlheapRel = heapRel; /* temporary hack */
#endif
/* do the insertion */
res = _bt_insertonpg(rel, buf, stack, natts, itup_scankey, btitem, 0);
......@@ -517,21 +525,38 @@ _bt_insertonpg(Relation rel,
#ifdef XLOG
/* XLOG stuff */
{
char xlbuf[sizeof(xl_btree_insert) + 2 * sizeof(CommandId)];
char xlbuf[sizeof(xl_btree_insert) +
sizeof(CommandId) + sizeof(RelFileNode)];
xl_btree_insert *xlrec = xlbuf;
int hsize = SizeOfBtreeInsert;
BTItemData truncitem;
BTItem xlitem = btitem;
Size xlsize = IndexTupleDSize(btitem->bti_itup) +
(sizeof(BTItemData) - sizeof(IndexTupleData));
xlrec->target.node = rel->rd_node;
ItemPointerSet(&(xlrec->target.tid), BufferGetBlockNumber(buf), newitemoff);
if (P_ISLEAF(lpageop))
{
{
CommandId cid = GetCurrentCommandId();
memcpy(xlbuf + SizeOfBtreeInsert, &(char*)cid, sizeof(CommandId));
memcpy(xlbuf + hsize, &cid, sizeof(CommandId));
hsize += sizeof(CommandId);
memcpy(xlbuf + hsize, &(_xlheapRel->rd_node), sizeof(RelFileNode));
hsize += sizeof(RelFileNode);
}
/*
* Read comments in _bt_pgaddtup
*/
else if (newitemoff == P_FIRSTDATAKEY(lpageop))
{
truncitem = *btitem;
truncitem.bti_itup.t_info = sizeof(BTItemData);
xlitem = &truncitem;
xlsize = sizeof(BTItemData);
}
XLogRecPtr recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_INSERT,
xlbuf, hsize, (char*) btitem, itemsz);
xlbuf, hsize, (char*) xlitem, xlsize);
PageSetLSN(page, recptr);
PageSetSUI(page, ThisStartUpID);
......@@ -752,7 +777,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
*/
{
char xlbuf[sizeof(xl_btree_split) +
2 * sizeof(CommandId) + BLCKSZ];
sizeof(CommandId) + sizeof(RelFileNode) + BLCKSZ];
xl_btree_split *xlrec = xlbuf;
int hsize = SizeOfBtreeSplit;
int flag = (newitemonleft) ?
......@@ -765,11 +790,30 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
CommandId cid = GetCurrentCommandId();
memcpy(xlbuf + hsize, &(char*)cid, sizeof(CommandId));
hsize += sizeof(CommandId);
memcpy(xlbuf + hsize, &(_xlheapRel->rd_node), sizeof(RelFileNode));
hsize += sizeof(RelFileNode);
}
if (newitemonleft)
{
memcpy(xlbuf + hsize, (char*) newitem, newitemsz);
hsize += newitemsz;
/*
* Read comments in _bt_pgaddtup.
* Actually, seems that in non-leaf splits newitem shouldn't
* go to first data key position.
*/
if (! P_ISLEAF(lopaque) && itup_off == P_FIRSTDATAKEY(lopaque))
{
BTItemData truncitem = *newitem;
truncitem.bti_itup.t_info = sizeof(BTItemData);
memcpy(xlbuf + hsize, &truncitem, sizeof(BTItemData));
hsize += sizeof(BTItemData);
}
else
{
Size itemsz = IndexTupleDSize(newitem->bti_itup) +
(sizeof(BTItemData) - sizeof(IndexTupleData));
memcpy(xlbuf + hsize, (char*) newitem, itemsz);
hsize += itemsz;
}
xlrec->otherblk = BufferGetBlockNumber(rbuf);
}
else
......@@ -1012,7 +1056,7 @@ static Buffer
_bt_getstackbuf(Relation rel, BTStack stack)
{
BlockNumber blkno;
Buffer buf;
Buffer buf, newbuf;
OffsetNumber start,
offnum,
maxoff;
......@@ -1101,11 +1145,18 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
Size itemsz;
BTItem new_item;
#ifdef XLOG
Buffer metabuf;
#endif
/* get a new root page */
rootbuf = _bt_getbuf(rel, P_NEW, BT_WRITE);
rootpage = BufferGetPage(rootbuf);
rootblknum = BufferGetBlockNumber(rootbuf);
#ifdef XLOG
metabuf = _bt_getbuf(rel, BTREE_METAPAGE,BT_WRITE);
#endif
/* NO ELOG(ERROR) from here till newroot op is logged */
......@@ -1168,9 +1219,12 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
#ifdef XLOG
/* XLOG stuff */
{
xl_btree_newroot xlrec;
xl_btree_newroot xlrec;
Page metapg = BufferGetPage(metabuf);
BTMetaPageData *metad = BTPageGetMeta(metapg);
xlrec.node = rel->rd_node;
xlrec.rootblk = rootblknum;
BlockIdSet(&(xlrec.rootblk), rootblknum);
/*
* Dirrect access to page is not good but faster - we should
......@@ -1181,16 +1235,25 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
(char*)rootpage + (PageHeader) rootpage)->pd_upper,
((PageHeader) rootpage)->pd_special - ((PageHeader) rootpage)->upper);
metad->btm_root = rootblknum;
(metad->btm_level)++;
PageSetLSN(rootpage, recptr);
PageSetSUI(rootpage, ThisStartUpID);
PageSetLSN(metapg, recptr);
PageSetSUI(metapg, ThisStartUpID);
_bt_wrtbuf(rel, metabuf);
}
#endif
/* write and let go of the new root buffer */
_bt_wrtbuf(rel, rootbuf);
#ifndef XLOG
/* update metadata page with new root block number */
_bt_metaproot(rel, rootblknum, 0);
#endif
/* update and release new sibling, and finally the old root */
_bt_wrtbuf(rel, rbuf);
......
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.38 2000/10/04 00:04:42 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.39 2000/10/13 02:03:00 vadim Exp $
*
* NOTES
* Postgres btree pages look like ordinary relation pages. The opaque
......@@ -27,23 +27,6 @@
#include "access/nbtree.h"
#include "miscadmin.h"
#define BTREE_METAPAGE 0
#define BTREE_MAGIC 0x053162
#define BTREE_VERSION 1
typedef struct BTMetaPageData
{
uint32 btm_magic;
uint32 btm_version;
BlockNumber btm_root;
int32 btm_level;
} BTMetaPageData;
#define BTPageGetMeta(p) \
((BTMetaPageData *) &((PageHeader) p)->pd_linp[0])
/*
* We use high-concurrency locking on btrees. There are two cases in
* which we don't do locking. One is when we're building the btree.
......@@ -188,14 +171,18 @@ _bt_getroot(Relation rel, int access)
#ifdef XLOG
/* XLOG stuff */
{
xl_btree_insert xlrec;
xl_btree_newroot xlrec;
xlrec.node = rel->rd_node;
BlockIdSet(&(xlrec.rootblk), rootblkno);
XLogRecPtr recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_NEWROOT,
&xlrec, SizeOfBtreeNewroot, NULL, 0);
PageSetLSN(rootpage, recptr);
PageSetSUI(rootpage, ThisStartUpID);
PageSetLSN(metapg, recptr);
PageSetSUI(metapg, ThisStartUpID);
}
#endif
......
This diff is collapsed.
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: nbtree.h,v 1.43 2000/10/04 00:04:43 vadim Exp $
* $Id: nbtree.h,v 1.44 2000/10/13 02:03:02 vadim Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -42,11 +42,28 @@ typedef struct BTPageOpaqueData
#define BTP_FREE (1 << 2) /* not currently used... */
#define BTP_META (1 << 3) /* Set in the meta-page only */
#ifdef XLOG
#define BTP_REORDER (1 << 4) /* items must be re-ordered */
#endif
} BTPageOpaqueData;
typedef BTPageOpaqueData *BTPageOpaque;
#define BTREE_METAPAGE 0 /* first page is meta */
#define BTREE_MAGIC 0x053162
#define BTREE_VERSION 1
typedef struct BTMetaPageData
{
uint32 btm_magic;
uint32 btm_version;
BlockNumber btm_root;
int32 btm_level;
} BTMetaPageData;
#define BTPageGetMeta(p) \
((BTMetaPageData *) &((PageHeader) p)->pd_linp[0])
/*
* BTScanOpaqueData is used to remember which buffers we're currently
......@@ -228,13 +245,13 @@ typedef struct xl_btree_delete
/*
* This is what we need to know about pure (without split) insert -
* 14 + [4] + btitem with key data. Note that we need in CommandID
* (4 bytes) only for leaf page insert.
* 14 + [4+8] + btitem with key data. Note that we need in CommandID
* and HeapNode (4 + 8 bytes) only for leaf page insert.
*/
typedef struct xl_btree_insert
{
xl_btreetid target; /* inserted tuple id */
/* [CommandID and ] BTITEM FOLLOWS AT END OF STRUCT */
/* [CommandID, HeapNode and ] BTITEM FOLLOWS AT END OF STRUCT */
} xl_btree_insert;
#define SizeOfBtreeInsert (offsetof(xl_btreetid, tid) + SizeOfIptrData)
......@@ -242,8 +259,8 @@ typedef struct xl_btree_insert
/*
* This is what we need to know about insert with split -
* 22 + [4] + [btitem] + right sibling btitems. Note that we need in
* CommandID (4 bytes) only for leaf page insert.
* 22 + [4+8] + [btitem] + right sibling btitems. Note that we need in
* CommandID and HeapNode (4 + 8 bytes) only for leaf page insert.
*/
typedef struct xl_btree_split
{
......@@ -255,7 +272,7 @@ typedef struct xl_btree_split
* We log all btitems from the right sibling. If new btitem goes on
* the left sibling then we log it too and it will be the first
* BTItemData at the end of this struct, but after (for the leaf
* pages) CommandId.
* pages) CommandId and HeapNode.
*/
} xl_btree_split;
......
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