Skip to content

Commit af0e7de

Browse files
committed
Don't destroy SMgrRelations at relcache invalidation
With commit 21d9c3e, SMgrRelations remain valid until end of transaction (or longer if they're "pinned"). Relcache invalidation can happen in the middle of a transaction, so we must not destroy them at relcache invalidation anymore. This was revealed by failures in the 'constraints' test in buildfarm animals using -DCLOBBER_CACHE_ALWAYS. That started failing with commit 8af2565, which was the first commit that started to rely on an SMgrRelation living until end of transaction. Diagnosed-by: Tomas Vondra, Thomas Munro Reviewed-by: Thomas Munro Discussion: https://www.postgresql.org/message-id/CA%2BhUKGK%2B5DOmLaBp3Z7C4S-Yv6yoROvr1UncjH2S1ZbPT8D%2BZg%40mail.gmail.com
1 parent e629846 commit af0e7de

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

src/backend/storage/smgr/smgr.c

-2
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,6 @@ smgrdestroyall(void)
348348

349349
/*
350350
* smgrreleaseall() -- Release resources used by all objects.
351-
*
352-
* This is called for PROCSIGNAL_BARRIER_SMGRRELEASE.
353351
*/
354352
void
355353
smgrreleaseall(void)

src/backend/utils/cache/relcache.c

+3-7
Original file line numberDiff line numberDiff line change
@@ -2985,9 +2985,6 @@ RelationCacheInvalidate(bool debug_discard)
29852985
{
29862986
relation = idhentry->reldesc;
29872987

2988-
/* Must close all smgr references to avoid leaving dangling ptrs */
2989-
RelationCloseSmgr(relation);
2990-
29912988
/*
29922989
* Ignore new relations; no other backend will manipulate them before
29932990
* we commit. Likewise, before replacing a relation's relfilelocator,
@@ -3039,11 +3036,10 @@ RelationCacheInvalidate(bool debug_discard)
30393036
}
30403037

30413038
/*
3042-
* Now zap any remaining smgr cache entries. This must happen before we
3043-
* start to rebuild entries, since that may involve catalog fetches which
3044-
* will re-open catalog files.
3039+
* We cannot destroy the SMgrRelations as there might still be references
3040+
* to them, but close the underlying file descriptors.
30453041
*/
3046-
smgrdestroyall();
3042+
smgrreleaseall();
30473043

30483044
/* Phase 2: rebuild the items found to need rebuild in phase 1 */
30493045
foreach(l, rebuildFirstList)

0 commit comments

Comments
 (0)