Skip to content

Commit aefe67b

Browse files
committed
Add compaction prefetching internal stats (facebook#13302)
Summary: Pull Request resolved: facebook#13302 Differential Revision: D68224419 Pulled By: archang19
1 parent 77d4663 commit aefe67b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+201
-118
lines changed

db/builder.cc

+1
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ Status BuildTable(
421421
std::unique_ptr<InternalIterator> it(table_cache->NewIterator(
422422
tboptions.read_options, file_options, tboptions.internal_comparator,
423423
*meta, nullptr /* range_del_agg */, mutable_cf_options, nullptr,
424+
(internal_stats == nullptr) ? nullptr : internal_stats,
424425
(internal_stats == nullptr) ? nullptr
425426
: internal_stats->GetFileReadHist(0),
426427
TableReaderCaller::kFlush, /*arena=*/nullptr,

db/column_family.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class ColumnFamilyData {
371371
const DBOptions& db_options,
372372
const std::unordered_map<std::string, std::string>& options_map);
373373

374-
InternalStats* internal_stats() { return internal_stats_.get(); }
374+
InternalStats* internal_stats() const { return internal_stats_.get(); }
375375

376376
MemTableList* imm() { return &imm_; }
377377
MemTable* mem() { return mem_; }

db/compaction/compaction_job.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ Status CompactionJob::Run() {
781781
cfd->internal_comparator(), files_output[file_idx]->meta,
782782
/*range_del_agg=*/nullptr,
783783
compact_->compaction->mutable_cf_options(),
784-
/*table_reader_ptr=*/nullptr,
784+
/*table_reader_ptr=*/nullptr, cfd->internal_stats(),
785785
cfd->internal_stats()->GetFileReadHist(
786786
compact_->compaction->output_level()),
787787
TableReaderCaller::kCompactionRefill, /*arena=*/nullptr,

db/compaction/compaction_job_test.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,12 @@ class CompactionJobTestBase : public testing::Test {
463463
TableReaderOptions(cfd->ioptions(), nullptr, FileOptions(),
464464
cfd_->internal_comparator(),
465465
0 /* block_protection_bytes_per_key */),
466-
std::move(freader), file_size, &table_reader, false);
466+
std::move(freader), file_size, &table_reader,
467+
/*internal_stast=*/nullptr, false);
467468
ASSERT_OK(s);
468469
assert(table_reader);
469470
std::unique_ptr<InternalIterator> iiter(
470-
table_reader->NewIterator(read_opts, nullptr, nullptr, true,
471+
table_reader->NewIterator(read_opts, nullptr, nullptr, nullptr, true,
471472
TableReaderCaller::kUncategorized));
472473
assert(iiter);
473474

db/convenience.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ Status VerifySstFileChecksumInternal(const Options& options,
8888
reader_options.largest_seqno = largest_seqno;
8989
s = options.table_factory->NewTableReader(
9090
read_options, reader_options, std::move(file_reader), file_size,
91-
&table_reader, false /* prefetch_index_and_filter_in_cache */);
91+
&table_reader, /*internal_stats=*/nullptr,
92+
false /* prefetch_index_and_filter_in_cache */);
9293
if (!s.ok()) {
9394
return s;
9495
}

db/external_sst_file_ingestion_job.cc

+2
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ Status ExternalSstFileIngestionJob::ResetTableReader(
760760
/* unique_id */ {}, /* largest_seqno */ 0,
761761
/* tail_size */ 0, user_defined_timestamps_persisted),
762762
std::move(sst_file_reader), file_to_ingest->file_size, table_reader,
763+
/*internal_stats=*/nullptr,
763764
// No need to prefetch index/filter if caching is not needed.
764765
/*prefetch_index_and_filter_in_cache=*/ingestion_options_.fill_cache);
765766
return status;
@@ -923,6 +924,7 @@ Status ExternalSstFileIngestionJob::GetIngestedFileInfo(
923924
ro.fill_cache = ingestion_options_.fill_cache;
924925
std::unique_ptr<InternalIterator> iter(table_reader->NewIterator(
925926
ro, sv->mutable_cf_options.prefix_extractor.get(), /*arena=*/nullptr,
927+
/*internal_stats=*/nullptr,
926928
/*skip_filters=*/false, TableReaderCaller::kExternalSSTIngestion));
927929

928930
// Get first (smallest) and last (largest) key from file.

db/forward_iterator.cc

+10-6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class ForwardLevelIterator : public InternalIterator {
8383
*files_[file_index_],
8484
read_options_.ignore_range_deletions ? nullptr : &range_del_agg,
8585
mutable_cf_options_, /*table_reader_ptr=*/nullptr,
86+
cfd_->internal_stats(),
8687
/*file_read_hist=*/nullptr, TableReaderCaller::kUserIterator,
8788
/*arena=*/nullptr, /*skip_filters=*/false, /*level=*/-1,
8889
/*max_file_size_for_l0_meta_pin=*/0,
@@ -749,8 +750,9 @@ void ForwardIterator::RebuildIterators(bool refresh_sv) {
749750
read_options_, *cfd_->soptions(), cfd_->internal_comparator(), *l0,
750751
read_options_.ignore_range_deletions ? nullptr : &range_del_agg,
751752
sv_->mutable_cf_options,
752-
/*table_reader_ptr=*/nullptr, /*file_read_hist=*/nullptr,
753-
TableReaderCaller::kUserIterator, /*arena=*/nullptr,
753+
/*table_reader_ptr=*/nullptr, cfd_->internal_stats(),
754+
/*file_read_hist=*/nullptr, TableReaderCaller::kUserIterator,
755+
/*arena=*/nullptr,
754756
/*skip_filters=*/false, /*level=*/-1,
755757
MaxFileSizeForL0MetaPin(sv_->mutable_cf_options),
756758
/*smallest_compaction_key=*/nullptr,
@@ -837,8 +839,9 @@ void ForwardIterator::RenewIterators() {
837839
*l0_files_new[inew],
838840
read_options_.ignore_range_deletions ? nullptr : &range_del_agg,
839841
svnew->mutable_cf_options,
840-
/*table_reader_ptr=*/nullptr, /*file_read_hist=*/nullptr,
841-
TableReaderCaller::kUserIterator, /*arena=*/nullptr,
842+
/*table_reader_ptr=*/nullptr, cfd_->internal_stats(),
843+
/*file_read_hist=*/nullptr, TableReaderCaller::kUserIterator,
844+
/*arena=*/nullptr,
842845
/*skip_filters=*/false, /*level=*/-1,
843846
MaxFileSizeForL0MetaPin(svnew->mutable_cf_options),
844847
/*smallest_compaction_key=*/nullptr,
@@ -902,8 +905,9 @@ void ForwardIterator::ResetIncompleteIterators() {
902905
l0_iters_[i] = cfd_->table_cache()->NewIterator(
903906
read_options_, *cfd_->soptions(), cfd_->internal_comparator(),
904907
*l0_files[i], /*range_del_agg=*/nullptr, sv_->mutable_cf_options,
905-
/*table_reader_ptr=*/nullptr, /*file_read_hist=*/nullptr,
906-
TableReaderCaller::kUserIterator, /*arena=*/nullptr,
908+
/*table_reader_ptr=*/nullptr, cfd_->internal_stats(),
909+
/*file_read_hist=*/nullptr, TableReaderCaller::kUserIterator,
910+
/*arena=*/nullptr,
907911
/*skip_filters=*/false, /*level=*/-1,
908912
MaxFileSizeForL0MetaPin(sv_->mutable_cf_options),
909913
/*smallest_compaction_key=*/nullptr,

db/import_column_family_job.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ Status ImportColumnFamilyJob::GetIngestedFileInfo(
338338
/*block_cache_tracer*/ nullptr,
339339
/*max_file_size_for_l0_meta_pin*/ 0, versions_->DbSessionId(),
340340
/*cur_file_num*/ new_file_number),
341-
std::move(sst_file_reader), file_to_import->file_size, &table_reader);
341+
std::move(sst_file_reader), file_to_import->file_size, &table_reader,
342+
/*internal_stats=*/nullptr);
342343
if (!status.ok()) {
343344
return status;
344345
}
@@ -362,6 +363,7 @@ Status ImportColumnFamilyJob::GetIngestedFileInfo(
362363
ReadOptions ro;
363364
std::unique_ptr<InternalIterator> iter(table_reader->NewIterator(
364365
ro, sv->mutable_cf_options.prefix_extractor.get(), /*arena=*/nullptr,
366+
/*internal_stats=*/nullptr,
365367
/*skip_filters=*/false, TableReaderCaller::kExternalSSTIngestion));
366368

367369
// Get first (smallest) key from file

db/plain_table_db_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class TestPlainTableFactory : public PlainTableFactory {
323323
Status NewTableReader(
324324
const ReadOptions& /*ro*/, const TableReaderOptions& table_reader_options,
325325
std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
326-
std::unique_ptr<TableReader>* table,
326+
std::unique_ptr<TableReader>* table, InternalStats* /*internal_stats*/,
327327
bool /*prefetch_index_and_filter_in_cache*/) const override {
328328
std::unique_ptr<TableProperties> props;
329329
const ReadOptions read_options;

db/repair.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,10 @@ class Repairer {
606606
InternalIterator* iter = table_cache_->NewIterator(
607607
ropts, file_options_, cfd->internal_comparator(), t->meta,
608608
nullptr /* range_del_agg */, cfd->GetLatestMutableCFOptions(),
609-
/*table_reader_ptr=*/nullptr, /*file_read_hist=*/nullptr,
610-
TableReaderCaller::kRepair, /*arena=*/nullptr, /*skip_filters=*/false,
609+
/*table_reader_ptr=*/nullptr,
610+
cfd == nullptr ? nullptr : cfd->internal_stats(),
611+
/*file_read_hist=*/nullptr, TableReaderCaller::kRepair,
612+
/*arena=*/nullptr, /*skip_filters=*/false,
611613
/*level=*/-1, /*max_file_size_for_l0_meta_pin=*/0,
612614
/*smallest_compaction_key=*/nullptr,
613615
/*largest_compaction_key=*/nullptr,

db/table_cache.cc

+7-6
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Status TableCache::GetTableReader(
155155
file_meta.fd.largest_seqno, file_meta.tail_size,
156156
file_meta.user_defined_timestamps_persisted),
157157
std::move(file_reader), file_meta.fd.GetFileSize(), table_reader,
158-
prefetch_index_and_filter_in_cache);
158+
/*internal_stats=*/nullptr, prefetch_index_and_filter_in_cache);
159159
TEST_SYNC_POINT("TableCache::GetTableReader:0");
160160
}
161161
return s;
@@ -222,14 +222,15 @@ InternalIterator* TableCache::NewIterator(
222222
const InternalKeyComparator& icomparator, const FileMetaData& file_meta,
223223
RangeDelAggregator* range_del_agg,
224224
const MutableCFOptions& mutable_cf_options, TableReader** table_reader_ptr,
225-
HistogramImpl* file_read_hist, TableReaderCaller caller, Arena* arena,
226-
bool skip_filters, int level, size_t max_file_size_for_l0_meta_pin,
225+
InternalStats* internal_stats, HistogramImpl* file_read_hist,
226+
TableReaderCaller caller, Arena* arena, bool skip_filters, int level,
227+
size_t max_file_size_for_l0_meta_pin,
227228
const InternalKey* smallest_compaction_key,
228229
const InternalKey* largest_compaction_key, bool allow_unprepared_value,
229230
const SequenceNumber* read_seqno,
230231
std::unique_ptr<TruncatedRangeDelIterator>* range_del_iter) {
231232
PERF_TIMER_GUARD(new_table_iterator_nanos);
232-
233+
(void)internal_stats;
233234
Status s;
234235
TableReader* table_reader = nullptr;
235236
TypedHandle* handle = nullptr;
@@ -258,8 +259,8 @@ InternalIterator* TableCache::NewIterator(
258259
} else {
259260
result = table_reader->NewIterator(
260261
options, mutable_cf_options.prefix_extractor.get(), arena,
261-
skip_filters, caller, file_options.compaction_readahead_size,
262-
allow_unprepared_value);
262+
internal_stats, skip_filters, caller,
263+
file_options.compaction_readahead_size, allow_unprepared_value);
263264
}
264265
if (handle != nullptr) {
265266
cache_.RegisterReleaseAsCleanup(handle, *result);

db/table_cache.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Arena;
3434
struct FileDescriptor;
3535
class GetContext;
3636
class HistogramImpl;
37+
class InternalStats;
3738

3839
// Manages caching for TableReader objects for a column family. The actual
3940
// cache is allocated separately and passed to the constructor. TableCache
@@ -93,9 +94,9 @@ class TableCache {
9394
const InternalKeyComparator& internal_comparator,
9495
const FileMetaData& file_meta, RangeDelAggregator* range_del_agg,
9596
const MutableCFOptions& mutable_cf_options,
96-
TableReader** table_reader_ptr, HistogramImpl* file_read_hist,
97-
TableReaderCaller caller, Arena* arena, bool skip_filters, int level,
98-
size_t max_file_size_for_l0_meta_pin,
97+
TableReader** table_reader_ptr, InternalStats* internal_stats,
98+
HistogramImpl* file_read_hist, TableReaderCaller caller, Arena* arena,
99+
bool skip_filters, int level, size_t max_file_size_for_l0_meta_pin,
99100
const InternalKey* smallest_compaction_key,
100101
const InternalKey* largest_compaction_key, bool allow_unprepared_value,
101102
const SequenceNumber* range_del_read_seqno = nullptr,
@@ -278,6 +279,7 @@ class TableCache {
278279
Status* read_status,
279280
SequenceNumber seq_no = kMaxSequenceNumber);
280281

282+
InternalStats* internal_stats_;
281283
const ImmutableOptions& ioptions_;
282284
const FileOptions& file_options_;
283285
CacheInterface cache_;

db/version_set.cc

+15-11
Original file line numberDiff line numberDiff line change
@@ -971,9 +971,9 @@ class LevelIterator final : public InternalIterator {
971971
TableCache* table_cache, const ReadOptions& read_options,
972972
const FileOptions& file_options, const InternalKeyComparator& icomparator,
973973
const LevelFilesBrief* flevel, const MutableCFOptions& mutable_cf_options,
974-
bool should_sample, HistogramImpl* file_read_hist,
975-
TableReaderCaller caller, bool skip_filters, int level,
976-
RangeDelAggregator* range_del_agg,
974+
bool should_sample, InternalStats* internal_stats,
975+
HistogramImpl* file_read_hist, TableReaderCaller caller,
976+
bool skip_filters, int level, RangeDelAggregator* range_del_agg,
977977
const std::vector<AtomicCompactionUnitBoundary>* compaction_boundaries =
978978
nullptr,
979979
bool allow_unprepared_value = false,
@@ -987,6 +987,7 @@ class LevelIterator final : public InternalIterator {
987987
flevel_(flevel),
988988
mutable_cf_options_(mutable_cf_options),
989989
prefix_extractor_(mutable_cf_options.prefix_extractor.get()),
990+
internal_stats_(internal_stats),
990991
file_read_hist_(file_read_hist),
991992
caller_(caller),
992993
file_index_(flevel_->num_files),
@@ -1149,7 +1150,8 @@ class LevelIterator final : public InternalIterator {
11491150
return table_cache_->NewIterator(
11501151
read_options_, file_options_, icomparator_, *file_meta.file_metadata,
11511152
range_del_agg_, mutable_cf_options_,
1152-
nullptr /* don't need reference to table */, file_read_hist_, caller_,
1153+
nullptr /* don't need reference to table */, internal_stats_,
1154+
file_read_hist_, caller_,
11531155
/*arena=*/nullptr, skip_filters_, level_,
11541156
/*max_file_size_for_l0_meta_pin=*/0, smallest_compaction_key,
11551157
largest_compaction_key, allow_unprepared_value_, &read_seq_,
@@ -1180,6 +1182,7 @@ class LevelIterator final : public InternalIterator {
11801182
const MutableCFOptions& mutable_cf_options_;
11811183
const SliceTransform* prefix_extractor_;
11821184

1185+
InternalStats* internal_stats_;
11831186
HistogramImpl* file_read_hist_;
11841187
TableReaderCaller caller_;
11851188
size_t file_index_;
@@ -1930,7 +1933,7 @@ InternalIterator* Version::TEST_GetLevelIterator(
19301933
auto level_iter = new (mem) LevelIterator(
19311934
cfd_->table_cache(), read_options, file_options_,
19321935
cfd_->internal_comparator(), &storage_info_.LevelFilesBrief(level),
1933-
mutable_cf_options_, should_sample_file_read(),
1936+
mutable_cf_options_, should_sample_file_read(), cfd_->internal_stats(),
19341937
cfd_->internal_stats()->GetFileReadHist(level),
19351938
TableReaderCaller::kUserIterator, IsFilterSkipped(level), level,
19361939
nullptr /* range_del_agg */, nullptr /* compaction_boundaries */,
@@ -2038,7 +2041,8 @@ void Version::AddIteratorsForLevel(const ReadOptions& read_options,
20382041
auto table_iter = cfd_->table_cache()->NewIterator(
20392042
read_options, soptions, cfd_->internal_comparator(),
20402043
*file.file_metadata, /*range_del_agg=*/nullptr, mutable_cf_options_,
2041-
nullptr, cfd_->internal_stats()->GetFileReadHist(0),
2044+
nullptr, cfd_->internal_stats(),
2045+
cfd_->internal_stats()->GetFileReadHist(0),
20422046
TableReaderCaller::kUserIterator, arena,
20432047
/*skip_filters=*/false, /*level=*/0, max_file_size_for_l0_meta_pin_,
20442048
/*smallest_compaction_key=*/nullptr,
@@ -2069,7 +2073,7 @@ void Version::AddIteratorsForLevel(const ReadOptions& read_options,
20692073
auto level_iter = new (mem) LevelIterator(
20702074
cfd_->table_cache(), read_options, soptions,
20712075
cfd_->internal_comparator(), &storage_info_.LevelFilesBrief(level),
2072-
mutable_cf_options_, should_sample_file_read(),
2076+
mutable_cf_options_, should_sample_file_read(), cfd_->internal_stats(),
20732077
cfd_->internal_stats()->GetFileReadHist(level),
20742078
TableReaderCaller::kUserIterator, IsFilterSkipped(level), level,
20752079
/*range_del_agg=*/nullptr,
@@ -2111,7 +2115,7 @@ Status Version::OverlapWithLevelIterator(const ReadOptions& read_options,
21112115
ScopedArenaPtr<InternalIterator> iter(cfd_->table_cache()->NewIterator(
21122116
read_options, file_options, cfd_->internal_comparator(),
21132117
*file->file_metadata, &range_del_agg, mutable_cf_options_, nullptr,
2114-
cfd_->internal_stats()->GetFileReadHist(0),
2118+
cfd_->internal_stats(), cfd_->internal_stats()->GetFileReadHist(0),
21152119
TableReaderCaller::kUserIterator, &arena,
21162120
/*skip_filters=*/false, /*level=*/0, max_file_size_for_l0_meta_pin_,
21172121
/*smallest_compaction_key=*/nullptr,
@@ -2128,7 +2132,7 @@ Status Version::OverlapWithLevelIterator(const ReadOptions& read_options,
21282132
ScopedArenaPtr<InternalIterator> iter(new (mem) LevelIterator(
21292133
cfd_->table_cache(), read_options, file_options,
21302134
cfd_->internal_comparator(), &storage_info_.LevelFilesBrief(level),
2131-
mutable_cf_options_, should_sample_file_read(),
2135+
mutable_cf_options_, should_sample_file_read(), cfd_->internal_stats(),
21322136
cfd_->internal_stats()->GetFileReadHist(level),
21332137
TableReaderCaller::kUserIterator, IsFilterSkipped(level), level,
21342138
&range_del_agg, nullptr, false));
@@ -7084,7 +7088,7 @@ InternalIterator* VersionSet::MakeInputIterator(
70847088
read_options, file_options_compactions,
70857089
cfd->internal_comparator(), fmd, range_del_agg,
70867090
c->mutable_cf_options(),
7087-
/*table_reader_ptr=*/nullptr,
7091+
/*table_reader_ptr=*/nullptr, cfd->internal_stats(),
70887092
/*file_read_hist=*/nullptr, TableReaderCaller::kCompaction,
70897093
/*arena=*/nullptr,
70907094
/*skip_filters=*/false,
@@ -7105,7 +7109,7 @@ InternalIterator* VersionSet::MakeInputIterator(
71057109
list[num++] = new LevelIterator(
71067110
cfd->table_cache(), read_options, file_options_compactions,
71077111
cfd->internal_comparator(), flevel, c->mutable_cf_options(),
7108-
/*should_sample=*/false,
7112+
/*should_sample=*/false, cfd->internal_stats(),
71097113
/*no per level latency histogram=*/nullptr,
71107114
TableReaderCaller::kCompaction, /*skip_filters=*/false,
71117115
/*level=*/static_cast<int>(c->level(which)), range_del_agg,

file/file_prefetch_buffer.cc

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <algorithm>
1313
#include <cassert>
1414

15+
#include "db/internal_stats.h" // This include works. Do NOT put it in the header file
1516
#include "file/random_access_file_reader.h"
1617
#include "monitoring/histogram.h"
1718
#include "monitoring/iostats_context_imp.h"
@@ -765,6 +766,8 @@ bool FilePrefetchBuffer::TryReadFromCache(const IOOptions& opts,
765766
RecordTick(stats_, TABLE_OPEN_PREFETCH_TAIL_MISS);
766767
}
767768
}
769+
// Placeholder value to confirm no compilation issues
770+
internal_stats_->AddDBStats(InternalStats::kIntStatsNumKeysWritten, 0, true);
768771
return ret;
769772
}
770773

file/file_prefetch_buffer.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ class FilePrefetchBuffer {
186186
FilePrefetchBuffer(
187187
const ReadaheadParams& readahead_params = {}, bool enable = true,
188188
bool track_min_offset = false, FileSystem* fs = nullptr,
189-
SystemClock* clock = nullptr, Statistics* stats = nullptr,
189+
SystemClock* clock = nullptr, InternalStats* internal_stats = nullptr,
190+
Statistics* stats = nullptr,
190191
const std::function<void(bool, uint64_t&, uint64_t&)>& cb = nullptr,
191192
FilePrefetchBufferUsage usage = FilePrefetchBufferUsage::kUnknown)
192193
: readahead_size_(readahead_params.initial_readahead_size),
@@ -204,6 +205,7 @@ class FilePrefetchBuffer {
204205
explicit_prefetch_submitted_(false),
205206
fs_(fs),
206207
clock_(clock),
208+
internal_stats_(internal_stats),
207209
stats_(stats),
208210
usage_(usage),
209211
readaheadsize_cb_(cb),
@@ -696,6 +698,7 @@ class FilePrefetchBuffer {
696698

697699
FileSystem* fs_;
698700
SystemClock* clock_;
701+
InternalStats* internal_stats_;
699702
Statistics* stats_;
700703

701704
FilePrefetchBufferUsage usage_;

0 commit comments

Comments
 (0)