Skip to content

Commit

Permalink
Use read tso instead of threrad ID in 'DBGInvoke search_log_for_key' (#…
Browse files Browse the repository at this point in the history
…5715)

close #5718
  • Loading branch information
JinheLin authored Aug 29, 2022
1 parent d0bba3e commit 7857124
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
26 changes: 13 additions & 13 deletions dbms/src/Debug/dbgFuncMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

namespace DB
{
inline size_t getThreadIdForLog(const String & line)
inline size_t getReadTSOForLog(const String & line)
{
auto sub_line = line.substr(line.find("thread_id="));
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::stoi(m[1]);
return std::stoul(m[1]);
else
return 0;
}
Expand All @@ -49,41 +49,41 @@ void dbgFuncSearchLogForKey(Context & context, const ASTs & args, DBGInvoker::Pr
if (args.size() < 2)
throw Exception("Args not matched, should be: key, thread_hint", ErrorCodes::BAD_ARGUMENTS);

String key = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[0]).value);
auto key = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[0]).value);
// the candidate line must be printed by a thread which also print a line contains `thread_hint`
String thread_hint = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[1]).value);
auto tso_hint = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[1]).value);
auto log_path = context.getConfigRef().getString("logger.log");

std::ifstream file(log_path);
// get the lines containing `thread_hint` and `key`
std::vector<String> thread_hint_line_candidates;
std::vector<String> tso_hint_line_candidates;
std::vector<String> key_line_candidates;
{
String line;
while (std::getline(file, line))
{
if ((line.find(thread_hint) != String::npos) && (line.find("DBGInvoke") == String::npos))
thread_hint_line_candidates.emplace_back(line);
if ((line.find(tso_hint) != String::npos) && (line.find("DBGInvoke") == String::npos))
tso_hint_line_candidates.emplace_back(line);
else if ((line.find(key) != String::npos) && (line.find("DBGInvoke") == String::npos))
key_line_candidates.emplace_back(line);
}
}
// get target thread id
if (thread_hint_line_candidates.empty() || key_line_candidates.empty())
// get target read tso
if (tso_hint_line_candidates.empty() || key_line_candidates.empty())
{
output("Invalid");
return;
}
size_t target_thread_id = getThreadIdForLog(thread_hint_line_candidates.back());
if (target_thread_id == 0)
size_t target_read_tso = getReadTSOForLog(tso_hint_line_candidates.back());
if (target_read_tso == 0)
{
output("Invalid");
return;
}
String target_line;
for (auto iter = key_line_candidates.rbegin(); iter != key_line_candidates.rend(); iter++)
{
if (getThreadIdForLog(*iter) == target_thread_id)
if (getReadTSOForLog(*iter) == target_read_tso)
{
target_line = *iter;
break;
Expand Down
5 changes: 3 additions & 2 deletions dbms/src/Storages/StorageDeltaMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,8 @@ BlockInputStreams StorageDeltaMerge::read(
throw Exception("TMTContext is not initialized", ErrorCodes::LOGICAL_ERROR);

const auto & mvcc_query_info = *query_info.mvcc_query_info;
auto tracing_logger = Logger::get("StorageDeltaMerge", log->identifier(), query_info.req_id);
auto req_id = fmt::format("{} read_tso={}", query_info.req_id, mvcc_query_info.read_tso);
auto tracing_logger = Logger::get("StorageDeltaMerge", log->identifier(), req_id);

LOG_FMT_DEBUG(tracing_logger, "Read with tso: {}", mvcc_query_info.read_tso);

Expand Down Expand Up @@ -756,7 +757,7 @@ BlockInputStreams StorageDeltaMerge::read(
num_streams,
/*max_version=*/mvcc_query_info.read_tso,
rs_operator,
query_info.req_id,
req_id,
query_info.keep_order,
/* is_fast_mode */ tidb_table_info.tiflash_mode == TiDB::TiFlashMode::Fast, // read in normal mode or read in fast mode
max_block_size,
Expand Down

0 comments on commit 7857124

Please sign in to comment.