Compare commits

...

2 Commits

Author SHA1 Message Date
Konstantin Knizhnik
890143fcfc Update pgxn/neon/pagestore_smgr.c
Co-authored-by: Heikki Linnakangas <heikki@neon.tech>
2024-06-01 22:01:39 +03:00
Konstantin Knizhnik
ab706fc88d Drop relation buffers in neon_end_unlogged_build 2024-06-01 14:52:55 +03:00

View File

@@ -3064,6 +3064,24 @@ neon_end_unlogged_build(SMgrRelation reln)
/* Make the relation look permanent again */
reln->smgr_relpersistence = RELPERSISTENCE_PERMANENT;
/*
* Drop all buffers of the relation from buffer cache. They have valid contents, so it's a bit sad to throw
* them away, but they might be marked as !BM_PERMANENT, which is no longer true and could cause
* trouble afterwards. Also, there's a race condition with checkpoint and the mdunlink call below: The
* checkpointer uses mdexists() to check if the buffer belongs to an unlogged relation, and then writes
* the page to disk if it exists, but we might unlink the file in between the mdexists() and mdwrite() calls,
* causing the write to fail.
*/
{
static ForkNumber forks[] = { MAIN_FORKNUM, FSM_FORKNUM, VISIBILITYMAP_FORKNUM };
static BlockNumber blocks[] = { 0, 0, 0 };
#if PG_MAJORVERSION_NUM < 16
DropRelFileNodeBuffers(reln, forks, 3, blocks);
#else
DropRelationBuffers(reln, forks, 3, blocks);
#endif
}
/* Remove local copy */
rinfob = InfoBFromSMgrRel(reln);
for (int forknum = 0; forknum <= MAX_FORKNUM; forknum++)