diff --git a/src/test/regress/expected/multi_modifications.out b/src/test/regress/expected/multi_modifications.out index 3b62f7c38..d28f173cc 100644 --- a/src/test/regress/expected/multi_modifications.out +++ b/src/test/regress/expected/multi_modifications.out @@ -258,20 +258,18 @@ SELECT kind, limit_price FROM limit_orders WHERE id = 246; (1 row) -- Test that shards which miss a modification are marked unhealthy -\set first_worker_port 57637 -\set second_worker_port 57638 -- First: Mark all placements for a node as inactive UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE nodename = 'localhost' AND - nodeport = :first_worker_port; + nodeport = :worker_1_port; -- Second: Perform an INSERT to the remaining node INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67); -- Third: Mark the original placements as healthy again UPDATE pg_dist_shard_placement SET shardstate = 1 WHERE nodename = 'localhost' AND - nodeport = :first_worker_port; + nodeport = :worker_1_port; -- Fourth: Perform the same INSERT (primary key violation) INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67); WARNING: Bad result from localhost:57638 @@ -288,7 +286,7 @@ FROM pg_dist_shard_placement AS sp, pg_dist_shard AS s WHERE sp.shardid = s.shardid AND sp.nodename = 'localhost' -AND sp.nodeport = :second_worker_port +AND sp.nodeport = :worker_2_port AND sp.shardstate = 3 AND s.logicalrelid = 'limit_orders'::regclass; count diff --git a/src/test/regress/expected/multi_repair_shards.out b/src/test/regress/expected/multi_repair_shards.out index 8cdc949aa..bf76df9c5 100644 --- a/src/test/regress/expected/multi_repair_shards.out +++ b/src/test/regress/expected/multi_repair_shards.out @@ -7,8 +7,6 @@ CREATE TABLE customer_engagements ( id integer, created_at date, event_data text CREATE INDEX ON customer_engagements (id); CREATE INDEX ON customer_engagements (created_at); CREATE INDEX ON customer_engagements (event_data); -\set first_worker_port 57637 -\set second_worker_port 57638 -- distribute the table SELECT master_create_distributed_table('customer_engagements', 'id', 'hash'); master_create_distributed_table @@ -37,24 +35,24 @@ INSERT INTO customer_engagements VALUES (1, '03-01-2015', 'third event'); SELECT shardid as newshardid FROM pg_dist_shard WHERE logicalrelid = 'customer_engagements'::regclass \gset -- now, update the second placement as unhealthy -UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE shardid = :newshardid AND nodeport = :second_worker_port; +UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE shardid = :newshardid AND nodeport = :worker_2_port; -- add a fake healthy placement for the tests INSERT INTO pg_dist_shard_placement (nodename, nodeport, shardid, shardstate, shardlength) - VALUES ('dummyhost', :second_worker_port, :newshardid, 1, 0); -SELECT master_copy_shard_placement(:newshardid, 'localhost', :first_worker_port, 'dummyhost', :second_worker_port); + VALUES ('dummyhost', :worker_2_port, :newshardid, 1, 0); +SELECT master_copy_shard_placement(:newshardid, 'localhost', :worker_1_port, 'dummyhost', :worker_2_port); ERROR: target placement must be in inactive state -- also try to copy from an inactive placement -SELECT master_copy_shard_placement(:newshardid, 'localhost', :second_worker_port, 'localhost', :first_worker_port); +SELECT master_copy_shard_placement(:newshardid, 'localhost', :worker_2_port, 'localhost', :worker_1_port); ERROR: source placement must be in finalized state -- "copy" this shard from the first placement to the second one -SELECT master_copy_shard_placement(:newshardid, 'localhost', :first_worker_port, 'localhost', :second_worker_port); +SELECT master_copy_shard_placement(:newshardid, 'localhost', :worker_1_port, 'localhost', :worker_2_port); master_copy_shard_placement ----------------------------- (1 row) -- now, update first placement as unhealthy (and raise a notice) so that queries are not routed to there -UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE shardid = :newshardid AND nodeport = :first_worker_port; +UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE shardid = :newshardid AND nodeport = :worker_1_port; -- get the data from the second placement SELECT * FROM customer_engagements; id | created_at | event_data @@ -89,8 +87,8 @@ NOTICE: foreign-data wrapper "fake_fdw" does not have an extension defined SELECT shardid as remotenewshardid FROM pg_dist_shard WHERE logicalrelid = 'remote_engagements'::regclass \gset -- now, update the second placement as unhealthy -UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE shardid = :remotenewshardid AND nodeport = :second_worker_port; +UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE shardid = :remotenewshardid AND nodeport = :worker_2_port; -- oops! we don't support repairing shards backed by foreign tables -SELECT master_copy_shard_placement(:remotenewshardid, 'localhost', :first_worker_port, 'localhost', :second_worker_port); +SELECT master_copy_shard_placement(:remotenewshardid, 'localhost', :worker_1_port, 'localhost', :worker_2_port); ERROR: cannot repair shard DETAIL: Repairing shards backed by foreign tables is not supported. diff --git a/src/test/regress/pg_regress_multi.pl b/src/test/regress/pg_regress_multi.pl index aa863021e..6c70536ac 100644 --- a/src/test/regress/pg_regress_multi.pl +++ b/src/test/regress/pg_regress_multi.pl @@ -14,6 +14,7 @@ use strict; use warnings; +use Fcntl; use Getopt::Long; @@ -124,11 +125,22 @@ for my $port (@workerPorts) system("rm", ('-rf', "tmp_check/worker.$port")) == 0 or die "Could not remove worker directory"; } -# Prepare a wrapper directory in which 'psql' is a symlink to 'csql' +# Prepare directory in which 'psql' is a wrapper around 'csql', which +# also adds some variables to csql. system("mkdir", ('-p', "tmp_check/tmp-bin")) == 0 or die "Could not create tmp-bin directory"; -system("ln", ('-s', "$bindir/csql", "tmp_check/tmp-bin/psql")) == 0 - or die "Could not create psql to csql symlink"; +sysopen my $fh, "tmp_check/tmp-bin/psql", O_CREAT|O_TRUNC|O_RDWR, 0700 + or die "Could not create psql wrapper"; +print $fh "#!/bin/bash\n"; +print $fh "exec $bindir/csql "; +print $fh "--variable=master_port=$masterPort "; +for my $workeroff (0 .. $#workerPorts) +{ + my $port = $workerPorts[$workeroff]; + print $fh "--variable=worker_".($workeroff+1)."_port=$port "; +} +print $fh "\"\$@\"\n"; # pass on the commandline arguments +close $fh; system("mkdir", ('-p', 'tmp_check/master/log')) == 0 or die "Could not create master directory"; for my $port (@workerPorts) diff --git a/src/test/regress/sql/multi_modifications.sql b/src/test/regress/sql/multi_modifications.sql index 605f8905f..dc439f017 100644 --- a/src/test/regress/sql/multi_modifications.sql +++ b/src/test/regress/sql/multi_modifications.sql @@ -186,14 +186,12 @@ UPDATE limit_orders SET (kind, limit_price) = ('buy', DEFAULT) WHERE id = 246; SELECT kind, limit_price FROM limit_orders WHERE id = 246; -- Test that shards which miss a modification are marked unhealthy -\set first_worker_port 57637 -\set second_worker_port 57638 -- First: Mark all placements for a node as inactive UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE nodename = 'localhost' AND - nodeport = :first_worker_port; + nodeport = :worker_1_port; -- Second: Perform an INSERT to the remaining node INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67); @@ -202,7 +200,7 @@ INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', UPDATE pg_dist_shard_placement SET shardstate = 1 WHERE nodename = 'localhost' AND - nodeport = :first_worker_port; + nodeport = :worker_1_port; -- Fourth: Perform the same INSERT (primary key violation) INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67); @@ -214,7 +212,7 @@ FROM pg_dist_shard_placement AS sp, pg_dist_shard AS s WHERE sp.shardid = s.shardid AND sp.nodename = 'localhost' -AND sp.nodeport = :second_worker_port +AND sp.nodeport = :worker_2_port AND sp.shardstate = 3 AND s.logicalrelid = 'limit_orders'::regclass; diff --git a/src/test/regress/sql/multi_repair_shards.sql b/src/test/regress/sql/multi_repair_shards.sql index 15fd58e13..7912f6a34 100644 --- a/src/test/regress/sql/multi_repair_shards.sql +++ b/src/test/regress/sql/multi_repair_shards.sql @@ -10,9 +10,6 @@ CREATE INDEX ON customer_engagements (id); CREATE INDEX ON customer_engagements (created_at); CREATE INDEX ON customer_engagements (event_data); -\set first_worker_port 57637 -\set second_worker_port 57638 - -- distribute the table SELECT master_create_distributed_table('customer_engagements', 'id', 'hash'); @@ -36,22 +33,22 @@ SELECT shardid as newshardid FROM pg_dist_shard WHERE logicalrelid = 'customer_e \gset -- now, update the second placement as unhealthy -UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE shardid = :newshardid AND nodeport = :second_worker_port; +UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE shardid = :newshardid AND nodeport = :worker_2_port; -- add a fake healthy placement for the tests INSERT INTO pg_dist_shard_placement (nodename, nodeport, shardid, shardstate, shardlength) - VALUES ('dummyhost', :second_worker_port, :newshardid, 1, 0); + VALUES ('dummyhost', :worker_2_port, :newshardid, 1, 0); -SELECT master_copy_shard_placement(:newshardid, 'localhost', :first_worker_port, 'dummyhost', :second_worker_port); +SELECT master_copy_shard_placement(:newshardid, 'localhost', :worker_1_port, 'dummyhost', :worker_2_port); -- also try to copy from an inactive placement -SELECT master_copy_shard_placement(:newshardid, 'localhost', :second_worker_port, 'localhost', :first_worker_port); +SELECT master_copy_shard_placement(:newshardid, 'localhost', :worker_2_port, 'localhost', :worker_1_port); -- "copy" this shard from the first placement to the second one -SELECT master_copy_shard_placement(:newshardid, 'localhost', :first_worker_port, 'localhost', :second_worker_port); +SELECT master_copy_shard_placement(:newshardid, 'localhost', :worker_1_port, 'localhost', :worker_2_port); -- now, update first placement as unhealthy (and raise a notice) so that queries are not routed to there -UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE shardid = :newshardid AND nodeport = :first_worker_port; +UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE shardid = :newshardid AND nodeport = :worker_1_port; -- get the data from the second placement SELECT * FROM customer_engagements; @@ -74,7 +71,7 @@ SELECT shardid as remotenewshardid FROM pg_dist_shard WHERE logicalrelid = 'remo \gset -- now, update the second placement as unhealthy -UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE shardid = :remotenewshardid AND nodeport = :second_worker_port; +UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE shardid = :remotenewshardid AND nodeport = :worker_2_port; -- oops! we don't support repairing shards backed by foreign tables -SELECT master_copy_shard_placement(:remotenewshardid, 'localhost', :first_worker_port, 'localhost', :second_worker_port); +SELECT master_copy_shard_placement(:remotenewshardid, 'localhost', :worker_1_port, 'localhost', :worker_2_port);