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

Commit2d2e40e

Browse files
committed
Fetch XIDs atomically during vac_truncate_clog().
Because vac_update_datfrozenxid() updates datfrozenxid and datminmxidin-place, it's unsafe to assume that successive reads of those values willgive consistent results. Fetch each one just once to ensure sane behaviorin the minimum calculation. Noted while reviewing Alexander Korotkov'spatch in the same area.Discussion: <8564.1464116473@sss.pgh.pa.us>
1 parent996d273 commit2d2e40e

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

‎src/backend/commands/vacuum.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,12 @@ vac_truncate_clog(TransactionId frozenXID,
10671067
/*
10681068
* Scan pg_database to compute the minimum datfrozenxid/datminmxid
10691069
*
1070+
* Since vac_update_datfrozenxid updates datfrozenxid/datminmxid in-place,
1071+
* the values could change while we look at them. Fetch each one just
1072+
* once to ensure sane behavior of the comparison logic. (Here, as in
1073+
* many other places, we assume that fetching or updating an XID in shared
1074+
* storage is atomic.)
1075+
*
10701076
* Note: we need not worry about a race condition with new entries being
10711077
* inserted by CREATE DATABASE. Any such entry will have a copy of some
10721078
* existing DB's datfrozenxid, and that source DB cannot be ours because
@@ -1082,10 +1088,12 @@ vac_truncate_clog(TransactionId frozenXID,
10821088

10831089
while ((tuple=heap_getnext(scan,ForwardScanDirection))!=NULL)
10841090
{
1085-
Form_pg_databasedbform= (Form_pg_database)GETSTRUCT(tuple);
1091+
volatileFormData_pg_database*dbform= (Form_pg_database)GETSTRUCT(tuple);
1092+
TransactionIddatfrozenxid=dbform->datfrozenxid;
1093+
TransactionIddatminmxid=dbform->datminmxid;
10861094

1087-
Assert(TransactionIdIsNormal(dbform->datfrozenxid));
1088-
Assert(MultiXactIdIsValid(dbform->datminmxid));
1095+
Assert(TransactionIdIsNormal(datfrozenxid));
1096+
Assert(MultiXactIdIsValid(datminmxid));
10891097

10901098
/*
10911099
* If things are working properly, no database should have a
@@ -1096,21 +1104,21 @@ vac_truncate_clog(TransactionId frozenXID,
10961104
* databases have been scanned and cleaned up. (We will issue the
10971105
* "already wrapped" warning if appropriate, though.)
10981106
*/
1099-
if (TransactionIdPrecedes(lastSaneFrozenXid,dbform->datfrozenxid)||
1100-
MultiXactIdPrecedes(lastSaneMinMulti,dbform->datminmxid))
1107+
if (TransactionIdPrecedes(lastSaneFrozenXid,datfrozenxid)||
1108+
MultiXactIdPrecedes(lastSaneMinMulti,datminmxid))
11011109
bogus= true;
11021110

1103-
if (TransactionIdPrecedes(nextXID,dbform->datfrozenxid))
1111+
if (TransactionIdPrecedes(nextXID,datfrozenxid))
11041112
frozenAlreadyWrapped= true;
1105-
elseif (TransactionIdPrecedes(dbform->datfrozenxid,frozenXID))
1113+
elseif (TransactionIdPrecedes(datfrozenxid,frozenXID))
11061114
{
1107-
frozenXID=dbform->datfrozenxid;
1115+
frozenXID=datfrozenxid;
11081116
oldestxid_datoid=HeapTupleGetOid(tuple);
11091117
}
11101118

1111-
if (MultiXactIdPrecedes(dbform->datminmxid,minMulti))
1119+
if (MultiXactIdPrecedes(datminmxid,minMulti))
11121120
{
1113-
minMulti=dbform->datminmxid;
1121+
minMulti=datminmxid;
11141122
minmulti_datoid=HeapTupleGetOid(tuple);
11151123
}
11161124
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp