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

Commitaf397c6

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 parent391f08f commitaf397c6

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
@@ -1847,24 +1847,6 @@ GetSerializableTransactionSnapshotInt(Snapshot snapshot,
18471847
returnsnapshot;
18481848
}
18491849

1850-
/* Maintain serializable global xmin info. */
1851-
if (!TransactionIdIsValid(PredXact->SxactGlobalXmin))
1852-
{
1853-
Assert(PredXact->SxactGlobalXminCount==0);
1854-
PredXact->SxactGlobalXmin=snapshot->xmin;
1855-
PredXact->SxactGlobalXminCount=1;
1856-
SerialSetActiveSerXmin(snapshot->xmin);
1857-
}
1858-
elseif (TransactionIdEquals(snapshot->xmin,PredXact->SxactGlobalXmin))
1859-
{
1860-
Assert(PredXact->SxactGlobalXminCount>0);
1861-
PredXact->SxactGlobalXminCount++;
1862-
}
1863-
else
1864-
{
1865-
Assert(TransactionIdFollows(snapshot->xmin,PredXact->SxactGlobalXmin));
1866-
}
1867-
18681850
/* Initialize the structure. */
18691851
sxact->vxid=vxid;
18701852
sxact->SeqNo.lastCommitBeforeSnapshot=PredXact->LastSxactCommitSeqNo;
@@ -1902,6 +1884,19 @@ GetSerializableTransactionSnapshotInt(Snapshot snapshot,
19021884
SetPossibleUnsafeConflict(sxact,othersxact);
19031885
}
19041886
}
1887+
1888+
/*
1889+
* If we didn't find any possibly unsafe conflicts because every
1890+
* uncommitted writable transaction turned out to be doomed, then we
1891+
* can "opt out" immediately. See comments above the earlier check for
1892+
* PredXact->WritableSxactCount == 0.
1893+
*/
1894+
if (SHMQueueEmpty(&sxact->possibleUnsafeConflicts))
1895+
{
1896+
ReleasePredXact(sxact);
1897+
LWLockRelease(SerializableXactHashLock);
1898+
returnsnapshot;
1899+
}
19051900
}
19061901
else
19071902
{
@@ -1910,6 +1905,24 @@ GetSerializableTransactionSnapshotInt(Snapshot snapshot,
19101905
(MaxBackends+max_prepared_xacts));
19111906
}
19121907

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp