Skip to content

Commit 7ceeeb6

Browse files
committed
New WAL version - CRC and data blocks backup.
1 parent c996c7f commit 7ceeeb6

File tree

18 files changed

+1197
-1196
lines changed

18 files changed

+1197
-1196
lines changed

src/backend/access/heap/heapam.c

Lines changed: 254 additions & 288 deletions
Large diffs are not rendered by default.

src/backend/access/nbtree/nbtinsert.c

Lines changed: 108 additions & 104 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.70 2000/12/03 10:27:26 vadim Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.71 2000/12/28 13:00:07 vadim Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -520,39 +520,40 @@ _bt_insertonpg(Relation rel,
520520
{
521521
/* XLOG stuff */
522522
{
523-
char xlbuf[sizeof(xl_btree_insert) +
524-
sizeof(CommandId) + sizeof(RelFileNode)];
525-
xl_btree_insert *xlrec = (xl_btree_insert*)xlbuf;
526-
int hsize = SizeOfBtreeInsert;
527-
BTItemData truncitem;
528-
BTItem xlitem = btitem;
529-
Size xlsize = IndexTupleDSize(btitem->bti_itup) +
530-
(sizeof(BTItemData) - sizeof(IndexTupleData));
523+
xl_btree_insert xlrec;
524+
uint8 flag = XLOG_BTREE_INSERT;
531525
XLogRecPtr recptr;
526+
XLogRecData rdata[2];
532527

533-
xlrec->target.node = rel->rd_node;
534-
ItemPointerSet(&(xlrec->target.tid), BufferGetBlockNumber(buf), newitemoff);
535-
if (P_ISLEAF(lpageop))
536-
{
537-
CommandId cid = GetCurrentCommandId();
538-
memcpy(xlbuf + hsize, &cid, sizeof(CommandId));
539-
hsize += sizeof(CommandId);
540-
memcpy(xlbuf + hsize, &(_xlheapRel->rd_node), sizeof(RelFileNode));
541-
hsize += sizeof(RelFileNode);
542-
}
543-
/*
544-
* Read comments in _bt_pgaddtup
545-
*/
546-
else if (newitemoff == P_FIRSTDATAKEY(lpageop))
528+
xlrec.target.node = rel->rd_node;
529+
ItemPointerSet(&(xlrec.target.tid), BufferGetBlockNumber(buf), newitemoff);
530+
rdata[0].buffer = InvalidBuffer;
531+
rdata[0].data = (char*)&xlrec;
532+
rdata[0].len = SizeOfBtreeInsert;
533+
rdata[0].next = &(rdata[1]);
534+
535+
/* Read comments in _bt_pgaddtup */
536+
if (!(P_ISLEAF(lpageop)) && newitemoff == P_FIRSTDATAKEY(lpageop))
547537
{
548-
truncitem = *btitem;
538+
BTItemData truncitem = *btitem;
539+
549540
truncitem.bti_itup.t_info = sizeof(BTItemData);
550-
xlitem = &truncitem;
551-
xlsize = sizeof(BTItemData);
541+
rdata[1].data = (char*)&truncitem;
542+
rdata[1].len = sizeof(BTItemData);
543+
}
544+
else
545+
{
546+
rdata[1].data = (char*)btitem;
547+
rdata[1].len = IndexTupleDSize(btitem->bti_itup) +
548+
(sizeof(BTItemData) - sizeof(IndexTupleData));
552549
}
550+
rdata[1].buffer = buf;
551+
rdata[1].next = NULL;
553552

554-
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_INSERT,
555-
xlbuf, hsize, (char*) xlitem, xlsize);
553+
if (P_ISLEAF(lpageop))
554+
flag |= XLOG_BTREE_LEAF;
555+
556+
recptr = XLogInsert(RM_BTREE_ID, flag, rdata);
556557

557558
PageSetLSN(page, recptr);
558559
PageSetSUI(page, ThisStartUpID);
@@ -774,71 +775,63 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
774775
*/
775776
START_CRIT_CODE;
776777
{
777-
char xlbuf[sizeof(xl_btree_split) +
778-
sizeof(CommandId) + sizeof(RelFileNode) + BLCKSZ];
779-
xl_btree_split *xlrec = (xl_btree_split*) xlbuf;
780-
int hsize = SizeOfBtreeSplit;
781-
int flag = (newitemonleft) ?
782-
XLOG_BTREE_SPLEFT : XLOG_BTREE_SPLIT;
783-
BlockNumber blkno;
784-
XLogRecPtr recptr;
785-
786-
xlrec->target.node = rel->rd_node;
787-
ItemPointerSet(&(xlrec->target.tid), *itup_blkno, *itup_off);
788-
if (P_ISLEAF(lopaque))
789-
{
790-
CommandId cid = GetCurrentCommandId();
791-
memcpy(xlbuf + hsize, &cid, sizeof(CommandId));
792-
hsize += sizeof(CommandId);
793-
memcpy(xlbuf + hsize, &(_xlheapRel->rd_node), sizeof(RelFileNode));
794-
hsize += sizeof(RelFileNode);
795-
}
796-
else
797-
{
798-
Size itemsz = IndexTupleDSize(lhikey->bti_itup) +
799-
(sizeof(BTItemData) - sizeof(IndexTupleData));
800-
memcpy(xlbuf + hsize, (char*) lhikey, itemsz);
801-
hsize += itemsz;
802-
}
778+
xl_btree_split xlrec;
779+
int flag = (newitemonleft) ?
780+
XLOG_BTREE_SPLEFT : XLOG_BTREE_SPLIT;
781+
BlockNumber blkno;
782+
XLogRecPtr recptr;
783+
XLogRecData rdata[4];
784+
785+
xlrec.target.node = rel->rd_node;
786+
ItemPointerSet(&(xlrec.target.tid), *itup_blkno, *itup_off);
803787
if (newitemonleft)
804788
{
805-
/*
806-
* Read comments in _bt_pgaddtup.
807-
* Actually, seems that in non-leaf splits newitem shouldn't
808-
* go to first data key position on left page.
809-
*/
810-
if (! P_ISLEAF(lopaque) && *itup_off == P_FIRSTDATAKEY(lopaque))
811-
{
812-
BTItemData truncitem = *newitem;
813-
truncitem.bti_itup.t_info = sizeof(BTItemData);
814-
memcpy(xlbuf + hsize, &truncitem, sizeof(BTItemData));
815-
hsize += sizeof(BTItemData);
816-
}
817-
else
818-
{
819-
Size itemsz = IndexTupleDSize(newitem->bti_itup) +
820-
(sizeof(BTItemData) - sizeof(IndexTupleData));
821-
memcpy(xlbuf + hsize, (char*) newitem, itemsz);
822-
hsize += itemsz;
823-
}
824789
blkno = BufferGetBlockNumber(rbuf);
825-
BlockIdSet(&(xlrec->otherblk), blkno);
790+
BlockIdSet(&(xlrec.otherblk), blkno);
826791
}
827792
else
828793
{
829794
blkno = BufferGetBlockNumber(buf);
830-
BlockIdSet(&(xlrec->otherblk), blkno);
795+
BlockIdSet(&(xlrec.otherblk), blkno);
831796
}
832-
833-
BlockIdSet(&(xlrec->rightblk), ropaque->btpo_next);
834-
797+
BlockIdSet(&(xlrec.parentblk), lopaque->btpo_parent);
798+
BlockIdSet(&(xlrec.leftblk), lopaque->btpo_prev);
799+
BlockIdSet(&(xlrec.rightblk), ropaque->btpo_next);
835800
/*
836801
* Dirrect access to page is not good but faster - we should
837802
* implement some new func in page API.
838803
*/
839-
recptr = XLogInsert(RM_BTREE_ID, flag, xlbuf,
840-
hsize, (char*)rightpage + ((PageHeader) rightpage)->pd_upper,
841-
((PageHeader) rightpage)->pd_special - ((PageHeader) rightpage)->pd_upper);
804+
xlrec.leftlen = ((PageHeader)leftpage)->pd_special -
805+
((PageHeader)leftpage)->pd_upper;
806+
rdata[0].buffer = InvalidBuffer;
807+
rdata[0].data = (char*)&xlrec;
808+
rdata[0].len = SizeOfBtreeSplit;
809+
rdata[0].next = &(rdata[1]);
810+
811+
rdata[1].buffer = InvalidBuffer;
812+
rdata[1].data = (char*)leftpage + ((PageHeader)leftpage)->pd_upper;
813+
rdata[1].len = xlrec.leftlen;
814+
rdata[1].next = &(rdata[2]);
815+
816+
rdata[2].buffer = InvalidBuffer;
817+
rdata[2].data = (char*)rightpage + ((PageHeader)rightpage)->pd_upper;
818+
rdata[2].len = ((PageHeader)rightpage)->pd_special -
819+
((PageHeader)rightpage)->pd_upper;
820+
rdata[2].next = NULL;
821+
822+
if (!P_RIGHTMOST(ropaque))
823+
{
824+
rdata[2].next = &(rdata[3]);
825+
rdata[3].buffer = sbuf;
826+
rdata[3].data = NULL;
827+
rdata[3].len = 0;
828+
rdata[3].next = NULL;
829+
}
830+
831+
if (P_ISLEAF(lopaque))
832+
flag |= XLOG_BTREE_LEAF;
833+
834+
recptr = XLogInsert(RM_BTREE_ID, flag, rdata);
842835

843836
PageSetLSN(leftpage, recptr);
844837
PageSetSUI(leftpage, ThisStartUpID);
@@ -1143,25 +1136,29 @@ _bt_getstackbuf(Relation rel, BTStack stack)
11431136
void
11441137
_bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
11451138
{
1146-
Buffer rootbuf;
1147-
Page lpage,
1148-
rpage,
1149-
rootpage;
1150-
BlockNumber lbkno,
1151-
rbkno;
1152-
BlockNumber rootblknum;
1153-
BTPageOpaque rootopaque;
1154-
ItemId itemid;
1155-
BTItem item;
1156-
Size itemsz;
1157-
BTItem new_item;
1158-
Buffer metabuf;
1139+
Buffer rootbuf;
1140+
Page lpage,
1141+
rpage,
1142+
rootpage;
1143+
BlockNumber lbkno,
1144+
rbkno;
1145+
BlockNumber rootblknum;
1146+
BTPageOpaque rootopaque;
1147+
ItemId itemid;
1148+
BTItem item;
1149+
Size itemsz;
1150+
BTItem new_item;
1151+
Buffer metabuf;
1152+
Page metapg;
1153+
BTMetaPageData *metad;
11591154

11601155
/* get a new root page */
11611156
rootbuf = _bt_getbuf(rel, P_NEW, BT_WRITE);
11621157
rootpage = BufferGetPage(rootbuf);
11631158
rootblknum = BufferGetBlockNumber(rootbuf);
1164-
metabuf = _bt_getbuf(rel, BTREE_METAPAGE,BT_WRITE);
1159+
metabuf = _bt_getbuf(rel, BTREE_METAPAGE, BT_WRITE);
1160+
metapg = BufferGetPage(metabuf);
1161+
metad = BTPageGetMeta(metapg);
11651162

11661163
/* NO ELOG(ERROR) from here till newroot op is logged */
11671164
START_CRIT_CODE;
@@ -1222,39 +1219,46 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
12221219
elog(STOP, "btree: failed to add rightkey to new root page");
12231220
pfree(new_item);
12241221

1222+
metad->btm_root = rootblknum;
1223+
(metad->btm_level)++;
1224+
12251225
/* XLOG stuff */
12261226
{
12271227
xl_btree_newroot xlrec;
1228-
Page metapg = BufferGetPage(metabuf);
1229-
BTMetaPageData *metad = BTPageGetMeta(metapg);
12301228
XLogRecPtr recptr;
1229+
XLogRecData rdata[2];
12311230

12321231
xlrec.node = rel->rd_node;
1232+
xlrec.level = metad->btm_level;
12331233
BlockIdSet(&(xlrec.rootblk), rootblknum);
1234+
rdata[0].buffer = InvalidBuffer;
1235+
rdata[0].data = (char*)&xlrec;
1236+
rdata[0].len = SizeOfBtreeNewroot;
1237+
rdata[0].next = &(rdata[1]);
12341238

12351239
/*
12361240
* Dirrect access to page is not good but faster - we should
12371241
* implement some new func in page API.
12381242
*/
1239-
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_NEWROOT,
1240-
(char*)&xlrec, SizeOfBtreeNewroot,
1241-
(char*)rootpage + ((PageHeader) rootpage)->pd_upper,
1242-
((PageHeader) rootpage)->pd_special - ((PageHeader) rootpage)->pd_upper);
1243+
rdata[1].buffer = InvalidBuffer;
1244+
rdata[1].data = (char*)rootpage + ((PageHeader) rootpage)->pd_upper;
1245+
rdata[1].len = ((PageHeader)rootpage)->pd_special -
1246+
((PageHeader)rootpage)->pd_upper;
1247+
rdata[1].next = NULL;
12431248

1244-
metad->btm_root = rootblknum;
1245-
(metad->btm_level)++;
1249+
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_NEWROOT, rdata);
12461250

12471251
PageSetLSN(rootpage, recptr);
12481252
PageSetSUI(rootpage, ThisStartUpID);
12491253
PageSetLSN(metapg, recptr);
12501254
PageSetSUI(metapg, ThisStartUpID);
12511255

1252-
_bt_wrtbuf(rel, metabuf);
12531256
}
12541257
END_CRIT_CODE;
12551258

12561259
/* write and let go of the new root buffer */
12571260
_bt_wrtbuf(rel, rootbuf);
1261+
_bt_wrtbuf(rel, metabuf);
12581262

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

src/backend/access/nbtree/nbtpage.c

Lines changed: 25 additions & 8 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.43 2000/12/03 10:27:26 vadim Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.44 2000/12/28 13:00:07 vadim Exp $
1313
*
1414
* NOTES
1515
* Postgres btree pages look like ordinary relation pages. The opaque
@@ -167,6 +167,9 @@ _bt_getroot(Relation rel, int access)
167167
/* NO ELOG(ERROR) till meta is updated */
168168
START_CRIT_CODE;
169169

170+
metad->btm_root = rootblkno;
171+
metad->btm_level = 1;
172+
170173
_bt_pageinit(rootpage, BufferGetPageSize(rootbuf));
171174
rootopaque = (BTPageOpaque) PageGetSpecialPointer(rootpage);
172175
rootopaque->btpo_flags |= (BTP_LEAF | BTP_ROOT);
@@ -175,22 +178,26 @@ _bt_getroot(Relation rel, int access)
175178
{
176179
xl_btree_newroot xlrec;
177180
XLogRecPtr recptr;
181+
XLogRecData rdata;
178182

179183
xlrec.node = rel->rd_node;
184+
xlrec.level = 1;
180185
BlockIdSet(&(xlrec.rootblk), rootblkno);
186+
rdata.buffer = InvalidBuffer;
187+
rdata.data = (char*)&xlrec;
188+
rdata.len = SizeOfBtreeNewroot;
189+
rdata.next = NULL;
181190

182-
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_NEWROOT,
183-
(char*)&xlrec, SizeOfBtreeNewroot, NULL, 0);
191+
recptr = XLogInsert(RM_BTREE_ID,
192+
XLOG_BTREE_NEWROOT|XLOG_BTREE_LEAF, &rdata);
184193

185194
PageSetLSN(rootpage, recptr);
186195
PageSetSUI(rootpage, ThisStartUpID);
187196
PageSetLSN(metapg, recptr);
188197
PageSetSUI(metapg, ThisStartUpID);
189198
}
190-
END_CRIT_CODE;
191199

192-
metad->btm_root = rootblkno;
193-
metad->btm_level = 1;
200+
END_CRIT_CODE;
194201

195202
_bt_wrtnorelbuf(rel, rootbuf);
196203

@@ -408,11 +415,21 @@ _bt_pagedel(Relation rel, ItemPointer tid)
408415
{
409416
xl_btree_delete xlrec;
410417
XLogRecPtr recptr;
418+
XLogRecData rdata[2];
411419

412420
xlrec.target.node = rel->rd_node;
413421
xlrec.target.tid = *tid;
414-
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_DELETE,
415-
(char*) &xlrec, SizeOfBtreeDelete, NULL, 0);
422+
rdata[0].buffer = InvalidBuffer;
423+
rdata[0].data = (char*)&xlrec;
424+
rdata[0].len = SizeOfBtreeDelete;
425+
rdata[0].next = &(rdata[1]);
426+
427+
rdata[1].buffer = buf;
428+
rdata[1].data = NULL;
429+
rdata[1].len = 0;
430+
rdata[1].next = NULL;
431+
432+
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_DELETE, rdata);
416433

417434
PageSetLSN(page, recptr);
418435
PageSetSUI(page, ThisStartUpID);

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