Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 237d1f3

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 cfe7bd1 commit 237d1f3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/backend/access/transam/commit_ts.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids,
168168
* subxid not on the previous page as head. This way, we only have to
169169
* lock/modify each SLRU page once.
170170
*/
171-
for (i = 0, headxid = xid;;)
171+
headxid = xid;
172+
i = 0;
173+
for (;;)
172174
{
173175
int pageno = TransactionIdToCTsPage(headxid);
174176
int j;
@@ -184,15 +186,15 @@ TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids,
184186
pageno);
185187

186188
/* if we wrote out all subxids, we're done. */
187-
if (j + 1 >= nsubxids)
189+
if (j >= nsubxids)
188190
break;
189191

190192
/*
191193
* Set the new head and skip over it, as well as over the subxids we
192194
* just wrote.
193195
*/
194196
headxid = subxids[j];
195-
i += j - i + 1;
197+
i = j + 1;
196198
}
197199

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

0 commit comments

Comments
 (0)