mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-08 21:49:21 +02:00
Ensure snapshot is registered within ScanPgRelation().
In 9.4 I added support to use a historical snapshot in ScanPgRelation(), while adding logical decoding. Unfortunately a conflict with the concurrent removal of SnapshotNow was incorrectly resolved, leading to an unregistered snapshot being used. It is not correct to use an unregistered (or non-active) snapshot for anything non-trivial, because catalog invalidations can cause the snapshot to be invalidated. Luckily it seems unlikely to actively cause problems in practice, as ScanPgRelation() requires that we already have a lock on the relation, we only look for a single row, and we don't appear to rely on the result's tid to be correct. It however is clearly wrong and potential negative consequences would likely be hard to find. So it seems worth backpatching the fix, even without a concrete hazard. Discussion: https://postgr.es/m/20200229052459.wzhqnbhrriezg4v2@alap3.anarazel.de Backpatch: 9.5-
This commit is contained in:
parent
deeda011b3
commit
00a0a428ef
8
src/backend/utils/cache/relcache.c
vendored
8
src/backend/utils/cache/relcache.c
vendored
@ -313,7 +313,7 @@ ScanPgRelation(Oid targetRelId, bool indexOK, bool force_non_historic)
|
|||||||
Relation pg_class_desc;
|
Relation pg_class_desc;
|
||||||
SysScanDesc pg_class_scan;
|
SysScanDesc pg_class_scan;
|
||||||
ScanKeyData key[1];
|
ScanKeyData key[1];
|
||||||
Snapshot snapshot;
|
Snapshot snapshot = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If something goes wrong during backend startup, we might find ourselves
|
* If something goes wrong during backend startup, we might find ourselves
|
||||||
@ -343,12 +343,12 @@ ScanPgRelation(Oid targetRelId, bool indexOK, bool force_non_historic)
|
|||||||
/*
|
/*
|
||||||
* The caller might need a tuple that's newer than the one the historic
|
* The caller might need a tuple that's newer than the one the historic
|
||||||
* snapshot; currently the only case requiring to do so is looking up the
|
* snapshot; currently the only case requiring to do so is looking up the
|
||||||
* relfilenode of non mapped system relations during decoding.
|
* relfilenode of non mapped system relations during decoding. That
|
||||||
|
* snapshot cant't change in the midst of a relcache build, so there's no
|
||||||
|
* need to register the snapshot.
|
||||||
*/
|
*/
|
||||||
if (force_non_historic)
|
if (force_non_historic)
|
||||||
snapshot = GetNonHistoricCatalogSnapshot(RelationRelationId);
|
snapshot = GetNonHistoricCatalogSnapshot(RelationRelationId);
|
||||||
else
|
|
||||||
snapshot = GetCatalogSnapshot(RelationRelationId);
|
|
||||||
|
|
||||||
pg_class_scan = systable_beginscan(pg_class_desc, ClassOidIndexId,
|
pg_class_scan = systable_beginscan(pg_class_desc, ClassOidIndexId,
|
||||||
indexOK && criticalRelcachesBuilt,
|
indexOK && criticalRelcachesBuilt,
|
||||||
|
Loading…
Reference in New Issue
Block a user