Skip to content

Commit 04a24c5

Browse files
authored
Add tests with DatabaseAtomic (#10714)
* add tests with DatabaseAtomic * fix
1 parent c135221 commit 04a24c5

File tree

8 files changed

+27
-5
lines changed

8 files changed

+27
-5
lines changed

docker/test/stateful/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ CMD dpkg -i package_folder/clickhouse-common-static_*.deb; \
2828
ln -s /usr/share/clickhouse-test/config/decimals_dictionary.xml /etc/clickhouse-server/; \
2929
ln -s /usr/share/clickhouse-test/config/macros.xml /etc/clickhouse-server/config.d/; \
3030
ln -s /usr/lib/llvm-9/bin/llvm-symbolizer /usr/bin/llvm-symbolizer; \
31+
if [ -n $USE_DATABASE_ATOMIC ] && [ $USE_DATABASE_ATOMIC -eq 1 ]; then ln -s /usr/share/clickhouse-test/config/database_atomic.xml /etc/clickhouse-server/config.d/; fi; \
3132
echo "TSAN_OPTIONS='verbosity=1000 halt_on_error=1 history_size=7'" >> /etc/environment; \
3233
echo "TSAN_SYMBOLIZER_PATH=/usr/lib/llvm-8/bin/llvm-symbolizer" >> /etc/environment; \
3334
echo "UBSAN_OPTIONS='print_stacktrace=1'" >> /etc/environment; \

docker/test/stateless/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ CMD dpkg -i package_folder/clickhouse-common-static_*.deb; \
7575
ln -s /usr/share/clickhouse-test/config/server.crt /etc/clickhouse-server/; \
7676
ln -s /usr/share/clickhouse-test/config/dhparam.pem /etc/clickhouse-server/; \
7777
if [ -n $USE_POLYMORPHIC_PARTS ] && [ $USE_POLYMORPHIC_PARTS -eq 1 ]; then ln -s /usr/share/clickhouse-test/config/polymorphic_parts.xml /etc/clickhouse-server/config.d/; fi; \
78+
if [ -n $USE_DATABASE_ATOMIC ] && [ $USE_DATABASE_ATOMIC -eq 1 ]; then ln -s /usr/share/clickhouse-test/config/database_atomic.xml /etc/clickhouse-server/config.d/; fi; \
7879
ln -sf /usr/share/clickhouse-test/config/client_config.xml /etc/clickhouse-client/config.xml; \
7980
service zookeeper start; sleep 5; \
8081
service clickhouse-server start && sleep 5 && clickhouse-test --testname --shard --zookeeper $ADDITIONAL_OPTIONS $SKIP_TESTS_OPTION 2>&1 | ts '%Y-%m-%d %H:%M:%S' | tee test_output/test_result.txt

src/Core/Settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ struct Settings : public SettingsCollection<Settings>
402402
\
403403
M(SettingDefaultDatabaseEngine, default_database_engine, DefaultDatabaseEngine::Ordinary, "Default database engine.", 0) \
404404
M(SettingBool, allow_experimental_database_atomic, false, "Allow to create database with Engine=Atomic.", 0) \
405+
M(SettingBool, show_table_uuid_in_table_create_query_if_not_nil, true, "For tables in databases with Engine=Atomic show UUID of the table in its CREATE query.", 0) \
405406
M(SettingBool, enable_scalar_subquery_optimization, true, "If it is set to true, prevent scalar subqueries from (de)serializing large scalar values and possibly avoid running the same subquery more than once.", 0) \
406407
M(SettingBool, optimize_trivial_count_query, true, "Process trivial 'SELECT count() FROM table' query from metadata.", 0) \
407408
M(SettingUInt64, mutations_sync, 0, "Wait for synchronous execution of ALTER TABLE UPDATE/DELETE queries (mutations). 0 - execute asynchronously. 1 - wait current server. 2 - wait all replicas if they exist.", 0) \

src/Interpreters/DatabaseCatalog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ StoragePtr TemporaryTableHolder::getTable() const
106106

107107
void DatabaseCatalog::loadDatabases()
108108
{
109-
drop_delay_sec = global_context->getConfigRef().getInt("database_atomic_delay_before_drop_table_sec", 60);
109+
drop_delay_sec = global_context->getConfigRef().getInt("database_atomic_delay_before_drop_table_sec", default_drop_delay_sec);
110110

111111
auto db_for_temporary_and_external_tables = std::make_shared<DatabaseMemory>(TEMPORARY_DATABASE);
112112
attachDatabase(TEMPORARY_DATABASE, db_for_temporary_and_external_tables);

src/Interpreters/DatabaseCatalog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ class DatabaseCatalog : boost::noncopyable
224224
mutable std::mutex tables_marked_dropped_mutex;
225225

226226
std::unique_ptr<BackgroundSchedulePoolTaskHolder> drop_task;
227-
time_t drop_delay_sec = 60;
227+
static constexpr time_t default_drop_delay_sec = 8 * 60;
228+
time_t drop_delay_sec = default_drop_delay_sec;
228229
};
229230

230231
}

src/Interpreters/InterpreterShowCreateQuery.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <Access/AccessFlags.h>
1414
#include <Interpreters/Context.h>
1515
#include <Interpreters/InterpreterShowCreateQuery.h>
16+
#include <Parsers/ASTCreateQuery.h>
1617

1718
namespace DB
1819
{
@@ -71,6 +72,12 @@ BlockInputStreamPtr InterpreterShowCreateQuery::executeImpl()
7172
if (!create_query && show_query && show_query->temporary)
7273
throw Exception("Unable to show the create query of " + show_query->table + ". Maybe it was created by the system.", ErrorCodes::THERE_IS_NO_QUERY);
7374

75+
if (!context.getSettingsRef().show_table_uuid_in_table_create_query_if_not_nil)
76+
{
77+
auto & create = create_query->as<ASTCreateQuery &>();
78+
create.uuid = UUIDHelpers::Nil;
79+
}
80+
7481
std::stringstream stream;
7582
formatAST(*create_query, stream, false, false);
7683
String res = stream.str();

tests/config/database_atomic.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<yandex>
2+
<profiles>
3+
<default>
4+
<default_database_engine>Atomic</default_database_engine>
5+
<allow_experimental_database_atomic>1</allow_experimental_database_atomic>
6+
<show_table_uuid_in_table_create_query_if_not_nil>0</show_table_uuid_in_table_create_query_if_not_nil>
7+
</default>
8+
</profiles>
9+
10+
<database_atomic_delay_before_drop_table_sec>60</database_atomic_delay_before_drop_table_sec>
11+
</yandex>

tests/queries/0_stateless/01114_database_atomic.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ $CLICKHOUSE_CLIENT -q "SELECT count() FROM test_01114_3.mt_tmp"
3030
$CLICKHOUSE_CLIENT -q "DROP DATABASE test_01114_3"
3131

3232
$CLICKHOUSE_CLIENT -q "CREATE TABLE test_01114_2.mt UUID '00001114-0000-4000-8000-000000000002' (n UInt64) ENGINE=MergeTree() ORDER BY tuple() PARTITION BY (n % 5)"
33-
$CLICKHOUSE_CLIENT -q "SHOW CREATE TABLE test_01114_2.mt"
33+
$CLICKHOUSE_CLIENT --show_table_uuid_in_table_create_query_if_not_nil=1 -q "SHOW CREATE TABLE test_01114_2.mt"
3434
$CLICKHOUSE_CLIENT -q "SELECT name, uuid, create_table_query FROM system.tables WHERE database='test_01114_2'"
3535

3636

@@ -47,8 +47,8 @@ $CLICKHOUSE_CLIENT -q "EXCHANGE TABLES test_01114_1.mt AND test_01114_2.mt"
4747
# Check that nothing changed
4848
$CLICKHOUSE_CLIENT -q "SELECT count() FROM test_01114_1.mt"
4949
uuid_mt1=`$CLICKHOUSE_CLIENT -q "SELECT uuid FROM system.tables WHERE database='test_01114_1' AND name='mt'"`
50-
$CLICKHOUSE_CLIENT -q "SHOW CREATE TABLE test_01114_1.mt" | sed "s/$uuid_mt1/00001114-0000-4000-8000-000000000001/g"
51-
$CLICKHOUSE_CLIENT -q "SHOW CREATE TABLE test_01114_2.mt"
50+
$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"
51+
$CLICKHOUSE_CLIENT --show_table_uuid_in_table_create_query_if_not_nil=1 -q "SHOW CREATE TABLE test_01114_2.mt"
5252

5353
$CLICKHOUSE_CLIENT -q "DROP TABLE test_01114_1.mt"
5454
$CLICKHOUSE_CLIENT -q "CREATE TABLE test_01114_1.mt (s String) ENGINE=Log()"

0 commit comments

Comments
 (0)