diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c index 4d33e986c40..56968b95acf 100644 --- a/src/backend/access/gin/gininsert.c +++ b/src/backend/access/gin/gininsert.c @@ -335,8 +335,6 @@ ginbuild(Relation heap, Relation index, IndexInfo *indexInfo) elog(ERROR, "index \"%s\" already contains data", RelationGetRelationName(index)); - smgr_start_unlogged_build(index->rd_smgr); - initGinState(&buildstate.ginstate, index); buildstate.indtuples = 0; memset(&buildstate.buildStats, 0, sizeof(GinStatsData)); @@ -410,8 +408,6 @@ ginbuild(Relation heap, Relation index, IndexInfo *indexInfo) buildstate.buildStats.nTotalPages = RelationGetNumberOfBlocks(index); ginUpdateStats(index, &buildstate.buildStats, true); - smgr_finish_unlogged_build_phase_1(index->rd_smgr); - /* * We didn't write WAL records as we built the index, so if WAL-logging is * required, write all pages to the WAL now. @@ -421,12 +417,8 @@ ginbuild(Relation heap, Relation index, IndexInfo *indexInfo) log_newpage_range(index, MAIN_FORKNUM, 0, RelationGetNumberOfBlocks(index), true); - SetLastWrittenLSNForBlockRange(XactLastRecEnd, index->rd_smgr->smgr_rlocator.locator, MAIN_FORKNUM, 0, RelationGetNumberOfBlocks(index)); - SetLastWrittenLSNForRelation(XactLastRecEnd, index->rd_smgr->smgr_rlocator.locator, MAIN_FORKNUM); } - smgr_end_unlogged_build(index->rd_smgr); - /* * Return statistics */ diff --git a/src/backend/access/gist/gistbuild.c b/src/backend/access/gist/gistbuild.c index b60cdbb627e..dc7867f7a5b 100644 --- a/src/backend/access/gist/gistbuild.c +++ b/src/backend/access/gist/gistbuild.c @@ -298,8 +298,6 @@ gistbuild(Relation heap, Relation index, IndexInfo *indexInfo) Buffer buffer; Page page; - smgr_start_unlogged_build(index->rd_smgr); - /* initialize the root page */ buffer = gistNewBuffer(index, heap); Assert(BufferGetBlockNumber(buffer) == GIST_ROOT_BLKNO); @@ -332,8 +330,6 @@ gistbuild(Relation heap, Relation index, IndexInfo *indexInfo) gistFreeBuildBuffers(buildstate.gfbb); } - smgr_finish_unlogged_build_phase_1(index->rd_smgr); - /* * We didn't write WAL records as we built the index, so if * WAL-logging is required, write all pages to the WAL now. @@ -343,13 +339,7 @@ gistbuild(Relation heap, Relation index, IndexInfo *indexInfo) log_newpage_range(index, MAIN_FORKNUM, 0, RelationGetNumberOfBlocks(index), true); - SetLastWrittenLSNForBlockRange(XactLastRecEnd, - index->rd_smgr->smgr_rlocator.locator, - MAIN_FORKNUM, 0, RelationGetNumberOfBlocks(index)); - SetLastWrittenLSNForRelation(XactLastRecEnd, index->rd_smgr->smgr_rlocator.locator, MAIN_FORKNUM); } - - smgr_end_unlogged_build(index->rd_smgr); } /* okay, all heap tuples are indexed */ diff --git a/src/backend/access/gist/gistutil.c b/src/backend/access/gist/gistutil.c index b6bc8c2c56d..738eedad5af 100644 --- a/src/backend/access/gist/gistutil.c +++ b/src/backend/access/gist/gistutil.c @@ -793,13 +793,15 @@ gistcheckpage(Relation rel, Buffer buf) * case, however. */ if (PageIsNew(page)) + { ereport(ERROR, (errcode(ERRCODE_INDEX_CORRUPTED), - errmsg("index \"%s\" contains unexpected zero page at block %u", + errmsg("index \"%s\" (%d) contains unexpected zero page at block %u", RelationGetRelationName(rel), + RelationGetRelid(rel), BufferGetBlockNumber(buf)), errhint("Please REINDEX it."))); - + } /* * Additionally check that the special area looks sane. */ diff --git a/src/backend/access/spgist/spginsert.c b/src/backend/access/spgist/spginsert.c index 7484149cbb7..4443f1918df 100644 --- a/src/backend/access/spgist/spginsert.c +++ b/src/backend/access/spgist/spginsert.c @@ -85,8 +85,6 @@ spgbuild(Relation heap, Relation index, IndexInfo *indexInfo) elog(ERROR, "index \"%s\" already contains data", RelationGetRelationName(index)); - smgr_start_unlogged_build(index->rd_smgr); - /* * Initialize the meta page and root pages */ @@ -133,8 +131,6 @@ spgbuild(Relation heap, Relation index, IndexInfo *indexInfo) SpGistUpdateMetaPage(index); - smgr_finish_unlogged_build_phase_1(index->rd_smgr); - /* * We didn't write WAL records as we built the index, so if WAL-logging is * required, write all pages to the WAL now. @@ -144,13 +140,8 @@ spgbuild(Relation heap, Relation index, IndexInfo *indexInfo) log_newpage_range(index, MAIN_FORKNUM, 0, RelationGetNumberOfBlocks(index), true); - SetLastWrittenLSNForBlockRange(XactLastRecEnd, index->rd_smgr->smgr_rlocator.locator, - MAIN_FORKNUM, 0, RelationGetNumberOfBlocks(index)); - SetLastWrittenLSNForRelation(XactLastRecEnd, index->rd_smgr->smgr_rlocator.locator, MAIN_FORKNUM); } - smgr_end_unlogged_build(index->rd_smgr); - result = (IndexBuildResult *) palloc0(sizeof(IndexBuildResult)); result->heap_tuples = reltuples; result->index_tuples = buildstate.indtuples; diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c index 1fc2159b193..6a737055972 100644 --- a/src/backend/access/transam/xloginsert.c +++ b/src/backend/access/transam/xloginsert.c @@ -41,6 +41,7 @@ #include "storage/bufmgr.h" #include "storage/proc.h" #include "utils/memutils.h" +#include "utils/rel.h" #include "utils/wait_event.h" /* @@ -94,6 +95,8 @@ int max_replication_apply_lag; int max_replication_flush_lag; int max_replication_write_lag; +log_newpage_range_callback_t log_newpage_range_callback; + static registered_buffer *registered_buffers; static int max_registered_buffers; /* allocated size */ static int max_registered_block_id = 0; /* highest block_id + 1 currently @@ -1305,6 +1308,7 @@ log_newpage_range(Relation rel, ForkNumber forknum, XLogRecPtr recptr; int nbufs; int i; + BlockNumber firstblk = blkno; CHECK_FOR_INTERRUPTS(); @@ -1335,7 +1339,6 @@ log_newpage_range(Relation rel, ForkNumber forknum, /* Write WAL record for this batch. */ XLogBeginInsert(); - START_CRIT_SECTION(); for (i = 0; i < nbufs; i++) { @@ -1344,7 +1347,9 @@ log_newpage_range(Relation rel, ForkNumber forknum, } recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI); - + SetLastWrittenLSNForBlockRange(recptr, rel->rd_smgr->smgr_rlocator.locator, + forknum, firstblk, blkno - firstblk); + SetLastWrittenLSNForRelation(recptr, rel->rd_smgr->smgr_rlocator.locator, forknum); for (i = 0; i < nbufs; i++) { PageSetLSN(BufferGetPage(bufpack[i]), recptr); @@ -1352,6 +1357,8 @@ log_newpage_range(Relation rel, ForkNumber forknum, } END_CRIT_SECTION(); } + if (log_newpage_range_callback) + log_newpage_range_callback(rel, forknum); } /* diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c index 0837a911557..444d0f4b8b9 100644 --- a/src/backend/storage/smgr/smgr.c +++ b/src/backend/storage/smgr/smgr.c @@ -725,30 +725,6 @@ smgrimmedsync(SMgrRelation reln, ForkNumber forknum) (*reln->smgr).smgr_immedsync(reln, forknum); } -/* - * Neon-added functions to mark the phases of an unlogged index build. - */ -void -smgr_start_unlogged_build(SMgrRelation reln) -{ - if ((*reln->smgr).smgr_start_unlogged_build) - (*reln->smgr).smgr_start_unlogged_build(reln); -} - -void -smgr_finish_unlogged_build_phase_1(SMgrRelation reln) -{ - if ((*reln->smgr).smgr_finish_unlogged_build_phase_1) - (*reln->smgr).smgr_finish_unlogged_build_phase_1(reln); -} - -void -smgr_end_unlogged_build(SMgrRelation reln) -{ - if ((*reln->smgr).smgr_end_unlogged_build) - (*reln->smgr).smgr_end_unlogged_build(reln); -} - /* * NEON: we do not want to include large pg_xact/multixact files in basebackup and prefer * to download them on demand to reduce startup time. diff --git a/src/include/access/xloginsert.h b/src/include/access/xloginsert.h index e29c27345ce..a46b470ec2a 100644 --- a/src/include/access/xloginsert.h +++ b/src/include/access/xloginsert.h @@ -67,4 +67,8 @@ extern XLogRecPtr XLogSaveBufferForHint(Buffer buffer, bool buffer_std); extern void InitXLogInsert(void); +typedef void (*log_newpage_range_callback_t)(Relation rel, ForkNumber forknum); +extern log_newpage_range_callback_t log_newpage_range_callback; + + #endif /* XLOGINSERT_H */ diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h index 0200b49b598..0b38d58c637 100644 --- a/src/include/storage/smgr.h +++ b/src/include/storage/smgr.h @@ -127,10 +127,6 @@ typedef struct f_smgr BlockNumber nblocks); void (*smgr_immedsync) (SMgrRelation reln, ForkNumber forknum); - void (*smgr_start_unlogged_build) (SMgrRelation reln); - void (*smgr_finish_unlogged_build_phase_1) (SMgrRelation reln); - void (*smgr_end_unlogged_build) (SMgrRelation reln); - int (*smgr_read_slru_segment) (SMgrRelation reln, const char *path, int segno, void* buffer); } f_smgr;