You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
uuid_db_1=`$CLICKHOUSE_CLIENT -q "SELECT uuid FROM system.databases WHERE name='test_01114_1'"`
30
-
uuid_db_2=`$CLICKHOUSE_CLIENT -q "SELECT uuid FROM system.databases WHERE name='test_01114_2'"`
26
+
uuid_db_1=`$CLICKHOUSE_CLIENT -q "SELECT uuid FROM system.databases WHERE name='${DATABASE_1}'"`
27
+
uuid_db_2=`$CLICKHOUSE_CLIENT -q "SELECT uuid FROM system.databases WHERE name='${DATABASE_2}'"`
31
28
$CLICKHOUSE_CLIENT -q "SELECT name,
32
29
engine,
33
30
splitByChar('/', data_path)[-2],
34
31
splitByChar('/', metadata_path)[-2] as uuid_path, ((splitByChar('/', metadata_path)[-3] as metadata) = substr(uuid_path, 1, 3)) OR metadata='metadata'
35
-
FROM system.databases WHERE name LIKE 'test_01114_%'"| sed "s/$uuid_db_1/00001114-1000-4000-8000-000000000001/g"| sed "s/$uuid_db_2/00001114-1000-4000-8000-000000000002/g"
32
+
FROM system.databases WHERE name LIKE '${CLICKHOUSE_DATABASE}_%'"| sed "s/$uuid_db_1/00001114-1000-4000-8000-000000000001/g"| sed "s/$uuid_db_2/00001114-1000-4000-8000-000000000002/g"
36
33
37
34
$CLICKHOUSE_CLIENT -nm -q "
38
-
CREATE TABLE test_01114_1.mt_tmp (n UInt64) ENGINE=MergeTree() ORDER BY tuple();
39
-
INSERT INTO test_01114_1.mt_tmp SELECT * FROM numbers(100);
40
-
CREATE TABLE test_01114_3.mt (n UInt64) ENGINE=MergeTree() ORDER BY tuple() PARTITION BY (n % 5);
41
-
INSERT INTO test_01114_3.mt SELECT * FROM numbers(110);
35
+
CREATE TABLE ${DATABASE_1}.mt_tmp (n UInt64) ENGINE=MergeTree() ORDER BY tuple();
36
+
INSERT INTO ${DATABASE_1}.mt_tmp SELECT * FROM numbers(100);
37
+
CREATE TABLE ${DATABASE_3}.mt (n UInt64) ENGINE=MergeTree() ORDER BY tuple() PARTITION BY (n % 5);
38
+
INSERT INTO ${DATABASE_3}.mt SELECT * FROM numbers(110);
42
39
43
-
RENAME TABLE test_01114_1.mt_tmp TO test_01114_3.mt_tmp; /* move from Atomic to Ordinary */
44
-
RENAME TABLE test_01114_3.mt TO test_01114_1.mt; /* move from Ordinary to Atomic */
45
-
SELECT count() FROM test_01114_1.mt;
46
-
SELECT count() FROM test_01114_3.mt_tmp;
40
+
RENAME TABLE ${DATABASE_1}.mt_tmp TO ${DATABASE_3}.mt_tmp; /* move from Atomic to Ordinary */
41
+
RENAME TABLE ${DATABASE_3}.mt TO ${DATABASE_1}.mt; /* move from Ordinary to Atomic */
$CLICKHOUSE_CLIENT -q "CREATE TABLE test_01114_2.mt UUID '$explicit_uuid' (n UInt64) ENGINE=MergeTree() ORDER BY tuple() PARTITION BY (n % 5)"
53
-
$CLICKHOUSE_CLIENT --show_table_uuid_in_table_create_query_if_not_nil=1 -q "SHOW CREATE TABLE test_01114_2.mt"| sed "s/$explicit_uuid/00001114-0000-4000-8000-000000000002/g"
54
-
$CLICKHOUSE_CLIENT -q "SELECT name, uuid, create_table_query FROM system.tables WHERE database='test_01114_2'"| sed "s/$explicit_uuid/00001114-0000-4000-8000-000000000002/g"
55
-
56
-
57
-
$CLICKHOUSE_CLIENT --function_sleep_max_microseconds_per_block 60000000 -q "SELECT count(col), sum(col) FROM (SELECT n + sleepEachRow(1.5) AS col FROM test_01114_1.mt)"&# 33s (1.5s * 22 rows per partition), result: 110, 5995
58
-
$CLICKHOUSE_CLIENT --function_sleep_max_microseconds_per_block 60000000 -q "INSERT INTO test_01114_2.mt SELECT number + sleepEachRow(1.5) FROM numbers(30)"&# 45s (1.5s * 30 rows)
59
-
sleep 1 # SELECT and INSERT should start before the following RENAMEs
49
+
$CLICKHOUSE_CLIENT -q "CREATE TABLE ${DATABASE_2}.mt UUID '$explicit_uuid' (n UInt64) ENGINE=MergeTree() ORDER BY tuple() PARTITION BY (n % 5)"
50
+
$CLICKHOUSE_CLIENT --show_table_uuid_in_table_create_query_if_not_nil=1 -q "SHOW CREATE TABLE ${DATABASE_2}.mt"| sed "s/$explicit_uuid/00001114-0000-4000-8000-000000000002/g"
51
+
$CLICKHOUSE_CLIENT -q "SELECT name, uuid, create_table_query FROM system.tables WHERE database='${DATABASE_2}'"| sed "s/$explicit_uuid/00001114-0000-4000-8000-000000000002/g"
52
+
53
+
RANDOM_COMMENT="$RANDOM"
54
+
$CLICKHOUSE_CLIENT --max-threads 5 --function_sleep_max_microseconds_per_block 60000000 -q "SELECT count(col), sum(col) FROM (SELECT n + sleepEachRow(1.5) AS col FROM ${DATABASE_1}.mt) -- ${RANDOM_COMMENT}"&# 33s (1.5s * 22 rows per partition [Using 5 threads in parallel]), result: 110, 5995
55
+
$CLICKHOUSE_CLIENT --max-threads 5 --function_sleep_max_microseconds_per_block 60000000 -q "INSERT INTO ${DATABASE_2}.mt SELECT number + sleepEachRow(1.5) FROM numbers(30) -- ${RANDOM_COMMENT}"&# 45s (1.5s * 30 rows)
56
+
57
+
it=0
58
+
while [[ $($CLICKHOUSE_CLIENT -q "SELECT count() FROM system.processes WHERE query_id != queryID() AND current_database = currentDatabase() AND query LIKE '%-- ${RANDOM_COMMENT}%'")-ne 2 ]];do
59
+
it=$((it+1))
60
+
if [ $it-ge 50 ];
61
+
then
62
+
echo"Failed to wait for first batch of queries"
63
+
$CLICKHOUSE_CLIENT -q "SELECT count() FROM system.processes WHERE query_id != queryID() AND current_database = currentDatabase() AND query LIKE '%-- ${RANDOM_COMMENT}%'"
64
+
fi
65
+
sleep 0.1
66
+
done
60
67
61
68
$CLICKHOUSE_CLIENT -nm -q "
62
-
RENAME TABLE test_01114_1.mt TO test_01114_1.mt_tmp;
63
-
RENAME TABLE test_01114_1.mt_tmp TO test_01114_2.mt_tmp;
64
-
EXCHANGE TABLES test_01114_2.mt AND test_01114_2.mt_tmp;
65
-
RENAME TABLE test_01114_2.mt_tmp TO test_01114_1.mt;
66
-
EXCHANGE TABLES test_01114_1.mt AND test_01114_2.mt;
69
+
RENAME TABLE ${DATABASE_1}.mt TO ${DATABASE_1}.mt_tmp;
70
+
RENAME TABLE ${DATABASE_1}.mt_tmp TO ${DATABASE_2}.mt_tmp;
71
+
EXCHANGE TABLES ${DATABASE_2}.mt AND ${DATABASE_2}.mt_tmp;
72
+
RENAME TABLE ${DATABASE_2}.mt_tmp TO ${DATABASE_1}.mt;
73
+
EXCHANGE TABLES ${DATABASE_1}.mt AND ${DATABASE_2}.mt;
67
74
"
68
75
69
76
# Check that nothing changed
70
-
$CLICKHOUSE_CLIENT -q "SELECT count() FROM test_01114_1.mt"
71
-
uuid_mt1=$($CLICKHOUSE_CLIENT -q "SELECT uuid FROM system.tables WHERE database='test_01114_1' AND name='mt'")
72
-
$CLICKHOUSE_CLIENT --show_table_uuid_in_table_create_query_if_not_nil=1 -q "SHOW CREATE TABLE test_01114_1.mt"| sed "s/$uuid_mt1/00001114-0000-4000-8000-000000000001/g"
73
-
$CLICKHOUSE_CLIENT --show_table_uuid_in_table_create_query_if_not_nil=1 -q "SHOW CREATE TABLE test_01114_2.mt"| sed "s/$explicit_uuid/00001114-0000-4000-8000-000000000002/g"
77
+
$CLICKHOUSE_CLIENT -q "SELECT count() FROM ${DATABASE_1}.mt"
78
+
uuid_mt1=$($CLICKHOUSE_CLIENT -q "SELECT uuid FROM system.tables WHERE database='${DATABASE_1}' AND name='mt'")
79
+
$CLICKHOUSE_CLIENT --show_table_uuid_in_table_create_query_if_not_nil=1 -q "SHOW CREATE TABLE ${DATABASE_1}.mt"| sed "s/$uuid_mt1/00001114-0000-4000-8000-000000000001/g"
80
+
$CLICKHOUSE_CLIENT --show_table_uuid_in_table_create_query_if_not_nil=1 -q "SHOW CREATE TABLE ${DATABASE_2}.mt"| sed "s/$explicit_uuid/00001114-0000-4000-8000-000000000002/g"
74
81
75
82
$CLICKHOUSE_CLIENT -nm -q "
76
-
DROP TABLE test_01114_1.mt SETTINGS database_atomic_wait_for_drop_and_detach_synchronously=0;
77
-
CREATE TABLE test_01114_1.mt (s String) ENGINE=Log();
78
-
INSERT INTO test_01114_1.mt SELECT 's' || toString(number) FROM numbers(5);
79
-
SELECT count() FROM test_01114_1.mt
83
+
DROP TABLE ${DATABASE_1}.mt SETTINGS database_atomic_wait_for_drop_and_detach_synchronously=0;
84
+
CREATE TABLE ${DATABASE_1}.mt (s String) ENGINE=Log();
85
+
INSERT INTO ${DATABASE_1}.mt SELECT 's' || toString(number) FROM numbers(5);
while [[ $($CLICKHOUSE_CLIENT -q "SELECT count() FROM system.processes WHERE query_id != queryID() AND current_database = currentDatabase() AND query LIKE '%-- ${RANDOM_TUPLE}%'")-ne 1 ]];do
93
+
it=$((it+1))
94
+
if [ $it-ge 50 ];
95
+
then
96
+
echo"Failed to wait for second batch of queries"
97
+
$CLICKHOUSE_CLIENT -q "SELECT count() FROM system.processes WHERE query_id != queryID() AND current_database = currentDatabase() AND query LIKE '%-- ${RANDOM_TUPLE}%'"
0 commit comments