提交 ffe7558f 编写于 作者: V Vitaliy Lyudvichenko

Add SYSTEM KILL and SHUTDOWN implementations. [#CLICKHOUSE-2931]

上级 eb057981
......@@ -382,6 +382,7 @@ namespace ErrorCodes
extern const int ILLEGAL_SYNTAX_FOR_DATA_TYPE = 377;
extern const int DATA_TYPE_CANNOT_HAVE_ARGUMENTS = 378;
extern const int UNKNOWN_STATUS_OF_DISTRIBUTED_DDL_TASK = 379;
extern const int CANNOT_KILL = 380;
extern const int KEEPER_EXCEPTION = 999;
extern const int POCO_EXCEPTION = 1000;
......
#include "InterpreterSystemQuery.h"
#include <Interpreters/InterpreterSystemQuery.h>
#include <Parsers/ASTSystemQuery.h>
#include <Common/typeid_cast.h>
#include <csignal>
namespace DB
{
namespace ErrorCodes
{
extern const int BAD_ARGUMENTS;
extern const int CANNOT_KILL;
}
InterpreterSystemQuery::InterpreterSystemQuery(const ASTPtr & query_ptr_, Context & context_)
: query_ptr(query_ptr_), context(context_) {}
BlockIO InterpreterSystemQuery::execute()
{
auto & query = typeid_cast<ASTSystemQuery &>(*query_ptr);
using Type = ASTSystemQuery::Type;
switch (query.type)
{
case Type::SHUTDOWN:
if (kill(0, SIGTERM))
throw Exception("System call kill() failed", ErrorCodes::CANNOT_KILL);
break;
case Type::KILL:
if (kill(0, SIGKILL))
throw Exception("System call kill() failed", ErrorCodes::CANNOT_KILL);
break;
case Type::DROP_DNS_CACHE:
break;
case Type::DROP_MARK_CACHE:
break;
case Type::DROP_UNCOMPRESSED_CACHE:
break;
case Type::STOP_LISTEN_QUERIES:break;
case Type::START_LISTEN_QUERIES:break;
case Type::RESTART_REPLICAS:break;
case Type::SYNC_REPLICA:break;
case Type::RELOAD_DICTIONARY:break;
case Type::RELOAD_DICTIONARIES:break;
case Type::STOP_MERGES:break;
case Type::START_MERGES:break;
case Type::STOP_REPLICATION_QUEUES:break;
case Type::START_REPLICATION_QUEUES:break;
default:
throw Exception("Unknown type of SYSTEM query", ErrorCodes::BAD_ARGUMENTS);
}
return BlockIO();
}
}
\ No newline at end of file
#pragma once
#include <Interpreters/IInterpreter.h>
namespace DB
{
......@@ -9,8 +10,6 @@ class IAST;
using ASTPtr = std::shared_ptr<IAST>;
/** Return list of currently executing queries.
*/
class InterpreterSystemQuery : public IInterpreter
{
public:
......
......@@ -2,14 +2,15 @@
#include <Parsers/ASTSystemQuery.h>
namespace ErrorCodes
namespace DB
{
extern const int BAD_TYPE_OF_FIELD;
}
namespace DB
namespace ErrorCodes
{
extern const int BAD_TYPE_OF_FIELD;
extern const int NOT_IMPLEMENTED;
}
const char * ASTSystemQuery::typeToString(Type type)
......@@ -52,4 +53,17 @@ const char * ASTSystemQuery::typeToString(Type type)
}
void ASTSystemQuery::formatImpl(const IAST::FormatSettings & settings, IAST::FormatState & state,
IAST::FormatStateStacked frame) 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);
}
}
\ No newline at end of file
......@@ -36,12 +36,13 @@ public:
Type type = Type::_UNKNOWN;
String target_dictionary;
//String target_replica;
//String target_replica_database;
//String target_replica_table;
ASTSystemQuery() = default;
explicit ASTSystemQuery(const StringRange range) : IAST(range) {}
String getID() const override { return "SYSTEM"; };
String getID() const override { return "SYSTEM query"; };
ASTPtr clone() const override { return std::make_shared<ASTSystemQuery>(*this); }
......@@ -49,10 +50,7 @@ public:
protected:
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SYSTEM " << (settings.hilite ? hilite_none : "");
}
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册