Skip to content

Commit 25a26a7

Browse files
committed
WAL
1 parent 0b33ace commit 25a26a7

File tree

5 files changed

+703
-40
lines changed

5 files changed

+703
-40
lines changed

src/backend/access/heap/heapam.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.86 2000/10/04 00:04:41 vadim Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.87 2000/10/13 02:02:59 vadim Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -2016,6 +2016,22 @@ void heap_redo(XLogRecPtr lsn, XLogRecord *record)
20162016
elog(STOP, "heap_redo: unknown op code %u", info);
20172017
}
20182018

2019+
void heap_undo(XLogRecPtr lsn, XLogRecord *record)
2020+
{
2021+
uint8 info = record->xl_info & ~XLR_INFO_MASK;
2022+
2023+
if (info == XLOG_HEAP_INSERT)
2024+
heap_xlog_insert(false, lsn, record);
2025+
else if (info == XLOG_HEAP_DELETE)
2026+
heap_xlog_delete(false, lsn, record);
2027+
else if (info == XLOG_HEAP_UPDATE)
2028+
heap_xlog_update(false, lsn, record);
2029+
else if (info == XLOG_HEAP_MOVE)
2030+
heap_xlog_move(false, lsn, record);
2031+
else
2032+
elog(STOP, "heap_undo: unknown op code %u", info);
2033+
}
2034+
20192035
void heap_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
20202036
{
20212037
xl_heap_delete *xlrec = (xl_heap_delete*) XLogRecGetData(record);
@@ -2199,7 +2215,7 @@ void heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
21992215
else /* we can't delete tuple right now */
22002216
{
22012217
lp->lp_flags |= LP_DELETE; /* mark for deletion */
2202-
MarkBufferForCleanup(buffer, PageCleanup);
2218+
MarkBufferForCleanup(buffer, HeapPageCleanup);
22032219
}
22042220

22052221
}

src/backend/access/nbtree/nbtinsert.c

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.64 2000/10/05 20:10:20 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.65 2000/10/13 02:03:00 vadim Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -61,6 +61,10 @@ static void _bt_pgaddtup(Relation rel, Page page,
6161
static bool _bt_isequal(TupleDesc itupdesc, Page page, OffsetNumber offnum,
6262
int keysz, ScanKey scankey);
6363

64+
#ifdef XLOG
65+
static Relation _xlheapRel; /* temporary hack */
66+
#endif
67+
6468
/*
6569
* _bt_doinsert() -- Handle insertion of a single btitem in the tree.
6670
*
@@ -119,6 +123,10 @@ _bt_doinsert(Relation rel, BTItem btitem,
119123
}
120124
}
121125

126+
#ifdef XLOG
127+
_xlheapRel = heapRel; /* temporary hack */
128+
#endif
129+
122130
/* do the insertion */
123131
res = _bt_insertonpg(rel, buf, stack, natts, itup_scankey, btitem, 0);
124132

@@ -517,21 +525,38 @@ _bt_insertonpg(Relation rel,
517525
#ifdef XLOG
518526
/* XLOG stuff */
519527
{
520-
char xlbuf[sizeof(xl_btree_insert) + 2 * sizeof(CommandId)];
528+
char xlbuf[sizeof(xl_btree_insert) +
529+
sizeof(CommandId) + sizeof(RelFileNode)];
521530
xl_btree_insert *xlrec = xlbuf;
522531
int hsize = SizeOfBtreeInsert;
532+
BTItemData truncitem;
533+
BTItem xlitem = btitem;
534+
Size xlsize = IndexTupleDSize(btitem->bti_itup) +
535+
(sizeof(BTItemData) - sizeof(IndexTupleData));
523536

524537
xlrec->target.node = rel->rd_node;
525538
ItemPointerSet(&(xlrec->target.tid), BufferGetBlockNumber(buf), newitemoff);
526539
if (P_ISLEAF(lpageop))
527-
{
540+
{
528541
CommandId cid = GetCurrentCommandId();
529-
memcpy(xlbuf + SizeOfBtreeInsert, &(char*)cid, sizeof(CommandId));
542+
memcpy(xlbuf + hsize, &cid, sizeof(CommandId));
530543
hsize += sizeof(CommandId);
544+
memcpy(xlbuf + hsize, &(_xlheapRel->rd_node), sizeof(RelFileNode));
545+
hsize += sizeof(RelFileNode);
546+
}
547+
/*
548+
* Read comments in _bt_pgaddtup
549+
*/
550+
else if (newitemoff == P_FIRSTDATAKEY(lpageop))
551+
{
552+
truncitem = *btitem;
553+
truncitem.bti_itup.t_info = sizeof(BTItemData);
554+
xlitem = &truncitem;
555+
xlsize = sizeof(BTItemData);
531556
}
532557

533558
XLogRecPtr recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_INSERT,
534-
xlbuf, hsize, (char*) btitem, itemsz);
559+
xlbuf, hsize, (char*) xlitem, xlsize);
535560

536561
PageSetLSN(page, recptr);
537562
PageSetSUI(page, ThisStartUpID);
@@ -752,7 +777,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
752777
*/
753778
{
754779
char xlbuf[sizeof(xl_btree_split) +
755-
2 * sizeof(CommandId) + BLCKSZ];
780+
sizeof(CommandId) + sizeof(RelFileNode) + BLCKSZ];
756781
xl_btree_split *xlrec = xlbuf;
757782
int hsize = SizeOfBtreeSplit;
758783
int flag = (newitemonleft) ?
@@ -765,11 +790,30 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
765790
CommandId cid = GetCurrentCommandId();
766791
memcpy(xlbuf + hsize, &(char*)cid, sizeof(CommandId));
767792
hsize += sizeof(CommandId);
793+
memcpy(xlbuf + hsize, &(_xlheapRel->rd_node), sizeof(RelFileNode));
794+
hsize += sizeof(RelFileNode);
768795
}
769796
if (newitemonleft)
770797
{
771-
memcpy(xlbuf + hsize, (char*) newitem, newitemsz);
772-
hsize += newitemsz;
798+
/*
799+
* Read comments in _bt_pgaddtup.
800+
* Actually, seems that in non-leaf splits newitem shouldn't
801+
* go to first data key position.
802+
*/
803+
if (! P_ISLEAF(lopaque) && itup_off == P_FIRSTDATAKEY(lopaque))
804+
{
805+
BTItemData truncitem = *newitem;
806+
truncitem.bti_itup.t_info = sizeof(BTItemData);
807+
memcpy(xlbuf + hsize, &truncitem, sizeof(BTItemData));
808+
hsize += sizeof(BTItemData);
809+
}
810+
else
811+
{
812+
Size itemsz = IndexTupleDSize(newitem->bti_itup) +
813+
(sizeof(BTItemData) - sizeof(IndexTupleData));
814+
memcpy(xlbuf + hsize, (char*) newitem, itemsz);
815+
hsize += itemsz;
816+
}
773817
xlrec->otherblk = BufferGetBlockNumber(rbuf);
774818
}
775819
else
@@ -1012,7 +1056,7 @@ static Buffer
10121056
_bt_getstackbuf(Relation rel, BTStack stack)
10131057
{
10141058
BlockNumber blkno;
1015-
Buffer buf;
1059+
Buffer buf, newbuf;
10161060
OffsetNumber start,
10171061
offnum,
10181062
maxoff;
@@ -1101,11 +1145,18 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
11011145
Size itemsz;
11021146
BTItem new_item;
11031147

1148+
#ifdef XLOG
1149+
Buffer metabuf;
1150+
#endif
1151+
11041152
/* get a new root page */
11051153
rootbuf = _bt_getbuf(rel, P_NEW, BT_WRITE);
11061154
rootpage = BufferGetPage(rootbuf);
11071155
rootblknum = BufferGetBlockNumber(rootbuf);
11081156

1157+
#ifdef XLOG
1158+
metabuf = _bt_getbuf(rel, BTREE_METAPAGE,BT_WRITE);
1159+
#endif
11091160

11101161
/* NO ELOG(ERROR) from here till newroot op is logged */
11111162

@@ -1168,9 +1219,12 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
11681219
#ifdef XLOG
11691220
/* XLOG stuff */
11701221
{
1171-
xl_btree_newroot xlrec;
1222+
xl_btree_newroot xlrec;
1223+
Page metapg = BufferGetPage(metabuf);
1224+
BTMetaPageData *metad = BTPageGetMeta(metapg);
1225+
11721226
xlrec.node = rel->rd_node;
1173-
xlrec.rootblk = rootblknum;
1227+
BlockIdSet(&(xlrec.rootblk), rootblknum);
11741228

11751229
/*
11761230
* Dirrect access to page is not good but faster - we should
@@ -1181,16 +1235,25 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
11811235
(char*)rootpage + (PageHeader) rootpage)->pd_upper,
11821236
((PageHeader) rootpage)->pd_special - ((PageHeader) rootpage)->upper);
11831237

1238+
metad->btm_root = rootblknum;
1239+
(metad->btm_level)++;
1240+
11841241
PageSetLSN(rootpage, recptr);
11851242
PageSetSUI(rootpage, ThisStartUpID);
1243+
PageSetLSN(metapg, recptr);
1244+
PageSetSUI(metapg, ThisStartUpID);
1245+
1246+
_bt_wrtbuf(rel, metabuf);
11861247
}
11871248
#endif
11881249

11891250
/* write and let go of the new root buffer */
11901251
_bt_wrtbuf(rel, rootbuf);
11911252

1253+
#ifndef XLOG
11921254
/* update metadata page with new root block number */
11931255
_bt_metaproot(rel, rootblknum, 0);
1256+
#endif
11941257

11951258
/* update and release new sibling, and finally the old root */
11961259
_bt_wrtbuf(rel, rbuf);

src/backend/access/nbtree/nbtpage.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.38 2000/10/04 00:04:42 vadim Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.39 2000/10/13 02:03:00 vadim Exp $
1313
*
1414
* NOTES
1515
* Postgres btree pages look like ordinary relation pages. The opaque
@@ -27,23 +27,6 @@
2727
#include "access/nbtree.h"
2828
#include "miscadmin.h"
2929

30-
#define BTREE_METAPAGE 0
31-
#define BTREE_MAGIC 0x053162
32-
33-
#define BTREE_VERSION 1
34-
35-
typedef struct BTMetaPageData
36-
{
37-
uint32 btm_magic;
38-
uint32 btm_version;
39-
BlockNumber btm_root;
40-
int32 btm_level;
41-
} BTMetaPageData;
42-
43-
#define BTPageGetMeta(p) \
44-
((BTMetaPageData *) &((PageHeader) p)->pd_linp[0])
45-
46-
4730
/*
4831
* We use high-concurrency locking on btrees. There are two cases in
4932
* which we don't do locking. One is when we're building the btree.
@@ -188,14 +171,18 @@ _bt_getroot(Relation rel, int access)
188171
#ifdef XLOG
189172
/* XLOG stuff */
190173
{
191-
xl_btree_insert xlrec;
174+
xl_btree_newroot xlrec;
175+
192176
xlrec.node = rel->rd_node;
177+
BlockIdSet(&(xlrec.rootblk), rootblkno);
193178

194179
XLogRecPtr recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_NEWROOT,
195180
&xlrec, SizeOfBtreeNewroot, NULL, 0);
196181

197182
PageSetLSN(rootpage, recptr);
198183
PageSetSUI(rootpage, ThisStartUpID);
184+
PageSetLSN(metapg, recptr);
185+
PageSetSUI(metapg, ThisStartUpID);
199186
}
200187
#endif
201188

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy