From dfe7b357c5fb2f2d61a0faeccd1b182627162ef6 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Wed, 26 Oct 2016 06:41:02 -0700 Subject: [PATCH] Simple isolationtester dml vs. repair tests. --- .../expected/isolation_dml_vs_repair.out | 200 ++++++++++++++++++ src/test/regress/isolation_schedule | 1 + .../specs/isolation_dml_vs_repair.spec | 110 ++++++++++ 3 files changed, 311 insertions(+) create mode 100644 src/test/regress/expected/isolation_dml_vs_repair.out create mode 100644 src/test/regress/specs/isolation_dml_vs_repair.spec diff --git a/src/test/regress/expected/isolation_dml_vs_repair.out b/src/test/regress/expected/isolation_dml_vs_repair.out new file mode 100644 index 000000000..0730dd370 --- /dev/null +++ b/src/test/regress/expected/isolation_dml_vs_repair.out @@ -0,0 +1,200 @@ +Parsed test spec with 2 sessions + +starting permutation: s2-invalidate-57637 s1-begin s1-insertone s2-repair s1-commit +master_create_worker_shards + + +step s2-invalidate-57637: + UPDATE pg_dist_shard_placement SET shardstate = '3' WHERE shardid = 102008 AND nodeport = 57637; + +step s1-begin: + BEGIN; + +step s1-insertone: + INSERT INTO test_table VALUES(1, 1); + +step s2-repair: + SELECT master_copy_shard_placement(102008, 'localhost', 57638, 'localhost', 57637); + +step s1-commit: + COMMIT; + +step s2-repair: <... completed> +master_copy_shard_placement + + + +starting permutation: s1-insertone s2-invalidate-57637 s1-begin s1-insertall s2-repair s1-commit +master_create_worker_shards + + +step s1-insertone: + INSERT INTO test_table VALUES(1, 1); + +step s2-invalidate-57637: + UPDATE pg_dist_shard_placement SET shardstate = '3' WHERE shardid = 102008 AND nodeport = 57637; + +step s1-begin: + BEGIN; + +step s1-insertall: + INSERT INTO test_table SELECT test_id, data+1 FROM test_table; + +step s2-repair: + SELECT master_copy_shard_placement(102008, 'localhost', 57638, 'localhost', 57637); + +step s1-commit: + COMMIT; + +step s2-repair: <... completed> +master_copy_shard_placement + + + +starting permutation: s2-invalidate-57637 s2-begin s2-repair s1-insertone s2-commit s2-invalidate-57638 s1-display s2-invalidate-57637 s2-revalidate-57638 s1-display +master_create_worker_shards + + +step s2-invalidate-57637: + UPDATE pg_dist_shard_placement SET shardstate = '3' WHERE shardid = 102008 AND nodeport = 57637; + +step s2-begin: + BEGIN; + +step s2-repair: + SELECT master_copy_shard_placement(102008, 'localhost', 57638, 'localhost', 57637); + +master_copy_shard_placement + + +step s1-insertone: + INSERT INTO test_table VALUES(1, 1); + +step s2-commit: + COMMIT; + +step s1-insertone: <... completed> +step s2-invalidate-57638: + UPDATE pg_dist_shard_placement SET shardstate = '3' WHERE shardid = 102008 AND nodeport = 57638; + +step s1-display: + SELECT * FROM test_table WHERE test_id = 1; + +test_id data + +1 1 +step s2-invalidate-57637: + UPDATE pg_dist_shard_placement SET shardstate = '3' WHERE shardid = 102008 AND nodeport = 57637; + +step s2-revalidate-57638: + UPDATE pg_dist_shard_placement SET shardstate = '1' WHERE shardid = 102008 AND nodeport = 57638; + +step s1-display: + SELECT * FROM test_table WHERE test_id = 1; + +test_id data + +1 1 + +starting permutation: s2-invalidate-57637 s1-prepared-insertone s2-begin s2-repair s1-prepared-insertone s2-commit s2-invalidate-57638 s1-display s2-invalidate-57637 s2-revalidate-57638 s1-display +master_create_worker_shards + + +step s2-invalidate-57637: + UPDATE pg_dist_shard_placement SET shardstate = '3' WHERE shardid = 102008 AND nodeport = 57637; + +step s1-prepared-insertone: + EXECUTE insertone; + +step s2-begin: + BEGIN; + +step s2-repair: + SELECT master_copy_shard_placement(102008, 'localhost', 57638, 'localhost', 57637); + +master_copy_shard_placement + + +step s1-prepared-insertone: + EXECUTE insertone; + +step s2-commit: + COMMIT; + +step s1-prepared-insertone: <... completed> +error in steps s2-commit s1-prepared-insertone: ERROR: prepared modifications cannot be executed on a shard while it is being copied +step s2-invalidate-57638: + UPDATE pg_dist_shard_placement SET shardstate = '3' WHERE shardid = 102008 AND nodeport = 57638; + +step s1-display: + SELECT * FROM test_table WHERE test_id = 1; + +test_id data + +1 1 +step s2-invalidate-57637: + UPDATE pg_dist_shard_placement SET shardstate = '3' WHERE shardid = 102008 AND nodeport = 57637; + +step s2-revalidate-57638: + UPDATE pg_dist_shard_placement SET shardstate = '1' WHERE shardid = 102008 AND nodeport = 57638; + +step s1-display: + SELECT * FROM test_table WHERE test_id = 1; + +test_id data + +1 1 + +starting permutation: s2-invalidate-57637 s1-insertone s1-prepared-insertall s2-begin s2-repair s1-prepared-insertall s2-commit s2-invalidate-57638 s1-display s2-invalidate-57637 s2-revalidate-57638 s1-display +master_create_worker_shards + + +step s2-invalidate-57637: + UPDATE pg_dist_shard_placement SET shardstate = '3' WHERE shardid = 102008 AND nodeport = 57637; + +step s1-insertone: + INSERT INTO test_table VALUES(1, 1); + +step s1-prepared-insertall: + EXECUTE insertall; + +step s2-begin: + BEGIN; + +step s2-repair: + SELECT master_copy_shard_placement(102008, 'localhost', 57638, 'localhost', 57637); + +master_copy_shard_placement + + +step s1-prepared-insertall: + EXECUTE insertall; + +step s2-commit: + COMMIT; + +step s1-prepared-insertall: <... completed> +error in steps s2-commit s1-prepared-insertall: ERROR: prepared modifications cannot be executed on a shard while it is being copied +step s2-invalidate-57638: + UPDATE pg_dist_shard_placement SET shardstate = '3' WHERE shardid = 102008 AND nodeport = 57638; + +step s1-display: + SELECT * FROM test_table WHERE test_id = 1; + +test_id data + +1 1 +1 2 +step s2-invalidate-57637: + UPDATE pg_dist_shard_placement SET shardstate = '3' WHERE shardid = 102008 AND nodeport = 57637; + +step s2-revalidate-57638: + UPDATE pg_dist_shard_placement SET shardstate = '1' WHERE shardid = 102008 AND nodeport = 57638; + +step s1-display: + SELECT * FROM test_table WHERE test_id = 1; + +test_id data + +1 1 +1 2 diff --git a/src/test/regress/isolation_schedule b/src/test/regress/isolation_schedule index d702c065f..93a2f5ab8 100644 --- a/src/test/regress/isolation_schedule +++ b/src/test/regress/isolation_schedule @@ -1,2 +1,3 @@ test: isolation_cluster_management test: isolation_concurrent_dml +test: isolation_dml_vs_repair diff --git a/src/test/regress/specs/isolation_dml_vs_repair.spec b/src/test/regress/specs/isolation_dml_vs_repair.spec new file mode 100644 index 000000000..e4e9219ee --- /dev/null +++ b/src/test/regress/specs/isolation_dml_vs_repair.spec @@ -0,0 +1,110 @@ +setup +{ + ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 102008; + CREATE TABLE test_table (test_id integer NOT NULL, data int); + SELECT master_create_distributed_table('test_table', 'test_id', 'hash'); + SELECT master_create_worker_shards('test_table', 1, 2); +} + +teardown +{ + DROP TABLE IF EXISTS test_table CASCADE; +} + +session "s1" + +setup +{ + DEALLOCATE all; + TRUNCATE test_table; + PREPARE insertone AS INSERT INTO test_table VALUES(1, 1); + PREPARE insertall AS INSERT INTO test_table SELECT test_id, data+1 FROM test_table; +} + +step "s1-begin" +{ + BEGIN; +} + +step "s1-insertone" +{ + INSERT INTO test_table VALUES(1, 1); +} + +step "s1-prepared-insertone" +{ + EXECUTE insertone; +} + +step "s1-insertall" +{ + INSERT INTO test_table SELECT test_id, data+1 FROM test_table; +} + +step "s1-prepared-insertall" +{ + EXECUTE insertall; +} + +step "s1-display" +{ + SELECT * FROM test_table WHERE test_id = 1; +} + +step "s1-commit" +{ + COMMIT; +} + +session "s2" + + +step "s2-begin" +{ + BEGIN; +} + +step "s2-invalidate-57637" +{ + UPDATE pg_dist_shard_placement SET shardstate = '3' WHERE shardid = 102008 AND nodeport = 57637; +} + +step "s2-revalidate-57637" +{ + UPDATE pg_dist_shard_placement SET shardstate = '1' WHERE shardid = 102008 AND nodeport = 57637; +} + +step "s2-invalidate-57638" +{ + UPDATE pg_dist_shard_placement SET shardstate = '3' WHERE shardid = 102008 AND nodeport = 57638; +} + +step "s2-revalidate-57638" +{ + UPDATE pg_dist_shard_placement SET shardstate = '1' WHERE shardid = 102008 AND nodeport = 57638; +} + +step "s2-repair" +{ + SELECT master_copy_shard_placement(102008, 'localhost', 57638, 'localhost', 57637); +} + +step "s2-commit" +{ + COMMIT; +} + +# verify that repair is blocked by ongoing modifying simple transaction +permutation "s2-invalidate-57637" "s1-begin" "s1-insertone" "s2-repair" "s1-commit" + +# verify that repair is blocked by ongoing modifying insert...select transaction +permutation "s1-insertone" "s2-invalidate-57637" "s1-begin" "s1-insertall" "s2-repair" "s1-commit" + +# verify that modifications wait for shard repair +permutation "s2-invalidate-57637" "s2-begin" "s2-repair" "s1-insertone" "s2-commit" "s2-invalidate-57638" "s1-display" "s2-invalidate-57637" "s2-revalidate-57638" "s1-display" + +# verify that prepared plain modifications wait for shard repair (and then fail to avoid race) +permutation "s2-invalidate-57637" "s1-prepared-insertone" "s2-begin" "s2-repair" "s1-prepared-insertone" "s2-commit" "s2-invalidate-57638" "s1-display" "s2-invalidate-57637" "s2-revalidate-57638" "s1-display" + +# verify that prepared INSERT ... SELECT waits for shard repair (and then fail to avoid race) +permutation "s2-invalidate-57637" "s1-insertone" "s1-prepared-insertall" "s2-begin" "s2-repair" "s1-prepared-insertall" "s2-commit" "s2-invalidate-57638" "s1-display" "s2-invalidate-57637" "s2-revalidate-57638" "s1-display"