Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Update last written LSN for gin/gist index metadata (#182)" #183

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions contrib/neon/pagestore_smgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ zenith_wallog_page(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
* Remember the LSN on this page. When we read the page again, we must
* read the same or newer version of it.
*/
SetLastWrittenLSNForBlock(lsn, reln->smgr_rnode.node.relNode, blocknum);
SetLastWrittenPageLSN(lsn);
}


Expand Down Expand Up @@ -603,7 +603,7 @@ zm_adjust_lsn(XLogRecPtr lsn)
* Return LSN for requesting pages and number of blocks from page server
*/
static XLogRecPtr
zenith_get_request_lsn(bool *latest, Oid rnode, BlockNumber blkno)
zenith_get_request_lsn(bool *latest)
{
XLogRecPtr lsn;

Expand All @@ -630,9 +630,9 @@ zenith_get_request_lsn(bool *latest, Oid rnode, BlockNumber blkno)
* so our request cannot concern those.
*/
*latest = true;
lsn = GetLastWrittenLSN(rnode, blkno);
lsn = GetLastWrittenPageLSN();
Assert(lsn != InvalidXLogRecPtr);
elog(DEBUG1, "zenith_get_request_lsn GetLastWrittenLSN lsn %X/%X ",
elog(DEBUG1, "zenith_get_request_lsn GetLastWrittenPageLSN lsn %X/%X ",
(uint32) ((lsn) >> 32), (uint32) (lsn));

lsn = zm_adjust_lsn(lsn);
Expand Down Expand Up @@ -716,7 +716,7 @@ zenith_exists(SMgrRelation reln, ForkNumber forkNum)
return false;
}

request_lsn = zenith_get_request_lsn(&latest, reln->smgr_rnode.node.relNode, REL_METADATA_PSEUDO_BLOCKNO);
request_lsn = zenith_get_request_lsn(&latest);
{
ZenithExistsRequest request = {
.req.tag = T_ZenithExistsRequest,
Expand Down Expand Up @@ -791,7 +791,7 @@ zenith_create(SMgrRelation reln, ForkNumber forkNum, bool isRedo)
*
* FIXME: This is currently not just an optimization, but required for
* correctness. Postgres can call smgrnblocks() on the newly-created
* relation. Currently, we don't call SetLastWrittenLSN() when a new
* relation. Currently, we don't call SetLastWrittenPageLSN() when a new
* relation created, so if we didn't remember the size in the relsize
* cache, we might call smgrnblocks() on the newly-created relation before
* the creation WAL record hass been received by the page server.
Expand Down Expand Up @@ -904,8 +904,6 @@ zenith_extend(SMgrRelation reln, ForkNumber forkNum, BlockNumber blkno,
if (IS_LOCAL_REL(reln))
mdextend(reln, forkNum, blkno, buffer, skipFsync);
#endif

SetLastWrittenLSNForRelation(lsn, reln->smgr_rnode.node.relNode);
}

/*
Expand Down Expand Up @@ -1081,7 +1079,7 @@ zenith_read(SMgrRelation reln, ForkNumber forkNum, BlockNumber blkno,
elog(ERROR, "unknown relpersistence '%c'", reln->smgr_relpersistence);
}

request_lsn = zenith_get_request_lsn(&latest, reln->smgr_rnode.node.relNode, blkno);
request_lsn = zenith_get_request_lsn(&latest);
zenith_read_at_lsn(reln->smgr_rnode.node, forkNum, blkno, request_lsn, latest, buffer);

#ifdef DEBUG_COMPARE_LOCAL
Expand Down Expand Up @@ -1286,7 +1284,7 @@ zenith_nblocks(SMgrRelation reln, ForkNumber forknum)
return n_blocks;
}

request_lsn = zenith_get_request_lsn(&latest, reln->smgr_rnode.node.relNode, REL_METADATA_PSEUDO_BLOCKNO);
request_lsn = zenith_get_request_lsn(&latest);
{
ZenithNblocksRequest request = {
.req.tag = T_ZenithNblocksRequest,
Expand Down Expand Up @@ -1346,7 +1344,7 @@ zenith_dbsize(Oid dbNode)
XLogRecPtr request_lsn;
bool latest;

request_lsn = zenith_get_request_lsn(&latest, InvalidOid, REL_METADATA_PSEUDO_BLOCKNO);
request_lsn = zenith_get_request_lsn(&latest);
{
ZenithDbSizeRequest request = {
.req.tag = T_ZenithDbSizeRequest,
Expand Down Expand Up @@ -1433,11 +1431,7 @@ zenith_truncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks)
*/
XLogFlush(lsn);

/*
* Truncate may affect several chunks of relations. So we should either update last written LSN for all of them,
* either update LSN for "dummy" metadata block. Second approach seems to be more efficient.
*/
SetLastWrittenLSNForRelation(lsn, reln->smgr_rnode.node.relNode);
SetLastWrittenPageLSN(lsn);

#ifdef DEBUG_COMPARE_LOCAL
if (IS_LOCAL_REL(reln))
Expand Down
3 changes: 1 addition & 2 deletions src/backend/access/gin/gininsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,8 @@ ginbuild(Relation heap, Relation index, IndexInfo *indexInfo)
log_newpage_range(index, MAIN_FORKNUM,
0, RelationGetNumberOfBlocks(index),
true);
SetLastWrittenLSNForBlockRange(XactLastRecEnd, index->rd_smgr->smgr_rnode.node.relNode, 0, RelationGetNumberOfBlocks(index));
SetLastWrittenLSNForRelation(XactLastRecEnd, index->rd_smgr->smgr_rnode.node.relNode);
}
SetLastWrittenPageLSN(XactLastRecEnd);

smgr_end_unlogged_build(index->rd_smgr);

Expand Down
10 changes: 3 additions & 7 deletions src/backend/access/gist/gistbuild.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,9 @@ gistbuild(Relation heap, Relation index, IndexInfo *indexInfo)
log_newpage_range(index, MAIN_FORKNUM,
0, RelationGetNumberOfBlocks(index),
true);
SetLastWrittenLSNForBlockRange(XactLastRecEnd,
index->rd_smgr->smgr_rnode.node.relNode,
0, RelationGetNumberOfBlocks(index));
SetLastWrittenLSNForRelation(XactLastRecEnd, index->rd_smgr->smgr_rnode.node.relNode);
}
SetLastWrittenPageLSN(XactLastRecEnd);

smgr_end_unlogged_build(index->rd_smgr);
}

Expand Down Expand Up @@ -471,9 +469,7 @@ gist_indexsortbuild(GISTBuildState *state)

lsn = log_newpage(&state->indexrel->rd_node, MAIN_FORKNUM, GIST_ROOT_BLKNO,
pagestate->page, true);
SetLastWrittenLSNForBlock(lsn, state->indexrel->rd_smgr->smgr_rnode.node.relNode,
GIST_ROOT_BLKNO);
SetLastWrittenLSNForRelation(lsn, state->indexrel->rd_smgr->smgr_rnode.node.relNode);
SetLastWrittenPageLSN(lsn);
}

pfree(pagestate->page);
Expand Down
4 changes: 1 addition & 3 deletions src/backend/access/spgist/spginsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,8 @@ spgbuild(Relation heap, Relation index, IndexInfo *indexInfo)
log_newpage_range(index, MAIN_FORKNUM,
0, RelationGetNumberOfBlocks(index),
true);
SetLastWrittenLSNForBlockRange(XactLastRecEnd, index->rd_smgr->smgr_rnode.node.relNode,
0, RelationGetNumberOfBlocks(index));
SetLastWrittenLSNForRelation(XactLastRecEnd, index->rd_smgr->smgr_rnode.node.relNode);
}
SetLastWrittenPageLSN(XactLastRecEnd);

smgr_end_unlogged_build(index->rd_smgr);

Expand Down
Loading