Skip to content

Commit d20015a

Browse files
KVStore: More log for Parallel Prehandle (pingcap#9160) (pingcap#223)
Co-authored-by: JaySon <[email protected]>
1 parent 7416418 commit d20015a

File tree

5 files changed

+47
-23
lines changed

5 files changed

+47
-23
lines changed

dbms/src/Storages/DeltaMerge/Decode/SSTFilesToBlockInputStream.cpp

+18-7
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ SSTFilesToBlockInputStream::SSTFilesToBlockInputStream( //
6565
auto make_inner_func = [&](const TiFlashRaftProxyHelper * proxy_helper,
6666
SSTView snap,
6767
SSTReader::RegionRangeFilter range,
68-
size_t split_id) {
69-
return std::make_unique<MonoSSTReader>(proxy_helper, snap, range, split_id);
68+
size_t split_id,
69+
size_t region_id) {
70+
return std::make_unique<MonoSSTReader>(proxy_helper, snap, range, split_id, region_id);
7071
};
7172
for (UInt64 i = 0; i < snaps.len; ++i)
7273
{
@@ -95,7 +96,8 @@ SSTFilesToBlockInputStream::SSTFilesToBlockInputStream( //
9596
ssts_default,
9697
log,
9798
region->getRange(),
98-
soft_limit.has_value() ? soft_limit.value().split_id : DM::SSTScanSoftLimit::HEAD_OR_ONLY_SPLIT);
99+
soft_limit.has_value() ? soft_limit.value().split_id : DM::SSTScanSoftLimit::HEAD_OR_ONLY_SPLIT,
100+
region->id());
99101
}
100102
if (!ssts_write.empty())
101103
{
@@ -106,7 +108,8 @@ SSTFilesToBlockInputStream::SSTFilesToBlockInputStream( //
106108
ssts_write,
107109
log,
108110
region->getRange(),
109-
soft_limit.has_value() ? soft_limit.value().split_id : DM::SSTScanSoftLimit::HEAD_OR_ONLY_SPLIT);
111+
soft_limit.has_value() ? soft_limit.value().split_id : DM::SSTScanSoftLimit::HEAD_OR_ONLY_SPLIT,
112+
region->id());
110113
}
111114
if (!ssts_lock.empty())
112115
{
@@ -117,7 +120,8 @@ SSTFilesToBlockInputStream::SSTFilesToBlockInputStream( //
117120
ssts_lock,
118121
log,
119122
region->getRange(),
120-
soft_limit.has_value() ? soft_limit.value().split_id : DM::SSTScanSoftLimit::HEAD_OR_ONLY_SPLIT);
123+
soft_limit.has_value() ? soft_limit.value().split_id : DM::SSTScanSoftLimit::HEAD_OR_ONLY_SPLIT,
124+
region->id());
121125
}
122126
LOG_INFO(
123127
log,
@@ -451,6 +455,7 @@ bool SSTFilesToBlockInputStream::maybeSkipBySoftLimit(ColumnFamilyType cf, SSTRe
451455

452456
// Skip other versions of the same PK.
453457
// TODO(split) use seek to optimize if failed several iterations.
458+
size_t skipped_times = 0;
454459
while (reader && reader->remained())
455460
{
456461
// Read until find the next pk.
@@ -463,17 +468,22 @@ bool SSTFilesToBlockInputStream::maybeSkipBySoftLimit(ColumnFamilyType cf, SSTRe
463468
{
464469
RUNTIME_CHECK_MSG(
465470
current_truncated_ts > start_limit,
466-
"current pk decreases as reader advances, start_raw {} start_pk {} current {}, cf={}, split_id={}, "
471+
"current pk decreases as reader advances, skipped_times={} start_raw={} start_pk={} current_pk={} "
472+
"current_raw={} cf={} split_id={}, "
467473
"region_id={}",
474+
skipped_times,
468475
soft_limit.value().raw_start.toDebugString(),
469476
start_limit.value().toDebugString(),
470477
current_truncated_ts.toDebugString(),
478+
tikv_key.toDebugString(),
471479
magic_enum::enum_name(cf),
472480
soft_limit.value().split_id,
473481
region->id());
474482
LOG_INFO(
475483
log,
476-
"Re-Seek after start_raw {} start_pk {} to {}, current_pk = {}, cf={}, split_id={}, region_id={}",
484+
"Re-Seek after skipped_times={} start_raw={} start_pk={} current_raw={} current_pk={} cf={} "
485+
"split_id={} region_id={}",
486+
skipped_times,
477487
soft_limit.value().raw_start.toDebugString(),
478488
start_limit.value().toDebugString(),
479489
tikv_key.toDebugString(),
@@ -483,6 +493,7 @@ bool SSTFilesToBlockInputStream::maybeSkipBySoftLimit(ColumnFamilyType cf, SSTRe
483493
region->id());
484494
return true;
485495
}
496+
skipped_times++;
486497
reader->next();
487498
}
488499
// `start_limit` is the last pk of the sst file.

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,15 @@ MonoSSTReader::MonoSSTReader(
109109
const TiFlashRaftProxyHelper * proxy_helper_,
110110
SSTView view,
111111
RegionRangeFilter range_,
112-
size_t split_id_)
112+
size_t split_id_,
113+
size_t region_id_)
113114
: proxy_helper(proxy_helper_)
114115
, inner(proxy_helper->sst_reader_interfaces.fn_get_sst_reader(view, proxy_helper->proxy_ptr))
115116
, type(view.type)
116117
, range(range_)
117118
, tail_checked(false)
118119
, split_id(split_id_)
120+
, region_id(region_id_)
119121
{
120122
log = &Poco::Logger::get("MonoSSTReader");
121123
kind = proxy_helper->sst_reader_interfaces.fn_kind(inner, view.type);
@@ -126,10 +128,11 @@ MonoSSTReader::MonoSSTReader(
126128
// 'z' will be added in proxy.
127129
LOG_INFO(
128130
log,
129-
"Seek cf {} to {}, split_id={}",
131+
"Seek cf {} to {}, split_id={} region_id={}",
130132
magic_enum::enum_name(type),
131133
Redact::keyToDebugString(start.data(), start.size()),
132-
split_id);
134+
split_id,
135+
region_id);
133136
if (!start.empty())
134137
{
135138
proxy_helper->sst_reader_interfaces

dbms/src/Storages/KVStore/FFI/SSTReader.h

+17-9
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class MonoSSTReader : public SSTReader
6161
const TiFlashRaftProxyHelper * proxy_helper_,
6262
SSTView view,
6363
RegionRangeFilter range_,
64-
size_t split_id_);
64+
size_t split_id_,
65+
size_t region_id_);
6566
~MonoSSTReader() override;
6667

6768
private:
@@ -72,6 +73,7 @@ class MonoSSTReader : public SSTReader
7273
SSTFormatKind kind;
7374
mutable bool tail_checked;
7475
size_t split_id;
76+
size_t region_id;
7577
Poco::Logger * log;
7678
};
7779

@@ -86,7 +88,8 @@ template <typename R, typename E>
8688
class MultiSSTReader : public SSTReader
8789
{
8890
public:
89-
using Initer = std::function<std::unique_ptr<R>(const TiFlashRaftProxyHelper *, E, RegionRangeFilter, size_t)>;
91+
using Initer
92+
= std::function<std::unique_ptr<R>(const TiFlashRaftProxyHelper *, E, RegionRangeFilter, size_t, size_t)>;
9093

9194
DISALLOW_COPY_AND_MOVE(MultiSSTReader);
9295

@@ -162,12 +165,13 @@ class MultiSSTReader : public SSTReader
162165
// The `path` is serialized changeset under cse-proxy, don't print it to logging
163166
LOG_INFO(
164167
log,
165-
"Open sst file, range={} sst_idx={} sst_tot={} split_id={}",
168+
"Open sst file range={} sst_idx={} sst_tot={} split_id={} region_id={}",
166169
range->toDebugString(),
167170
sst_idx,
168171
args.size(),
169-
split_id);
170-
mono = initer(proxy_helper, args[sst_idx], range, split_id);
172+
split_id,
173+
region_id);
174+
mono = initer(proxy_helper, args[sst_idx], range, split_id, region_id);
171175
}
172176
}
173177

@@ -178,7 +182,8 @@ class MultiSSTReader : public SSTReader
178182
std::vector<E> args_,
179183
LoggerPtr log_,
180184
RegionRangeFilter range_,
181-
size_t split_id_)
185+
size_t split_id_,
186+
size_t region_id_)
182187
: log(log_)
183188
, proxy_helper(proxy_helper_)
184189
, type(type_)
@@ -187,15 +192,17 @@ class MultiSSTReader : public SSTReader
187192
, sst_idx(0)
188193
, range(range_)
189194
, split_id(split_id_)
195+
, region_id(region_id_)
190196
{
191197
assert(args.size() > 0);
192198
LOG_INFO(
193199
log,
194-
"Open sst file first, range={} sst_tot={} split_id={}",
200+
"Open sst file first, range={} sst_tot={} split_id={} region_id={}",
195201
range->toDebugString(),
196202
args.size(),
197-
split_id);
198-
mono = initer(proxy_helper, args[sst_idx], range, split_id);
203+
split_id,
204+
region_id);
205+
mono = initer(proxy_helper, args[sst_idx], range, split_id, region_id);
199206
}
200207

201208
~MultiSSTReader() override
@@ -215,6 +222,7 @@ class MultiSSTReader : public SSTReader
215222
size_t sst_idx;
216223
RegionRangeFilter range;
217224
const size_t split_id;
225+
const size_t region_id;
218226
};
219227

220228
} // namespace DB

dbms/src/Storages/KVStore/MultiRaft/PrehandleSnapshot.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static inline std::tuple<ReadFromStreamResult, PrehandleResult> executeTransform
205205
res = ReadFromStreamResult{.error = ReadFromStreamError::Aborted, .extra_msg = "", .region = new_region};
206206
}
207207
auto keys_per_second = (sst_stream->getProcessKeys().write_cf + sst_stream->getProcessKeys().lock_cf
208-
+ sst_stream->getProcessKeys().write_cf)
208+
+ sst_stream->getProcessKeys().default_cf)
209209
* 1.0 / sw.elapsedSeconds();
210210
GET_METRIC(tiflash_raft_command_throughput, type_prehandle_snapshot).Observe(keys_per_second);
211211
return std::make_pair(

dbms/src/Storages/KVStore/tests/region_kvstore_test.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ static inline void validateSSTGeneration(
6262
auto make_inner_func = [](const TiFlashRaftProxyHelper * proxy_helper,
6363
SSTView snap,
6464
SSTReader::RegionRangeFilter range,
65-
size_t split_id) -> std::unique_ptr<MonoSSTReader> {
65+
size_t split_id,
66+
size_t region_id) -> std::unique_ptr<MonoSSTReader> {
6667
auto parsed_kind = MockSSTGenerator::parseSSTViewKind(buffToStrView(snap.path));
67-
auto reader = std::make_unique<MonoSSTReader>(proxy_helper, snap, range, split_id);
68+
auto reader = std::make_unique<MonoSSTReader>(proxy_helper, snap, range, split_id, region_id);
6869
assert(reader->sstFormatKind() == parsed_kind);
6970
return reader;
7071
};
@@ -75,7 +76,8 @@ static inline void validateSSTGeneration(
7576
ssts,
7677
Logger::get(),
7778
kvr1->getRange(),
78-
DM::SSTScanSoftLimit::HEAD_OR_ONLY_SPLIT};
79+
DM::SSTScanSoftLimit::HEAD_OR_ONLY_SPLIT,
80+
region_id};
7981

8082
size_t counter = 0;
8183
while (reader.remained())

0 commit comments

Comments
 (0)