Skip to content

Commit 86bcaf6

Browse files
committed
brin ptrack with xlog
1 parent 132c495 commit 86bcaf6

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

src/backend/access/brin/brin.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "access/reloptions.h"
2323
#include "access/relscan.h"
2424
#include "access/xloginsert.h"
25+
#include "access/ptrack.h"
2526
#include "catalog/index.h"
2627
#include "catalog/pg_am.h"
2728
#include "miscadmin.h"
@@ -685,6 +686,7 @@ brinbuildempty(Relation index)
685686
LockBuffer(metabuf, BUFFER_LOCK_EXCLUSIVE);
686687

687688
/* Initialize and xlog metabuffer. */
689+
ptrack_add_block(index, BufferGetBlockNumber(metabuf));
688690
START_CRIT_SECTION();
689691
brin_metapage_init(BufferGetPage(metabuf), BrinGetPagesPerRange(index),
690692
BRIN_CURRENT_VERSION);

src/backend/access/brin/brin_pageops.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "access/brin_revmap.h"
1616
#include "access/brin_xlog.h"
1717
#include "access/xloginsert.h"
18+
#include "access/ptrack.h"
1819
#include "miscadmin.h"
1920
#include "storage/bufmgr.h"
2021
#include "storage/freespace.h"
@@ -177,6 +178,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
177178
UnlockReleaseBuffer(newbuf);
178179
}
179180

181+
ptrack_add_block(idxrel, BufferGetBlockNumber(oldbuf));
180182
START_CRIT_SECTION();
181183
PageIndexDeleteNoCompact(oldpage, &oldoff, 1);
182184
if (PageAddItemExtended(oldpage, (Item) newtup, newsz, oldoff,
@@ -237,6 +239,9 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
237239

238240
revmapbuf = brinLockRevmapPageForUpdate(revmap, heapBlk);
239241

242+
ptrack_add_block(idxrel, BufferGetBlockNumber(newbuf));
243+
ptrack_add_block(idxrel, BufferGetBlockNumber(oldbuf));
244+
ptrack_add_block(idxrel, BufferGetBlockNumber(revmapbuf));
240245
START_CRIT_SECTION();
241246

242247
/*
@@ -408,6 +413,8 @@ brin_doinsert(Relation idxrel, BlockNumber pagesPerRange,
408413
blk = BufferGetBlockNumber(*buffer);
409414

410415
/* Execute the actual insertion */
416+
ptrack_add_block(idxrel, BufferGetBlockNumber(*buffer));
417+
ptrack_add_block(idxrel, BufferGetBlockNumber(revmapbuf));
411418
START_CRIT_SECTION();
412419
if (extended)
413420
brin_page_init(BufferGetPage(*buffer), BRIN_PAGETYPE_REGULAR);
@@ -862,6 +869,7 @@ brin_initialize_empty_new_buffer(Relation idxrel, Buffer buffer)
862869
"brin_initialize_empty_new_buffer: initializing blank page %u",
863870
BufferGetBlockNumber(buffer)));
864871

872+
ptrack_add_block(idxrel, BufferGetBlockNumber(buffer));
865873
START_CRIT_SECTION();
866874
page = BufferGetPage(buffer);
867875
brin_page_init(page, BRIN_PAGETYPE_REGULAR);

src/backend/access/brin/brin_revmap.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "access/brin_xlog.h"
2828
#include "access/rmgr.h"
2929
#include "access/xloginsert.h"
30+
#include "access/ptrack.h"
3031
#include "miscadmin.h"
3132
#include "storage/bufmgr.h"
3233
#include "storage/lmgr.h"
@@ -475,6 +476,8 @@ revmap_physical_extend(BrinRevmap *revmap)
475476
* Ok, we have now locked the metapage and the target block. Re-initialize
476477
* it as a revmap page.
477478
*/
479+
ptrack_add_block(irel, BufferGetBlockNumber(buf));
480+
ptrack_add_block(irel, BufferGetBlockNumber(revmap->rm_metaBuf));
478481
START_CRIT_SECTION();
479482

480483
/* the rm_tids array is initialized to all invalid by PageInit */

src/backend/access/brin/brin_xlog.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "access/brin_pageops.h"
1515
#include "access/brin_xlog.h"
1616
#include "access/xlogutils.h"
17+
#include "access/ptrack.h"
1718

1819

1920
/*
@@ -26,6 +27,11 @@ brin_xlog_createidx(XLogReaderState *record)
2627
xl_brin_createidx *xlrec = (xl_brin_createidx *) XLogRecGetData(record);
2728
Buffer buf;
2829
Page page;
30+
RelFileNode rnode;
31+
BlockNumber blkno;
32+
33+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
34+
ptrack_add_block_redo(rnode, blkno);
2935

3036
/* create the index' metapage */
3137
buf = XLogInitBufferForRedo(record, 0);
@@ -50,6 +56,13 @@ brin_xlog_insert_update(XLogReaderState *record,
5056
BlockNumber regpgno;
5157
Page page;
5258
XLogRedoAction action;
59+
RelFileNode rnode;
60+
BlockNumber blkno;
61+
62+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
63+
ptrack_add_block_redo(rnode, blkno);
64+
XLogRecGetBlockTag(record, 1, &rnode, NULL, &blkno);
65+
ptrack_add_block_redo(rnode, blkno);
5366

5467
/*
5568
* If we inserted the first and only tuple on the page, re-initialize the
@@ -137,9 +150,15 @@ brin_xlog_update(XLogReaderState *record)
137150
xl_brin_update *xlrec = (xl_brin_update *) XLogRecGetData(record);
138151
Buffer buffer;
139152
XLogRedoAction action;
153+
RelFileNode rnode;
154+
BlockNumber blkno;
155+
156+
XLogRecGetBlockTag(record, 2, &rnode, NULL, &blkno);
157+
ptrack_add_block_redo(rnode, blkno);
140158

141159
/* First remove the old tuple */
142160
action = XLogReadBufferForRedo(record, 2, &buffer);
161+
143162
if (action == BLK_NEEDS_REDO)
144163
{
145164
Page page;
@@ -174,9 +193,15 @@ brin_xlog_samepage_update(XLogReaderState *record)
174193
xl_brin_samepage_update *xlrec;
175194
Buffer buffer;
176195
XLogRedoAction action;
196+
RelFileNode rnode;
197+
BlockNumber blkno;
198+
199+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
200+
ptrack_add_block_redo(rnode, blkno);
177201

178202
xlrec = (xl_brin_samepage_update *) XLogRecGetData(record);
179203
action = XLogReadBufferForRedo(record, 0, &buffer);
204+
180205
if (action == BLK_NEEDS_REDO)
181206
{
182207
Size tuplen;
@@ -220,14 +245,21 @@ brin_xlog_revmap_extend(XLogReaderState *record)
220245
Page page;
221246
BlockNumber targetBlk;
222247
XLogRedoAction action;
248+
RelFileNode rnode;
249+
BlockNumber blkno;
223250

224251
xlrec = (xl_brin_revmap_extend *) XLogRecGetData(record);
225252

226-
XLogRecGetBlockTag(record, 1, NULL, NULL, &targetBlk);
253+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
254+
ptrack_add_block_redo(rnode, blkno);
255+
XLogRecGetBlockTag(record, 1, &rnode, NULL, &targetBlk);
256+
ptrack_add_block_redo(rnode, targetBlk);
257+
227258
Assert(xlrec->targetBlk == targetBlk);
228259

229260
/* Update the metapage */
230261
action = XLogReadBufferForRedo(record, 0, &metabuf);
262+
231263
if (action == BLK_NEEDS_REDO)
232264
{
233265
Page metapg;

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