Skip to content

Commit 126ec0b

Browse files
committed
Restore relmapper state early enough in parallel workers.
We need to do RestoreRelationMap before loading catalog-derived state, else the worker may end up with catalog relcache entries containing stale relfilenode data. Move up RestoreReindexState too, on the principle that that should also happen before we do much of any catalog access. I think ideally these things would happen even before InitPostgres, but there are various problems standing in the way of that, notably that the relmapper thinks "active" mappings should be discarded at transaction end. The implication of this is that InitPostgres and RestoreLibraryState will see the same catalog state as an independent backend would see, which is probably fine; at least, it's been like that all along. Per report from Justin Pryzby. There is a case to be made that this should be back-patched. But given the lack of complaints before 6e086fa and the short amount of time remaining before 17.0 wraps, I'll just put it in HEAD for now. Discussion: https://postgr.es/m/ZuoU_8EbSTE14o1U@pryzbyj2023
1 parent 91287b5 commit 126ec0b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/backend/access/transam/parallel.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,17 @@ ParallelWorkerMain(Datum main_arg)
14201420
tstatespace = shm_toc_lookup(toc, PARALLEL_KEY_TRANSACTION_STATE, false);
14211421
StartParallelWorkerTransaction(tstatespace);
14221422

1423+
/*
1424+
* Restore relmapper and reindex state early, since these affect catalog
1425+
* access. Ideally we'd do this even before calling InitPostgres, but
1426+
* that has order-of-initialization problems, and also the relmapper would
1427+
* get confused during the CommitTransactionCommand call above.
1428+
*/
1429+
relmapperspace = shm_toc_lookup(toc, PARALLEL_KEY_RELMAPPER_STATE, false);
1430+
RestoreRelationMap(relmapperspace);
1431+
reindexspace = shm_toc_lookup(toc, PARALLEL_KEY_REINDEX_STATE, false);
1432+
RestoreReindexState(reindexspace);
1433+
14231434
/* Restore combo CID state. */
14241435
combocidspace = shm_toc_lookup(toc, PARALLEL_KEY_COMBO_CID, false);
14251436
RestoreComboCIDState(combocidspace);
@@ -1482,14 +1493,6 @@ ParallelWorkerMain(Datum main_arg)
14821493
false);
14831494
RestorePendingSyncs(pendingsyncsspace);
14841495

1485-
/* Restore reindex state. */
1486-
reindexspace = shm_toc_lookup(toc, PARALLEL_KEY_REINDEX_STATE, false);
1487-
RestoreReindexState(reindexspace);
1488-
1489-
/* Restore relmapper state. */
1490-
relmapperspace = shm_toc_lookup(toc, PARALLEL_KEY_RELMAPPER_STATE, false);
1491-
RestoreRelationMap(relmapperspace);
1492-
14931496
/* Restore uncommitted enums. */
14941497
uncommittedenumsspace = shm_toc_lookup(toc, PARALLEL_KEY_UNCOMMITTEDENUMS,
14951498
false);

0 commit comments

Comments
 (0)