Set last-written LSN as part of smgr_end_unlogged_build() (#11584)

This way, the callers don't need to do it, reducing the footprint of
changes we've had to made to various index AM's build functions.
This commit is contained in:
Heikki Linnakangas
2025-04-16 15:34:18 +03:00
committed by GitHub
parent 96b46365e4
commit b4e26a6284
8 changed files with 40 additions and 46 deletions

View File

@@ -15,7 +15,7 @@ index 7a4b88c..56678af 100644
HEADERS = src/halfvec.h src/sparsevec.h src/vector.h HEADERS = src/halfvec.h src/sparsevec.h src/vector.h
diff --git a/src/hnswbuild.c b/src/hnswbuild.c diff --git a/src/hnswbuild.c b/src/hnswbuild.c
index b667478..dc95d89 100644 index b667478..1298aa1 100644
--- a/src/hnswbuild.c --- a/src/hnswbuild.c
+++ b/src/hnswbuild.c +++ b/src/hnswbuild.c
@@ -843,9 +843,17 @@ HnswParallelBuildMain(dsm_segment *seg, shm_toc *toc) @@ -843,9 +843,17 @@ HnswParallelBuildMain(dsm_segment *seg, shm_toc *toc)
@@ -36,7 +36,7 @@ index b667478..dc95d89 100644
/* Close relations within worker */ /* Close relations within worker */
index_close(indexRel, indexLockmode); index_close(indexRel, indexLockmode);
table_close(heapRel, heapLockmode); table_close(heapRel, heapLockmode);
@@ -1100,12 +1108,39 @@ BuildIndex(Relation heap, Relation index, IndexInfo *indexInfo, @@ -1100,13 +1108,25 @@ BuildIndex(Relation heap, Relation index, IndexInfo *indexInfo,
SeedRandom(42); SeedRandom(42);
#endif #endif
@@ -48,32 +48,17 @@ index b667478..dc95d89 100644
BuildGraph(buildstate, forkNum); BuildGraph(buildstate, forkNum);
- if (RelationNeedsWAL(index) || forkNum == INIT_FORKNUM)
+#ifdef NEON_SMGR +#ifdef NEON_SMGR
+ smgr_finish_unlogged_build_phase_1(RelationGetSmgr(index)); + smgr_finish_unlogged_build_phase_1(RelationGetSmgr(index));
+#endif +#endif
+ +
+ if (RelationNeedsWAL(index) || forkNum == INIT_FORKNUM) { if (RelationNeedsWAL(index) || forkNum == INIT_FORKNUM)
log_newpage_range(index, forkNum, 0, RelationGetNumberOfBlocksInFork(index, forkNum), true); log_newpage_range(index, forkNum, 0, RelationGetNumberOfBlocksInFork(index, forkNum), true);
+#ifdef NEON_SMGR
+ {
+#if PG_VERSION_NUM >= 160000
+ RelFileLocator rlocator = RelationGetSmgr(index)->smgr_rlocator.locator;
+#else
+ RelFileNode rlocator = RelationGetSmgr(index)->smgr_rnode.node;
+#endif
+ if (set_lwlsn_block_range_hook)
+ set_lwlsn_block_range_hook(XactLastRecEnd, rlocator,
+ MAIN_FORKNUM, 0, RelationGetNumberOfBlocks(index));
+ if (set_lwlsn_relation_hook)
+ set_lwlsn_relation_hook(XactLastRecEnd, rlocator, MAIN_FORKNUM);
+ }
+#endif
+ }
+
+#ifdef NEON_SMGR +#ifdef NEON_SMGR
+ smgr_end_unlogged_build(RelationGetSmgr(index)); + smgr_end_unlogged_build(RelationGetSmgr(index));
+#endif +#endif
+
FreeBuildState(buildstate); FreeBuildState(buildstate);
} }

View File

@@ -1,5 +1,5 @@
diff --git a/src/ruminsert.c b/src/ruminsert.c diff --git a/src/ruminsert.c b/src/ruminsert.c
index 255e616..7a2240f 100644 index 255e616..1c6edb7 100644
--- a/src/ruminsert.c --- a/src/ruminsert.c
+++ b/src/ruminsert.c +++ b/src/ruminsert.c
@@ -628,6 +628,10 @@ rumbuild(Relation heap, Relation index, struct IndexInfo *indexInfo) @@ -628,6 +628,10 @@ rumbuild(Relation heap, Relation index, struct IndexInfo *indexInfo)
@@ -24,24 +24,12 @@ index 255e616..7a2240f 100644
/* /*
* Write index to xlog * Write index to xlog
*/ */
@@ -713,6 +721,22 @@ rumbuild(Relation heap, Relation index, struct IndexInfo *indexInfo) @@ -713,6 +721,10 @@ rumbuild(Relation heap, Relation index, struct IndexInfo *indexInfo)
UnlockReleaseBuffer(buffer); UnlockReleaseBuffer(buffer);
} }
+#ifdef NEON_SMGR +#ifdef NEON_SMGR
+ { + smgr_end_unlogged_build(index->rd_smgr);
+#if PG_VERSION_NUM >= 160000
+ RelFileLocator rlocator = RelationGetSmgr(index)->smgr_rlocator.locator;
+#else
+ RelFileNode rlocator = RelationGetSmgr(index)->smgr_rnode.node;
+#endif
+ if (set_lwlsn_block_range_hook)
+ set_lwlsn_block_range_hook(XactLastRecEnd, rlocator, MAIN_FORKNUM, 0, RelationGetNumberOfBlocks(index));
+ if (set_lwlsn_relation_hook)
+ set_lwlsn_relation_hook(XactLastRecEnd, rlocator, MAIN_FORKNUM);
+
+ smgr_end_unlogged_build(index->rd_smgr);
+ }
+#endif +#endif
+ +
/* /*

View File

@@ -2040,7 +2040,7 @@ neon_finish_unlogged_build_phase_1(SMgrRelation reln)
/* /*
* neon_end_unlogged_build() -- Finish an unlogged rel build. * neon_end_unlogged_build() -- Finish an unlogged rel build.
* *
* Call this after you have finished WAL-logging an relation that was * Call this after you have finished WAL-logging a relation that was
* first populated without WAL-logging. * first populated without WAL-logging.
* *
* This removes the local copy of the rel, since it's now been fully * This removes the local copy of the rel, since it's now been fully
@@ -2059,14 +2059,35 @@ neon_end_unlogged_build(SMgrRelation reln)
if (unlogged_build_phase != UNLOGGED_BUILD_NOT_PERMANENT) if (unlogged_build_phase != UNLOGGED_BUILD_NOT_PERMANENT)
{ {
XLogRecPtr recptr;
BlockNumber nblocks;
Assert(unlogged_build_phase == UNLOGGED_BUILD_PHASE_2); Assert(unlogged_build_phase == UNLOGGED_BUILD_PHASE_2);
Assert(reln->smgr_relpersistence == RELPERSISTENCE_UNLOGGED); Assert(reln->smgr_relpersistence == RELPERSISTENCE_UNLOGGED);
/*
* Update the last-written LSN cache.
*
* The relation is still on local disk so we can get the size by
* calling mdnblocks() directly. For the LSN, GetXLogInsertRecPtr() is
* very conservative. If we could assume that this function is called
* from the same backend that WAL-logged the contents, we could use
* XactLastRecEnd here. But better safe than sorry.
*/
nblocks = mdnblocks(reln, MAIN_FORKNUM);
recptr = GetXLogInsertRecPtr();
neon_set_lwlsn_block_range(recptr,
InfoFromNInfoB(rinfob),
MAIN_FORKNUM, 0, nblocks);
neon_set_lwlsn_relation(recptr,
InfoFromNInfoB(rinfob),
MAIN_FORKNUM);
/* Make the relation look permanent again */ /* Make the relation look permanent again */
reln->smgr_relpersistence = RELPERSISTENCE_PERMANENT; reln->smgr_relpersistence = RELPERSISTENCE_PERMANENT;
/* Remove local copy */ /* Remove local copy */
rinfob = InfoBFromSMgrRel(reln);
for (int forknum = 0; forknum <= MAX_FORKNUM; forknum++) for (int forknum = 0; forknum <= MAX_FORKNUM; forknum++)
{ {
neon_log(SmgrTrace, "forgetting cached relsize for %u/%u/%u.%u", neon_log(SmgrTrace, "forgetting cached relsize for %u/%u/%u.%u",

View File

@@ -1,18 +1,18 @@
{ {
"v17": [ "v17": [
"17.4", "17.4",
"66114c23bc61205b0e3fb1e77ee76a4abc1eb4b8" "eab3a37834cac6ec0719bf817ac918a201712d66"
], ],
"v16": [ "v16": [
"16.8", "16.8",
"d56e79cd5d6136c159b1d8d98acb7981d4b69364" "37496f87b5324af53c56127e278ee5b1e8435253"
], ],
"v15": [ "v15": [
"15.12", "15.12",
"aeb292eeace9072e07071254b6ffc7a74007d4d2" "8ecb12f21d862dfa39f7204b8f5e1c00a2a225b3"
], ],
"v14": [ "v14": [
"14.17", "14.17",
"a0391901a2af13aa029b905272a5b2024133c926" "d3c9d61fb7a362a165dac7060819dd9d6ad68c28"
] ]
} }