initdb -c "track_commit_timestamp=on" crashes in case of debug build

Started by Hayato Kuroda (Fujitsu)about 1 year ago3 messages
#1Hayato Kuroda (Fujitsu)
kuroda.hayato@fujitsu.com
1 attachment(s)

Hi hackers,

While working on another thread I found $subject. I've tested only on master,
but I doubt this could happen even on PG16 and 17. You can reproduce by:
```
$ initdb -D data -c "track_commit_timestamp=on"
...
child process was terminated by signal 6: Aborted
initdb: removing data directory "data"
```

Back-trace I got is shown in [1]``` (gdb) bt #0 0x00007f1da8dd8387 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:55 #1 0x00007f1da8dd9a78 in __GI_abort () at abort.c:90 #2 0x0000000000bd3c0c in ExceptionalCondition (conditionName=0xc7a21b "TransactionIdIsNormal(xid)", fileName=0xc7a20f "commit_ts.c", lineNumber=255) at assert.c:66 #3 0x000000000056467f in TransactionIdSetCommitTs (xid=1, ts=789482588771230, nodeid=0, slotno=0) at commit_ts.c:255 #4 0x00000000005645c3 in SetXidCommitTsInPage (xid=1, nsubxids=0, subxids=0x0, ts=789482588771230, nodeid=0, pageno=0) at commit_ts.c:234 #5 0x0000000000564494 in TransactionTreeSetCommitTsData (xid=1, nsubxids=0, subxids=0x0, timestamp=789482588771230, nodeid=0) at commit_ts.c:190 #6 0x0000000000579c18 in RecordTransactionCommit () at xact.c:1467 #7 0x000000000057aa15 in CommitTransaction () at xact.c:2364 #8 0x000000000057b7cf in CommitTransactionCommandInternal () at xact.c:3194 #9 0x000000000057b738 in CommitTransactionCommand () at xact.c:3155 #10 0x00000000005b1b0e in BootstrapModeMain (argc=7, argv=0x1be1048, check_only=false) at bootstrap.c:390 #11 0x00000000007de1c5 in main (argc=8, argv=0x1be1040) at main.c:21 ```.

IIUC the crash was caused at TransactionIdSetCommitTs(), and the primal reason was that
commit_ts module tried to store the bootstrap transaction.

In the first place I'm not sure we want to fix this because this happens only for
the debug mode... but if needed, the easiest way is not to activate the commit_ts
in the bootstrap mode. I think this fix is enough because pg_last_committed_xact()
and TransactionIdGetCommitTsData() won't seek the un-normal xid.
Attached patch was created based on the idea.

Thought?

[1]: ``` (gdb) bt #0 0x00007f1da8dd8387 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:55 #1 0x00007f1da8dd9a78 in __GI_abort () at abort.c:90 #2 0x0000000000bd3c0c in ExceptionalCondition (conditionName=0xc7a21b "TransactionIdIsNormal(xid)", fileName=0xc7a20f "commit_ts.c", lineNumber=255) at assert.c:66 #3 0x000000000056467f in TransactionIdSetCommitTs (xid=1, ts=789482588771230, nodeid=0, slotno=0) at commit_ts.c:255 #4 0x00000000005645c3 in SetXidCommitTsInPage (xid=1, nsubxids=0, subxids=0x0, ts=789482588771230, nodeid=0, pageno=0) at commit_ts.c:234 #5 0x0000000000564494 in TransactionTreeSetCommitTsData (xid=1, nsubxids=0, subxids=0x0, timestamp=789482588771230, nodeid=0) at commit_ts.c:190 #6 0x0000000000579c18 in RecordTransactionCommit () at xact.c:1467 #7 0x000000000057aa15 in CommitTransaction () at xact.c:2364 #8 0x000000000057b7cf in CommitTransactionCommandInternal () at xact.c:3194 #9 0x000000000057b738 in CommitTransactionCommand () at xact.c:3155 #10 0x00000000005b1b0e in BootstrapModeMain (argc=7, argv=0x1be1048, check_only=false) at bootstrap.c:390 #11 0x00000000007de1c5 in main (argc=8, argv=0x1be1040) at main.c:21 ```
```
(gdb) bt
#0 0x00007f1da8dd8387 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:55
#1 0x00007f1da8dd9a78 in __GI_abort () at abort.c:90
#2 0x0000000000bd3c0c in ExceptionalCondition (conditionName=0xc7a21b "TransactionIdIsNormal(xid)",
fileName=0xc7a20f "commit_ts.c", lineNumber=255) at assert.c:66
#3 0x000000000056467f in TransactionIdSetCommitTs (xid=1, ts=789482588771230, nodeid=0, slotno=0) at commit_ts.c:255
#4 0x00000000005645c3 in SetXidCommitTsInPage (xid=1, nsubxids=0, subxids=0x0, ts=789482588771230, nodeid=0, pageno=0)
at commit_ts.c:234
#5 0x0000000000564494 in TransactionTreeSetCommitTsData (xid=1, nsubxids=0, subxids=0x0, timestamp=789482588771230,
nodeid=0) at commit_ts.c:190
#6 0x0000000000579c18 in RecordTransactionCommit () at xact.c:1467
#7 0x000000000057aa15 in CommitTransaction () at xact.c:2364
#8 0x000000000057b7cf in CommitTransactionCommandInternal () at xact.c:3194
#9 0x000000000057b738 in CommitTransactionCommand () at xact.c:3155
#10 0x00000000005b1b0e in BootstrapModeMain (argc=7, argv=0x1be1048, check_only=false) at bootstrap.c:390
#11 0x00000000007de1c5 in main (argc=8, argv=0x1be1040) at main.c:21
```

Best regards,
Hayato Kuroda
FUJITSU LIMITED

Attachments:

0001-Avoid-activating-commit_ts-while-bootstrap.patchapplication/octet-stream; name=0001-Avoid-activating-commit_ts-while-bootstrap.patchDownload
From 8d1903ebca853bb74e524bd4bf01ec678481e50e Mon Sep 17 00:00:00 2001
From: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Date: Mon, 6 Jan 2025 13:08:04 +0000
Subject: [PATCH] Avoid activating commit_ts while bootstrap

---
 src/backend/access/transam/commit_ts.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/backend/access/transam/commit_ts.c b/src/backend/access/transam/commit_ts.c
index 95049acd0b..ea42d3a95e 100644
--- a/src/backend/access/transam/commit_ts.c
+++ b/src/backend/access/transam/commit_ts.c
@@ -707,6 +707,13 @@ ActivateCommitTs(void)
 	TransactionId xid;
 	int64		pageno;
 
+	/*
+	 * commit_ts assumes that we are not in the bootstrap mode: skip the
+	 * activation.
+	 */
+	if (IsBootstrapProcessingMode())
+		return;
+
 	/* If we've done this already, there's nothing to do */
 	LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
 	if (commitTsShared->commitTsActive)
-- 
2.43.0

#2Peter Eisentraut
peter@eisentraut.org
In reply to: Hayato Kuroda (Fujitsu) (#1)
Re: initdb -c "track_commit_timestamp=on" crashes in case of debug build

On 06.01.25 14:14, Hayato Kuroda (Fujitsu) wrote:

While working on another thread I found $subject. I've tested only on master,
but I doubt this could happen even on PG16 and 17. You can reproduce by:
```
$ initdb -D data -c "track_commit_timestamp=on"
...
child process was terminated by signal 6: Aborted
initdb: removing data directory "data"
```

Back-trace I got is shown in [1].

IIUC the crash was caused at TransactionIdSetCommitTs(), and the primal reason was that
commit_ts module tried to store the bootstrap transaction.

In the first place I'm not sure we want to fix this because this happens only for
the debug mode... but if needed, the easiest way is not to activate the commit_ts
in the bootstrap mode. I think this fix is enough because pg_last_committed_xact()
and TransactionIdGetCommitTsData() won't seek the un-normal xid.
Attached patch was created based on the idea.

Yes, this was previously reported [0]/messages/by-id/8a8fda29-5a68-ba68-a2ff-8d17602b3762@enterprisedb.com but nothing was done about it. We
just need to find some place to "do nothing" in bootstrap mode to avoid
the crash. Your patch seems ok to me for that.

[0]: /messages/by-id/8a8fda29-5a68-ba68-a2ff-8d17602b3762@enterprisedb.com
/messages/by-id/8a8fda29-5a68-ba68-a2ff-8d17602b3762@enterprisedb.com

#3Hayato Kuroda (Fujitsu)
kuroda.hayato@fujitsu.com
In reply to: Peter Eisentraut (#2)
RE: initdb -c "track_commit_timestamp=on" crashes in case of debug build

Dear Peter,

Yes, this was previously reported [0] but nothing was done about it. We
just need to find some place to "do nothing" in bootstrap mode to avoid
the crash. Your patch seems ok to me for that.

Thanks for giving the old discussion. I couldn't find it. According to the post [1]/messages/by-id/0307b599-9528-643d-934c-a7e76d376e94@enterprisedb.com,
there are no similar failures for boolean GUCs.

From this perspective, we do not have to do some fundamental ways to fix this bug,
i.e., my patch is enough.

[1]: /messages/by-id/0307b599-9528-643d-934c-a7e76d376e94@enterprisedb.com

Best regards,
Hayato Kuroda
FUJITSU LIMITED