From 242a9135ad92152fa6917449404479392cc39a0d Mon Sep 17 00:00:00 2001 From: jinhelin Date: Tue, 30 Aug 2022 16:18:18 +0800 Subject: [PATCH 1/3] Fix getReadTSOForLog. --- dbms/src/Debug/dbgFuncMisc.cpp | 55 +++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/dbms/src/Debug/dbgFuncMisc.cpp b/dbms/src/Debug/dbgFuncMisc.cpp index a1d592f88e9..e210ddc867c 100644 --- a/dbms/src/Debug/dbgFuncMisc.cpp +++ b/dbms/src/Debug/dbgFuncMisc.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -25,13 +26,25 @@ namespace DB { inline size_t getReadTSOForLog(const String & line) { - auto sub_line = line.substr(line.find("read_tso=")); - std::regex rx(R"((0|[1-9][0-9]*))"); - std::smatch m; - if (regex_search(sub_line, m, rx)) - return std::stoul(m[1]); - else - return 0; + String sub_line; + try + { + std::regex rx(R"((0|[1-9][0-9]*))"); + std::smatch m; + sub_line = line.substr(line.find("read_tso=")); + if (!sub_line.empty() && regex_search(sub_line, m, rx)) + { + return std::stoul(m[1]); + } + else + { + return 0; + } + } + catch (std::exception & e) + { + throw Exception(fmt::format("Parse 'read tso' failed, exception: {}, sub_line {}, line {}", e.what(), sub_line, line)); + } } // Usage example: @@ -89,14 +102,28 @@ void dbgFuncSearchLogForKey(Context & context, const ASTs & args, DBGInvoker::Pr break; } } + static auto * log = &Poco::Logger::get("SearchLog"); + LOG_FMT_DEBUG(log, "target_read_tso {} target_line {}", target_read_tso, target_line); // try parse the first number following the key - auto sub_line = target_line.substr(target_line.find(key)); - std::regex rx(R"([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+))"); - std::smatch m; - if (regex_search(sub_line, m, rx)) - output(m[1]); - else - output("Invalid"); + String sub_line; + try + { + std::regex rx(R"([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+))"); + std::smatch m; + sub_line = target_line.substr(target_line.find(key)); + if (!sub_line.empty() && regex_search(sub_line, m, rx)) + { + output(m[1]); + } + else + { + output("Invalid"); + } + } + catch (std::exception & e) + { + throw Exception(fmt::format("Parse 'RSFilter exclude rate' failed, exception: {}, sub_line {}, target_line {}", e.what(), sub_line, target_line)); + } } void dbgFuncTriggerGlobalPageStorageGC(Context & context, const ASTs & /*args*/, DBGInvoker::Printer /*output*/) From 3d2dd847d80994a101c06bb7515a4a1b71ee7b00 Mon Sep 17 00:00:00 2001 From: jinhelin Date: Tue, 30 Aug 2022 16:51:42 +0800 Subject: [PATCH 2/3] ci --- dbms/src/Debug/dbgFuncMisc.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/dbms/src/Debug/dbgFuncMisc.cpp b/dbms/src/Debug/dbgFuncMisc.cpp index e210ddc867c..0f92fad8a99 100644 --- a/dbms/src/Debug/dbgFuncMisc.cpp +++ b/dbms/src/Debug/dbgFuncMisc.cpp @@ -26,13 +26,12 @@ namespace DB { inline size_t getReadTSOForLog(const String & line) { - String sub_line; try { std::regex rx(R"((0|[1-9][0-9]*))"); std::smatch m; - sub_line = line.substr(line.find("read_tso=")); - if (!sub_line.empty() && regex_search(sub_line, m, rx)) + auto pos = line.find("read_tso="); + if (pos != std::string::npos && regex_search(line.cbegin() + pos, line.cend(), m, rx)) { return std::stoul(m[1]); } @@ -43,7 +42,7 @@ inline size_t getReadTSOForLog(const String & line) } catch (std::exception & e) { - throw Exception(fmt::format("Parse 'read tso' failed, exception: {}, sub_line {}, line {}", e.what(), sub_line, line)); + throw Exception(fmt::format("Parse 'read tso' failed, exception: {}, line {}", e.what(), line)); } } @@ -105,13 +104,12 @@ void dbgFuncSearchLogForKey(Context & context, const ASTs & args, DBGInvoker::Pr static auto * log = &Poco::Logger::get("SearchLog"); LOG_FMT_DEBUG(log, "target_read_tso {} target_line {}", target_read_tso, target_line); // try parse the first number following the key - String sub_line; try { std::regex rx(R"([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+))"); std::smatch m; - sub_line = target_line.substr(target_line.find(key)); - if (!sub_line.empty() && regex_search(sub_line, m, rx)) + auto pos = target_line.find(key); + if (pos != std::string::npos && regex_search(target_line.cbegin() + pos, target_line.cend(), m, rx)) { output(m[1]); } @@ -122,7 +120,7 @@ void dbgFuncSearchLogForKey(Context & context, const ASTs & args, DBGInvoker::Pr } catch (std::exception & e) { - throw Exception(fmt::format("Parse 'RSFilter exclude rate' failed, exception: {}, sub_line {}, target_line {}", e.what(), sub_line, target_line)); + throw Exception(fmt::format("Parse 'RSFilter exclude rate' failed, exception: {}, target_line {}", e.what(), target_line)); } } From f3409e734f6616dfd7da8d7772b3e114ae9afc0b Mon Sep 17 00:00:00 2001 From: jinhelin Date: Tue, 30 Aug 2022 16:59:01 +0800 Subject: [PATCH 3/3] ci --- dbms/src/Debug/dbgFuncMisc.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/dbms/src/Debug/dbgFuncMisc.cpp b/dbms/src/Debug/dbgFuncMisc.cpp index 0f92fad8a99..b6f4521b4fa 100644 --- a/dbms/src/Debug/dbgFuncMisc.cpp +++ b/dbms/src/Debug/dbgFuncMisc.cpp @@ -18,7 +18,6 @@ #include #include -#include #include #include @@ -101,8 +100,6 @@ void dbgFuncSearchLogForKey(Context & context, const ASTs & args, DBGInvoker::Pr break; } } - static auto * log = &Poco::Logger::get("SearchLog"); - LOG_FMT_DEBUG(log, "target_read_tso {} target_line {}", target_read_tso, target_line); // try parse the first number following the key try {