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

Commitae632f7

Browse files
committed
Fix race in SERIALIZABLE READ ONLY.
Commitbdaabb9 started skipping doomed transactions when building thelist of possible conflicts for SERIALIZABLE READ ONLY. That makessense, because doomed transactions won't commit, but a couple of subtlethings broke:1. If all uncommitted r/w transactions are doomed, a READ ONLYtransaction would arbitrarily not benefit from the safe snapshotoptimization. It would not be taken immediately, and yet no othertransaction would set SXACT_FLAG_RO_SAFE later.2. In the same circumstances but with DEFERRABLE, GetSafeSnapshot()would correctly exit its wait loop without sleeping and then take theoptimization in non-assert builds, but assert builds would fail a sanitycheck that SXACT_FLAG_RO_SAFE had been set by another transaction.This is similar to the case for PredXact->WritableSxactCount == 0. Weshould opt out immediately if our possibleUnsafeConflicts list is emptyafter filtering.The code to maintain the serializable global xmin is moved down belowthe new opt out site, because otherwise we'd have to reverse its effectsbefore returning.Back-patch to all supported releases. Bug #17368.Reported-by: Alexander Lakhin <exclusion@gmail.com>Discussion:https://postgr.es/m/17116-d6ca217acc180e30%40postgresql.orgDiscussion:https://postgr.es/m/20110707212159.GF76634%40csail.mit.edu
1 parente6d77f2 commitae632f7

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

‎src/backend/storage/lmgr/predicate.c

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,24 +1851,6 @@ GetSerializableTransactionSnapshotInt(Snapshot snapshot,
18511851
returnsnapshot;
18521852
}
18531853

1854-
/* Maintain serializable global xmin info. */
1855-
if (!TransactionIdIsValid(PredXact->SxactGlobalXmin))
1856-
{
1857-
Assert(PredXact->SxactGlobalXminCount==0);
1858-
PredXact->SxactGlobalXmin=snapshot->xmin;
1859-
PredXact->SxactGlobalXminCount=1;
1860-
SerialSetActiveSerXmin(snapshot->xmin);
1861-
}
1862-
elseif (TransactionIdEquals(snapshot->xmin,PredXact->SxactGlobalXmin))
1863-
{
1864-
Assert(PredXact->SxactGlobalXminCount>0);
1865-
PredXact->SxactGlobalXminCount++;
1866-
}
1867-
else
1868-
{
1869-
Assert(TransactionIdFollows(snapshot->xmin,PredXact->SxactGlobalXmin));
1870-
}
1871-
18721854
/* Initialize the structure. */
18731855
sxact->vxid=vxid;
18741856
sxact->SeqNo.lastCommitBeforeSnapshot=PredXact->LastSxactCommitSeqNo;
@@ -1905,6 +1887,19 @@ GetSerializableTransactionSnapshotInt(Snapshot snapshot,
19051887
SetPossibleUnsafeConflict(sxact,othersxact);
19061888
}
19071889
}
1890+
1891+
/*
1892+
* If we didn't find any possibly unsafe conflicts because every
1893+
* uncommitted writable transaction turned out to be doomed, then we
1894+
* can "opt out" immediately. See comments above the earlier check for
1895+
* PredXact->WritableSxactCount == 0.
1896+
*/
1897+
if (SHMQueueEmpty(&sxact->possibleUnsafeConflicts))
1898+
{
1899+
ReleasePredXact(sxact);
1900+
LWLockRelease(SerializableXactHashLock);
1901+
returnsnapshot;
1902+
}
19081903
}
19091904
else
19101905
{
@@ -1913,6 +1908,24 @@ GetSerializableTransactionSnapshotInt(Snapshot snapshot,
19131908
(MaxBackends+max_prepared_xacts));
19141909
}
19151910

1911+
/* Maintain serializable global xmin info. */
1912+
if (!TransactionIdIsValid(PredXact->SxactGlobalXmin))
1913+
{
1914+
Assert(PredXact->SxactGlobalXminCount==0);
1915+
PredXact->SxactGlobalXmin=snapshot->xmin;
1916+
PredXact->SxactGlobalXminCount=1;
1917+
SerialSetActiveSerXmin(snapshot->xmin);
1918+
}
1919+
elseif (TransactionIdEquals(snapshot->xmin,PredXact->SxactGlobalXmin))
1920+
{
1921+
Assert(PredXact->SxactGlobalXminCount>0);
1922+
PredXact->SxactGlobalXminCount++;
1923+
}
1924+
else
1925+
{
1926+
Assert(TransactionIdFollows(snapshot->xmin,PredXact->SxactGlobalXmin));
1927+
}
1928+
19161929
MySerializableXact=sxact;
19171930
MyXactDidWrite= false;/* haven't written anything yet */
19181931

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp