Skip to content

Commit 10a8ab5

Browse files
committed
Merge branch 'PGPRO9622_ptrack1_2' into PGPRO9_6
2 parents 65a7e1d + 214c007 commit 10a8ab5

File tree

15 files changed

+85
-3
lines changed

15 files changed

+85
-3
lines changed

src/backend/access/heap/pruneheap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "access/transam.h"
2020
#include "access/htup_details.h"
2121
#include "access/xlog.h"
22+
#include "access/ptrack.h"
2223
#include "catalog/catalog.h"
2324
#include "miscadmin.h"
2425
#include "pgstat.h"
@@ -228,6 +229,7 @@ heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin,
228229
}
229230

230231
/* Any error while applying the changes is critical */
232+
ptrack_add_block(relation, BufferGetBlockNumber(buffer));
231233
START_CRIT_SECTION();
232234

233235
/* Have we found any prunable items? */

src/backend/access/heap/ptrack.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "utils/inval.h"
2929
#include "utils/array.h"
3030
#include "utils/relfilenodemap.h"
31+
#include "utils/builtins.h"
3132
#include <unistd.h>
3233
#include <sys/stat.h>
3334

@@ -661,3 +662,13 @@ pg_ptrack_get_and_clear(PG_FUNCTION_ARGS)
661662

662663
PG_RETURN_BYTEA_P(ptrack_get_and_clear(PG_GETARG_OID(0), PG_GETARG_OID(1)));
663664
}
665+
666+
/*
667+
* Returns ptrack version currently in use.
668+
*/
669+
PG_FUNCTION_INFO_V1(ptrack_version);
670+
Datum
671+
ptrack_version(PG_FUNCTION_ARGS)
672+
{
673+
PG_RETURN_TEXT_P(cstring_to_text(PTRACK_VERSION));
674+
}

src/backend/access/heap/rewriteheap.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
#include "access/tuptoaster.h"
115115
#include "access/xact.h"
116116
#include "access/xloginsert.h"
117+
#include "access/ptrack.h"
117118

118119
#include "catalog/catalog.h"
119120

@@ -330,11 +331,15 @@ end_heap_rewrite(RewriteState state)
330331
if (state->rs_buffer_valid)
331332
{
332333
if (state->rs_use_wal)
334+
{
335+
/* Don't forget to set ptrack bit even if we're skipping bufmgr stage */
336+
ptrack_add_block_redo(state->rs_new_rel->rd_node, state->rs_blockno);
333337
log_newpage(&state->rs_new_rel->rd_node,
334338
MAIN_FORKNUM,
335339
state->rs_blockno,
336340
state->rs_buffer,
337341
true);
342+
}
338343
RelationOpenSmgr(state->rs_new_rel);
339344

340345
PageSetChecksumInplace(state->rs_buffer, state->rs_blockno);
@@ -679,11 +684,15 @@ raw_heap_insert(RewriteState state, HeapTuple tup)
679684

680685
/* XLOG stuff */
681686
if (state->rs_use_wal)
687+
{
688+
/* Don't forget to set ptrack bit even if we're skipping bufmgr stage */
689+
ptrack_add_block_redo(state->rs_new_rel->rd_node, state->rs_blockno);
682690
log_newpage(&state->rs_new_rel->rd_node,
683691
MAIN_FORKNUM,
684692
state->rs_blockno,
685693
page,
686694
true);
695+
}
687696

688697
/*
689698
* Now write the page. We say isTemp = true even if it's not a

src/backend/access/nbtree/nbtree.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "access/nbtree.h"
2222
#include "access/relscan.h"
2323
#include "access/xlog.h"
24+
#include "access/ptrack.h"
2425
#include "catalog/index.h"
2526
#include "commands/vacuum.h"
2627
#include "storage/indexfsm.h"
@@ -253,9 +254,13 @@ btbuildempty(Relation index)
253254
PageSetChecksumInplace(metapage, BTREE_METAPAGE);
254255
smgrwrite(index->rd_smgr, INIT_FORKNUM, BTREE_METAPAGE,
255256
(char *) metapage, true);
257+
258+
/* Don't forget to set ptrack bit even if we're skipping bufmgr stage */
259+
ptrack_add_block_redo(index->rd_smgr->smgr_rnode.node, BTREE_METAPAGE);
256260
log_newpage(&index->rd_smgr->smgr_rnode.node, INIT_FORKNUM,
257261
BTREE_METAPAGE, metapage, false);
258-
262+
/* Ensure rd_smgr is open (could have been closed by relcache flush!) */
263+
RelationOpenSmgr(index);
259264
/*
260265
* An immediate sync is required even if we xlog'd the page, because the
261266
* write did not go through shared_buffers and therefore a concurrent

src/backend/access/nbtree/nbtsort.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#include "access/nbtree.h"
7070
#include "access/xlog.h"
7171
#include "access/xloginsert.h"
72+
#include "access/ptrack.h"
7273
#include "miscadmin.h"
7374
#include "storage/smgr.h"
7475
#include "tcop/tcopprot.h"
@@ -276,8 +277,12 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno)
276277
/* XLOG stuff */
277278
if (wstate->btws_use_wal)
278279
{
280+
/* Don't forget to set ptrack bit even if we're skipping bufmgr stage */
281+
ptrack_add_block_redo(wstate->index->rd_node, blkno);
279282
/* We use the heap NEWPAGE record type for this */
280283
log_newpage(&wstate->index->rd_node, MAIN_FORKNUM, blkno, page, true);
284+
/* Ensure rd_smgr is open (could have been closed by relcache flush!) */
285+
RelationOpenSmgr(wstate->index);
281286
}
282287

283288
/*

src/backend/access/spgist/spgdoinsert.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ addLeafTuple(Relation index, SpGistState *state, SpGistLeafTuple leafTuple,
215215
xlrec.nodeI = 0;
216216

217217
ptrack_add_block(index, BufferGetBlockNumber(current->buffer));
218+
if (parent->buffer)
219+
ptrack_add_block(index, BufferGetBlockNumber(parent->buffer));
218220
START_CRIT_SECTION();
219221

220222
if (current->offnum == InvalidOffsetNumber ||

src/backend/access/spgist/spginsert.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ spgbuildempty(Relation index)
196196
log_newpage(&index->rd_smgr->smgr_rnode.node, INIT_FORKNUM,
197197
SPGIST_NULL_BLKNO, page, true);
198198

199+
/* Don't forget to set ptrack bit even if we're skipping bufmgr stage */
200+
ptrack_add_block_redo(index->rd_smgr->smgr_rnode.node, SPGIST_METAPAGE_BLKNO);
201+
ptrack_add_block_redo(index->rd_smgr->smgr_rnode.node, SPGIST_ROOT_BLKNO);
202+
ptrack_add_block_redo(index->rd_smgr->smgr_rnode.node, SPGIST_NULL_BLKNO);
203+
204+
/* Ensure rd_smgr is open (could have been closed by relcache flush!) */
205+
RelationOpenSmgr(index);
199206
/*
200207
* An immediate sync is required even if we xlog'd the pages, because the
201208
* writes did not go through shared buffers and therefore a concurrent

src/backend/access/transam/xlog.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "access/xloginsert.h"
3636
#include "access/xlogreader.h"
3737
#include "access/xlogutils.h"
38+
#include "access/ptrack.h"
3839
#include "catalog/catversion.h"
3940
#include "catalog/pg_control.h"
4041
#include "catalog/pg_database.h"
@@ -9479,6 +9480,11 @@ xlog_redo(XLogReaderState *record)
94799480
else if (info == XLOG_FPI || info == XLOG_FPI_FOR_HINT)
94809481
{
94819482
Buffer buffer;
9483+
RelFileNode rnode;
9484+
BlockNumber blkno;
9485+
9486+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
9487+
ptrack_add_block_redo(rnode, blkno);
94829488

94839489
/*
94849490
* Full-page image (FPI) records contain nothing else but a backup

src/backend/access/transam/xloginsert.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "access/xlog.h"
2424
#include "access/xlog_internal.h"
2525
#include "access/xloginsert.h"
26+
#include "access/ptrack.h"
2627
#include "catalog/pg_control.h"
2728
#include "common/pg_lzcompress.h"
2829
#include "miscadmin.h"

src/backend/access/transam/xlogutils.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,6 @@ CreateFakeRelcacheEntry(RelFileNode rnode)
550550
FakeRelCacheEntry fakeentry;
551551
Relation rel;
552552

553-
Assert(InRecovery);
554-
555553
/* Allocate the Relation struct and all related space in one block. */
556554
fakeentry = palloc0(sizeof(FakeRelCacheEntryData));
557555
rel = (Relation) fakeentry;

src/backend/commands/sequence.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "access/xlog.h"
2222
#include "access/xloginsert.h"
2323
#include "access/xlogutils.h"
24+
#include "access/ptrack.h"
2425
#include "catalog/dependency.h"
2526
#include "catalog/namespace.h"
2627
#include "catalog/objectaccess.h"
@@ -365,6 +366,7 @@ fill_seq_with_data(Relation rel, HeapTuple tuple)
365366
if (RelationNeedsWAL(rel))
366367
GetTopTransactionId();
367368

369+
ptrack_add_block(rel, BufferGetBlockNumber(buf));
368370
START_CRIT_SECTION();
369371

370372
MarkBufferDirty(buf);
@@ -451,6 +453,7 @@ AlterSequence(AlterSeqStmt *stmt)
451453
GetTopTransactionId();
452454

453455
/* Now okay to update the on-disk tuple */
456+
ptrack_add_block(seqrel, BufferGetBlockNumber(buf));
454457
START_CRIT_SECTION();
455458

456459
memcpy(seq, &new, sizeof(FormData_pg_sequence));
@@ -711,6 +714,7 @@ nextval_internal(Oid relid)
711714
GetTopTransactionId();
712715

713716
/* ready to change the on-disk (or really, in-buffer) tuple */
717+
ptrack_add_block(seqrel, BufferGetBlockNumber(buf));
714718
START_CRIT_SECTION();
715719

716720
/*
@@ -910,6 +914,7 @@ do_setval(Oid relid, int64 next, bool iscalled)
910914
GetTopTransactionId();
911915

912916
/* ready to change the on-disk (or really, in-buffer) tuple */
917+
ptrack_add_block(seqrel, BufferGetBlockNumber(buf));
913918
START_CRIT_SECTION();
914919

915920
seq->last_value = next; /* last fetched number */
@@ -1586,6 +1591,11 @@ seq_redo(XLogReaderState *record)
15861591
Size itemsz;
15871592
xl_seq_rec *xlrec = (xl_seq_rec *) XLogRecGetData(record);
15881593
sequence_magic *sm;
1594+
RelFileNode rnode;
1595+
BlockNumber blkno;
1596+
1597+
XLogRecGetBlockTag(record, 0, &rnode, NULL, &blkno);
1598+
ptrack_add_block_redo(rnode, blkno);
15891599

15901600
if (info != XLOG_SEQ_LOG)
15911601
elog(PANIC, "seq_redo: unknown op code %u", info);

src/backend/commands/tablecmds.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "access/tupconvert.h"
2424
#include "access/xact.h"
2525
#include "access/xlog.h"
26+
#include "access/ptrack.h"
2627
#include "catalog/catalog.h"
2728
#include "catalog/dependency.h"
2829
#include "catalog/heap.h"
@@ -9761,6 +9762,13 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode)
97619762
/* copy those extra forks that exist */
97629763
for (forkNum = MAIN_FORKNUM + 1; forkNum <= MAX_FORKNUM; forkNum++)
97639764
{
9765+
/*
9766+
* Do not copy ptrack fork, because it will be created
9767+
* for new relation while copying data.
9768+
*/
9769+
if (forkNum == PAGESTRACK_FORKNUM)
9770+
continue;
9771+
97649772
if (smgrexists(rel->rd_smgr, forkNum))
97659773
{
97669774
smgrcreate(dstrel, forkNum, false);
@@ -10044,7 +10052,11 @@ copy_relation_data(SMgrRelation src, SMgrRelation dst,
1004410052
* space.
1004510053
*/
1004610054
if (use_wal)
10055+
{
10056+
if (forkNum == MAIN_FORKNUM)
10057+
ptrack_add_block_redo(dst->smgr_rnode.node, blkno);
1004710058
log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false);
10059+
}
1004810060

1004910061
PageSetChecksumInplace(page, blkno);
1005010062

src/backend/commands/vacuumlazy.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "access/transam.h"
4646
#include "access/visibilitymap.h"
4747
#include "access/xlog.h"
48+
#include "access/ptrack.h"
4849
#include "catalog/catalog.h"
4950
#include "catalog/storage.h"
5051
#include "commands/dbcommands.h"
@@ -856,6 +857,7 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats,
856857
empty_pages++;
857858
}
858859
freespace = PageGetHeapFreeSpace(page);
860+
ptrack_add_block(onerel, BufferGetBlockNumber(buf));
859861
MarkBufferDirty(buf);
860862
UnlockReleaseBuffer(buf);
861863

@@ -871,6 +873,7 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats,
871873
/* empty pages are always all-visible and all-frozen */
872874
if (!PageIsAllVisible(page))
873875
{
876+
ptrack_add_block(onerel, BufferGetBlockNumber(buf));
874877
START_CRIT_SECTION();
875878

876879
/* mark buffer dirty before writing a WAL record */
@@ -1096,6 +1099,7 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats,
10961099
*/
10971100
if (nfrozen > 0)
10981101
{
1102+
ptrack_add_block(onerel, BufferGetBlockNumber(buf));
10991103
START_CRIT_SECTION();
11001104

11011105
MarkBufferDirty(buf);
@@ -1169,6 +1173,7 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats,
11691173
* rare cases after a crash, it is not worth optimizing.
11701174
*/
11711175
PageSetAllVisible(page);
1176+
ptrack_add_block(onerel, BufferGetBlockNumber(buf));
11721177
MarkBufferDirty(buf);
11731178
visibilitymap_set(onerel, blkno, buf, InvalidXLogRecPtr,
11741179
vmbuffer, visibility_cutoff_xid, flags);
@@ -1208,6 +1213,7 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats,
12081213
elog(WARNING, "page containing dead tuples is marked as all-visible in relation \"%s\" page %u",
12091214
relname, blkno);
12101215
PageClearAllVisible(page);
1216+
ptrack_add_block(onerel, BufferGetBlockNumber(buf));
12111217
MarkBufferDirty(buf);
12121218
visibilitymap_clear(onerel, blkno, vmbuffer,
12131219
VISIBILITYMAP_VALID_BITS);
@@ -1444,6 +1450,7 @@ lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer,
14441450

14451451
pgstat_progress_update_param(PROGRESS_VACUUM_HEAP_BLKS_VACUUMED, blkno);
14461452

1453+
ptrack_add_block(onerel, BufferGetBlockNumber(buffer));
14471454
START_CRIT_SECTION();
14481455

14491456
for (; tupindex < vacrelstats->num_dead_tuples; tupindex++)

src/include/access/ptrack.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
#include "storage/relfilenode.h"
88
#include "utils/relcache.h"
99

10+
/* Ptrack version as a string */
11+
#define PTRACK_VERSION "1.2"
12+
/* Ptrack version as a number */
13+
#define PTRACK_VERSION_NUM 102
14+
1015
/* Number of bits allocated for each heap block. */
1116
#define PTRACK_BITS_PER_HEAPBLOCK 1
1217

src/include/catalog/pg_proc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5363,6 +5363,8 @@ DATA(insert OID = 6017 ( pg_ptrack_test PGNSP PGUID 12 1 0 0 0 f f f f t f v u
53635363
DESCR("test ptrack fork relation");
53645364
DATA(insert OID = 6018 ( pg_ptrack_get_and_clear PGNSP PGUID 12 1 0 0 0 f f f f t f v s 2 0 17 "26 26" _null_ _null_ _null_ _null_ _null_ pg_ptrack_get_and_clear _null_ _null_ _null_ ));
53655365
DESCR("get ptrack file as bytea and clear him");
5366+
DATA(insert OID = 6021 ( ptrack_version PGNSP PGUID 12 1 0 0 0 f f f f t f s s 0 0 25 "" _null_ _null_ _null_ _null_ _null_ ptrack_version _null_ _null_ _null_ ));
5367+
DESCR("Ptrack version string");
53665368

53675369
/*
53685370
* Symbolic values for proargmodes column. Note that these must agree with

0 commit comments

Comments
 (0)