diff --git a/dbms/src/Common/Exception.cpp b/dbms/src/Common/Exception.cpp index 24e91b6c7a325269f3d9452b42b96c69f092d31f..3a50dc19ea49bf48101f70fa7a43c6f93c2fa938 100644 --- a/dbms/src/Common/Exception.cpp +++ b/dbms/src/Common/Exception.cpp @@ -259,7 +259,7 @@ std::string ExecutionStatus::serializeText() const std::string res; { WriteBufferFromString wb(res); - wb << code << "\n" << message; + wb << code << "\n" << escape << message; } return res; } @@ -267,7 +267,7 @@ std::string ExecutionStatus::serializeText() const void ExecutionStatus::deserializeText(const std::string & data) { ReadBufferFromString rb(data); - rb >> code >> "\n" >> message; + rb >> code >> "\n" >> escape >> message; } ExecutionStatus ExecutionStatus::fromCurrentException(const std::string & start_of_message) diff --git a/dbms/src/Common/Exception.h b/dbms/src/Common/Exception.h index 7296b1640f724cc04426b0717611afc0517e4076..4465a407ddc8067a0ef3f71cac34691614b7681d 100644 --- a/dbms/src/Common/Exception.h +++ b/dbms/src/Common/Exception.h @@ -91,7 +91,7 @@ std::string getCurrentExceptionMessage(bool with_stacktrace, bool check_embedded int getCurrentExceptionCode(); -/// An execution status of any piece of code +/// An execution status of any piece of code, contains return code and optional error struct ExecutionStatus { int code = 0; diff --git a/dbms/src/Interpreters/DDLWorker.cpp b/dbms/src/Interpreters/DDLWorker.cpp index 25a03ea9bfee51833614b7652c497fb4e915ec6c..ff44d19d13b53b77f5777d93fee768b276f5dff2 100644 --- a/dbms/src/Interpreters/DDLWorker.cpp +++ b/dbms/src/Interpreters/DDLWorker.cpp @@ -50,6 +50,10 @@ namespace ErrorCodes } +const size_t DDLWorker::node_max_lifetime_seconds = 7 * 24 * 60 * 60; // week +const size_t DDLWorker::cleanup_min_period_seconds = 60; // minute + + struct DDLLogEntry { String query; @@ -65,7 +69,7 @@ struct DDLLogEntry WriteBufferFromString wb(res); wb << "version: " << CURRENT_VERSION << "\n"; - wb << "query: " << query << "\n"; + wb << "query: " << escape << query << "\n"; wb << "hosts: " << hosts << "\n"; wb << "initiator: " << initiator << "\n"; } @@ -83,7 +87,7 @@ struct DDLLogEntry if (version != CURRENT_VERSION) throw Exception("Unknown DDLLogEntry format version: " + version, ErrorCodes::UNKNOWN_FORMAT_VERSION); - rb >> "query: " >> query >> "\n"; + rb >> "query: " >> escape >> query >> "\n"; rb >> "hosts: " >> hosts >> "\n"; if (!rb.eof()) @@ -128,7 +132,7 @@ static bool isSupportedAlterType(int type) DDLWorker::DDLWorker(const std::string & zk_root_dir, Context & context_) - : context(context_), stop_flag(false) + : context(context_) { queue_dir = zk_root_dir; if (queue_dir.back() == '/') @@ -169,7 +173,9 @@ void DDLWorker::processTasks() for (auto it = begin_node; it != queue_nodes.end(); ++it) { - String node_data, node_name = *it, node_path = queue_dir + "/" + node_name; + const String & node_name = *it; + String node_path = queue_dir + "/" + node_name; + String node_data; if (!zookeeper->tryGet(node_path, node_data)) { diff --git a/dbms/src/Interpreters/DDLWorker.h b/dbms/src/Interpreters/DDLWorker.h index fa232daa0eb9121de9b29ea2aa45d6768081f363..d2fe5edbdd75895967f70ac6b6f9708c4eebd00c 100644 --- a/dbms/src/Interpreters/DDLWorker.h +++ b/dbms/src/Interpreters/DDLWorker.h @@ -65,7 +65,7 @@ private: std::string queue_dir; /// dir with queue of queries std::string master_dir; /// dir with queries was initiated by the server - /// Used to omit already processed nodes; + /// Used to omit already processed nodes. Maybe usage of set is more obvious. std::string last_processed_node_name; std::shared_ptr zookeeper; @@ -76,12 +76,15 @@ private: ExecutionStatus current_node_execution_status; std::shared_ptr event_queue_updated; - std::atomic stop_flag; + std::atomic stop_flag{false}; std::thread thread; size_t last_cleanup_time_seconds = 0; - static constexpr size_t node_max_lifetime_seconds = 60; // 7 * 24 * 60 * 60; - static constexpr size_t cleanup_min_period_seconds = 60; + + /// Delete node if its age is greater than that + static const size_t node_max_lifetime_seconds; + /// Cleaning starts after new node event is received if the last cleaning wasn't made sooner than N seconds ago + static const size_t cleanup_min_period_seconds; friend class DDLQueryStatusInputSream; }; diff --git a/dbms/src/Parsers/IAST.h b/dbms/src/Parsers/IAST.h index 5b3ee192a32734149d2aca8b94e322103ce5b780..0cc861e6571aed07e62f50ad2e1df83d1df599e9 100644 --- a/dbms/src/Parsers/IAST.h +++ b/dbms/src/Parsers/IAST.h @@ -177,11 +177,7 @@ private: }; -<<<<<<< HEAD -/// Quota the identifier with backquotes, if required. -======= /// Surrounds an identifier by back quotes if it is necessary. ->>>>>>> Parsers refactoring. [#CLICKHOUSE-5] String backQuoteIfNeed(const String & x);