Skip to content

Commit e7d70a3

Browse files
authored
Raft: Revert the cpp logging changes from #10515 (#10541)
close #10540 Signed-off-by: JaySon-Huang <[email protected]>
1 parent 5787a3a commit e7d70a3

File tree

12 files changed

+100
-280
lines changed

12 files changed

+100
-280
lines changed

dbms/src/Common/TiFlashMetrics.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,6 @@ static_assert(RAFT_REGION_BIG_WRITE_THRES * 4 < RAFT_REGION_BIG_WRITE_MAX, "Inva
580580
F(type_key_not_in_region, {{"type", "key_not_in_region"}}), \
581581
F(type_tikv_server_issue, {{"type", "tikv_server_issue"}}), \
582582
F(type_tikv_lock, {{"type", "tikv_lock"}}), \
583-
F(type_server_is_busy, {{"type", "server_is_busy"}}), \
584-
F(type_stale_command, {{"type", "stale_command"}}), \
585-
F(type_store_not_match, {{"type", "store_not_match"}}), \
586583
F(type_other, {{"type", "other"}})) \
587584
/* required by DBaaS */ \
588585
M(tiflash_server_info, \

dbms/src/Debug/ReadIndexStressTest.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ static const std::map<std::string, ReadIndexStressTest::TestType> TestName2Type
3838

3939
ReadIndexStressTest::ReadIndexStressTest(const TMTContext & tmt_)
4040
: tmt(tmt_)
41-
, logger(Logger::get("ReadIndexStressTest"))
4241
{
4342
MockStressTestCfg::enable = true;
4443
LOG_WARNING(logger, "enable MockStressTest");

dbms/src/Debug/ReadIndexStressTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ReadIndexStressTest
5757

5858
private:
5959
const TMTContext & tmt;
60-
LoggerPtr logger;
60+
Poco::Logger * logger{&Poco::Logger::get("ReadIndexStressTest")};
6161
};
6262

6363

dbms/src/Storages/KVStore/FFI/ProxyFFI.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const std::string ColumnFamilyName::Lock = "lock";
5151
const std::string ColumnFamilyName::Default = "default";
5252
const std::string ColumnFamilyName::Write = "write";
5353

54+
extern const uint64_t DEFAULT_BATCH_READ_INDEX_TIMEOUT_MS;
55+
5456
ColumnFamilyType NameToCF(const std::string & cf)
5557
{
5658
if (cf.empty() || cf == ColumnFamilyName::Default)

dbms/src/Storages/KVStore/Read/LearnerReadWorker.cpp

Lines changed: 51 additions & 137 deletions
Large diffs are not rendered by default.

dbms/src/Storages/KVStore/Read/LearnerReadWorker.h

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,40 +48,57 @@ struct UnavailableRegions
4848
, is_wn_disagg_read(is_wn_disagg_read_)
4949
{}
5050

51-
size_t size() const { return unavailable_ids.size(); }
51+
size_t size() const { return ids.size(); }
5252

53-
bool empty() const { return unavailable_ids.empty(); }
53+
bool empty() const { return ids.empty(); }
5454

55-
bool contains(RegionID region_id) const { return unavailable_ids.contains(region_id); }
55+
bool contains(RegionID region_id) const { return ids.contains(region_id); }
5656

57-
void addStatus(RegionID region_id, RegionException::RegionReadStatus status_, std::string && extra_msg_)
57+
void addStatus(RegionID id, RegionException::RegionReadStatus status_, std::string && extra_msg_)
5858
{
59-
unavailable_ids[region_id] = UnavailableDesc{status_, std::move(extra_msg_)};
59+
status = status_;
60+
ids.emplace(id);
61+
extra_msg = std::move(extra_msg_);
6062
}
6163

6264
void addRegionLock(RegionID region_id_, LockInfoPtr && region_lock_)
6365
{
6466
region_locks.emplace_back(region_id_, std::move(region_lock_));
65-
unavailable_ids[region_id_] = UnavailableDesc{RegionException::RegionReadStatus::MEET_LOCK, ""};
67+
ids.emplace(region_id_);
6668
}
6769

6870
void tryThrowRegionException();
6971

7072
void addRegionWaitIndexTimeout(RegionID region_id, UInt64 index_to_wait, UInt64 current_applied_index);
7173

72-
String toDebugString(size_t num_show) const;
74+
String toDebugString() const
75+
{
76+
FmtBuffer buffer;
77+
buffer.append("{ids=[");
78+
buffer.joinStr(
79+
ids.begin(),
80+
ids.end(),
81+
[](const auto & v, FmtBuffer & f) { f.fmtAppend("{}", v); },
82+
"|");
83+
buffer.append("] locks=");
84+
buffer.append("[");
85+
buffer.joinStr(
86+
region_locks.begin(),
87+
region_locks.end(),
88+
[](const auto & v, FmtBuffer & f) { f.fmtAppend("{}({})", v.first, v.second->DebugString()); },
89+
"|");
90+
buffer.append("]}");
91+
return buffer.toString();
92+
}
7393

7494
private:
7595
const bool batch_cop;
7696
const bool is_wn_disagg_read;
7797

78-
struct UnavailableDesc
79-
{
80-
RegionException::RegionReadStatus s;
81-
std::string extra_msg;
82-
};
83-
std::unordered_map<RegionID, UnavailableDesc> unavailable_ids;
98+
RegionException::UnavailableRegions ids;
8499
std::vector<std::pair<RegionID, LockInfoPtr>> region_locks;
100+
RegionException::RegionReadStatus status{RegionException::RegionReadStatus::NOT_FOUND};
101+
std::string extra_msg;
85102
};
86103

87104
using RegionsReadIndexResult = std::unordered_map<RegionID, kvrpcpb::ReadIndexResponse>;

dbms/src/Storages/KVStore/Read/ReadIndex.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,9 @@ void WaitCheckRegionReadyImpl(
137137
static constexpr double BATCH_READ_INDEX_TIME_RATE = 0.2;
138138
auto log = Logger::get(__FUNCTION__);
139139

140-
UInt64 read_index_timeout = tmt.batchReadIndexTimeout();
141-
142140
LOG_INFO(
143141
log,
144-
"start to check regions ready, read_index_timeout={} min_wait_tick={:.3f}s max_wait_tick={:.3f}s "
145-
"wait_region_ready_timeout={:.3f}s",
146-
read_index_timeout,
142+
"start to check regions ready, min_wait_tick={:.3f}s max_wait_tick={:.3f}s wait_region_ready_timeout={:.3f}s",
147143
wait_tick_time,
148144
max_wait_tick_time,
149145
get_wait_region_ready_timeout_sec);
@@ -176,7 +172,7 @@ void WaitCheckRegionReadyImpl(
176172
}
177173

178174
// Record the latest commit index in TiKV
179-
auto read_index_res = kvstore.batchReadIndex(batch_read_index_req, read_index_timeout);
175+
auto read_index_res = kvstore.batchReadIndex(batch_read_index_req, tmt.batchReadIndexTimeout());
180176
for (auto && [resp, region_id] : read_index_res)
181177
{
182178
bool need_retry = resp.read_index() == 0;

dbms/src/Storages/KVStore/Read/ReadIndexWorker.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <common/logger_useful.h>
2222
#include <kvproto/kvrpcpb.pb.h>
2323

24+
#include <algorithm>
25+
#include <condition_variable>
2426
#include <memory>
2527
#include <thread>
2628

@@ -30,7 +32,6 @@ namespace tests
3032
{
3133
class ReadIndexTest;
3234
} // namespace tests
33-
class KVStore;
3435

3536
struct AsyncWaker
3637
{
@@ -94,7 +95,9 @@ class ReadIndexWorkerManager : boost::noncopyable
9495
void runOneRound(SteadyClock::duration min_dur, size_t id);
9596
void stop();
9697
~ReadIndexWorkerManager();
97-
BatchReadIndexRes batchReadIndex(const std::vector<kvrpcpb::ReadIndexRequest> & reqs, uint64_t timeout_ms);
98+
BatchReadIndexRes batchReadIndex(
99+
const std::vector<kvrpcpb::ReadIndexRequest> & reqs,
100+
uint64_t timeout_ms = 10 * 1000);
98101

99102
static std::unique_ptr<ReadIndexWorkerManager> newReadIndexWorkerManager(
100103
const TiFlashRaftProxyHelper & proxy_helper,

dbms/src/Storages/KVStore/Read/ReadIndexWorkerManager.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include <Common/setThreadName.h>
1616
#include <Storages/KVStore/Read/ReadIndexWorkerImpl.h>
17-
#include <common/logger_useful.h>
1817

1918
namespace DB
2019
{
@@ -245,16 +244,8 @@ BatchReadIndexRes ReadIndexWorkerManager::batchReadIndex(
245244
}
246245
else
247246
{
248-
// The read index request might be dropped by a leader/candidate/follower.
249-
// The learner will retry the read index request internally in raftstore.
250-
// See https://github.com/tikv/tikv/pull/19071. The default retry interval is 4s at the time of writing.
251-
// Reaching this point means the request still timed out after retries.
252-
GET_METRIC(tiflash_raft_learner_read_failures_count, type_read_index_timeout).Increment();
253-
// Generate a "region not found" error response for the region that still has no response after timeout
254247
kvrpcpb::ReadIndexResponse tmp;
255-
auto * e = tmp.mutable_region_error();
256-
e->mutable_region_not_found()->set_region_id(it.first);
257-
e->set_message("tiflash read index timeout(" + std::to_string(timeout_ms) + "ms)");
248+
tmp.mutable_region_error()->mutable_region_not_found();
258249
resps.emplace_back(std::move(tmp), it.first);
259250
}
260251
tasks.pop();

dbms/src/Storages/KVStore/Read/RegionException.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ class RegionException : public Exception
3939
KEY_NOT_IN_REGION,
4040
TIKV_SERVER_ISSUE,
4141
READ_INDEX_TIMEOUT,
42-
STALE_COMMAND,
43-
STORE_NOT_MATCH,
44-
MEET_LOCK, // meet LockInfoPtr when reading
4542
OTHER,
4643
};
4744

0 commit comments

Comments
 (0)