From ff706cf556fd9f0d70d15ef67587eb79c82db3c7 Mon Sep 17 00:00:00 2001 From: Hadi Moshayedi Date: Thu, 30 Nov 2017 12:34:06 -0500 Subject: [PATCH] Test that COPY blocks UPDATE/DELETE/INSERT...SELECT when rep factor 2. --- src/backend/distributed/commands/multi_copy.c | 2 +- .../expected/isolation_hash_copy_vs_all.out | 99 +++++++++++++++++++ .../specs/isolation_hash_copy_vs_all.spec | 13 +++ 3 files changed, 113 insertions(+), 1 deletion(-) diff --git a/src/backend/distributed/commands/multi_copy.c b/src/backend/distributed/commands/multi_copy.c index e61c93f1d..b586bbd57 100644 --- a/src/backend/distributed/commands/multi_copy.c +++ b/src/backend/distributed/commands/multi_copy.c @@ -2091,7 +2091,7 @@ CitusCopyDestReceiverStartup(DestReceiver *dest, int operation, /* * Prevent concurrent UPDATE/DELETE on replication factor >1 - * (see multi_router_executor.c) + * (see AcquireExecutorMultiShardLocks() at multi_router_executor.c) */ LockShardListResources(shardIntervalList, RowExclusiveLock); diff --git a/src/test/regress/expected/isolation_hash_copy_vs_all.out b/src/test/regress/expected/isolation_hash_copy_vs_all.out index 4e7097881..c75b51aac 100644 --- a/src/test/regress/expected/isolation_hash_copy_vs_all.out +++ b/src/test/regress/expected/isolation_hash_copy_vs_all.out @@ -354,6 +354,105 @@ count 15 +starting permutation: s1-recreate-with-replication-2 s1-initialize s1-begin s1-copy s2-update s1-commit s1-select-count +create_distributed_table + + +step s1-recreate-with-replication-2: + DROP TABLE hash_copy; + SET citus.shard_replication_factor TO 2; + CREATE TABLE hash_copy(id integer, data text, int_data int); + SELECT create_distributed_table('hash_copy', 'id'); + +create_distributed_table + + +step s1-initialize: COPY hash_copy FROM PROGRAM 'echo 0, a, 0\\n1, b, 1\\n2, c, 2\\n3, d, 3\\n4, e, 4' WITH CSV; +step s1-begin: BEGIN; +step s1-copy: COPY hash_copy FROM PROGRAM 'echo 5, f, 5\\n6, g, 6\\n7, h, 7\\n8, i, 8\\n9, j, 9' WITH CSV; +step s2-update: UPDATE hash_copy SET data = 'l' WHERE id = 0; +step s1-commit: COMMIT; +step s2-update: <... completed> +step s1-select-count: SELECT COUNT(*) FROM hash_copy; +count + +10 + +starting permutation: s1-recreate-with-replication-2 s1-initialize s1-begin s1-copy s2-delete s1-commit s1-select-count +create_distributed_table + + +step s1-recreate-with-replication-2: + DROP TABLE hash_copy; + SET citus.shard_replication_factor TO 2; + CREATE TABLE hash_copy(id integer, data text, int_data int); + SELECT create_distributed_table('hash_copy', 'id'); + +create_distributed_table + + +step s1-initialize: COPY hash_copy FROM PROGRAM 'echo 0, a, 0\\n1, b, 1\\n2, c, 2\\n3, d, 3\\n4, e, 4' WITH CSV; +step s1-begin: BEGIN; +step s1-copy: COPY hash_copy FROM PROGRAM 'echo 5, f, 5\\n6, g, 6\\n7, h, 7\\n8, i, 8\\n9, j, 9' WITH CSV; +step s2-delete: DELETE FROM hash_copy WHERE id = 1; +step s1-commit: COMMIT; +step s2-delete: <... completed> +step s1-select-count: SELECT COUNT(*) FROM hash_copy; +count + +9 + +starting permutation: s1-recreate-with-replication-2 s1-initialize s1-begin s1-copy s2-insert-select s1-commit s1-select-count +create_distributed_table + + +step s1-recreate-with-replication-2: + DROP TABLE hash_copy; + SET citus.shard_replication_factor TO 2; + CREATE TABLE hash_copy(id integer, data text, int_data int); + SELECT create_distributed_table('hash_copy', 'id'); + +create_distributed_table + + +step s1-initialize: COPY hash_copy FROM PROGRAM 'echo 0, a, 0\\n1, b, 1\\n2, c, 2\\n3, d, 3\\n4, e, 4' WITH CSV; +step s1-begin: BEGIN; +step s1-copy: COPY hash_copy FROM PROGRAM 'echo 5, f, 5\\n6, g, 6\\n7, h, 7\\n8, i, 8\\n9, j, 9' WITH CSV; +step s2-insert-select: INSERT INTO hash_copy SELECT * FROM hash_copy; +step s1-commit: COMMIT; +step s2-insert-select: <... completed> +step s1-select-count: SELECT COUNT(*) FROM hash_copy; +count + +20 + +starting permutation: s1-recreate-with-replication-2 s1-initialize s1-begin s1-copy s2-master-modify-multiple-shards s1-commit s1-select-count +create_distributed_table + + +step s1-recreate-with-replication-2: + DROP TABLE hash_copy; + SET citus.shard_replication_factor TO 2; + CREATE TABLE hash_copy(id integer, data text, int_data int); + SELECT create_distributed_table('hash_copy', 'id'); + +create_distributed_table + + +step s1-initialize: COPY hash_copy FROM PROGRAM 'echo 0, a, 0\\n1, b, 1\\n2, c, 2\\n3, d, 3\\n4, e, 4' WITH CSV; +step s1-begin: BEGIN; +step s1-copy: COPY hash_copy FROM PROGRAM 'echo 5, f, 5\\n6, g, 6\\n7, h, 7\\n8, i, 8\\n9, j, 9' WITH CSV; +step s2-master-modify-multiple-shards: SELECT master_modify_multiple_shards('DELETE FROM hash_copy;'); +step s1-commit: COMMIT; +step s2-master-modify-multiple-shards: <... completed> +master_modify_multiple_shards + +10 +step s1-select-count: SELECT COUNT(*) FROM hash_copy; +count + +0 + starting permutation: s1-initialize s1-begin s1-router-select s2-copy s1-commit s1-select-count create_distributed_table diff --git a/src/test/regress/specs/isolation_hash_copy_vs_all.spec b/src/test/regress/specs/isolation_hash_copy_vs_all.spec index 5c9a469f7..5e69d9aa2 100644 --- a/src/test/regress/specs/isolation_hash_copy_vs_all.spec +++ b/src/test/regress/specs/isolation_hash_copy_vs_all.spec @@ -50,6 +50,13 @@ step "s1-select-count" { SELECT COUNT(*) FROM hash_copy; } step "s1-show-indexes" { SELECT run_command_on_workers('SELECT COUNT(*) FROM pg_indexes WHERE tablename LIKE ''hash_copy%'''); } step "s1-show-columns" { SELECT run_command_on_workers('SELECT column_name FROM information_schema.columns WHERE table_name LIKE ''hash_copy%'' AND column_name = ''new_column'' ORDER BY 1 LIMIT 1'); } step "s1-commit" { COMMIT; } +step "s1-recreate-with-replication-2" +{ + DROP TABLE hash_copy; + SET citus.shard_replication_factor TO 2; + CREATE TABLE hash_copy(id integer, data text, int_data int); + SELECT create_distributed_table('hash_copy', 'id'); +} # session 2 session "s2" @@ -103,6 +110,12 @@ permutation "s1-initialize" "s1-begin" "s1-copy" "s2-master-modify-multiple-shar permutation "s1-initialize" "s1-begin" "s1-copy" "s2-master-drop-all-shards" "s1-commit" "s1-select-count" permutation "s1-drop" "s1-create-non-distributed-table" "s1-initialize" "s1-begin" "s1-copy" "s2-distribute-table" "s1-commit" "s1-select-count" +# permutations - COPY first (replication factor 2) +permutation "s1-recreate-with-replication-2" "s1-initialize" "s1-begin" "s1-copy" "s2-update" "s1-commit" "s1-select-count" +permutation "s1-recreate-with-replication-2" "s1-initialize" "s1-begin" "s1-copy" "s2-delete" "s1-commit" "s1-select-count" +permutation "s1-recreate-with-replication-2" "s1-initialize" "s1-begin" "s1-copy" "s2-insert-select" "s1-commit" "s1-select-count" +permutation "s1-recreate-with-replication-2" "s1-initialize" "s1-begin" "s1-copy" "s2-master-modify-multiple-shards" "s1-commit" "s1-select-count" + # permutations - COPY second permutation "s1-initialize" "s1-begin" "s1-router-select" "s2-copy" "s1-commit" "s1-select-count" permutation "s1-initialize" "s1-begin" "s1-real-time-select" "s2-copy" "s1-commit" "s1-select-count"