Skip to content

Commit

Permalink
add more log when learner read meet error (#7655)
Browse files Browse the repository at this point in the history
close #7647
  • Loading branch information
windtalker authored Jun 14, 2023
1 parent d011017 commit d15d97d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
23 changes: 17 additions & 6 deletions dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ MakeRegionQueryInfos(
const std::unordered_set<RegionID> & region_force_retry,
TMTContext & tmt,
MvccQueryInfo & mvcc_info,
bool batch_cop [[maybe_unused]])
bool batch_cop [[maybe_unused]],
const LoggerPtr & log)
{
mvcc_info.regions_query_info.clear();
RegionRetryList region_need_retry;
Expand All @@ -108,7 +109,7 @@ MakeRegionQueryInfos(
if (r.key_ranges.empty())
{
throw TiFlashException(
fmt::format("Income key ranges is empty for region: {}", r.region_id),
fmt::format("Income key ranges is empty for region: {}, version {}, conf_version {}", r.region_id, r.region_version, r.region_conf_version),
Errors::Coprocessor::BadRequest);
}
if (region_force_retry.count(id))
Expand Down Expand Up @@ -143,16 +144,24 @@ MakeRegionQueryInfos(
{
throw TiFlashException(
fmt::format(
"Income key ranges is illegal for region: {}, table id in key range is {}, table id in region is {}",
"Income key ranges is illegal for region: {}, version {}, conf_version {}, table id in key range is {}, table id in region is {}",
r.region_id,
r.region_version,
r.region_conf_version,
table_id_in_range,
physical_table_id),
Errors::Coprocessor::BadRequest);
}
if (p.first->compare(*info.range_in_table.first) < 0 || p.second->compare(*info.range_in_table.second) > 0)
{
LOG_WARNING(log, fmt::format("Income key ranges is illegal for region: {}, version {}, conf_version {}, request range: [{}, {}), region range: [{}, {})", r.region_id, r.region_version, r.region_conf_version, p.first->toDebugString(), p.second->toDebugString(), info.range_in_table.first->toDebugString(), info.range_in_table.second->toDebugString()));
throw TiFlashException(
fmt::format("Income key ranges is illegal for region: {}", r.region_id),
fmt::format("Income key ranges is illegal for region: {}, version {}, conf_version {}",
r.region_id,
r.region_version,
r.region_conf_version),
Errors::Coprocessor::BadRequest);
}
}
info.required_handle_ranges = r.key_ranges;
info.bypass_lock_ts = r.bypass_lock_ts;
Expand Down Expand Up @@ -687,7 +696,8 @@ LearnerReadSnapshot DAGStorageInterpreter::doCopLearnerRead()
{},
tmt,
*mvcc_query_info,
false);
false,
log);

if (info_retry)
throw RegionException({info_retry->begin()->get().region_id}, status);
Expand Down Expand Up @@ -717,7 +727,8 @@ LearnerReadSnapshot DAGStorageInterpreter::doBatchCopLearnerRead()
force_retry,
tmt,
*mvcc_query_info,
true);
true,
log);
UNUSED(status);

if (retry)
Expand Down
6 changes: 6 additions & 0 deletions dbms/src/Storages/Transaction/TiKVKeyValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ std::string_view DecodedTiKVKey::getUserKey() const
return TiKVKeyspaceID::removeKeyspaceID(std::string_view(data(), size()));
}

std::string DecodedTiKVKey::toDebugString() const
{
const auto & user_key = getUserKey();
return Redact::keyToDebugString(user_key.data(), user_key.size());
}

std::string DecodedTiKVKey::makeKeyspacePrefix(KeyspaceID keyspace_id)
{
return TiKVKeyspaceID::makeKeyspacePrefix(keyspace_id);
Expand Down
2 changes: 2 additions & 0 deletions dbms/src/Storages/Transaction/TiKVKeyValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ struct DecodedTiKVKey : std::string

KeyspaceID getKeyspaceID() const;
std::string_view getUserKey() const;
// Format as a hex string for debugging. The value will be converted to '?' if redact-log is on
std::string toDebugString() const;
static std::string makeKeyspacePrefix(KeyspaceID keyspace_id);
};

Expand Down

0 comments on commit d15d97d

Please sign in to comment.