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

Commit e52f7cb

Browse files
committed
Make index_set_state_flags() transactional
3c84046 is the original commit that introduced index_set_state_flags(), where the presence of SnapshotNow made necessary the use of an in-place update. SnapshotNow has been removed in 813fb03, so there is no actual reasons to not make this operation transactional. As reported by Andrey, it is possible to trigger the assertion of this routine expecting no transactional updates when switching the pg_index state flags, using a predicate mark as immutable but calling stable or volatile functions. 83158f7 has been around for a couple of months on HEAD now with no issues found related to it, so it looks safe enough for a backpatch. Reported-by: Andrey Lepikhov Author: Michael Paquier Reviewed-by: Anastasia Lubennikova Discussion: https://postgr.es/m/20200903080440.GA8559@paquier.xyz Discussion: https://postgr.es/m/9b905019-5297-7372-0ad2-e1a4bb66a719@postgrespro.ru Backpatch-through: 9.6
1 parent bc031cf commit e52f7cb

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/backend/catalog/index.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3384,18 +3384,10 @@ validate_index_callback(ItemPointer itemptr, void *opaque)
33843384
* index_set_state_flags - adjust pg_index state flags
33853385
*
33863386
* This is used during CREATE/DROP INDEX CONCURRENTLY to adjust the pg_index
3387-
* flags that denote the index's state. Because the update is not
3388-
* transactional and will not roll back on error, this must only be used as
3389-
* the last step in a transaction that has not made any transactional catalog
3390-
* updates!
3387+
* flags that denote the index's state.
33913388
*
3392-
* Note that heap_inplace_update does send a cache inval message for the
3389+
* Note that CatalogTupleUpdate() sends a cache invalidation message for the
33933390
* tuple, so other sessions will hear about the update as soon as we commit.
3394-
*
3395-
* NB: In releases prior to PostgreSQL 9.4, the use of a non-transactional
3396-
* update here would have been unsafe; now that MVCC rules apply even for
3397-
* system catalog scans, we could potentially use a transactional update here
3398-
* instead.
33993391
*/
34003392
void
34013393
index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
@@ -3404,9 +3396,6 @@ index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
34043396
HeapTuple indexTuple;
34053397
Form_pg_index indexForm;
34063398

3407-
/* Assert that current xact hasn't done any transactional updates */
3408-
Assert(GetTopTransactionIdIfAny() == InvalidTransactionId);
3409-
34103399
/* Open pg_index and fetch a writable copy of the index's tuple */
34113400
pg_index = table_open(IndexRelationId, RowExclusiveLock);
34123401

@@ -3465,8 +3454,8 @@ index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
34653454
break;
34663455
}
34673456

3468-
/* ... and write it back in-place */
3469-
heap_inplace_update(pg_index, indexTuple);
3457+
/* ... and update it */
3458+
CatalogTupleUpdate(pg_index, &indexTuple->t_self, indexTuple);
34703459

34713460
table_close(pg_index, RowExclusiveLock);
34723461
}

0 commit comments

Comments
 (0)