diff --git a/src/Parsers/ASTSystemQuery.cpp b/src/Parsers/ASTSystemQuery.cpp index 992971dd1ac8..00925e561219 100644 --- a/src/Parsers/ASTSystemQuery.cpp +++ b/src/Parsers/ASTSystemQuery.cpp @@ -163,7 +163,13 @@ void ASTSystemQuery::formatImpl(WriteBuffer & ostr, const FormatSettings & setti print_keyword("SYSTEM") << " "; print_keyword(typeToString(type)); - if (!cluster.empty()) + + std::unordered_set queries_with_on_cluster_at_end = { + Type::DROP_FILESYSTEM_CACHE, + Type::SYNC_FILESYSTEM_CACHE, + }; + + if (!queries_with_on_cluster_at_end.contains(type) && !cluster.empty()) formatOnCluster(ostr, settings); switch (type) @@ -519,6 +525,9 @@ void ASTSystemQuery::formatImpl(WriteBuffer & ostr, const FormatSettings & setti case Type::END: throw Exception(ErrorCodes::LOGICAL_ERROR, "Unknown SYSTEM command"); } + + if (queries_with_on_cluster_at_end.contains(type) && !cluster.empty()) + formatOnCluster(ostr, settings); } diff --git a/tests/queries/0_stateless/03643_system_drop_filesystem_cache_on_cluster.reference b/tests/queries/0_stateless/03643_system_drop_filesystem_cache_on_cluster.reference new file mode 100644 index 000000000000..1444d39d9578 --- /dev/null +++ b/tests/queries/0_stateless/03643_system_drop_filesystem_cache_on_cluster.reference @@ -0,0 +1,2 @@ +localhost 9000 0 0 0 +localhost 9000 0 0 0 diff --git a/tests/queries/0_stateless/03643_system_drop_filesystem_cache_on_cluster.sh b/tests/queries/0_stateless/03643_system_drop_filesystem_cache_on_cluster.sh new file mode 100755 index 000000000000..8f40316ac5d1 --- /dev/null +++ b/tests/queries/0_stateless/03643_system_drop_filesystem_cache_on_cluster.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# Tags: no-fasttest, no-parallel, no-object-storage, no-random-settings + +# set -x + +CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CUR_DIR"/../shell_config.sh + + +disk_name="${CLICKHOUSE_TEST_UNIQUE_NAME}" +$CLICKHOUSE_CLIENT -m --query """ +DROP TABLE IF EXISTS test; +CREATE TABLE test (a Int32, b String) +ENGINE = MergeTree() ORDER BY tuple() +SETTINGS disk = disk(name = '$disk_name', type = cache, max_size = '100Ki', path = ${CLICKHOUSE_TEST_UNIQUE_NAME}, disk = s3_disk); + +INSERT INTO test SELECT 1, 'test'; +""" + +$CLICKHOUSE_CLIENT --query """ +SYSTEM SYNC FILESYSTEM CACHE '$disk_name' ON CLUSTER 'test_shard_localhost'; +""" + +$CLICKHOUSE_CLIENT --query """ +SYSTEM DROP FILESYSTEM CACHE '$disk_name' ON CLUSTER 'test_shard_localhost'; +""" + +$CLICKHOUSE_CLIENT --query """ +DROP TABLE IF EXISTS test; +"""