Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0f9692b

Browse files
committed
Fix relpersistence setting in reindex_index
Buildfarm members with CLOBBER_CACHE_ALWAYS advised us that commit 85b506b was mistaken in setting the relpersistence value of the index directly in the relcache entry, within reindex_index. The reason for the failure is that an invalidation message that comes after mucking with the relcache entry directly, but before writing it to the catalogs, would cause the entry to become rebuilt in place from catalogs with the old contents, losing the update. Fix by passing the correct persistence value to RelationSetNewRelfilenode instead; this routine also writes the updated tuple to pg_class, avoiding the problem. Suggested by Tom Lane.
1 parent 7466a1b commit 0f9692b

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

src/backend/catalog/index.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3191,11 +3191,8 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence)
31913191
indexInfo->ii_ExclusionStrats = NULL;
31923192
}
31933193

3194-
/* Set the relpersistence of the new index */
3195-
iRel->rd_rel->relpersistence = persistence;
3196-
31973194
/* We'll build a new physical relation for the index */
3198-
RelationSetNewRelfilenode(iRel, InvalidTransactionId,
3195+
RelationSetNewRelfilenode(iRel, persistence, InvalidTransactionId,
31993196
InvalidMultiXactId);
32003197

32013198
/* Initialize the index and rebuild */

src/backend/commands/sequence.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ ResetSequence(Oid seq_relid)
303303
* sequence's relfrozenxid at 0, since it won't contain any unfrozen XIDs.
304304
* Same with relminmxid, since a sequence will never contain multixacts.
305305
*/
306-
RelationSetNewRelfilenode(seq_rel, InvalidTransactionId,
307-
InvalidMultiXactId);
306+
RelationSetNewRelfilenode(seq_rel, seq_rel->rd_rel->relpersistence,
307+
InvalidTransactionId, InvalidMultiXactId);
308308

309309
/*
310310
* Insert the modified tuple into the new storage file.

src/backend/commands/tablecmds.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,8 @@ ExecuteTruncate(TruncateStmt *stmt)
11961196
* as the relfilenode value. The old storage file is scheduled for
11971197
* deletion at commit.
11981198
*/
1199-
RelationSetNewRelfilenode(rel, RecentXmin, minmulti);
1199+
RelationSetNewRelfilenode(rel, rel->rd_rel->relpersistence,
1200+
RecentXmin, minmulti);
12001201
if (rel->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED)
12011202
heap_create_init_fork(rel);
12021203

@@ -1209,7 +1210,8 @@ ExecuteTruncate(TruncateStmt *stmt)
12091210
if (OidIsValid(toast_relid))
12101211
{
12111212
rel = relation_open(toast_relid, AccessExclusiveLock);
1212-
RelationSetNewRelfilenode(rel, RecentXmin, minmulti);
1213+
RelationSetNewRelfilenode(rel, rel->rd_rel->relpersistence,
1214+
RecentXmin, minmulti);
12131215
if (rel->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED)
12141216
heap_create_init_fork(rel);
12151217
heap_close(rel, NoLock);

src/backend/utils/cache/relcache.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,10 +3005,14 @@ RelationBuildLocalRelation(const char *relname,
30053005
* The relation is marked with relfrozenxid = freezeXid (InvalidTransactionId
30063006
* must be passed for indexes and sequences). This should be a lower bound on
30073007
* the XIDs that will be put into the new relation contents.
3008+
*
3009+
* The new filenode's persistence is set to the given value. This is useful
3010+
* for the cases that are changing the relation's persistence; other callers
3011+
* need to pass the original relpersistence value.
30083012
*/
30093013
void
3010-
RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid,
3011-
MultiXactId minmulti)
3014+
RelationSetNewRelfilenode(Relation relation, char persistence,
3015+
TransactionId freezeXid, MultiXactId minmulti)
30123016
{
30133017
Oid newrelfilenode;
30143018
RelFileNodeBackend newrnode;
@@ -3025,7 +3029,7 @@ RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid,
30253029

30263030
/* Allocate a new relfilenode */
30273031
newrelfilenode = GetNewRelFileNode(relation->rd_rel->reltablespace, NULL,
3028-
relation->rd_rel->relpersistence);
3032+
persistence);
30293033

30303034
/*
30313035
* Get a writable copy of the pg_class tuple for the given relation.
@@ -3048,7 +3052,7 @@ RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid,
30483052
newrnode.node = relation->rd_node;
30493053
newrnode.node.relNode = newrelfilenode;
30503054
newrnode.backend = relation->rd_backend;
3051-
RelationCreateStorage(newrnode.node, relation->rd_rel->relpersistence);
3055+
RelationCreateStorage(newrnode.node, persistence);
30523056
smgrclosenode(newrnode);
30533057

30543058
/*
@@ -3078,7 +3082,7 @@ RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid,
30783082
}
30793083
classform->relfrozenxid = freezeXid;
30803084
classform->relminmxid = minmulti;
3081-
classform->relpersistence = relation->rd_rel->relpersistence;
3085+
classform->relpersistence = persistence;
30823086

30833087
simple_heap_update(pg_class, &tuple->t_self, tuple);
30843088
CatalogUpdateIndexes(pg_class, tuple);

src/include/utils/relcache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ extern Relation RelationBuildLocalRelation(const char *relname,
9595
/*
9696
* Routine to manage assignment of new relfilenode to a relation
9797
*/
98-
extern void RelationSetNewRelfilenode(Relation relation,
98+
extern void RelationSetNewRelfilenode(Relation relation, char persistence,
9999
TransactionId freezeXid, MultiXactId minmulti);
100100

101101
/*

0 commit comments

Comments
 (0)