From 5bde51a3d9be356bd454d4426c5e2f82888c41f8 Mon Sep 17 00:00:00 2001 From: Mats Kindahl Date: Fri, 19 Mar 2021 12:48:04 +0100 Subject: [PATCH] Re-enable CREATE/DROP INDEX isolation test The flake in `multi_transaction_indexing` is because of a race between `CREATE INDEX` and `DROP INDEX` and this commit add a debug waitpoint so that we can reliably reproduce the race condition in the isolation test. --- src/process_utility.c | 3 +++ .../expected/multi_transaction_indexing.out | 25 ++++++++++++++++++- test/isolation/specs/CMakeLists.txt | 6 +---- ...pec => multi_transaction_indexing.spec.in} | 22 ++++++++++------ 4 files changed, 42 insertions(+), 14 deletions(-) rename test/isolation/specs/{multi_transaction_indexing.spec => multi_transaction_indexing.spec.in} (86%) diff --git a/src/process_utility.c b/src/process_utility.c index bdeb8a690..73d0b6e6b 100644 --- a/src/process_utility.c +++ b/src/process_utility.c @@ -66,6 +66,7 @@ #include "continuous_agg.h" #include "compression_with_clause.h" #include "partitioning.h" +#include "debug_wait.h" #include "cross_module_fn.h" @@ -2392,6 +2393,8 @@ process_index_start(ProcessUtilityArgs *args) UnlockRelationIdForSession(&main_table_index_lock_relid, AccessShareLock); + DEBUG_WAITPOINT("indexing_done"); + return DDL_DONE; } diff --git a/test/isolation/expected/multi_transaction_indexing.out b/test/isolation/expected/multi_transaction_indexing.out index 6b64a787d..8eec08cf3 100644 --- a/test/isolation/expected/multi_transaction_indexing.out +++ b/test/isolation/expected/multi_transaction_indexing.out @@ -1,4 +1,4 @@ -Parsed test spec with 6 sessions +Parsed test spec with 8 sessions starting permutation: CI I1 Ic Bc P Sc step CI: CREATE INDEX test_index ON ts_index_test(location) WITH (timescaledb.transaction_per_chunk, timescaledb.barrier_table='barrier'); @@ -41,6 +41,29 @@ hypertable_index_size 49152 step Ic: COMMIT; +starting permutation: F WPE CI DI Bc WPR P Ic Sc +step F: SET client_min_messages TO 'error'; +step WPE: SELECT debug_waitpoint_enable('indexing_done'); +debug_waitpoint_enable + + +step CI: CREATE INDEX test_index ON ts_index_test(location) WITH (timescaledb.transaction_per_chunk, timescaledb.barrier_table='barrier'); +step DI: DROP INDEX test_index; +step Bc: ROLLBACK; +step WPR: SELECT debug_waitpoint_release('indexing_done'); +debug_waitpoint_release + + +step CI: <... completed> +step DI: <... completed> +error in steps WPR CI DI: ERROR: tuple concurrently updated +step P: SELECT * FROM hypertable_index_size('test_index'); +hypertable_index_size + +49152 +step Ic: COMMIT; +step Sc: COMMIT; + starting permutation: CI RI Bc P Ic Sc step CI: CREATE INDEX test_index ON ts_index_test(location) WITH (timescaledb.transaction_per_chunk, timescaledb.barrier_table='barrier'); step RI: ALTER TABLE test_index RENAME COLUMN location TO height; diff --git a/test/isolation/specs/CMakeLists.txt b/test/isolation/specs/CMakeLists.txt index 683f74f5f..275a4366f 100644 --- a/test/isolation/specs/CMakeLists.txt +++ b/test/isolation/specs/CMakeLists.txt @@ -16,6 +16,7 @@ set(TEST_TEMPLATES set(TEST_TEMPLATES_DEBUG dropchunks_race.spec.in + multi_transaction_indexing.spec.in ) if (CMAKE_BUILD_TYPE MATCHES Debug) @@ -29,11 +30,6 @@ foreach(TEMPLATE_FILE ${TEST_TEMPLATES}) list(APPEND TEST_FILES "${TEST_FILE}") endforeach(TEMPLATE_FILE) -if (CMAKE_BUILD_TYPE MATCHES Debug) - list(APPEND TEST_FILES - multi_transaction_indexing.spec) -endif (CMAKE_BUILD_TYPE MATCHES Debug) - foreach(TEST_FILE ${TEST_FILES}) string(REGEX REPLACE "(.+)\.spec" "\\1" TESTS_TO_RUN ${TEST_FILE}) file(APPEND ${ISOLATION_TEST_SCHEDULE} "test: ${TESTS_TO_RUN}\n") diff --git a/test/isolation/specs/multi_transaction_indexing.spec b/test/isolation/specs/multi_transaction_indexing.spec.in similarity index 86% rename from test/isolation/specs/multi_transaction_indexing.spec rename to test/isolation/specs/multi_transaction_indexing.spec.in index 01595f131..c9818cfa2 100644 --- a/test/isolation/specs/multi_transaction_indexing.spec +++ b/test/isolation/specs/multi_transaction_indexing.spec.in @@ -10,6 +10,12 @@ setup { (21, 19.5, 3); CREATE TABLE barrier(i INTEGER); + + CREATE OR REPLACE FUNCTION debug_waitpoint_enable(TEXT) RETURNS VOID LANGUAGE C VOLATILE STRICT + AS '@TS_MODULE_PATHNAME@', 'ts_debug_waitpoint_enable'; + + CREATE OR REPLACE FUNCTION debug_waitpoint_release(TEXT) RETURNS VOID LANGUAGE C VOLATILE STRICT + AS '@TS_MODULE_PATHNAME@', 'ts_debug_waitpoint_release'; } teardown { @@ -17,8 +23,12 @@ teardown { DROP TABLE barrier; } +session "Waitpoints" +step "WPE" { SELECT debug_waitpoint_enable('indexing_done'); } +step "WPR" { SELECT debug_waitpoint_release('indexing_done'); } + session "CREATE INDEX" -#step "F" { SET client_min_messages TO 'error'; } +step "F" { SET client_min_messages TO 'error'; } step "CI" { CREATE INDEX test_index ON ts_index_test(location) WITH (timescaledb.transaction_per_chunk, timescaledb.barrier_table='barrier'); } session "RELEASE BARRIER" @@ -35,8 +45,8 @@ setup { BEGIN; SET LOCAL lock_timeout = '500ms'; SET LOCAL deadlock_timeout = ' step "I1" { INSERT INTO ts_index_test VALUES (31, 6.4, 1); } step "Ic" { COMMIT; } -#session "DROP INDEX" -#step "DI" { DROP INDEX test_index; } +session "DROP INDEX" +step "DI" { DROP INDEX test_index; } session "RENAME COLUMN" step "RI" { ALTER TABLE test_index RENAME COLUMN location TO height; } @@ -55,11 +65,7 @@ permutation "I1" "CI" "Bc" "Ic" "P" "Sc" permutation "S1" "CI" "Bc" "Sc" "P" "Ic" # drop works (the error message outputs an OID, remove the "F" to see the error) -# -# TODO(3021): Disabled since a race condition between CREATE INDEX -# and DROP INDEX cause a flake. Enable when race condition is fixed. -# -#permutation "F" "CI" "DI" "Bc" "P" "Ic" "Sc" +permutation "F" "WPE" "CI" "DI" "Bc" "WPR" "P" "Ic" "Sc" # rename should block permutation "CI" "RI" "Bc" "P" "Ic" "Sc"