ClickHouse/src/Parsers/ASTSystemQuery.h

125 lines
2.9 KiB
C++
Raw Normal View History

#pragma once
2019-12-19 03:46:20 +00:00
#include <Parsers/ASTQueryWithOnCluster.h>
#include <Parsers/IAST.h>
2021-10-27 23:10:39 +00:00
#include "config_core.h"
namespace DB
{
2019-12-19 03:46:20 +00:00
class ASTSystemQuery : public IAST, public ASTQueryWithOnCluster
{
public:
2021-09-20 15:15:23 +00:00
enum class Type : UInt64
{
UNKNOWN,
SHUTDOWN,
KILL,
2021-01-07 19:19:33 +00:00
SUSPEND,
DROP_DNS_CACHE,
DROP_MARK_CACHE,
DROP_UNCOMPRESSED_CACHE,
DROP_INDEX_MARK_CACHE,
DROP_INDEX_UNCOMPRESSED_CACHE,
DROP_MMAP_CACHE,
#if USE_EMBEDDED_COMPILER
DROP_COMPILED_EXPRESSION_CACHE,
#endif
2022-03-30 11:47:44 +00:00
DROP_FILESYSTEM_CACHE,
STOP_LISTEN_QUERIES,
START_LISTEN_QUERIES,
RESTART_REPLICAS,
RESTART_REPLICA,
SYSTEM RESTORE REPLICA replica [ON CLUSTER cluster] (#13652) * initial commit: add setting and stub * typo * added test stub * fix * wip merging new integration test and code proto * adding steps interpreters * adding firstly proposed solution (moving parts etc) * added checking zookeeper path existence * fixing the include * fixing and sorting includes * fixing outdated struct * fix the name * added ast ptr as level of indirection * fix ref * updating the changes * working on test stub * fix iterator -> reference * revert rocksdb submodule update * fixed show privileges test * updated the test stub * replaced rand() with thread_local_rng(), updated the tests updated the test fixed test config path test fix removed error messages fixed the test updated the test fixed string literal fixed literal typo: = * fixed the empty replica error message * updated the test and the code with logs * updated the possible test cases, updated * added the code/test milestone comments * updated the test (added more testcases) * replaced native assert with CH one * individual replicas recursive delete fix * updated the AS db.name AST * two small logging fixes * manually generated AST fixes * Updated the test, added the possible algo change * Some thoughts about optimizing the solution: ALTER MOVE PARTITION .. TO TABLE -> move to detached/ + ALTER ... ATTACH * fix * Removed the replica sync in test as it's invalid * Some test tweaks * tmp * Rewrote the algo by using the executeQuery instead of hand-crafting the ASTPtr. Two questions still active. * tr: logging active parts * Extracted the parts moving algo into a separate helper function * Fixed the test data and the queries slightly * Replaced query to system.parts to direct invocation, started building the test that breaks on various parts. * Added the case for tables when at least one replica is alive * Updated the test to test replicas restoration by detaching/attaching * Altered the test to check restoration without replica restart * Added the tables swap in the start if the server failed last time * Hotfix when only /replicas/replica... path was deleted * Restore ZK paths while creating a replicated MergeTree table * Updated the docs, fixed the algo for individual replicas restoration case * Initial parts table storage fix, tests sync fix * Reverted individual replica restoration to general algo * Slightly optimised getDataParts * Trying another solution with parts detaching * Rewrote algo without any steps, added ON CLUSTER support * Attaching parts from other replica on restoration * Getting part checksums from ZK * Removed ON CLUSTER, finished working solution * Multiple small changes after review * Fixing parallel test * Supporting rewritten form on cluster * Test fix * Moar logging * Using source replica as checksum provider * improve test, remove some code from parser * Trying solution with move to detached + forget * Moving all parts (not only Committed) to detached * Edited docs for RESTORE REPLICA * Re-merging * minor fixes Co-authored-by: Alexander Tokmakov <avtokmakov@yandex-team.ru>
2021-06-20 08:24:43 +00:00
RESTORE_REPLICA,
2020-05-17 12:44:22 +00:00
DROP_REPLICA,
SYNC_REPLICA,
SYNC_DATABASE_REPLICA,
RELOAD_DICTIONARY,
RELOAD_DICTIONARIES,
2021-04-16 09:56:40 +00:00
RELOAD_MODEL,
RELOAD_MODELS,
RELOAD_FUNCTION,
RELOAD_FUNCTIONS,
RELOAD_EMBEDDED_DICTIONARIES,
RELOAD_CONFIG,
2020-11-30 14:30:55 +00:00
RELOAD_SYMBOLS,
2021-04-20 19:23:54 +00:00
RESTART_DISK,
STOP_MERGES,
START_MERGES,
2019-08-01 15:36:12 +00:00
STOP_TTL_MERGES,
START_TTL_MERGES,
STOP_FETCHES,
START_FETCHES,
2019-09-03 14:50:49 +00:00
STOP_MOVES,
START_MOVES,
STOP_REPLICATED_SENDS,
2019-02-02 11:28:43 +00:00
START_REPLICATED_SENDS,
STOP_REPLICATION_QUEUES,
START_REPLICATION_QUEUES,
FLUSH_LOGS,
FLUSH_DISTRIBUTED,
2019-04-22 15:11:16 +00:00
STOP_DISTRIBUTED_SENDS,
START_DISTRIBUTED_SENDS,
START_THREAD_FUZZER,
STOP_THREAD_FUZZER,
END
};
2021-09-20 15:15:23 +00:00
static const char * typeToString(Type type);
Type type = Type::UNKNOWN;
2021-10-12 18:11:00 +00:00
ASTPtr database;
ASTPtr table;
String getDatabase() const;
String getTable() const;
void setDatabase(const String & name);
void setTable(const String & name);
2021-04-16 09:56:40 +00:00
String target_model;
String target_function;
2020-05-17 12:44:22 +00:00
String replica;
String replica_zk_path;
2021-01-07 19:19:33 +00:00
bool is_drop_whole_replica{};
String storage_policy;
String volume;
2021-04-20 19:23:54 +00:00
String disk;
2021-01-07 19:19:33 +00:00
UInt64 seconds{};
2022-04-25 16:49:00 +00:00
2022-04-25 17:40:28 +00:00
/// Values for `drop filesystem cache` system query.
2022-03-30 11:47:44 +00:00
String filesystem_cache_path;
2022-04-25 16:49:00 +00:00
bool force_removal = false;
String getID(char) const override { return "SYSTEM query"; }
2021-10-12 18:11:00 +00:00
ASTPtr clone() const override
{
auto res = std::make_shared<ASTSystemQuery>(*this);
res->children.clear();
if (database) { res->database = database->clone(); res->children.push_back(res->database); }
if (table) { res->table = table->clone(); res->children.push_back(res->table); }
return res;
}
ASTPtr getRewrittenASTWithoutOnCluster(const WithoutOnClusterASTRewriteParams & params) const override
2019-12-19 03:46:20 +00:00
{
return removeOnCluster<ASTSystemQuery>(clone(), params.default_database);
2019-12-19 03:46:20 +00:00
}
2021-12-29 12:32:49 +00:00
virtual QueryKind getQueryKind() const override { return QueryKind::System; }
2021-08-04 14:09:23 +00:00
protected:
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
};
}