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

Commit4aaddf2

Browse files
committed
Fix commit_ts for FrozenXid and BootstrapXid
Previously, requesting commit timestamp for transactionsFrozenTransactionId and BootstrapTransactionId resulted in an error.But since those values can validly appear in committed tuples' Xmin,this behavior is unhelpful and error prone: each caller would have tospecial-case those values before requesting timestamp data for an Xid.We already have a perfectly good interface for returning "the Xid yourequested is too old for us to have commit TS data for it", so let's usethat instead.Backpatch to 9.5, where commit timestamps appeared.Author: Craig RingerDiscussion:https://www.postgresql.org/message-id/CAMsr+YFM5Q=+ry3mKvWEqRTxrB0iU3qUSRnS28nz6FJYtBwhJg@mail.gmail.com
1 parent6fa391b commit4aaddf2

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

‎src/backend/access/transam/commit_ts.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,18 @@ TransactionIdGetCommitTsData(TransactionId xid, TimestampTz *ts,
289289
TransactionIdoldestCommitTsXid;
290290
TransactionIdnewestCommitTsXid;
291291

292-
/* error if the given Xid doesn't normally commit */
293-
if (!TransactionIdIsNormal(xid))
292+
if (!TransactionIdIsValid(xid))
294293
ereport(ERROR,
295294
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
296295
errmsg("cannot retrieve commit timestamp for transaction %u",xid)));
296+
elseif (!TransactionIdIsNormal(xid))
297+
{
298+
/* frozen and bootstrap xids are always committed far in the past */
299+
*ts=0;
300+
if (nodeid)
301+
*nodeid=0;
302+
return false;
303+
}
297304

298305
LWLockAcquire(CommitTsLock,LW_SHARED);
299306

‎src/test/modules/commit_ts/expected/commit_timestamp.out

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@ DROP TABLE committs_test;
2828
SELECT pg_xact_commit_timestamp('0'::xid);
2929
ERROR: cannot retrieve commit timestamp for transaction 0
3030
SELECT pg_xact_commit_timestamp('1'::xid);
31-
ERROR: cannot retrieve commit timestamp for transaction 1
31+
pg_xact_commit_timestamp
32+
--------------------------
33+
34+
(1 row)
35+
3236
SELECT pg_xact_commit_timestamp('2'::xid);
33-
ERROR: cannot retrieve commit timestamp for transaction 2
37+
pg_xact_commit_timestamp
38+
--------------------------
39+
40+
(1 row)
41+
3442
SELECT x.xid::text::bigint > 0, x.timestamp > '-infinity'::timestamptz, x.timestamp <= now() FROM pg_last_committed_xact() x;
3543
?column? | ?column? | ?column?
3644
----------+----------+----------

‎src/test/modules/commit_ts/expected/commit_timestamp_1.out

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ DROP TABLE committs_test;
2323
SELECT pg_xact_commit_timestamp('0'::xid);
2424
ERROR: cannot retrieve commit timestamp for transaction 0
2525
SELECT pg_xact_commit_timestamp('1'::xid);
26-
ERROR: cannot retrieve commit timestamp for transaction 1
26+
pg_xact_commit_timestamp
27+
--------------------------
28+
29+
(1 row)
30+
2731
SELECT pg_xact_commit_timestamp('2'::xid);
28-
ERROR: cannot retrieve commit timestamp for transaction 2
32+
pg_xact_commit_timestamp
33+
--------------------------
34+
35+
(1 row)
36+
2937
SELECT x.xid::text::bigint > 0, x.timestamp > '-infinity'::timestamptz, x.timestamp <= now() FROM pg_last_committed_xact() x;
3038
ERROR: could not get commit timestamp data
3139
HINT: Make sure the configuration parameter "track_commit_timestamp" is set.

‎src/test/modules/commit_ts/t/004_restart.pl

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,13 @@
2525

2626
($ret,$stdout,$stderr) =
2727
$node_master->psql('postgres',qq[SELECT pg_xact_commit_timestamp('1');]);
28-
is($ret, 3,'getting ts of BootstrapTransactionId reports error');
29-
like(
30-
$stderr,
31-
qr/cannot retrieve commit timestamp for transaction/,
32-
'expected error from BootstrapTransactionId');
28+
is($ret, 0,'getting ts of BootstrapTransactionId succeeds');
29+
is($stdout,'','timestamp of BootstrapTransactionId is null');
3330

3431
($ret,$stdout,$stderr) =
3532
$node_master->psql('postgres',qq[SELECT pg_xact_commit_timestamp('2');]);
36-
is($ret, 3,'getting ts of FrozenTransactionId reports error');
37-
like(
38-
$stderr,
39-
qr/cannot retrieve commit timestamp for transaction/,
40-
'expected error from FrozenTransactionId');
33+
is($ret, 0,'getting ts of FrozenTransactionId succeeds');
34+
is($stdout,'','timestamp of FrozenTransactionId is null');
4135

4236
# Since FirstNormalTransactionId will've occurred during initdb, long before we
4337
# enabled commit timestamps, it'll be null since we have no cts data for it but

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp