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

Commit f45d12d

Browse files
committed
gin ptrack with xlog
1 parent d2282cd commit f45d12d

File tree

7 files changed

+105
-0
lines changed

7 files changed

+105
-0
lines changed

src/backend/access/gin/ginbtree.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "access/gin_private.h"
1818
#include "access/xloginsert.h"
19+
#include "access/ptrack.h"
1920
#include "miscadmin.h"
2021
#include "utils/memutils.h"
2122
#include "utils/rel.h"
@@ -385,6 +386,9 @@ ginPlaceToPage(GinBtree btree, GinBtreeStack *stack,
385386
else if (rc == GPTP_INSERT)
386387
{
387388
/* It will fit, perform the insertion */
389+
ptrack_add_block(btree->index, BufferGetBlockNumber(stack->buffer));
390+
if (BufferIsValid(childbuf))
391+
ptrack_add_block(btree->index, BufferGetBlockNumber(childbuf));
388392
START_CRIT_SECTION();
389393

390394
if (RelationNeedsWAL(btree->index) && !btree->isBuild)
@@ -534,6 +538,12 @@ ginPlaceToPage(GinBtree btree, GinBtreeStack *stack,
534538
* the new contents of the root.
535539
*/
536540

541+
ptrack_add_block(btree->index, BufferGetBlockNumber(rbuffer));
542+
ptrack_add_block(btree->index, BufferGetBlockNumber(stack->buffer));
543+
if (stack->parent == NULL)
544+
ptrack_add_block(btree->index, BufferGetBlockNumber(lbuffer));
545+
if (BufferIsValid(childbuf))
546+
ptrack_add_block(btree->index, BufferGetBlockNumber(childbuf));
537547
START_CRIT_SECTION();
538548

539549
MarkBufferDirty(rbuffer);

src/backend/access/gin/gindatapage.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "access/gin_private.h"
1818
#include "access/xloginsert.h"
19+
#include "access/ptrack.h"
1920
#include "lib/ilist.h"
2021
#include "miscadmin.h"
2122
#include "utils/rel.h"
@@ -835,6 +836,7 @@ ginVacuumPostingTreeLeaf(Relation indexrel, Buffer buffer, GinVacuumState *gvs)
835836
computeLeafRecompressWALData(leaf);
836837

837838
/* Apply changes to page */
839+
ptrack_add_block(indexrel, BufferGetBlockNumber(buffer));
838840
START_CRIT_SECTION();
839841

840842
dataPlaceToPageLeafRecompress(buffer, leaf);
@@ -1811,6 +1813,7 @@ createPostingTree(Relation index, ItemPointerData *items, uint32 nitems,
18111813
page = BufferGetPage(buffer);
18121814
blkno = BufferGetBlockNumber(buffer);
18131815

1816+
ptrack_add_block(index, BufferGetBlockNumber(buffer));
18141817
START_CRIT_SECTION();
18151818

18161819
PageRestoreTempPage(tmppage, page);

src/backend/access/gin/ginfast.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "access/gin_private.h"
2222
#include "access/xloginsert.h"
23+
#include "access/ptrack.h"
2324
#include "access/xlog.h"
2425
#include "commands/vacuum.h"
2526
#include "catalog/pg_am.h"
@@ -67,6 +68,7 @@ writeListPage(Relation index, Buffer buffer,
6768
/* workspace could be a local array; we use palloc for alignment */
6869
workspace = palloc(BLCKSZ);
6970

71+
ptrack_add_block(index, BufferGetBlockNumber(buffer));
7072
START_CRIT_SECTION();
7173

7274
GinInitBuffer(buffer, GIN_LIST);
@@ -293,6 +295,7 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
293295
/*
294296
* Main list is empty, so just insert sublist as main list
295297
*/
298+
ptrack_add_block(index, BufferGetBlockNumber(metabuffer));
296299
START_CRIT_SECTION();
297300

298301
metadata->head = sublist.head;
@@ -316,6 +319,8 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
316319

317320
Assert(GinPageGetOpaque(page)->rightlink == InvalidBlockNumber);
318321

322+
ptrack_add_block(index, BufferGetBlockNumber(metabuffer));
323+
ptrack_add_block(index, BufferGetBlockNumber(buffer));
319324
START_CRIT_SECTION();
320325

321326
GinPageGetOpaque(page)->rightlink = sublist.head;
@@ -358,6 +363,8 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
358363
if (needWal)
359364
XLogBeginInsert();
360365

366+
ptrack_add_block(index, BufferGetBlockNumber(metabuffer));
367+
ptrack_add_block(index, BufferGetBlockNumber(buffer));
361368
START_CRIT_SECTION();
362369

363370
/*
@@ -553,6 +560,7 @@ shiftList(Relation index, Buffer metabuffer, BlockNumber newHead,
553560
if (RelationNeedsWAL(index))
554561
XLogEnsureRecordSpace(data.ndeleted, 0);
555562

563+
ptrack_add_block(index, BufferGetBlockNumber(metabuffer));
556564
START_CRIT_SECTION();
557565

558566
metadata->head = blknoToDelete;

src/backend/access/gin/gininsert.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "access/gin_private.h"
1818
#include "access/xloginsert.h"
1919
#include "access/generic_xlog.h"
20+
#include "access/ptrack.h"
2021
#include "catalog/index.h"
2122
#include "miscadmin.h"
2223
#include "storage/bufmgr.h"
@@ -337,6 +338,8 @@ ginbuild(Relation heap, Relation index, IndexInfo *indexInfo)
337338
/* initialize the root page */
338339
RootBuffer = GinNewBuffer(index);
339340

341+
ptrack_add_block(index, BufferGetBlockNumber(MetaBuffer));
342+
ptrack_add_block(index, BufferGetBlockNumber(RootBuffer));
340343
START_CRIT_SECTION();
341344
GinInitMetabuffer(MetaBuffer);
342345
MarkBufferDirty(MetaBuffer);
@@ -430,6 +433,8 @@ ginbuildempty(Relation index)
430433
LockBuffer(RootBuffer, BUFFER_LOCK_EXCLUSIVE);
431434

432435
/* Initialize and xlog metabuffer and root buffer. */
436+
ptrack_add_block(index, BufferGetBlockNumber(MetaBuffer));
437+
ptrack_add_block(index, BufferGetBlockNumber(RootBuffer));
433438
START_CRIT_SECTION();
434439
GinInitMetabuffer(MetaBuffer);
435440
MarkBufferDirty(MetaBuffer);

src/backend/access/gin/ginutil.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "access/gin_private.h"
1818
#include "access/reloptions.h"
1919
#include "access/xloginsert.h"
20+
#include "access/ptrack.h"
2021
#include "catalog/pg_collation.h"
2122
#include "catalog/pg_type.h"
2223
#include "miscadmin.h"
@@ -639,6 +640,7 @@ ginUpdateStats(Relation index, const GinStatsData *stats, bool is_build)
639640
metapage = BufferGetPage(metabuffer);
640641
metadata = GinPageGetMeta(metapage);
641642

643+
ptrack_add_block(index, BufferGetBlockNumber(metabuffer));
642644
START_CRIT_SECTION();
643645

644646
metadata->nTotalPages = stats->nTotalPages;

src/backend/access/gin/ginvacuum.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "access/gin_private.h"
1818
#include "access/xloginsert.h"
19+
#include "access/ptrack.h"
1920
#include "commands/vacuum.h"
2021
#include "miscadmin.h"
2122
#include "postmaster/autovacuum.h"
@@ -209,6 +210,9 @@ ginDeletePage(GinVacuumState *gvs, BlockNumber deleteBlkno, BlockNumber leftBlkn
209210
* LockBufferForCleanup() */
210211
LockBuffer(pBuffer, GIN_EXCLUSIVE);
211212

213+
ptrack_add_block(gvs->index, BufferGetBlockNumber(pBuffer));
214+
ptrack_add_block(gvs->index, BufferGetBlockNumber(lBuffer));
215+
ptrack_add_block(gvs->index, BufferGetBlockNumber(dBuffer));
212216
START_CRIT_SECTION();
213217

214218
/* Unlink the page by changing left sibling's rightlink */
@@ -603,6 +607,7 @@ ginbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
603607

604608
if (resPage)
605609
{
610+
ptrack_add_block(gvs.index, BufferGetBlockNumber(buffer));
606611
START_CRIT_SECTION();
607612
PageRestoreTempPage(resPage, page);
608613
MarkBufferDirty(buffer);

src/backend/access/gin/ginxlog.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "access/gin_private.h"
1717
#include "access/xlogutils.h"
18+
#include "access/ptrack.h"
1819
#include "utils/memutils.h"
1920

2021
static MemoryContext opCtx; /* working memory for operations */
@@ -25,6 +26,11 @@ ginRedoClearIncompleteSplit(XLogReaderState *record, uint8 block_id)
2526
XLogRecPtr lsn = record->EndRecPtr;
2627
Buffer buffer;
2728
Page page;
29+
RelFileNode rnode;
30+
BlockNumber blkno;
31+
32+
XLogRecGetBlockTag(record, block_id, &rnode, NULL, &blkno);
33+
ptrack_add_block_redo(rnode, blkno);
2834

2935
if (XLogReadBufferForRedo(record, block_id, &buffer) == BLK_NEEDS_REDO)
3036
{
@@ -45,8 +51,12 @@ ginRedoCreateIndex(XLogReaderState *record)
4551
Buffer RootBuffer,
4652
MetaBuffer;
4753
Page page;
54+
RelFileNode rnode;
55+
56+
XLogRecGetBlockTag(record, 0, &rnode, NULL, NULL);
4857

4958
MetaBuffer = XLogInitBufferForRedo(record, 0);
59+
ptrack_add_block_redo(rnode, BufferGetBlockNumber(MetaBuffer));
5060
Assert(BufferGetBlockNumber(MetaBuffer) == GIN_METAPAGE_BLKNO);
5161
page = (Page) BufferGetPage(MetaBuffer);
5262

@@ -56,6 +66,7 @@ ginRedoCreateIndex(XLogReaderState *record)
5666
MarkBufferDirty(MetaBuffer);
5767

5868
RootBuffer = XLogInitBufferForRedo(record, 1);
69+
ptrack_add_block_redo(rnode, BufferGetBlockNumber(RootBuffer));
5970
Assert(BufferGetBlockNumber(RootBuffer) == GIN_ROOT_BLKNO);
6071
page = (Page) BufferGetPage(RootBuffer);
6172

@@ -76,8 +87,13 @@ ginRedoCreatePTree(XLogReaderState *record)
7687
char *ptr;
7788
Buffer buffer;
7889
Page page;
90+
RelFileNode rnode;
91+
92+
XLogRecGetBlockTag(record, 0, &rnode, NULL, NULL);
7993

8094
buffer = XLogInitBufferForRedo(record, 0);
95+
ptrack_add_block_redo(rnode, BufferGetBlockNumber(buffer));
96+
8197
page = (Page) BufferGetPage(buffer);
8298

8399
GinInitBuffer(buffer, GIN_DATA | GIN_LEAF | GIN_COMPRESSED);
@@ -329,6 +345,11 @@ ginRedoInsert(XLogReaderState *record)
329345
#endif
330346
BlockNumber rightChildBlkno = InvalidBlockNumber;
331347
bool isLeaf = (data->flags & GIN_INSERT_ISLEAF) != 0;
348+
RelFileNode rnode;
349+
BlockNumber blkno;
350+
351+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
352+
ptrack_add_block_redo(rnode, blkno);
332353

333354
/*
334355
* First clear incomplete-split flag on child page if this finishes a
@@ -382,6 +403,18 @@ ginRedoSplit(XLogReaderState *record)
382403
rootbuf;
383404
bool isLeaf = (data->flags & GIN_INSERT_ISLEAF) != 0;
384405
bool isRoot = (data->flags & GIN_SPLIT_ROOT) != 0;
406+
RelFileNode rnode;
407+
BlockNumber blkno;
408+
409+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
410+
ptrack_add_block_redo(rnode, blkno);
411+
XLogRecGetBlockTag(record, 1, &rnode, NULL, &blkno);
412+
ptrack_add_block_redo(rnode, blkno);
413+
if (isRoot)
414+
{
415+
XLogRecGetBlockTag(record, 2, &rnode, NULL, &blkno);
416+
ptrack_add_block_redo(rnode, blkno);
417+
}
385418

386419
/*
387420
* First clear incomplete-split flag on child page if this finishes a
@@ -415,6 +448,11 @@ static void
415448
ginRedoVacuumPage(XLogReaderState *record)
416449
{
417450
Buffer buffer;
451+
RelFileNode rnode;
452+
BlockNumber blkno;
453+
454+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
455+
ptrack_add_block_redo(rnode, blkno);
418456

419457
if (XLogReadBufferForRedo(record, 0, &buffer) != BLK_RESTORED)
420458
{
@@ -428,6 +466,11 @@ ginRedoVacuumDataLeafPage(XLogReaderState *record)
428466
{
429467
XLogRecPtr lsn = record->EndRecPtr;
430468
Buffer buffer;
469+
RelFileNode rnode;
470+
BlockNumber blkno;
471+
472+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
473+
ptrack_add_block_redo(rnode, blkno);
431474

432475
if (XLogReadBufferForRedo(record, 0, &buffer) == BLK_NEEDS_REDO)
433476
{
@@ -457,6 +500,15 @@ ginRedoDeletePage(XLogReaderState *record)
457500
Buffer pbuffer;
458501
Buffer lbuffer;
459502
Page page;
503+
RelFileNode rnode;
504+
BlockNumber blkno;
505+
506+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
507+
ptrack_add_block_redo(rnode, blkno);
508+
XLogRecGetBlockTag(record, 1, &rnode, NULL, &blkno);
509+
ptrack_add_block_redo(rnode, blkno);
510+
XLogRecGetBlockTag(record, 2, &rnode, NULL, &blkno);
511+
ptrack_add_block_redo(rnode, blkno);
460512

461513
if (XLogReadBufferForRedo(record, 0, &dbuffer) == BLK_NEEDS_REDO)
462514
{
@@ -502,6 +554,13 @@ ginRedoUpdateMetapage(XLogReaderState *record)
502554
Buffer metabuffer;
503555
Page metapage;
504556
Buffer buffer;
557+
RelFileNode rnode;
558+
BlockNumber blkno;
559+
560+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
561+
ptrack_add_block_redo(rnode, blkno);
562+
XLogRecGetBlockTag(record, 1, &rnode, NULL, &blkno);
563+
ptrack_add_block_redo(rnode, blkno);
505564

506565
/*
507566
* Restore the metapage. This is essentially the same as a full-page
@@ -600,6 +659,11 @@ ginRedoInsertListPage(XLogReaderState *record)
600659
char *payload;
601660
IndexTuple tuples;
602661
Size totaltupsize;
662+
RelFileNode rnode;
663+
BlockNumber blkno;
664+
665+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
666+
ptrack_add_block_redo(rnode, blkno);
603667

604668
/* We always re-initialize the page. */
605669
buffer = XLogInitBufferForRedo(record, 0);
@@ -649,6 +713,11 @@ ginRedoDeleteListPages(XLogReaderState *record)
649713
Buffer metabuffer;
650714
Page metapage;
651715
int i;
716+
RelFileNode rnode;
717+
BlockNumber blkno;
718+
719+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
720+
ptrack_add_block_redo(rnode, blkno);
652721

653722
metabuffer = XLogInitBufferForRedo(record, 0);
654723
Assert(BufferGetBlockNumber(metabuffer) == GIN_METAPAGE_BLKNO);
@@ -680,6 +749,9 @@ ginRedoDeleteListPages(XLogReaderState *record)
680749
Buffer buffer;
681750
Page page;
682751

752+
XLogRecGetBlockTag(record, i+1, &rnode, NULL, &blkno);
753+
ptrack_add_block_redo(rnode, blkno);
754+
683755
buffer = XLogInitBufferForRedo(record, i + 1);
684756
page = BufferGetPage(buffer);
685757
GinInitBuffer(buffer, GIN_DELETED);

0 commit comments

Comments
 (0)