@@ -92,6 +92,7 @@ Status TableCache::GetTableReader(
92
92
const InternalKeyComparator& internal_comparator,
93
93
const FileMetaData& file_meta, bool sequential_mode, bool record_read_stats,
94
94
HistogramImpl* file_read_hist, std::unique_ptr<TableReader>* table_reader,
95
+ TableReaderCaller caller,
95
96
const std::shared_ptr<const SliceTransform>& prefix_extractor,
96
97
bool skip_filters, int level, bool prefetch_index_and_filter_in_cache,
97
98
size_t max_file_size_for_l0_meta_pin, Temperature file_temperature) {
@@ -124,11 +125,23 @@ Status TableCache::GetTableReader(
124
125
if (!sequential_mode && ioptions_.advise_random_on_open ) {
125
126
file->Hint (FSRandomAccessFile::kRandom );
126
127
}
127
- StopWatch sw (ioptions_.clock , ioptions_.stats , TABLE_OPEN_IO_MICROS);
128
+ IOActivity io_activity;
129
+ if (caller == TableReaderCaller::kFlush ) {
130
+ io_activity = IOActivity::kFlush ;
131
+ } else if (caller == TableReaderCaller::kCompaction ||
132
+ caller == TableReaderCaller::kCompactionRefill ) {
133
+ io_activity = IOActivity::kCompaction ;
134
+ } else {
135
+ io_activity = IOActivity::kUnknown ;
136
+ }
137
+ StopWatch sw (ioptions_.clock , ioptions_.stats , {TABLE_OPEN_IO_MICROS});
128
138
std::unique_ptr<RandomAccessFileReader> file_reader (
129
139
new RandomAccessFileReader (
130
140
std::move (file), fname, ioptions_.clock , io_tracer_,
131
- record_read_stats ? ioptions_.stats : nullptr , SST_READ_MICROS,
141
+ record_read_stats ? ioptions_.stats : nullptr , io_activity,
142
+ io_activity == IOActivity::kUnknown
143
+ ? Histograms::SST_READ_MICROS
144
+ : Histograms::HISTOGRAM_ENUM_MAX,
132
145
file_read_hist, ioptions_.rate_limiter .get (), ioptions_.listeners ,
133
146
file_temperature, level == ioptions_.num_levels - 1 ));
134
147
UniqueId64x2 expected_unique_id;
@@ -156,6 +169,7 @@ Status TableCache::FindTable(
156
169
const ReadOptions& ro, const FileOptions& file_options,
157
170
const InternalKeyComparator& internal_comparator,
158
171
const FileMetaData& file_meta, TypedHandle** handle,
172
+ TableReaderCaller caller,
159
173
const std::shared_ptr<const SliceTransform>& prefix_extractor,
160
174
const bool no_io, bool record_read_stats, HistogramImpl* file_read_hist,
161
175
bool skip_filters, int level, bool prefetch_index_and_filter_in_cache,
@@ -182,7 +196,7 @@ Status TableCache::FindTable(
182
196
Status s =
183
197
GetTableReader (ro, file_options, internal_comparator, file_meta,
184
198
false /* sequential mode */ , record_read_stats,
185
- file_read_hist, &table_reader, prefix_extractor,
199
+ file_read_hist, &table_reader, caller, prefix_extractor,
186
200
skip_filters, level, prefetch_index_and_filter_in_cache,
187
201
max_file_size_for_l0_meta_pin, file_temperature);
188
202
if (!s.ok ()) {
@@ -226,7 +240,7 @@ InternalIterator* TableCache::NewIterator(
226
240
table_reader = fd.table_reader ;
227
241
if (table_reader == nullptr ) {
228
242
s = FindTable (
229
- options, file_options, icomparator, file_meta, &handle,
243
+ options, file_options, icomparator, file_meta, &handle, caller,
230
244
prefix_extractor, options.read_tier == kBlockCacheTier /* no_io */ ,
231
245
!for_compaction /* record_read_stats */ , file_read_hist, skip_filters,
232
246
level, true /* prefetch_index_and_filter_in_cache */ ,
@@ -317,7 +331,7 @@ Status TableCache::GetRangeTombstoneIterator(
317
331
TypedHandle* handle = nullptr ;
318
332
if (t == nullptr ) {
319
333
s = FindTable (options, file_options_, internal_comparator, file_meta,
320
- &handle);
334
+ &handle, TableReaderCaller:: kUncategorized );
321
335
if (s.ok ()) {
322
336
t = cache_.Value (handle);
323
337
}
@@ -430,7 +444,8 @@ Status TableCache::Get(
430
444
assert (s.ok ());
431
445
if (t == nullptr ) {
432
446
s = FindTable (options, file_options_, internal_comparator, file_meta,
433
- &handle, prefix_extractor,
447
+ &handle, TableReaderCaller::kUncategorized ,
448
+ prefix_extractor,
434
449
options.read_tier == kBlockCacheTier /* no_io */ ,
435
450
true /* record_read_stats */ , file_read_hist, skip_filters,
436
451
level, true /* prefetch_index_and_filter_in_cache */ ,
@@ -531,12 +546,13 @@ Status TableCache::MultiGetFilter(
531
546
MultiGetContext::Range tombstone_range (*mget_range, mget_range->begin (),
532
547
mget_range->end ());
533
548
if (t == nullptr ) {
534
- s = FindTable (
535
- options, file_options_, internal_comparator, file_meta, &handle,
536
- prefix_extractor, options.read_tier == kBlockCacheTier /* no_io */ ,
537
- true /* record_read_stats */ , file_read_hist, /* skip_filters=*/ false ,
538
- level, true /* prefetch_index_and_filter_in_cache */ ,
539
- /* max_file_size_for_l0_meta_pin=*/ 0 , file_meta.temperature );
549
+ s = FindTable (options, file_options_, internal_comparator, file_meta,
550
+ &handle, TableReaderCaller::kUncategorized , prefix_extractor,
551
+ options.read_tier == kBlockCacheTier /* no_io */ ,
552
+ true /* record_read_stats */ , file_read_hist,
553
+ /* skip_filters=*/ false , level,
554
+ true /* prefetch_index_and_filter_in_cache */ ,
555
+ /* max_file_size_for_l0_meta_pin=*/ 0 , file_meta.temperature );
540
556
if (s.ok ()) {
541
557
t = cache_.Value (handle);
542
558
}
@@ -574,8 +590,10 @@ Status TableCache::GetTableProperties(
574
590
}
575
591
576
592
TypedHandle* table_handle = nullptr ;
577
- Status s = FindTable (ReadOptions (), file_options, internal_comparator,
578
- file_meta, &table_handle, prefix_extractor, no_io);
593
+ Status s =
594
+ FindTable (ReadOptions (), file_options, internal_comparator, file_meta,
595
+ &table_handle, TableReaderCaller::kUncategorized ,
596
+ prefix_extractor, no_io);
579
597
if (!s.ok ()) {
580
598
return s;
581
599
}
@@ -593,7 +611,8 @@ Status TableCache::ApproximateKeyAnchors(
593
611
TableReader* t = file_meta.fd .table_reader ;
594
612
TypedHandle* handle = nullptr ;
595
613
if (t == nullptr ) {
596
- s = FindTable (ro, file_options_, internal_comparator, file_meta, &handle);
614
+ s = FindTable (ro, file_options_, internal_comparator, file_meta, &handle,
615
+ TableReaderCaller::kUncategorized );
597
616
if (s.ok ()) {
598
617
t = cache_.Value (handle);
599
618
}
@@ -619,8 +638,9 @@ size_t TableCache::GetMemoryUsageByTableReader(
619
638
}
620
639
621
640
TypedHandle* table_handle = nullptr ;
622
- Status s = FindTable (ReadOptions (), file_options, internal_comparator,
623
- file_meta, &table_handle, prefix_extractor, true );
641
+ Status s = FindTable (
642
+ ReadOptions (), file_options, internal_comparator, file_meta,
643
+ &table_handle, TableReaderCaller::kUncategorized , prefix_extractor, true );
624
644
if (!s.ok ()) {
625
645
return 0 ;
626
646
}
@@ -644,10 +664,10 @@ uint64_t TableCache::ApproximateOffsetOf(
644
664
TypedHandle* table_handle = nullptr ;
645
665
if (table_reader == nullptr ) {
646
666
const bool for_compaction = (caller == TableReaderCaller::kCompaction );
647
- Status s =
648
- FindTable ( ReadOptions (), file_options_, internal_comparator, file_meta,
649
- &table_handle, prefix_extractor, false /* no_io */ ,
650
- !for_compaction /* record_read_stats */ );
667
+ Status s = FindTable (
668
+ ReadOptions (), file_options_, internal_comparator, file_meta,
669
+ &table_handle, TableReaderCaller:: kUncategorized , prefix_extractor ,
670
+ false /* no_io */ , !for_compaction /* record_read_stats */ );
651
671
if (s.ok ()) {
652
672
table_reader = cache_.Value (table_handle);
653
673
}
@@ -672,10 +692,10 @@ uint64_t TableCache::ApproximateSize(
672
692
TypedHandle* table_handle = nullptr ;
673
693
if (table_reader == nullptr ) {
674
694
const bool for_compaction = (caller == TableReaderCaller::kCompaction );
675
- Status s =
676
- FindTable ( ReadOptions (), file_options_, internal_comparator, file_meta,
677
- &table_handle, prefix_extractor, false /* no_io */ ,
678
- !for_compaction /* record_read_stats */ );
695
+ Status s = FindTable (
696
+ ReadOptions (), file_options_, internal_comparator, file_meta,
697
+ &table_handle, TableReaderCaller:: kUncategorized , prefix_extractor ,
698
+ false /* no_io */ , !for_compaction /* record_read_stats */ );
679
699
if (s.ok ()) {
680
700
table_reader = cache_.Value (table_handle);
681
701
}
0 commit comments