From 9112c3b400d5d07329bea7bf9398a25a6f68cf8f Mon Sep 17 00:00:00 2001 From: ywqzzy <592838129@qq.com> Date: Wed, 6 Apr 2022 16:03:52 +0800 Subject: [PATCH] update. --- dbms/src/Interpreters/InterpreterFactory.cpp | 7 - .../Interpreters/InterpreterSystemQuery.cpp | 131 ------------------ .../src/Interpreters/InterpreterSystemQuery.h | 39 ------ dbms/src/Parsers/ASTSystemQuery.cpp | 84 ----------- dbms/src/Parsers/ASTSystemQuery.h | 67 --------- dbms/src/Parsers/ParserQuery.cpp | 23 ++- dbms/src/Parsers/ParserSystemQuery.cpp | 70 ---------- dbms/src/Parsers/ParserSystemQuery.h | 30 ---- 8 files changed, 9 insertions(+), 442 deletions(-) delete mode 100644 dbms/src/Interpreters/InterpreterSystemQuery.cpp delete mode 100644 dbms/src/Interpreters/InterpreterSystemQuery.h delete mode 100644 dbms/src/Parsers/ASTSystemQuery.cpp delete mode 100644 dbms/src/Parsers/ASTSystemQuery.h delete mode 100644 dbms/src/Parsers/ParserSystemQuery.cpp delete mode 100644 dbms/src/Parsers/ParserSystemQuery.h diff --git a/dbms/src/Interpreters/InterpreterFactory.cpp b/dbms/src/Interpreters/InterpreterFactory.cpp index 5231bbd3dd6..aabff463369 100644 --- a/dbms/src/Interpreters/InterpreterFactory.cpp +++ b/dbms/src/Interpreters/InterpreterFactory.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -52,7 +51,6 @@ #include #include #include -#include #include #include #include @@ -173,11 +171,6 @@ std::unique_ptr InterpreterFactory::get(ASTPtr & query, Context & { return std::make_unique(query, context); } - else if (typeid_cast(query.get())) - { - throwIfReadOnly(context); - return std::make_unique(query, context); - } else if (typeid_cast(query.get())) { throwIfReadOnly(context); diff --git a/dbms/src/Interpreters/InterpreterSystemQuery.cpp b/dbms/src/Interpreters/InterpreterSystemQuery.cpp deleted file mode 100644 index 32437fcc3fd..00000000000 --- a/dbms/src/Interpreters/InterpreterSystemQuery.cpp +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include -#include -#include -#include -#include - -#include - - -namespace DB -{ -namespace ErrorCodes -{ -extern const int BAD_ARGUMENTS; -extern const int CANNOT_KILL; -extern const int NOT_IMPLEMENTED; -} // namespace ErrorCodes - - -namespace -{ -ExecutionStatus getOverallExecutionStatusOfCommands() -{ - return ExecutionStatus(0); -} - -/// Consequently execute all commands and genreates final exception message for failed commands -template -ExecutionStatus getOverallExecutionStatusOfCommands(Callable && command, Callables &&... commands) -{ - ExecutionStatus status_head(0); - try - { - command(); - } - catch (...) - { - status_head = ExecutionStatus::fromCurrentException(); - } - - ExecutionStatus status_tail = getOverallExecutionStatusOfCommands(std::forward(commands)...); - - auto res_status = status_head.code != 0 ? status_head.code : status_tail.code; - auto res_message = status_head.message + (status_tail.message.empty() ? "" : ("\n" + status_tail.message)); - - return ExecutionStatus(res_status, res_message); -} - -} // namespace - - -InterpreterSystemQuery::InterpreterSystemQuery(const ASTPtr & query_ptr_, Context & context_) - : query_ptr(query_ptr_) - , context(context_) -{} - - -BlockIO InterpreterSystemQuery::execute() -{ - auto & query = typeid_cast(*query_ptr); - - using Type = ASTSystemQuery::Type; - - switch (query.type) - { - case Type::SHUTDOWN: - if (kill(0, SIGTERM)) - throwFromErrno("System call kill(0, SIGTERM) failed", ErrorCodes::CANNOT_KILL); - break; - case Type::KILL: - if (kill(0, SIGKILL)) - throwFromErrno("System call kill(0, SIGKILL) failed", ErrorCodes::CANNOT_KILL); - break; - case Type::DROP_DNS_CACHE: - DNSCache::instance().drop(); - break; - case Type::DROP_MARK_CACHE: - context.dropMarkCache(); - break; - case Type::DROP_UNCOMPRESSED_CACHE: - context.dropUncompressedCache(); - break; - case Type::RELOAD_DICTIONARY: - context.getExternalDictionaries().reloadDictionary(query.target_dictionary); - break; - case Type::RELOAD_DICTIONARIES: - { - auto status = getOverallExecutionStatusOfCommands( - [&] { context.getExternalDictionaries().reload(); }, - [&] { context.getEmbeddedDictionaries().reload(); }); - if (status.code != 0) - throw Exception(status.message, status.code); - break; - } - case Type::RELOAD_CONFIG: - context.reloadConfig(); - break; - case Type::STOP_LISTEN_QUERIES: - case Type::START_LISTEN_QUERIES: - case Type::RESTART_REPLICAS: - case Type::SYNC_REPLICA: - case Type::STOP_MERGES: - case Type::START_MERGES: - case Type::STOP_REPLICATION_QUEUES: - case Type::START_REPLICATION_QUEUES: - throw Exception(String(ASTSystemQuery::typeToString(query.type)) + " is not supported yet", ErrorCodes::NOT_IMPLEMENTED); - default: - throw Exception("Unknown type of SYSTEM query", ErrorCodes::BAD_ARGUMENTS); - } - - return BlockIO(); -} - - -} // namespace DB diff --git a/dbms/src/Interpreters/InterpreterSystemQuery.h b/dbms/src/Interpreters/InterpreterSystemQuery.h deleted file mode 100644 index 2f5c30fc480..00000000000 --- a/dbms/src/Interpreters/InterpreterSystemQuery.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once -#include - - -namespace DB -{ -class Context; -class IAST; -using ASTPtr = std::shared_ptr; - - -class InterpreterSystemQuery : public IInterpreter -{ -public: - InterpreterSystemQuery(const ASTPtr & query_ptr_, Context & context_); - - BlockIO execute() override; - -private: - ASTPtr query_ptr; - Context & context; -}; - - -} // namespace DB diff --git a/dbms/src/Parsers/ASTSystemQuery.cpp b/dbms/src/Parsers/ASTSystemQuery.cpp deleted file mode 100644 index b1a2dbbc752..00000000000 --- a/dbms/src/Parsers/ASTSystemQuery.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include - - -namespace DB -{ - - -namespace ErrorCodes -{ - extern const int BAD_TYPE_OF_FIELD; - extern const int NOT_IMPLEMENTED; -} - - -const char * ASTSystemQuery::typeToString(Type type) -{ - switch (type) - { - case Type::SHUTDOWN: - return "SHUTDOWN"; - case Type::KILL: - return "KILL"; - case Type::DROP_DNS_CACHE: - return "DROP DNS CACHE"; - case Type::DROP_MARK_CACHE: - return "DROP MARK CACHE"; - case Type::DROP_UNCOMPRESSED_CACHE: - return "DROP UNCOMPRESSED CACHE"; - case Type::STOP_LISTEN_QUERIES: - return "STOP LISTEN QUERIES"; - case Type::START_LISTEN_QUERIES: - return "START LISTEN QUERIES"; - case Type::RESTART_REPLICAS: - return "RESTART REPLICAS"; - case Type::SYNC_REPLICA: - return "SYNC REPLICA"; - case Type::RELOAD_DICTIONARY: - return "RELOAD DICTIONARY"; - case Type::RELOAD_DICTIONARIES: - return "RELOAD DICTIONARIES"; - case Type::RELOAD_CONFIG: - return "RELOAD CONFIG"; - case Type::STOP_MERGES: - return "STOP MERGES"; - case Type::START_MERGES: - return "START MERGES"; - case Type::STOP_REPLICATION_QUEUES: - return "STOP REPLICATION QUEUES"; - case Type::START_REPLICATION_QUEUES: - return "START REPLICATION QUEUES"; - default: - throw Exception("Unknown SYSTEM query command", ErrorCodes::BAD_TYPE_OF_FIELD); - } -} - - -void ASTSystemQuery::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const -{ - settings.ostr << (settings.hilite ? hilite_keyword : "") << "SYSTEM " << (settings.hilite ? hilite_none : ""); - settings.ostr << typeToString(type); - - if (type == Type::RELOAD_DICTIONARY) - settings.ostr << " " << backQuoteIfNeed(target_dictionary); - else if (type == Type::SYNC_REPLICA) - throw Exception("SYNC_REPLICA isn't supported yet", ErrorCodes::NOT_IMPLEMENTED); -} - - -} diff --git a/dbms/src/Parsers/ASTSystemQuery.h b/dbms/src/Parsers/ASTSystemQuery.h deleted file mode 100644 index 06841542114..00000000000 --- a/dbms/src/Parsers/ASTSystemQuery.h +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include - - -namespace DB -{ - -class ASTSystemQuery : public IAST -{ -public: - - enum class Type - { - UNKNOWN, - SHUTDOWN, - KILL, - DROP_DNS_CACHE, - DROP_MARK_CACHE, - DROP_UNCOMPRESSED_CACHE, - STOP_LISTEN_QUERIES, - START_LISTEN_QUERIES, - RESTART_REPLICAS, - SYNC_REPLICA, - RELOAD_DICTIONARY, - RELOAD_DICTIONARIES, - RELOAD_CONFIG, - STOP_MERGES, - START_MERGES, - STOP_REPLICATION_QUEUES, - START_REPLICATION_QUEUES, - END - }; - - static const char * typeToString(Type type); - - Type type = Type::UNKNOWN; - - String target_dictionary; - //String target_replica_database; - //String target_replica_table; - - String getID() const override { return "SYSTEM query"; }; - - ASTPtr clone() const override { return std::make_shared(*this); } - -protected: - - void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override; -}; - - -} diff --git a/dbms/src/Parsers/ParserQuery.cpp b/dbms/src/Parsers/ParserQuery.cpp index f6bb7d8ca32..a4d77552acc 100644 --- a/dbms/src/Parsers/ParserQuery.cpp +++ b/dbms/src/Parsers/ParserQuery.cpp @@ -12,26 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include +#include #include -#include -#include #include +#include #include -#include +#include +#include #include -#include +#include +#include +#include #include -#include -#include #include -#include +#include namespace DB { - - bool ParserQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { ParserQueryWithOutput query_with_output_p; @@ -41,7 +38,6 @@ bool ParserQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) ParserDeleteQuery delete_p; ParserDBGInvokeQuery dbginvoke_p; ParserOptimizeQuery optimize_p; - ParserSystemQuery system_p; ParserTruncateQuery truncate_p; ParserManageQuery manage_p; @@ -52,11 +48,10 @@ bool ParserQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) || delete_p.parse(pos, node, expected) || dbginvoke_p.parse(pos, node, expected) || optimize_p.parse(pos, node, expected) - || system_p.parse(pos, node, expected) || truncate_p.parse(pos, node, expected) || manage_p.parse(pos, node, expected); return res; } -} +} // namespace DB diff --git a/dbms/src/Parsers/ParserSystemQuery.cpp b/dbms/src/Parsers/ParserSystemQuery.cpp deleted file mode 100644 index eca26bd8122..00000000000 --- a/dbms/src/Parsers/ParserSystemQuery.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include -#include -#include -#include - - -namespace ErrorCodes -{ - extern const int NOT_IMPLEMENTED; -} - - -namespace DB -{ - - -bool ParserSystemQuery::parseImpl(IParser::Pos & pos, ASTPtr & node, Expected & expected) -{ - if (!ParserKeyword{"SYSTEM"}.ignore(pos)) - return false; - - using Type = ASTSystemQuery::Type; - - auto res = std::make_shared(); - - bool found = false; - for (int i = static_cast(Type::UNKNOWN) + 1; i < static_cast(Type::END); ++i) - { - Type t = static_cast(i); - if (ParserKeyword{ASTSystemQuery::typeToString(t)}.ignore(pos)) - { - res->type = t; - found = true; - } - } - - if (!found) - return false; - - if (res->type == Type::RELOAD_DICTIONARY) - { - if (!parseIdentifierOrStringLiteral(pos, expected, res->target_dictionary)) - return false; - } - else if (res->type == Type::SYNC_REPLICA) - { - throw Exception("SYNC REPLICA is not supported yet", ErrorCodes::NOT_IMPLEMENTED); - } - - node = std::move(res); - return true; -} - -} diff --git a/dbms/src/Parsers/ParserSystemQuery.h b/dbms/src/Parsers/ParserSystemQuery.h deleted file mode 100644 index 3e4539b8600..00000000000 --- a/dbms/src/Parsers/ParserSystemQuery.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once -#include - - -namespace DB -{ - - -class ParserSystemQuery : public IParserBase -{ -protected: - const char * getName() const override { return "SYSTEM query"; } - bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override; -}; - -}