Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d2282cd

Browse files
committed
btree ptrack with xlog
1 parent 0289709 commit d2282cd

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

src/backend/access/nbtree/nbtinsert.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "access/nbtree.h"
2020
#include "access/transam.h"
2121
#include "access/xloginsert.h"
22+
#include "access/ptrack.h"
2223
#include "miscadmin.h"
2324
#include "storage/lmgr.h"
2425
#include "storage/predicate.h"
@@ -839,6 +840,11 @@ _bt_insertonpg(Relation rel,
839840
}
840841

841842
/* Do the update. No ereport(ERROR) until changes are logged */
843+
ptrack_add_block(rel, BufferGetBlockNumber(buf));
844+
if (BufferIsValid(metabuf))
845+
ptrack_add_block(rel, BufferGetBlockNumber(metabuf));
846+
if (BufferIsValid(cbuf))
847+
ptrack_add_block(rel, BufferGetBlockNumber(cbuf));
842848
START_CRIT_SECTION();
843849

844850
if (!_bt_pgaddtup(page, itemsz, itup, newitemoff))
@@ -1243,6 +1249,12 @@ _bt_split(Relation rel, Buffer buf, Buffer cbuf, OffsetNumber firstright,
12431249
* not starting the critical section till here because we haven't been
12441250
* scribbling on the original page yet; see comments above.
12451251
*/
1252+
ptrack_add_block(rel, BufferGetBlockNumber(buf));
1253+
ptrack_add_block(rel, BufferGetBlockNumber(rbuf));
1254+
if (!P_RIGHTMOST(ropaque))
1255+
ptrack_add_block(rel, BufferGetBlockNumber(sbuf));
1256+
if (BufferIsValid(cbuf))
1257+
ptrack_add_block(rel, BufferGetBlockNumber(cbuf));
12461258
START_CRIT_SECTION();
12471259

12481260
/*
@@ -1995,6 +2007,9 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
19952007
ItemPointerSet(&(right_item->t_tid), rbkno, P_HIKEY);
19962008

19972009
/* NO EREPORT(ERROR) from here till newroot op is logged */
2010+
ptrack_add_block(rel, BufferGetBlockNumber(lbuf));
2011+
ptrack_add_block(rel, BufferGetBlockNumber(rootbuf));
2012+
ptrack_add_block(rel, BufferGetBlockNumber(metabuf));
19982013
START_CRIT_SECTION();
19992014

20002015
/* set btree special data */

src/backend/access/nbtree/nbtpage.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "access/transam.h"
2727
#include "access/xlog.h"
2828
#include "access/xloginsert.h"
29+
#include "access/ptrack.h"
2930
#include "miscadmin.h"
3031
#include "storage/indexfsm.h"
3132
#include "storage/lmgr.h"
@@ -221,6 +222,8 @@ _bt_getroot(Relation rel, int access)
221222
rootopaque->btpo_cycleid = 0;
222223

223224
/* NO ELOG(ERROR) till meta is updated */
225+
ptrack_add_block(rel, BufferGetBlockNumber(rootbuf));
226+
ptrack_add_block(rel, BufferGetBlockNumber(metabuf));
224227
START_CRIT_SECTION();
225228

226229
metad->btm_root = rootblkno;
@@ -793,6 +796,7 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
793796
BTPageOpaque opaque;
794797

795798
/* No ereport(ERROR) until changes are logged */
799+
ptrack_add_block(rel, BufferGetBlockNumber(buf));
796800
START_CRIT_SECTION();
797801

798802
/* Fix the page */
@@ -869,6 +873,7 @@ _bt_delitems_delete(Relation rel, Buffer buf,
869873
Assert(nitems > 0);
870874

871875
/* No ereport(ERROR) until changes are logged */
876+
ptrack_add_block(rel, BufferGetBlockNumber(buf));
872877
START_CRIT_SECTION();
873878

874879
/* Fix the page */
@@ -1410,6 +1415,8 @@ _bt_mark_page_halfdead(Relation rel, Buffer leafbuf, BTStack stack)
14101415
PredicateLockPageCombine(rel, leafblkno, leafrightsib);
14111416

14121417
/* No ereport(ERROR) until changes are logged */
1418+
ptrack_add_block(rel, BufferGetBlockNumber(topparent));
1419+
ptrack_add_block(rel, BufferGetBlockNumber(leafbuf));
14131420
START_CRIT_SECTION();
14141421

14151422
/*
@@ -1732,6 +1739,12 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, bool *rightsib_empty)
17321739
*/
17331740

17341741
/* No ereport(ERROR) until changes are logged */
1742+
ptrack_add_block(rel, BufferGetBlockNumber(rbuf));
1743+
ptrack_add_block(rel, BufferGetBlockNumber(buf));
1744+
if (BufferIsValid(lbuf))
1745+
ptrack_add_block(rel, BufferGetBlockNumber(lbuf));
1746+
if (BufferIsValid(metabuf))
1747+
ptrack_add_block(rel, BufferGetBlockNumber(metabuf));
17351748
START_CRIT_SECTION();
17361749

17371750
/*

src/backend/access/nbtree/nbtxlog.c

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "access/transam.h"
2121
#include "access/xlog.h"
2222
#include "access/xlogutils.h"
23+
#include "access/ptrack.h"
2324
#include "storage/procarray.h"
2425
#include "miscadmin.h"
2526

@@ -83,6 +84,11 @@ _bt_restore_meta(XLogReaderState *record, uint8 block_id)
8384
xl_btree_metadata *xlrec;
8485
char *ptr;
8586
Size len;
87+
RelFileNode rnode;
88+
BlockNumber blkno;
89+
90+
XLogRecGetBlockTag(record, block_id, &rnode, NULL, &blkno);
91+
ptrack_add_block_redo(rnode, blkno);
8692

8793
metabuf = XLogInitBufferForRedo(record, block_id);
8894
ptr = XLogRecGetBlockData(record, block_id, &len);
@@ -128,6 +134,11 @@ _bt_clear_incomplete_split(XLogReaderState *record, uint8 block_id)
128134
{
129135
XLogRecPtr lsn = record->EndRecPtr;
130136
Buffer buf;
137+
RelFileNode rnode;
138+
BlockNumber blkno;
139+
140+
XLogRecGetBlockTag(record, block_id, &rnode, NULL, &blkno);
141+
ptrack_add_block_redo(rnode, blkno);
131142

132143
if (XLogReadBufferForRedo(record, block_id, &buf) == BLK_NEEDS_REDO)
133144
{
@@ -151,6 +162,11 @@ btree_xlog_insert(bool isleaf, bool ismeta, XLogReaderState *record)
151162
xl_btree_insert *xlrec = (xl_btree_insert *) XLogRecGetData(record);
152163
Buffer buffer;
153164
Page page;
165+
RelFileNode rnode;
166+
BlockNumber blkno;
167+
168+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
169+
ptrack_add_block_redo(rnode, blkno);
154170

155171
/*
156172
* Insertion to an internal page finishes an incomplete split at the child
@@ -208,11 +224,17 @@ btree_xlog_split(bool onleft, bool isroot, XLogReaderState *record)
208224
BlockNumber leftsib;
209225
BlockNumber rightsib;
210226
BlockNumber rnext;
227+
RelFileNode rnode;
228+
229+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &leftsib);
230+
ptrack_add_block_redo(rnode, leftsib);
231+
XLogRecGetBlockTag(record, 1, &rnode, NULL, &rightsib);
232+
ptrack_add_block_redo(rnode, rightsib);
211233

212-
XLogRecGetBlockTag(record, 0, NULL, NULL, &leftsib);
213-
XLogRecGetBlockTag(record, 1, NULL, NULL, &rightsib);
214234
if (!XLogRecGetBlockTag(record, 2, NULL, NULL, &rnext))
215235
rnext = P_NONE;
236+
else
237+
ptrack_add_block_redo(rnode, rnext);
216238

217239
/*
218240
* Clear the incomplete split flag on the left sibling of the child page
@@ -389,6 +411,12 @@ btree_xlog_vacuum(XLogReaderState *record)
389411
Buffer buffer;
390412
Page page;
391413
BTPageOpaque opaque;
414+
RelFileNode rnode;
415+
BlockNumber blkno;
416+
417+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
418+
ptrack_add_block_redo(rnode, blkno);
419+
392420
#ifdef UNUSED
393421
xl_btree_vacuum *xlrec = (xl_btree_vacuum *) XLogRecGetData(record);
394422

@@ -567,6 +595,7 @@ btree_xlog_delete_get_latestRemovedXid(XLogReaderState *record)
567595
* overkill, but it's safe, and certainly better than panicking here.
568596
*/
569597
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
598+
ptrack_add_block_redo(rnode, blkno);
570599
ibuffer = XLogReadBufferExtended(rnode, MAIN_FORKNUM, blkno, RBM_NORMAL);
571600
if (!BufferIsValid(ibuffer))
572601
return InvalidTransactionId;
@@ -592,6 +621,7 @@ btree_xlog_delete_get_latestRemovedXid(XLogReaderState *record)
592621
*/
593622
hblkno = ItemPointerGetBlockNumber(&(itup->t_tid));
594623
hbuffer = XLogReadBufferExtended(xlrec->hnode, MAIN_FORKNUM, hblkno, RBM_NORMAL);
624+
ptrack_add_block_redo(rnode, hblkno);
595625
if (!BufferIsValid(hbuffer))
596626
{
597627
UnlockReleaseBuffer(ibuffer);
@@ -670,6 +700,11 @@ btree_xlog_delete(XLogReaderState *record)
670700
Buffer buffer;
671701
Page page;
672702
BTPageOpaque opaque;
703+
RelFileNode rnode;
704+
BlockNumber blkno;
705+
706+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
707+
ptrack_add_block_redo(rnode, blkno);
673708

674709
/*
675710
* If we have any conflict processing to do, it must happen before we
@@ -732,6 +767,13 @@ btree_xlog_mark_page_halfdead(uint8 info, XLogReaderState *record)
732767
Page page;
733768
BTPageOpaque pageop;
734769
IndexTupleData trunctuple;
770+
RelFileNode rnode;
771+
BlockNumber blkno;
772+
773+
XLogRecGetBlockTag(record, 1, &rnode, NULL, &blkno);
774+
ptrack_add_block_redo(rnode, blkno);
775+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
776+
ptrack_add_block_redo(rnode, blkno);
735777

736778
/*
737779
* In normal operation, we would lock all the pages this WAL record
@@ -815,10 +857,27 @@ btree_xlog_unlink_page(uint8 info, XLogReaderState *record)
815857
Buffer buffer;
816858
Page page;
817859
BTPageOpaque pageop;
860+
RelFileNode rnode;
861+
BlockNumber blkno;
818862

819863
leftsib = xlrec->leftsib;
820864
rightsib = xlrec->rightsib;
821865

866+
XLogRecGetBlockTag(record, 2, &rnode, NULL, &blkno);
867+
ptrack_add_block_redo(rnode, blkno);
868+
if (leftsib != P_NONE)
869+
{
870+
XLogRecGetBlockTag(record, 1, &rnode, NULL, &blkno);
871+
ptrack_add_block_redo(rnode, blkno);
872+
}
873+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
874+
ptrack_add_block_redo(rnode, blkno);
875+
if (XLogRecHasBlockRef(record, 3))
876+
{
877+
XLogRecGetBlockTag(record, 3, &rnode, NULL, &blkno);
878+
ptrack_add_block_redo(rnode, blkno);
879+
}
880+
822881
/*
823882
* In normal operation, we would lock all the pages this WAL record
824883
* touches before changing any of them. In WAL replay, it should be okay
@@ -929,6 +988,11 @@ btree_xlog_newroot(XLogReaderState *record)
929988
BTPageOpaque pageop;
930989
char *ptr;
931990
Size len;
991+
RelFileNode rnode;
992+
BlockNumber blkno;
993+
994+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
995+
ptrack_add_block_redo(rnode, blkno);
932996

933997
buffer = XLogInitBufferForRedo(record, 0);
934998
page = (Page) BufferGetPage(buffer);

0 commit comments

Comments
 (0)