mirror of
https://github.com/postgres/postgres.git
synced 2025-08-25 20:23:07 +03:00
Replace RelationOpenSmgr() with RelationGetSmgr().
The idea behind this patch is to design out bugs like the one fixed
by commit 9d523119f
. Previously, once one did RelationOpenSmgr(rel),
it was considered okay to access rel->rd_smgr directly for some
not-very-clear interval. But since that pointer will be cleared by
relcache flushes, we had bugs arising from overreliance on a previous
RelationOpenSmgr call still being effective.
Now, very little code except that in rel.h and relcache.c should ever
touch the rd_smgr field directly. The normal coding rule is to use
RelationGetSmgr(rel) and not expect the result to be valid for longer
than one smgr function call. There are a couple of places where using
the function every single time seemed like overkill, but they are now
annotated with large warning comments.
Amul Sul, after an idea of mine.
Discussion: https://postgr.es/m/CANiYTQsU7yMFpQYnv=BrcRVqK_3U3mtAzAsJCaqtzsDHfsUbdQ@mail.gmail.com
This commit is contained in:
@@ -326,9 +326,8 @@ end_heap_rewrite(RewriteState state)
|
||||
|
||||
PageSetChecksumInplace(state->rs_buffer, state->rs_blockno);
|
||||
|
||||
RelationOpenSmgr(state->rs_new_rel);
|
||||
smgrextend(state->rs_new_rel->rd_smgr, MAIN_FORKNUM, state->rs_blockno,
|
||||
(char *) state->rs_buffer, true);
|
||||
smgrextend(RelationGetSmgr(state->rs_new_rel), MAIN_FORKNUM,
|
||||
state->rs_blockno, (char *) state->rs_buffer, true);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -339,11 +338,7 @@ end_heap_rewrite(RewriteState state)
|
||||
* wrote before the checkpoint.
|
||||
*/
|
||||
if (RelationNeedsWAL(state->rs_new_rel))
|
||||
{
|
||||
/* for an empty table, this could be first smgr access */
|
||||
RelationOpenSmgr(state->rs_new_rel);
|
||||
smgrimmedsync(state->rs_new_rel->rd_smgr, MAIN_FORKNUM);
|
||||
}
|
||||
smgrimmedsync(RelationGetSmgr(state->rs_new_rel), MAIN_FORKNUM);
|
||||
|
||||
logical_end_heap_rewrite(state);
|
||||
|
||||
@@ -695,11 +690,9 @@ raw_heap_insert(RewriteState state, HeapTuple tup)
|
||||
* need for smgr to schedule an fsync for this write; we'll do it
|
||||
* ourselves in end_heap_rewrite.
|
||||
*/
|
||||
RelationOpenSmgr(state->rs_new_rel);
|
||||
|
||||
PageSetChecksumInplace(page, state->rs_blockno);
|
||||
|
||||
smgrextend(state->rs_new_rel->rd_smgr, MAIN_FORKNUM,
|
||||
smgrextend(RelationGetSmgr(state->rs_new_rel), MAIN_FORKNUM,
|
||||
state->rs_blockno, (char *) page, true);
|
||||
|
||||
state->rs_blockno++;
|
||||
|
Reference in New Issue
Block a user