From acbc0fe0decf1ada1c8262b25cb03285bc0b943b Mon Sep 17 00:00:00 2001 From: Marco Slot Date: Fri, 24 Nov 2017 22:38:51 +0100 Subject: [PATCH] Use RowExclusiveLock shard resource lock in COPY --- src/backend/distributed/commands/multi_copy.c | 7 ++++++- .../expected/isolation_hash_copy_vs_all.out | 20 ++++++++----------- .../isolation_insert_select_vs_all.out | 10 ++++------ .../isolation_partitioned_copy_vs_all.out | 20 ++++++++----------- .../isolation_reference_copy_vs_all.out | 6 ++---- 5 files changed, 28 insertions(+), 35 deletions(-) diff --git a/src/backend/distributed/commands/multi_copy.c b/src/backend/distributed/commands/multi_copy.c index af0fd69d2..e61c93f1d 100644 --- a/src/backend/distributed/commands/multi_copy.c +++ b/src/backend/distributed/commands/multi_copy.c @@ -2088,7 +2088,12 @@ CitusCopyDestReceiverStartup(DestReceiver *dest, int operation, /* prevent concurrent placement changes and non-commutative DML statements */ LockShardListMetadata(shardIntervalList, ShareLock); - LockShardListResources(shardIntervalList, ShareLock); + + /* + * Prevent concurrent UPDATE/DELETE on replication factor >1 + * (see multi_router_executor.c) + */ + LockShardListResources(shardIntervalList, RowExclusiveLock); /* keep the table metadata to avoid looking it up for every tuple */ copyDest->tableMetadata = cacheEntry; 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 488b313bc..4e7097881 100644 --- a/src/test/regress/expected/isolation_hash_copy_vs_all.out +++ b/src/test/regress/expected/isolation_hash_copy_vs_all.out @@ -97,13 +97,12 @@ 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 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 +15 starting permutation: s1-initialize s1-begin s1-copy s2-update s1-commit s1-select-count create_distributed_table @@ -307,16 +306,15 @@ 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> +step s2-master-modify-multiple-shards: SELECT master_modify_multiple_shards('DELETE FROM hash_copy;'); master_modify_multiple_shards -10 +5 +step s1-commit: COMMIT; step s1-select-count: SELECT COUNT(*) FROM hash_copy; count -0 +5 starting permutation: s1-initialize s1-begin s1-copy s2-master-drop-all-shards s1-commit s1-select-count create_distributed_table @@ -439,9 +437,8 @@ 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-insert-select: INSERT INTO hash_copy SELECT * FROM hash_copy; -step s2-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-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 s1-commit: COMMIT; -step s2-copy: <... completed> step s1-select-count: SELECT COUNT(*) FROM hash_copy; count @@ -634,9 +631,8 @@ step s1-master-modify-multiple-shards: SELECT master_modify_multiple_shards('DEL master_modify_multiple_shards 5 -step s2-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-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 s1-commit: COMMIT; -step s2-copy: <... completed> step s1-select-count: SELECT COUNT(*) FROM hash_copy; count diff --git a/src/test/regress/expected/isolation_insert_select_vs_all.out b/src/test/regress/expected/isolation_insert_select_vs_all.out index 3e19c6460..d04022061 100644 --- a/src/test/regress/expected/isolation_insert_select_vs_all.out +++ b/src/test/regress/expected/isolation_insert_select_vs_all.out @@ -288,12 +288,11 @@ step s1-initialize: step s1-begin: BEGIN; step s1-insert-select: INSERT INTO insert_of_insert_select_hash SELECT * FROM select_of_insert_select_hash ORDER BY 1, 2 LIMIT 5;; -step s2-master-modify-multiple-shards-on-inserted: SELECT master_modify_multiple_shards('DELETE FROM insert_of_insert_select_hash;'); -step s1-commit: COMMIT; -step s2-master-modify-multiple-shards-on-inserted: <... completed> +step s2-master-modify-multiple-shards-on-inserted: SELECT master_modify_multiple_shards('DELETE FROM insert_of_insert_select_hash;'); master_modify_multiple_shards -15 +10 +step s1-commit: COMMIT; step s1-select-count: SELECT COUNT(*) FROM select_of_insert_select_hash; count @@ -908,9 +907,8 @@ step s1-master-modify-multiple-shards-on-inserted: SELECT master_modify_multiple master_modify_multiple_shards 10 -step s2-insert-select: INSERT INTO insert_of_insert_select_hash SELECT * FROM select_of_insert_select_hash ORDER BY 1, 2 LIMIT 5; +step s2-insert-select: INSERT INTO insert_of_insert_select_hash SELECT * FROM select_of_insert_select_hash ORDER BY 1, 2 LIMIT 5; step s1-commit: COMMIT; -step s2-insert-select: <... completed> step s1-select-count: SELECT COUNT(*) FROM select_of_insert_select_hash; count diff --git a/src/test/regress/expected/isolation_partitioned_copy_vs_all.out b/src/test/regress/expected/isolation_partitioned_copy_vs_all.out index e9d403e98..551fc1991 100644 --- a/src/test/regress/expected/isolation_partitioned_copy_vs_all.out +++ b/src/test/regress/expected/isolation_partitioned_copy_vs_all.out @@ -97,13 +97,12 @@ create_distributed_table step s1-initialize: COPY partitioned_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 partitioned_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 partitioned_copy SELECT * FROM partitioned_copy; +step s2-insert-select: INSERT INTO partitioned_copy SELECT * FROM partitioned_copy; step s1-commit: COMMIT; -step s2-insert-select: <... completed> step s1-select-count: SELECT COUNT(*) FROM partitioned_copy; count -20 +15 starting permutation: s1-initialize s1-begin s1-copy s2-update s1-commit s1-select-count create_distributed_table @@ -246,16 +245,15 @@ create_distributed_table step s1-initialize: COPY partitioned_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 partitioned_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 partitioned_copy;'); -step s1-commit: COMMIT; -step s2-master-modify-multiple-shards: <... completed> +step s2-master-modify-multiple-shards: SELECT master_modify_multiple_shards('DELETE FROM partitioned_copy;'); master_modify_multiple_shards -10 +5 +step s1-commit: COMMIT; step s1-select-count: SELECT COUNT(*) FROM partitioned_copy; count -0 +5 starting permutation: s1-initialize s1-begin s1-copy s2-master-drop-all-shards s1-commit s1-select-count create_distributed_table @@ -378,9 +376,8 @@ create_distributed_table step s1-initialize: COPY partitioned_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-insert-select: INSERT INTO partitioned_copy SELECT * FROM partitioned_copy; -step s2-copy: COPY partitioned_copy FROM PROGRAM 'echo 5, f, 5\\n6, g, 6\\n7, h, 7\\n8, i, 8\\n9, j, 9' WITH CSV; +step s2-copy: COPY partitioned_copy FROM PROGRAM 'echo 5, f, 5\\n6, g, 6\\n7, h, 7\\n8, i, 8\\n9, j, 9' WITH CSV; step s1-commit: COMMIT; -step s2-copy: <... completed> step s1-select-count: SELECT COUNT(*) FROM partitioned_copy; count @@ -532,9 +529,8 @@ step s1-master-modify-multiple-shards: SELECT master_modify_multiple_shards('DEL master_modify_multiple_shards 5 -step s2-copy: COPY partitioned_copy FROM PROGRAM 'echo 5, f, 5\\n6, g, 6\\n7, h, 7\\n8, i, 8\\n9, j, 9' WITH CSV; +step s2-copy: COPY partitioned_copy FROM PROGRAM 'echo 5, f, 5\\n6, g, 6\\n7, h, 7\\n8, i, 8\\n9, j, 9' WITH CSV; step s1-commit: COMMIT; -step s2-copy: <... completed> step s1-select-count: SELECT COUNT(*) FROM partitioned_copy; count diff --git a/src/test/regress/expected/isolation_reference_copy_vs_all.out b/src/test/regress/expected/isolation_reference_copy_vs_all.out index bafbd664c..c1e6e8e82 100644 --- a/src/test/regress/expected/isolation_reference_copy_vs_all.out +++ b/src/test/regress/expected/isolation_reference_copy_vs_all.out @@ -83,9 +83,8 @@ create_reference_table step s1-initialize: COPY reference_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 reference_copy FROM PROGRAM 'echo 5, f, 5\\n6, g, 6\\n7, h, 7\\n8, i, 8\\n9, j, 9' WITH CSV; -step s2-insert: INSERT INTO reference_copy VALUES(0, 'k', 0); +step s2-insert: INSERT INTO reference_copy VALUES(0, 'k', 0); step s1-commit: COMMIT; -step s2-insert: <... completed> step s1-select-count: SELECT COUNT(*) FROM reference_copy; count @@ -410,9 +409,8 @@ create_reference_table step s1-initialize: COPY reference_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-insert: INSERT INTO reference_copy VALUES(0, 'k', 0); -step s2-copy: COPY reference_copy FROM PROGRAM 'echo 5, f, 5\\n6, g, 6\\n7, h, 7\\n8, i, 8\\n9, j, 9' WITH CSV; +step s2-copy: COPY reference_copy FROM PROGRAM 'echo 5, f, 5\\n6, g, 6\\n7, h, 7\\n8, i, 8\\n9, j, 9' WITH CSV; step s1-commit: COMMIT; -step s2-copy: <... completed> step s1-select-count: SELECT COUNT(*) FROM reference_copy; count