Skip to content

Commit 1c0452c

Browse files
committed
Fix one-off bug causing missing commit timestamps for subtransactions
The logic in charge of writing commit timestamps (enabled with track_commit_timestamp) for subtransactions had a one-bug bug, where it would be possible that commit timestamps go missing for the last subtransaction committed. While on it, simplify a bit the iteration logic in the loop writing the commit timestamps, as per suggestions from Kyotaro Horiguchi and Tom Lane, so as some variable initializations are not part of the loop itself. Issue introduced in 73c986a. Analyzed-by: Alex Kingsborough Author: Alex Kingsborough, Kyotaro Horiguchi Discussion: https://postgr.es/m/73A66172-4050-4F2A-B7F1-13508EDA2144@amazon.com Backpatch-through: 10
1 parent f0b0b1d commit 1c0452c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/backend/access/transam/commit_ts.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids,
184184
* subxid not on the previous page as head. This way, we only have to
185185
* lock/modify each SLRU page once.
186186
*/
187-
for (i = 0, headxid = xid;;)
187+
headxid = xid;
188+
i = 0;
189+
for (;;)
188190
{
189191
int pageno = TransactionIdToCTsPage(headxid);
190192
int j;
@@ -200,15 +202,15 @@ TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids,
200202
pageno);
201203

202204
/* if we wrote out all subxids, we're done. */
203-
if (j + 1 >= nsubxids)
205+
if (j >= nsubxids)
204206
break;
205207

206208
/*
207209
* Set the new head and skip over it, as well as over the subxids we
208210
* just wrote.
209211
*/
210212
headxid = subxids[j];
211-
i += j - i + 1;
213+
i = j + 1;
212214
}
213215

214216
/* update the cached value in shared memory */

0 commit comments

Comments
 (0)