From 2105eb0cd44f2e3e2b04c0033df2e1c19c177ff3 Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Fri, 3 Apr 2020 12:06:32 +1300 Subject: [PATCH v9 3/3] Replace all txid_XXX usage in tests with xid8_XXX. We're deprecating the txid_XXX functions, so let's stop using them in tests. The only remaining uses are now isolated in the txid.sql file, which exists to check that the deprecated functions still work for now. Discussion: https://postgr.es/m/20190725000636.666m5mad25wfbrri%40alap3.anarazel.de --- contrib/test_decoding/expected/ddl.out | 2 +- contrib/test_decoding/expected/decoding_in_xact.out | 6 +++--- contrib/test_decoding/expected/oldest_xmin.out | 2 +- contrib/test_decoding/expected/ondisk_startup.out | 6 +++--- contrib/test_decoding/expected/snapshot_transfer.out | 4 ++-- contrib/test_decoding/specs/oldest_xmin.spec | 2 +- contrib/test_decoding/specs/ondisk_startup.spec | 4 ++-- contrib/test_decoding/specs/snapshot_transfer.spec | 2 +- contrib/test_decoding/sql/ddl.sql | 2 +- contrib/test_decoding/sql/decoding_in_xact.sql | 6 +++--- src/test/modules/commit_ts/t/004_restart.pl | 6 +++--- .../modules/test_ddl_deparse/expected/create_table.out | 2 +- src/test/modules/test_ddl_deparse/sql/create_table.sql | 2 +- src/test/recovery/t/003_recovery_targets.pl | 2 +- src/test/recovery/t/011_crash_recovery.pl | 10 +++++----- src/test/regress/expected/alter_table.out | 4 ++-- src/test/regress/expected/hs_standby_functions.out | 6 +++--- src/test/regress/expected/update.out | 6 ++---- src/test/regress/sql/alter_table.sql | 4 ++-- src/test/regress/sql/hs_standby_functions.sql | 4 ++-- src/test/regress/sql/update.sql | 6 ++---- 21 files changed, 42 insertions(+), 46 deletions(-) diff --git a/contrib/test_decoding/expected/ddl.out b/contrib/test_decoding/expected/ddl.out index cf0318f697..dd267a049d 100644 --- a/contrib/test_decoding/expected/ddl.out +++ b/contrib/test_decoding/expected/ddl.out @@ -382,7 +382,7 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'inc -- test whether a known, but not yet logged toplevel xact, followed by a -- subxact commit is handled correctly BEGIN; -SELECT txid_current() != 0; -- so no fixed xid apears in the outfile +SELECT xid8_current() != '0'; -- so no fixed xid apears in the outfile ?column? ---------- t diff --git a/contrib/test_decoding/expected/decoding_in_xact.out b/contrib/test_decoding/expected/decoding_in_xact.out index ab4d3aee72..3e570c010f 100644 --- a/contrib/test_decoding/expected/decoding_in_xact.out +++ b/contrib/test_decoding/expected/decoding_in_xact.out @@ -2,7 +2,7 @@ SET synchronous_commit = on; -- fail because we're creating a slot while in an xact with xid BEGIN; -SELECT txid_current() = 0; +SELECT xid8_current() = '0'; ?column? ---------- f @@ -13,7 +13,7 @@ ERROR: cannot create logical replication slot in transaction that has performed ROLLBACK; -- fail because we're creating a slot while in a subxact whose topxact has an xid BEGIN; -SELECT txid_current() = 0; +SELECT xid8_current() = '0'; ?column? ---------- f @@ -50,7 +50,7 @@ CREATE TABLE nobarf(id serial primary key, data text); INSERT INTO nobarf(data) VALUES('1'); -- decoding works in transaction with xid BEGIN; -SELECT txid_current() = 0; +SELECT xid8_current() = '0'; ?column? ---------- f diff --git a/contrib/test_decoding/expected/oldest_xmin.out b/contrib/test_decoding/expected/oldest_xmin.out index d1b4f17e3a..f8d44f262c 100644 --- a/contrib/test_decoding/expected/oldest_xmin.out +++ b/contrib/test_decoding/expected/oldest_xmin.out @@ -2,7 +2,7 @@ Parsed test spec with 2 sessions starting permutation: s0_begin s0_getxid s1_begin s1_insert s0_alter s0_commit s0_checkpoint s0_get_changes s0_get_changes s1_commit s0_vacuum s0_get_changes step s0_begin: BEGIN; -step s0_getxid: SELECT txid_current() IS NULL; +step s0_getxid: SELECT xid8_current() IS NULL; ?column? f diff --git a/contrib/test_decoding/expected/ondisk_startup.out b/contrib/test_decoding/expected/ondisk_startup.out index c7b1f45b46..500673773c 100644 --- a/contrib/test_decoding/expected/ondisk_startup.out +++ b/contrib/test_decoding/expected/ondisk_startup.out @@ -2,20 +2,20 @@ Parsed test spec with 3 sessions starting permutation: s2b s2txid s1init s3b s3txid s2alter s2c s2b s2txid s3c s2c s1insert s1checkpoint s1start s1insert s1alter s1insert s1start step s2b: BEGIN; -step s2txid: SELECT txid_current() IS NULL; +step s2txid: SELECT xid8_current() IS NULL; ?column? f step s1init: SELECT 'init' FROM pg_create_logical_replication_slot('isolation_slot', 'test_decoding'); step s3b: BEGIN; -step s3txid: SELECT txid_current() IS NULL; +step s3txid: SELECT xid8_current() IS NULL; ?column? f step s2alter: ALTER TABLE do_write ADD COLUMN addedbys2 int; step s2c: COMMIT; step s2b: BEGIN; -step s2txid: SELECT txid_current() IS NULL; +step s2txid: SELECT xid8_current() IS NULL; ?column? f diff --git a/contrib/test_decoding/expected/snapshot_transfer.out b/contrib/test_decoding/expected/snapshot_transfer.out index 87bed03f76..0688bea0b1 100644 --- a/contrib/test_decoding/expected/snapshot_transfer.out +++ b/contrib/test_decoding/expected/snapshot_transfer.out @@ -3,7 +3,7 @@ Parsed test spec with 2 sessions starting permutation: s0_begin s0_begin_sub0 s0_log_assignment s0_sub_get_base_snap s1_produce_new_snap s0_insert s0_end_sub0 s0_commit s0_get_changes step s0_begin: BEGIN; step s0_begin_sub0: SAVEPOINT s0; -step s0_log_assignment: SELECT txid_current() IS NULL; +step s0_log_assignment: SELECT xid8_current() IS NULL; ?column? f @@ -26,7 +26,7 @@ stop starting permutation: s0_begin s0_begin_sub0 s0_log_assignment s0_begin_sub1 s0_sub_get_base_snap s1_produce_new_snap s0_insert s0_end_sub1 s0_end_sub0 s0_commit s0_get_changes step s0_begin: BEGIN; step s0_begin_sub0: SAVEPOINT s0; -step s0_log_assignment: SELECT txid_current() IS NULL; +step s0_log_assignment: SELECT xid8_current() IS NULL; ?column? f diff --git a/contrib/test_decoding/specs/oldest_xmin.spec b/contrib/test_decoding/specs/oldest_xmin.spec index 6cb13e85ce..d38b4f21bc 100644 --- a/contrib/test_decoding/specs/oldest_xmin.spec +++ b/contrib/test_decoding/specs/oldest_xmin.spec @@ -19,7 +19,7 @@ teardown session "s0" setup { SET synchronous_commit=on; } step "s0_begin" { BEGIN; } -step "s0_getxid" { SELECT txid_current() IS NULL; } +step "s0_getxid" { SELECT xid8_current() IS NULL; } step "s0_alter" { ALTER TYPE basket DROP ATTRIBUTE mangos; } step "s0_commit" { COMMIT; } step "s0_checkpoint" { CHECKPOINT; } diff --git a/contrib/test_decoding/specs/ondisk_startup.spec b/contrib/test_decoding/specs/ondisk_startup.spec index 12c57a813d..07281e9d28 100644 --- a/contrib/test_decoding/specs/ondisk_startup.spec +++ b/contrib/test_decoding/specs/ondisk_startup.spec @@ -25,7 +25,7 @@ session "s2" setup { SET synchronous_commit=on; } step "s2b" { BEGIN; } -step "s2txid" { SELECT txid_current() IS NULL; } +step "s2txid" { SELECT xid8_current() IS NULL; } step "s2alter" { ALTER TABLE do_write ADD COLUMN addedbys2 int; } step "s2c" { COMMIT; } @@ -34,7 +34,7 @@ session "s3" setup { SET synchronous_commit=on; } step "s3b" { BEGIN; } -step "s3txid" { SELECT txid_current() IS NULL; } +step "s3txid" { SELECT xid8_current() IS NULL; } step "s3c" { COMMIT; } # Force usage of ondisk snapshot by starting and not finishing a diff --git a/contrib/test_decoding/specs/snapshot_transfer.spec b/contrib/test_decoding/specs/snapshot_transfer.spec index ae81e8f102..9775c59320 100644 --- a/contrib/test_decoding/specs/snapshot_transfer.spec +++ b/contrib/test_decoding/specs/snapshot_transfer.spec @@ -20,7 +20,7 @@ session "s0" setup { SET synchronous_commit=on; } step "s0_begin" { BEGIN; } step "s0_begin_sub0" { SAVEPOINT s0; } -step "s0_log_assignment" { SELECT txid_current() IS NULL; } +step "s0_log_assignment" { SELECT xid8_current() IS NULL; } step "s0_begin_sub1" { SAVEPOINT s1; } step "s0_sub_get_base_snap" { INSERT INTO dummy VALUES (0); } step "s0_insert" { INSERT INTO harvest VALUES (1, 2, 3); } diff --git a/contrib/test_decoding/sql/ddl.sql b/contrib/test_decoding/sql/ddl.sql index 0f2b9992f7..22a2b56e04 100644 --- a/contrib/test_decoding/sql/ddl.sql +++ b/contrib/test_decoding/sql/ddl.sql @@ -220,7 +220,7 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'inc -- test whether a known, but not yet logged toplevel xact, followed by a -- subxact commit is handled correctly BEGIN; -SELECT txid_current() != 0; -- so no fixed xid apears in the outfile +SELECT xid8_current() != '0'; -- so no fixed xid apears in the outfile SAVEPOINT a; INSERT INTO tr_sub(path) VALUES ('4-top-1-#1'); RELEASE SAVEPOINT a; diff --git a/contrib/test_decoding/sql/decoding_in_xact.sql b/contrib/test_decoding/sql/decoding_in_xact.sql index b524eb9a6e..b594a5b723 100644 --- a/contrib/test_decoding/sql/decoding_in_xact.sql +++ b/contrib/test_decoding/sql/decoding_in_xact.sql @@ -3,13 +3,13 @@ SET synchronous_commit = on; -- fail because we're creating a slot while in an xact with xid BEGIN; -SELECT txid_current() = 0; +SELECT xid8_current() = '0'; SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); ROLLBACK; -- fail because we're creating a slot while in a subxact whose topxact has an xid BEGIN; -SELECT txid_current() = 0; +SELECT xid8_current() = '0'; SAVEPOINT barf; SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); ROLLBACK TO SAVEPOINT barf; @@ -29,7 +29,7 @@ INSERT INTO nobarf(data) VALUES('1'); -- decoding works in transaction with xid BEGIN; -SELECT txid_current() = 0; +SELECT xid8_current() = '0'; -- don't show yet, haven't committed INSERT INTO nobarf(data) VALUES('2'); SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); diff --git a/src/test/modules/commit_ts/t/004_restart.pl b/src/test/modules/commit_ts/t/004_restart.pl index bd4b943305..f21f986fe7 100644 --- a/src/test/modules/commit_ts/t/004_restart.pl +++ b/src/test/modules/commit_ts/t/004_restart.pl @@ -45,7 +45,7 @@ my $xid = $node_master->safe_psql( 'postgres', qq[ BEGIN; INSERT INTO committs_test(x, y) VALUES (1, current_timestamp); - SELECT txid_current(); + SELECT xid8_current()::xid; COMMIT; ]); @@ -93,7 +93,7 @@ DECLARE i int; BEGIN FOR i in 1..cnt LOOP - EXECUTE 'SELECT txid_current()'; + EXECUTE 'SELECT xid8_current()'; COMMIT; END LOOP; END; @@ -115,7 +115,7 @@ my $xid_disabled = $node_master->safe_psql( 'postgres', qq[ BEGIN; INSERT INTO committs_test(x, y) VALUES (2, current_timestamp); - SELECT txid_current(); + SELECT xid8_current(); COMMIT; ]); diff --git a/src/test/modules/test_ddl_deparse/expected/create_table.out b/src/test/modules/test_ddl_deparse/expected/create_table.out index 523c996093..3d5704a793 100644 --- a/src/test/modules/test_ddl_deparse/expected/create_table.out +++ b/src/test/modules/test_ddl_deparse/expected/create_table.out @@ -43,7 +43,7 @@ CREATE TABLE datatype_table ( v_json JSON, v_xml XML, v_uuid UUID, - v_txid_snapshot txid_snapshot, + v_xid8_snapshot xid8_snapshot, v_enum ENUM_TEST, v_postal_code japanese_postal_code, v_int2range int2range, diff --git a/src/test/modules/test_ddl_deparse/sql/create_table.sql b/src/test/modules/test_ddl_deparse/sql/create_table.sql index dd3a908638..6e16f27c1a 100644 --- a/src/test/modules/test_ddl_deparse/sql/create_table.sql +++ b/src/test/modules/test_ddl_deparse/sql/create_table.sql @@ -44,7 +44,7 @@ CREATE TABLE datatype_table ( v_json JSON, v_xml XML, v_uuid UUID, - v_txid_snapshot txid_snapshot, + v_xid8_snapshot xid8_snapshot, v_enum ENUM_TEST, v_postal_code japanese_postal_code, v_int2range int2range, diff --git a/src/test/recovery/t/003_recovery_targets.pl b/src/test/recovery/t/003_recovery_targets.pl index fd14bab208..774d10224d 100644 --- a/src/test/recovery/t/003_recovery_targets.pl +++ b/src/test/recovery/t/003_recovery_targets.pl @@ -68,7 +68,7 @@ $node_master->backup('my_backup'); $node_master->safe_psql('postgres', "INSERT INTO tab_int VALUES (generate_series(1001,2000))"); my $ret = $node_master->safe_psql('postgres', - "SELECT pg_current_wal_lsn(), txid_current();"); + "SELECT pg_current_wal_lsn(), xid8_current();"); my ($lsn2, $recovery_txid) = split /\|/, $ret; # More data, with recovery target timestamp diff --git a/src/test/recovery/t/011_crash_recovery.pl b/src/test/recovery/t/011_crash_recovery.pl index 526a3481fb..cc38c9f6b2 100644 --- a/src/test/recovery/t/011_crash_recovery.pl +++ b/src/test/recovery/t/011_crash_recovery.pl @@ -24,7 +24,7 @@ $node->start; my ($stdin, $stdout, $stderr) = ('', '', ''); -# Ensure that txid_status reports 'aborted' for xacts +# Ensure that xid8_status reports 'aborted' for xacts # that were in-progress during crash. To do that, we need # an xact to be in-progress when we crash and we need to know # its xid. @@ -42,7 +42,7 @@ my $tx = IPC::Run::start( $stdin .= q[ BEGIN; CREATE TABLE mine(x integer); -SELECT txid_current(); +SELECT xid8_current(); ]; $tx->pump until $stdout =~ /[[:digit:]]+[\r\n]$/; @@ -50,7 +50,7 @@ $tx->pump until $stdout =~ /[[:digit:]]+[\r\n]$/; my $xid = $stdout; chomp($xid); -is($node->safe_psql('postgres', qq[SELECT txid_status('$xid');]), +is($node->safe_psql('postgres', qq[SELECT xid8_status('$xid');]), 'in progress', 'own xid is in-progress'); # Crash and restart the postmaster @@ -58,11 +58,11 @@ $node->stop('immediate'); $node->start; # Make sure we really got a new xid -cmp_ok($node->safe_psql('postgres', 'SELECT txid_current()'), +cmp_ok($node->safe_psql('postgres', 'SELECT xid8_current()'), '>', $xid, 'new xid after restart is greater'); # and make sure we show the in-progress xact as aborted -is($node->safe_psql('postgres', qq[SELECT txid_status('$xid');]), +is($node->safe_psql('postgres', qq[SELECT xid8_status('$xid');]), 'aborted', 'xid is aborted after crash'); $tx->kill_kill; diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out index fb6d86a269..74fe5f2bf8 100644 --- a/src/test/regress/expected/alter_table.out +++ b/src/test/regress/expected/alter_table.out @@ -2550,7 +2550,7 @@ from pg_locks l join pg_class c on l.relation = c.oid where virtualtransaction = ( select virtualtransaction from pg_locks - where transactionid = txid_current()::integer) + where transactionid = xid8_current()::xid) and locktype = 'relation' and relnamespace != (select oid from pg_namespace where nspname = 'pg_catalog') and c.relname != 'my_locks' @@ -2713,7 +2713,7 @@ from pg_locks l join pg_class c on l.relation = c.oid where virtualtransaction = ( select virtualtransaction from pg_locks - where transactionid = txid_current()::integer) + where transactionid = xid8_current()::xid) and locktype = 'relation' and relnamespace != (select oid from pg_namespace where nspname = 'pg_catalog') and c.relname = 'my_locks' diff --git a/src/test/regress/expected/hs_standby_functions.out b/src/test/regress/expected/hs_standby_functions.out index e0af677ea1..1f9459bcd6 100644 --- a/src/test/regress/expected/hs_standby_functions.out +++ b/src/test/regress/expected/hs_standby_functions.out @@ -4,9 +4,9 @@ -- hs_standby_functions.sql -- -- should fail -select txid_current(); -ERROR: cannot execute txid_current() during recovery -select length(txid_current_snapshot()::text) >= 4; +select xid8_current(); +ERROR: cannot execute xid8_current() during recovery +select length(xid8_current_snapshot()::text) >= 4; ?column? ---------- t diff --git a/src/test/regress/expected/update.out b/src/test/regress/expected/update.out index b7f90de52b..cea5fd0dc0 100644 --- a/src/test/regress/expected/update.out +++ b/src/test/regress/expected/update.out @@ -230,10 +230,9 @@ INSERT INTO upsert_test VALUES (1, 'Bat') ON CONFLICT(a) -- ON CONFLICT using system attributes in RETURNING, testing both the -- inserting and updating paths. See bug report at: -- /message-id/73436355-6432-49B1-92ED-1FE4F7E7E100%40finefun.com.au -CREATE FUNCTION xid_current() RETURNS xid LANGUAGE SQL AS $$SELECT (txid_current() % ((1::int8<<32)))::text::xid;$$; INSERT INTO upsert_test VALUES (2, 'Beeble') ON CONFLICT(a) DO UPDATE SET (b, a) = (SELECT b || ', Excluded', a from upsert_test i WHERE i.a = excluded.a) - RETURNING tableoid::regclass, xmin = xid_current() AS xmin_correct, xmax = 0 AS xmax_correct; + RETURNING tableoid::regclass, xmin = xid8_current()::xid AS xmin_correct, xmax = 0 AS xmax_correct; tableoid | xmin_correct | xmax_correct -------------+--------------+-------------- upsert_test | t | t @@ -243,13 +242,12 @@ INSERT INTO upsert_test VALUES (2, 'Beeble') ON CONFLICT(a) -- but it seems worthwhile to have to be explicit if that changes. INSERT INTO upsert_test VALUES (2, 'Brox') ON CONFLICT(a) DO UPDATE SET (b, a) = (SELECT b || ', Excluded', a from upsert_test i WHERE i.a = excluded.a) - RETURNING tableoid::regclass, xmin = xid_current() AS xmin_correct, xmax = xid_current() AS xmax_correct; + RETURNING tableoid::regclass, xmin = xid8_current()::xid AS xmin_correct, xmax = xid8_current()::xid AS xmax_correct; tableoid | xmin_correct | xmax_correct -------------+--------------+-------------- upsert_test | t | t (1 row) -DROP FUNCTION xid_current(); DROP TABLE update_test; DROP TABLE upsert_test; --------------------------- diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql index 3801f19c58..11f14df144 100644 --- a/src/test/regress/sql/alter_table.sql +++ b/src/test/regress/sql/alter_table.sql @@ -1638,7 +1638,7 @@ from pg_locks l join pg_class c on l.relation = c.oid where virtualtransaction = ( select virtualtransaction from pg_locks - where transactionid = txid_current()::integer) + where transactionid = xid8_current()::xid) and locktype = 'relation' and relnamespace != (select oid from pg_namespace where nspname = 'pg_catalog') and c.relname != 'my_locks' @@ -1725,7 +1725,7 @@ from pg_locks l join pg_class c on l.relation = c.oid where virtualtransaction = ( select virtualtransaction from pg_locks - where transactionid = txid_current()::integer) + where transactionid = xid8_current()::xid) and locktype = 'relation' and relnamespace != (select oid from pg_namespace where nspname = 'pg_catalog') and c.relname = 'my_locks' diff --git a/src/test/regress/sql/hs_standby_functions.sql b/src/test/regress/sql/hs_standby_functions.sql index 251bac0a43..8199f15bd9 100644 --- a/src/test/regress/sql/hs_standby_functions.sql +++ b/src/test/regress/sql/hs_standby_functions.sql @@ -5,9 +5,9 @@ -- -- should fail -select txid_current(); +select xid8_current(); -select length(txid_current_snapshot()::text) >= 4; +select length(xid8_current_snapshot()::text) >= 4; select pg_start_backup('should fail'); select pg_switch_wal(); diff --git a/src/test/regress/sql/update.sql b/src/test/regress/sql/update.sql index bb9c24e40f..cd697cecee 100644 --- a/src/test/regress/sql/update.sql +++ b/src/test/regress/sql/update.sql @@ -117,18 +117,16 @@ INSERT INTO upsert_test VALUES (1, 'Bat') ON CONFLICT(a) -- ON CONFLICT using system attributes in RETURNING, testing both the -- inserting and updating paths. See bug report at: -- /message-id/73436355-6432-49B1-92ED-1FE4F7E7E100%40finefun.com.au -CREATE FUNCTION xid_current() RETURNS xid LANGUAGE SQL AS $$SELECT (txid_current() % ((1::int8<<32)))::text::xid;$$; INSERT INTO upsert_test VALUES (2, 'Beeble') ON CONFLICT(a) DO UPDATE SET (b, a) = (SELECT b || ', Excluded', a from upsert_test i WHERE i.a = excluded.a) - RETURNING tableoid::regclass, xmin = xid_current() AS xmin_correct, xmax = 0 AS xmax_correct; + RETURNING tableoid::regclass, xmin = xid8_current()::xid AS xmin_correct, xmax = 0 AS xmax_correct; -- currently xmax is set after a conflict - that's probably not good, -- but it seems worthwhile to have to be explicit if that changes. INSERT INTO upsert_test VALUES (2, 'Brox') ON CONFLICT(a) DO UPDATE SET (b, a) = (SELECT b || ', Excluded', a from upsert_test i WHERE i.a = excluded.a) - RETURNING tableoid::regclass, xmin = xid_current() AS xmin_correct, xmax = xid_current() AS xmax_correct; + RETURNING tableoid::regclass, xmin = xid8_current()::xid AS xmin_correct, xmax = xid8_current()::xid AS xmax_correct; -DROP FUNCTION xid_current(); DROP TABLE update_test; DROP TABLE upsert_test; -- 2.20.1