Skip to content

Commit 86073a2

Browse files
committed
Correctly detect SSI conflicts of prepared transactions after crash.
A prepared transaction can get new conflicts in and out after preparing, so we cannot rely on the in- and out-flags stored in the statefile at prepare- time. As a quick fix, make the conservative assumption that after a restart, all prepared transactions are considered to have both in- and out-conflicts. That can lead to unnecessary rollbacks after a crash, but that shouldn't be a big problem in practice; you don't want prepared transactions to hang around for a long time anyway. Dan Ports
1 parent 57b100f commit 86073a2

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/backend/storage/lmgr/predicate.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4659,14 +4659,11 @@ AtPrepare_PredicateLocks(void)
46594659
xactRecord->flags = MySerializableXact->flags;
46604660

46614661
/*
4662-
* Tweak the flags. Since we're not going to output the inConflicts and
4663-
* outConflicts lists, if they're non-empty we'll represent that by
4664-
* setting the appropriate summary conflict flags.
4662+
* Note that we don't include the list of conflicts in our out in
4663+
* the statefile, because new conflicts can be added even after the
4664+
* transaction prepares. We'll just make a conservative assumption
4665+
* during recovery instead.
46654666
*/
4666-
if (!SHMQueueEmpty(&MySerializableXact->inConflicts))
4667-
xactRecord->flags |= SXACT_FLAG_SUMMARY_CONFLICT_IN;
4668-
if (!SHMQueueEmpty(&MySerializableXact->outConflicts))
4669-
xactRecord->flags |= SXACT_FLAG_SUMMARY_CONFLICT_OUT;
46704667

46714668
RegisterTwoPhaseRecord(TWOPHASE_RM_PREDICATELOCK_ID, 0,
46724669
&record, sizeof(record));
@@ -4801,15 +4798,6 @@ predicatelock_twophase_recover(TransactionId xid, uint16 info,
48014798

48024799
sxact->SeqNo.lastCommitBeforeSnapshot = RecoverySerCommitSeqNo;
48034800

4804-
4805-
/*
4806-
* We don't need the details of a prepared transaction's conflicts,
4807-
* just whether it had conflicts in or out (which we get from the
4808-
* flags)
4809-
*/
4810-
SHMQueueInit(&(sxact->outConflicts));
4811-
SHMQueueInit(&(sxact->inConflicts));
4812-
48134801
/*
48144802
* Don't need to track this; no transactions running at the time the
48154803
* recovered xact started are still active, except possibly other
@@ -4831,6 +4819,17 @@ predicatelock_twophase_recover(TransactionId xid, uint16 info,
48314819
(MaxBackends + max_prepared_xacts));
48324820
}
48334821

4822+
/*
4823+
* We don't know whether the transaction had any conflicts or
4824+
* not, so we'll conservatively assume that it had both a
4825+
* conflict in and a conflict out, and represent that with the
4826+
* summary conflict flags.
4827+
*/
4828+
SHMQueueInit(&(sxact->outConflicts));
4829+
SHMQueueInit(&(sxact->inConflicts));
4830+
sxact->flags |= SXACT_FLAG_SUMMARY_CONFLICT_IN;
4831+
sxact->flags |= SXACT_FLAG_SUMMARY_CONFLICT_OUT;
4832+
48344833
/* Register the transaction's xid */
48354834
sxidtag.xid = xid;
48364835
sxid = (SERIALIZABLEXID *) hash_search(SerializableXidHash,

0 commit comments

Comments
 (0)