summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier2022-01-21 05:54:04 +0000
committerMichael Paquier2022-01-21 05:54:04 +0000
commit237d1f317240b60b3fff698f4e9b184d1db83a6e (patch)
treec62c5acb9d7dd340fffde157b45d07404d388686
parentcfe7bd17e4fa987c9ba14add48ea58a41c45ccdb (diff)
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/[email protected] Backpatch-through: 10
-rw-r--r--src/backend/access/transam/commit_ts.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/backend/access/transam/commit_ts.c b/src/backend/access/transam/commit_ts.c
index 659109f8d4..9419a5ca41 100644
--- a/src/backend/access/transam/commit_ts.c
+++ b/src/backend/access/transam/commit_ts.c
@@ -168,7 +168,9 @@ TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids,
* subxid not on the previous page as head. This way, we only have to
* lock/modify each SLRU page once.
*/
- for (i = 0, headxid = xid;;)
+ headxid = xid;
+ i = 0;
+ for (;;)
{
int pageno = TransactionIdToCTsPage(headxid);
int j;
@@ -184,7 +186,7 @@ TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids,
pageno);
/* if we wrote out all subxids, we're done. */
- if (j + 1 >= nsubxids)
+ if (j >= nsubxids)
break;
/*
@@ -192,7 +194,7 @@ TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids,
* just wrote.
*/
headxid = subxids[j];
- i += j - i + 1;
+ i = j + 1;
}
/* update the cached value in shared memory */