Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6f9dd22

Browse files
committed
Revert "For inplace update, send nontransactional invalidations."
This reverts commit95c5acb (v17) andcounterparts in each other non-master branch. If released, that commitwould have caused a worst-in-years minor release regression, viaundetected LWLock self-deadlock. This commit and its self-deadlock fixwarrant more bake time in the master branch.Reported by Alexander Lakhin.Discussion:https://postgr.es/m/10ec0bc3-5933-1189-6bb8-5dec4114558e@gmail.com
1 parentd5be107 commit6f9dd22

File tree

12 files changed

+132
-320
lines changed

12 files changed

+132
-320
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6195,24 +6195,6 @@ heap_inplace_update_and_unlock(Relation relation,
61956195
if (oldlen!=newlen||htup->t_hoff!=tuple->t_data->t_hoff)
61966196
elog(ERROR,"wrong tuple length");
61976197

6198-
/*
6199-
* Construct shared cache inval if necessary. Note that because we only
6200-
* pass the new version of the tuple, this mustn't be used for any
6201-
* operations that could change catcache lookup keys. But we aren't
6202-
* bothering with index updates either, so that's true a fortiori.
6203-
*/
6204-
CacheInvalidateHeapTupleInplace(relation,tuple,NULL);
6205-
6206-
/*
6207-
* Unlink relcache init files as needed. If unlinking, acquire
6208-
* RelCacheInitLock until after associated invalidations. By doing this
6209-
* in advance, if we checkpoint and then crash between inplace
6210-
* XLogInsert() and inval, we don't rely on StartupXLOG() ->
6211-
* RelationCacheInitFileRemove(). That uses elevel==LOG, so replay would
6212-
* neglect to PANIC on EIO.
6213-
*/
6214-
PreInplace_Inval();
6215-
62166198
/* NO EREPORT(ERROR) from here till changes are logged */
62176199
START_CRIT_SECTION();
62186200

@@ -6256,28 +6238,17 @@ heap_inplace_update_and_unlock(Relation relation,
62566238
PageSetLSN(BufferGetPage(buffer),recptr);
62576239
}
62586240

6259-
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
6260-
6261-
/*
6262-
* Send invalidations to shared queue. SearchSysCacheLocked1() assumes we
6263-
* do this before UnlockTuple().
6264-
*
6265-
* If we're mutating a tuple visible only to this transaction, there's an
6266-
* equivalent transactional inval from the action that created the tuple,
6267-
* and this inval is superfluous.
6268-
*/
6269-
AtInplace_Inval();
6270-
62716241
END_CRIT_SECTION();
6272-
UnlockTuple(relation,&tuple->t_self,InplaceUpdateTupleLock);
62736242

6274-
AcceptInvalidationMessages();/* local processing of just-sent inval */
6243+
heap_inplace_unlock(relation,oldtup,buffer);
62756244

62766245
/*
6277-
* Queue a transactional inval. The immediate invalidation we just sent
6278-
* is the only one known to be necessary. To reduce risk from the
6279-
* transition to immediate invalidation, continue sending a transactional
6280-
* invalidation like we've long done. Third-party code might rely on it.
6246+
* Send out shared cache inval if necessary. Note that because we only
6247+
* pass the new version of the tuple, this mustn't be used for any
6248+
* operations that could change catcache lookup keys. But we aren't
6249+
* bothering with index updates either, so that's true a fortiori.
6250+
*
6251+
* XXX ROLLBACK discards the invalidation. See test inplace-inval.spec.
62816252
*/
62826253
if (!IsBootstrapProcessingMode())
62836254
CacheInvalidateHeapTuple(relation,tuple,NULL);

‎src/backend/access/transam/xact.c

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,24 +1337,14 @@ RecordTransactionCommit(void)
13371337

13381338
/*
13391339
* Transactions without an assigned xid can contain invalidation
1340-
* messages. While inplace updates do this, this is not known to be
1341-
* necessary; see comment at inplace CacheInvalidateHeapTuple().
1342-
* Extensions might still rely on this capability, and standbys may
1343-
* need to process those invals. We can't emit a commit record
1344-
* without an xid, and we don't want to force assigning an xid,
1345-
* because that'd be problematic for e.g. vacuum. Hence we emit a
1346-
* bespoke record for the invalidations. We don't want to use that in
1347-
* case a commit record is emitted, so they happen synchronously with
1348-
* commits (besides not wanting to emit more WAL records).
1349-
*
1350-
* XXX Every known use of this capability is a defect. Since an XID
1351-
* isn't controlling visibility of the change that prompted invals,
1352-
* other sessions need the inval even if this transactions aborts.
1353-
*
1354-
* ON COMMIT DELETE ROWS does a nontransactional index_build(), which
1355-
* queues a relcache inval, including in transactions without an xid
1356-
* that had read the (empty) table. Standbys don't need any ON COMMIT
1357-
* DELETE ROWS invals, but we've not done the work to withhold them.
1340+
* messages (e.g. explicit relcache invalidations or catcache
1341+
* invalidations for inplace updates); standbys need to process those.
1342+
* We can't emit a commit record without an xid, and we don't want to
1343+
* force assigning an xid, because that'd be problematic for e.g.
1344+
* vacuum. Hence we emit a bespoke record for the invalidations. We
1345+
* don't want to use that in case a commit record is emitted, so they
1346+
* happen synchronously with commits (besides not wanting to emit more
1347+
* WAL records).
13581348
*/
13591349
if (nmsgs!=0)
13601350
{

‎src/backend/catalog/index.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,19 +2915,12 @@ index_update_stats(Relation rel,
29152915
if (dirty)
29162916
{
29172917
systable_inplace_update_finish(state,tuple);
2918-
/* the above sendstransactional and immediatecache invalmessages */
2918+
/* the above sendsacache invalmessage */
29192919
}
29202920
else
29212921
{
29222922
systable_inplace_update_cancel(state);
2923-
2924-
/*
2925-
* While we didn't change relhasindex, CREATE INDEX needs a
2926-
* transactional inval for when the new index's catalog rows become
2927-
* visible. Other CREATE INDEX and REINDEX code happens to also queue
2928-
* this inval, but keep this in case rare callers rely on this part of
2929-
* our API contract.
2930-
*/
2923+
/* no need to change tuple, but force relcache inval anyway */
29312924
CacheInvalidateRelcacheByTuple(tuple);
29322925
}
29332926

‎src/backend/replication/logical/decode.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -511,19 +511,23 @@ heap_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
511511

512512
/*
513513
* Inplace updates are only ever performed on catalog tuples and
514-
* can, per definition, not change tuple visibility. Inplace
515-
* updates don't affect storage or interpretation of table rows,
516-
* so they don't affect logicalrep_write_tuple() outcomes. Hence,
517-
* we don't process invalidations from the original operation. If
518-
* inplace updates did affect those things, invalidations wouldn't
519-
* make it work, since there are no snapshot-specific versions of
520-
* inplace-updated values. Since we also don't decode catalog
521-
* tuples, we're not interested in the record's contents.
514+
* can, per definition, not change tuple visibility. Since we
515+
* don't decode catalog tuples, we're not interested in the
516+
* record's contents.
522517
*
523-
* WAL contains likely-unnecessary commit-time invals from the
524-
* CacheInvalidateHeapTuple() call in heap_inplace_update().
525-
* Excess invalidation is safe.
518+
* In-place updates can be used either by XID-bearing transactions
519+
* (e.g. in CREATE INDEX CONCURRENTLY) or by XID-less
520+
* transactions (e.g. VACUUM). In the former case, the commit
521+
* record will include cache invalidations, so we mark the
522+
* transaction as catalog modifying here. Currently that's
523+
* redundant because the commit will do that as well, but once we
524+
* support decoding in-progress relations, this will be important.
526525
*/
526+
if (!TransactionIdIsValid(xid))
527+
break;
528+
529+
(void)SnapBuildProcessChange(builder,xid,buf->origptr);
530+
ReorderBufferXidSetCatalogChanges(ctx->reorder,xid,buf->origptr);
527531
break;
528532

529533
caseXLOG_HEAP_CONFIRM:

‎src/backend/utils/cache/catcache.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,8 +2219,7 @@ void
22192219
PrepareToInvalidateCacheTuple(Relationrelation,
22202220
HeapTupletuple,
22212221
HeapTuplenewtuple,
2222-
void (*function) (int,uint32,Oid,void*),
2223-
void*context)
2222+
void (*function) (int,uint32,Oid))
22242223
{
22252224
slist_iteriter;
22262225
Oidreloid;
@@ -2261,7 +2260,7 @@ PrepareToInvalidateCacheTuple(Relation relation,
22612260
hashvalue=CatalogCacheComputeTupleHashValue(ccp,ccp->cc_nkeys,tuple);
22622261
dbid=ccp->cc_relisshared ? (Oid)0 :MyDatabaseId;
22632262

2264-
(*function) (ccp->id,hashvalue,dbid,context);
2263+
(*function) (ccp->id,hashvalue,dbid);
22652264

22662265
if (newtuple)
22672266
{
@@ -2270,7 +2269,7 @@ PrepareToInvalidateCacheTuple(Relation relation,
22702269
newhashvalue=CatalogCacheComputeTupleHashValue(ccp,ccp->cc_nkeys,newtuple);
22712270

22722271
if (newhashvalue!=hashvalue)
2273-
(*function) (ccp->id,newhashvalue,dbid,context);
2272+
(*function) (ccp->id,newhashvalue,dbid);
22742273
}
22752274
}
22762275
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp