From c76a690d28d607806439bba647995f742f60e87e Mon Sep 17 00:00:00 2001 From: Andrew Chang Date: Wed, 15 Jan 2025 16:02:11 -0800 Subject: [PATCH] Add compaction prefetching internal stats Differential Revision: D68224419 --- db/builder.cc | 1 + db/column_family.h | 2 +- db/compaction/compaction_job.cc | 1 + db/compaction/compaction_job_test.cc | 4 +- db/convenience.cc | 2 +- db/external_sst_file_ingestion_job.cc | 3 +- db/forward_iterator.cc | 7 +-- db/import_column_family_job.cc | 4 +- db/plain_table_db_test.cc | 2 +- db/repair.cc | 2 +- db/table_cache.cc | 6 ++- db/table_cache.h | 4 +- db/version_set.cc | 14 +++-- file/file_prefetch_buffer.h | 4 +- file/prefetch_test.cc | 16 +++--- fuzz/sst_file_writer_fuzzer.cc | 2 +- include/rocksdb/table.h | 6 ++- options/options_test.cc | 2 +- table/adaptive/adaptive_table_factory.cc | 8 +-- table/adaptive/adaptive_table_factory.h | 2 +- .../block_based/block_based_table_factory.cc | 4 +- table/block_based/block_based_table_factory.h | 2 +- table/block_based/block_based_table_reader.cc | 7 +-- table/block_based/block_based_table_reader.h | 6 +-- .../block_based_table_reader_test.cc | 4 +- .../block_based/data_block_hash_index_test.cc | 2 +- table/block_fetcher_test.cc | 2 +- table/cuckoo/cuckoo_table_factory.cc | 2 +- table/cuckoo/cuckoo_table_factory.h | 2 +- table/cuckoo/cuckoo_table_reader.cc | 1 + table/cuckoo/cuckoo_table_reader.h | 2 +- table/cuckoo/cuckoo_table_reader_test.cc | 3 +- table/mock_table.cc | 3 +- table/mock_table.h | 3 +- table/plain/plain_table_factory.cc | 2 +- table/plain/plain_table_factory.h | 2 +- table/plain/plain_table_reader.cc | 2 +- table/plain/plain_table_reader.h | 2 +- table/sst_file_dumper.cc | 11 ++-- table/sst_file_dumper.h | 2 +- table/sst_file_reader.cc | 8 +-- table/table_reader.h | 3 +- table/table_test.cc | 54 +++++++++---------- utilities/options/options_util_test.cc | 2 +- 44 files changed, 125 insertions(+), 98 deletions(-) diff --git a/db/builder.cc b/db/builder.cc index 08a9fecc727..a08c0e3d291 100644 --- a/db/builder.cc +++ b/db/builder.cc @@ -421,6 +421,7 @@ Status BuildTable( std::unique_ptr it(table_cache->NewIterator( tboptions.read_options, file_options, tboptions.internal_comparator, *meta, nullptr /* range_del_agg */, mutable_cf_options, nullptr, + (internal_stats == nullptr) ? nullptr : internal_stats, (internal_stats == nullptr) ? nullptr : internal_stats->GetFileReadHist(0), TableReaderCaller::kFlush, /*arena=*/nullptr, diff --git a/db/column_family.h b/db/column_family.h index 2d9fb28a3d5..0434cff23ca 100644 --- a/db/column_family.h +++ b/db/column_family.h @@ -371,7 +371,7 @@ class ColumnFamilyData { const DBOptions& db_options, const std::unordered_map& options_map); - InternalStats* internal_stats() { return internal_stats_.get(); } + InternalStats* internal_stats() const { return internal_stats_.get(); } MemTableList* imm() { return &imm_; } MemTable* mem() { return mem_; } diff --git a/db/compaction/compaction_job.cc b/db/compaction/compaction_job.cc index 97721551bd3..edffc6fa82c 100644 --- a/db/compaction/compaction_job.cc +++ b/db/compaction/compaction_job.cc @@ -782,6 +782,7 @@ Status CompactionJob::Run() { /*range_del_agg=*/nullptr, compact_->compaction->mutable_cf_options(), /*table_reader_ptr=*/nullptr, + cfd->internal_stats(), cfd->internal_stats()->GetFileReadHist( compact_->compaction->output_level()), TableReaderCaller::kCompactionRefill, /*arena=*/nullptr, diff --git a/db/compaction/compaction_job_test.cc b/db/compaction/compaction_job_test.cc index 470c4445cc7..e034a0ae13f 100644 --- a/db/compaction/compaction_job_test.cc +++ b/db/compaction/compaction_job_test.cc @@ -463,11 +463,11 @@ class CompactionJobTestBase : public testing::Test { TableReaderOptions(cfd->ioptions(), nullptr, FileOptions(), cfd_->internal_comparator(), 0 /* block_protection_bytes_per_key */), - std::move(freader), file_size, &table_reader, false); + std::move(freader), file_size, &table_reader, /*internal_stast=*/nullptr, false); ASSERT_OK(s); assert(table_reader); std::unique_ptr iiter( - table_reader->NewIterator(read_opts, nullptr, nullptr, true, + table_reader->NewIterator(read_opts, nullptr, nullptr, nullptr, true, TableReaderCaller::kUncategorized)); assert(iiter); diff --git a/db/convenience.cc b/db/convenience.cc index 47ce59f2f8d..196a26554a4 100644 --- a/db/convenience.cc +++ b/db/convenience.cc @@ -88,7 +88,7 @@ Status VerifySstFileChecksumInternal(const Options& options, reader_options.largest_seqno = largest_seqno; s = options.table_factory->NewTableReader( read_options, reader_options, std::move(file_reader), file_size, - &table_reader, false /* prefetch_index_and_filter_in_cache */); + &table_reader, /*internal_stats=*/nullptr, false /* prefetch_index_and_filter_in_cache */); if (!s.ok()) { return s; } diff --git a/db/external_sst_file_ingestion_job.cc b/db/external_sst_file_ingestion_job.cc index a439189afa7..df6b5402474 100644 --- a/db/external_sst_file_ingestion_job.cc +++ b/db/external_sst_file_ingestion_job.cc @@ -760,6 +760,7 @@ Status ExternalSstFileIngestionJob::ResetTableReader( /* unique_id */ {}, /* largest_seqno */ 0, /* tail_size */ 0, user_defined_timestamps_persisted), std::move(sst_file_reader), file_to_ingest->file_size, table_reader, + /*internal_stats=*/nullptr, // No need to prefetch index/filter if caching is not needed. /*prefetch_index_and_filter_in_cache=*/ingestion_options_.fill_cache); return status; @@ -922,7 +923,7 @@ Status ExternalSstFileIngestionJob::GetIngestedFileInfo( ReadOptions ro; ro.fill_cache = ingestion_options_.fill_cache; std::unique_ptr iter(table_reader->NewIterator( - ro, sv->mutable_cf_options.prefix_extractor.get(), /*arena=*/nullptr, + ro, sv->mutable_cf_options.prefix_extractor.get(), /*arena=*/nullptr, /*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kExternalSSTIngestion)); // Get first (smallest) and last (largest) key from file. diff --git a/db/forward_iterator.cc b/db/forward_iterator.cc index f7c507d49fe..a215c345b39 100644 --- a/db/forward_iterator.cc +++ b/db/forward_iterator.cc @@ -83,6 +83,7 @@ class ForwardLevelIterator : public InternalIterator { *files_[file_index_], read_options_.ignore_range_deletions ? nullptr : &range_del_agg, mutable_cf_options_, /*table_reader_ptr=*/nullptr, + cfd_->internal_stats(), /*file_read_hist=*/nullptr, TableReaderCaller::kUserIterator, /*arena=*/nullptr, /*skip_filters=*/false, /*level=*/-1, /*max_file_size_for_l0_meta_pin=*/0, @@ -749,7 +750,7 @@ void ForwardIterator::RebuildIterators(bool refresh_sv) { read_options_, *cfd_->soptions(), cfd_->internal_comparator(), *l0, read_options_.ignore_range_deletions ? nullptr : &range_del_agg, sv_->mutable_cf_options, - /*table_reader_ptr=*/nullptr, /*file_read_hist=*/nullptr, + /*table_reader_ptr=*/nullptr, cfd_->internal_stats(),/*file_read_hist=*/nullptr, TableReaderCaller::kUserIterator, /*arena=*/nullptr, /*skip_filters=*/false, /*level=*/-1, MaxFileSizeForL0MetaPin(sv_->mutable_cf_options), @@ -837,7 +838,7 @@ void ForwardIterator::RenewIterators() { *l0_files_new[inew], read_options_.ignore_range_deletions ? nullptr : &range_del_agg, svnew->mutable_cf_options, - /*table_reader_ptr=*/nullptr, /*file_read_hist=*/nullptr, + /*table_reader_ptr=*/nullptr, cfd_->internal_stats(),/*file_read_hist=*/nullptr, TableReaderCaller::kUserIterator, /*arena=*/nullptr, /*skip_filters=*/false, /*level=*/-1, MaxFileSizeForL0MetaPin(svnew->mutable_cf_options), @@ -902,7 +903,7 @@ void ForwardIterator::ResetIncompleteIterators() { l0_iters_[i] = cfd_->table_cache()->NewIterator( read_options_, *cfd_->soptions(), cfd_->internal_comparator(), *l0_files[i], /*range_del_agg=*/nullptr, sv_->mutable_cf_options, - /*table_reader_ptr=*/nullptr, /*file_read_hist=*/nullptr, + /*table_reader_ptr=*/nullptr, cfd_->internal_stats(),/*file_read_hist=*/nullptr, TableReaderCaller::kUserIterator, /*arena=*/nullptr, /*skip_filters=*/false, /*level=*/-1, MaxFileSizeForL0MetaPin(sv_->mutable_cf_options), diff --git a/db/import_column_family_job.cc b/db/import_column_family_job.cc index 44a1c5d099a..a5a3e9974c3 100644 --- a/db/import_column_family_job.cc +++ b/db/import_column_family_job.cc @@ -338,7 +338,7 @@ Status ImportColumnFamilyJob::GetIngestedFileInfo( /*block_cache_tracer*/ nullptr, /*max_file_size_for_l0_meta_pin*/ 0, versions_->DbSessionId(), /*cur_file_num*/ new_file_number), - std::move(sst_file_reader), file_to_import->file_size, &table_reader); + std::move(sst_file_reader), file_to_import->file_size, &table_reader, /*internal_stats=*/nullptr); if (!status.ok()) { return status; } @@ -361,7 +361,7 @@ Status ImportColumnFamilyJob::GetIngestedFileInfo( // TODO: plumb Env::IOActivity, Env::IOPriority ReadOptions ro; std::unique_ptr iter(table_reader->NewIterator( - ro, sv->mutable_cf_options.prefix_extractor.get(), /*arena=*/nullptr, + ro, sv->mutable_cf_options.prefix_extractor.get(), /*arena=*/nullptr, /*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kExternalSSTIngestion)); // Get first (smallest) key from file diff --git a/db/plain_table_db_test.cc b/db/plain_table_db_test.cc index be2cc1c80c6..48b9af59488 100644 --- a/db/plain_table_db_test.cc +++ b/db/plain_table_db_test.cc @@ -323,7 +323,7 @@ class TestPlainTableFactory : public PlainTableFactory { Status NewTableReader( const ReadOptions& /*ro*/, const TableReaderOptions& table_reader_options, std::unique_ptr&& file, uint64_t file_size, - std::unique_ptr* table, + std::unique_ptr* table,InternalStats* /*internal_stats*/, bool /*prefetch_index_and_filter_in_cache*/) const override { std::unique_ptr props; const ReadOptions read_options; diff --git a/db/repair.cc b/db/repair.cc index 1713baf0a48..a407ae5ca1d 100644 --- a/db/repair.cc +++ b/db/repair.cc @@ -606,7 +606,7 @@ class Repairer { InternalIterator* iter = table_cache_->NewIterator( ropts, file_options_, cfd->internal_comparator(), t->meta, nullptr /* range_del_agg */, cfd->GetLatestMutableCFOptions(), - /*table_reader_ptr=*/nullptr, /*file_read_hist=*/nullptr, + /*table_reader_ptr=*/nullptr, cfd == nullptr ? nullptr : cfd->internal_stats(),/*file_read_hist=*/nullptr, TableReaderCaller::kRepair, /*arena=*/nullptr, /*skip_filters=*/false, /*level=*/-1, /*max_file_size_for_l0_meta_pin=*/0, /*smallest_compaction_key=*/nullptr, diff --git a/db/table_cache.cc b/db/table_cache.cc index 773446b6a58..b0d7dce7145 100644 --- a/db/table_cache.cc +++ b/db/table_cache.cc @@ -154,7 +154,7 @@ Status TableCache::GetTableReader( file_meta.fd.GetNumber(), expected_unique_id, file_meta.fd.largest_seqno, file_meta.tail_size, file_meta.user_defined_timestamps_persisted), - std::move(file_reader), file_meta.fd.GetFileSize(), table_reader, + std::move(file_reader), file_meta.fd.GetFileSize(), table_reader, /*internal_stats=*/nullptr, prefetch_index_and_filter_in_cache); TEST_SYNC_POINT("TableCache::GetTableReader:0"); } @@ -222,6 +222,7 @@ InternalIterator* TableCache::NewIterator( const InternalKeyComparator& icomparator, const FileMetaData& file_meta, RangeDelAggregator* range_del_agg, const MutableCFOptions& mutable_cf_options, TableReader** table_reader_ptr, + InternalStats* internal_stats, HistogramImpl* file_read_hist, TableReaderCaller caller, Arena* arena, bool skip_filters, int level, size_t max_file_size_for_l0_meta_pin, const InternalKey* smallest_compaction_key, @@ -229,7 +230,7 @@ InternalIterator* TableCache::NewIterator( const SequenceNumber* read_seqno, std::unique_ptr* range_del_iter) { PERF_TIMER_GUARD(new_table_iterator_nanos); - + (void) internal_stats; Status s; TableReader* table_reader = nullptr; TypedHandle* handle = nullptr; @@ -258,6 +259,7 @@ InternalIterator* TableCache::NewIterator( } else { result = table_reader->NewIterator( options, mutable_cf_options.prefix_extractor.get(), arena, + internal_stats, skip_filters, caller, file_options.compaction_readahead_size, allow_unprepared_value); } diff --git a/db/table_cache.h b/db/table_cache.h index 701f96f22aa..c310851acd1 100644 --- a/db/table_cache.h +++ b/db/table_cache.h @@ -34,6 +34,7 @@ class Arena; struct FileDescriptor; class GetContext; class HistogramImpl; +class InternalStats; // Manages caching for TableReader objects for a column family. The actual // cache is allocated separately and passed to the constructor. TableCache @@ -93,7 +94,7 @@ class TableCache { const InternalKeyComparator& internal_comparator, const FileMetaData& file_meta, RangeDelAggregator* range_del_agg, const MutableCFOptions& mutable_cf_options, - TableReader** table_reader_ptr, HistogramImpl* file_read_hist, + TableReader** table_reader_ptr, InternalStats* internal_stats, HistogramImpl* file_read_hist, TableReaderCaller caller, Arena* arena, bool skip_filters, int level, size_t max_file_size_for_l0_meta_pin, const InternalKey* smallest_compaction_key, @@ -278,6 +279,7 @@ class TableCache { Status* read_status, SequenceNumber seq_no = kMaxSequenceNumber); + InternalStats* internal_stats_; const ImmutableOptions& ioptions_; const FileOptions& file_options_; CacheInterface cache_; diff --git a/db/version_set.cc b/db/version_set.cc index 059d4584703..f669b39a939 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -971,7 +971,7 @@ class LevelIterator final : public InternalIterator { TableCache* table_cache, const ReadOptions& read_options, const FileOptions& file_options, const InternalKeyComparator& icomparator, const LevelFilesBrief* flevel, const MutableCFOptions& mutable_cf_options, - bool should_sample, HistogramImpl* file_read_hist, + bool should_sample, InternalStats* internal_stats,HistogramImpl* file_read_hist, TableReaderCaller caller, bool skip_filters, int level, RangeDelAggregator* range_del_agg, const std::vector* compaction_boundaries = @@ -987,6 +987,7 @@ class LevelIterator final : public InternalIterator { flevel_(flevel), mutable_cf_options_(mutable_cf_options), prefix_extractor_(mutable_cf_options.prefix_extractor.get()), + internal_stats_(internal_stats), file_read_hist_(file_read_hist), caller_(caller), file_index_(flevel_->num_files), @@ -1149,7 +1150,7 @@ class LevelIterator final : public InternalIterator { return table_cache_->NewIterator( read_options_, file_options_, icomparator_, *file_meta.file_metadata, range_del_agg_, mutable_cf_options_, - nullptr /* don't need reference to table */, file_read_hist_, caller_, + nullptr /* don't need reference to table */, internal_stats_, file_read_hist_, caller_, /*arena=*/nullptr, skip_filters_, level_, /*max_file_size_for_l0_meta_pin=*/0, smallest_compaction_key, largest_compaction_key, allow_unprepared_value_, &read_seq_, @@ -1180,6 +1181,7 @@ class LevelIterator final : public InternalIterator { const MutableCFOptions& mutable_cf_options_; const SliceTransform* prefix_extractor_; + InternalStats* internal_stats_; HistogramImpl* file_read_hist_; TableReaderCaller caller_; size_t file_index_; @@ -1931,6 +1933,7 @@ InternalIterator* Version::TEST_GetLevelIterator( cfd_->table_cache(), read_options, file_options_, cfd_->internal_comparator(), &storage_info_.LevelFilesBrief(level), mutable_cf_options_, should_sample_file_read(), + cfd_->internal_stats(), cfd_->internal_stats()->GetFileReadHist(level), TableReaderCaller::kUserIterator, IsFilterSkipped(level), level, nullptr /* range_del_agg */, nullptr /* compaction_boundaries */, @@ -2038,7 +2041,7 @@ void Version::AddIteratorsForLevel(const ReadOptions& read_options, auto table_iter = cfd_->table_cache()->NewIterator( read_options, soptions, cfd_->internal_comparator(), *file.file_metadata, /*range_del_agg=*/nullptr, mutable_cf_options_, - nullptr, cfd_->internal_stats()->GetFileReadHist(0), + nullptr, cfd_->internal_stats(), cfd_->internal_stats()->GetFileReadHist(0), TableReaderCaller::kUserIterator, arena, /*skip_filters=*/false, /*level=*/0, max_file_size_for_l0_meta_pin_, /*smallest_compaction_key=*/nullptr, @@ -2070,6 +2073,7 @@ void Version::AddIteratorsForLevel(const ReadOptions& read_options, cfd_->table_cache(), read_options, soptions, cfd_->internal_comparator(), &storage_info_.LevelFilesBrief(level), mutable_cf_options_, should_sample_file_read(), + cfd_->internal_stats(), cfd_->internal_stats()->GetFileReadHist(level), TableReaderCaller::kUserIterator, IsFilterSkipped(level), level, /*range_del_agg=*/nullptr, @@ -2111,6 +2115,7 @@ Status Version::OverlapWithLevelIterator(const ReadOptions& read_options, ScopedArenaPtr iter(cfd_->table_cache()->NewIterator( read_options, file_options, cfd_->internal_comparator(), *file->file_metadata, &range_del_agg, mutable_cf_options_, nullptr, + cfd_->internal_stats(), cfd_->internal_stats()->GetFileReadHist(0), TableReaderCaller::kUserIterator, &arena, /*skip_filters=*/false, /*level=*/0, max_file_size_for_l0_meta_pin_, @@ -2129,6 +2134,7 @@ Status Version::OverlapWithLevelIterator(const ReadOptions& read_options, cfd_->table_cache(), read_options, file_options, cfd_->internal_comparator(), &storage_info_.LevelFilesBrief(level), mutable_cf_options_, should_sample_file_read(), + cfd_->internal_stats(), cfd_->internal_stats()->GetFileReadHist(level), TableReaderCaller::kUserIterator, IsFilterSkipped(level), level, &range_del_agg, nullptr, false)); @@ -7085,6 +7091,7 @@ InternalIterator* VersionSet::MakeInputIterator( cfd->internal_comparator(), fmd, range_del_agg, c->mutable_cf_options(), /*table_reader_ptr=*/nullptr, + cfd->internal_stats(), /*file_read_hist=*/nullptr, TableReaderCaller::kCompaction, /*arena=*/nullptr, /*skip_filters=*/false, @@ -7106,6 +7113,7 @@ InternalIterator* VersionSet::MakeInputIterator( cfd->table_cache(), read_options, file_options_compactions, cfd->internal_comparator(), flevel, c->mutable_cf_options(), /*should_sample=*/false, + cfd->internal_stats(), /*no per level latency histogram=*/nullptr, TableReaderCaller::kCompaction, /*skip_filters=*/false, /*level=*/static_cast(c->level(which)), range_del_agg, diff --git a/file/file_prefetch_buffer.h b/file/file_prefetch_buffer.h index b8b6812bc83..c905998126f 100644 --- a/file/file_prefetch_buffer.h +++ b/file/file_prefetch_buffer.h @@ -186,7 +186,7 @@ class FilePrefetchBuffer { FilePrefetchBuffer( const ReadaheadParams& readahead_params = {}, bool enable = true, bool track_min_offset = false, FileSystem* fs = nullptr, - SystemClock* clock = nullptr, Statistics* stats = nullptr, + SystemClock* clock = nullptr, InternalStats* internal_stats = nullptr, Statistics* stats = nullptr, const std::function& cb = nullptr, FilePrefetchBufferUsage usage = FilePrefetchBufferUsage::kUnknown) : readahead_size_(readahead_params.initial_readahead_size), @@ -204,6 +204,7 @@ class FilePrefetchBuffer { explicit_prefetch_submitted_(false), fs_(fs), clock_(clock), + internal_stats_(internal_stats), stats_(stats), usage_(usage), readaheadsize_cb_(cb), @@ -696,6 +697,7 @@ class FilePrefetchBuffer { FileSystem* fs_; SystemClock* clock_; + InternalStats* internal_stats_; Statistics* stats_; FilePrefetchBufferUsage usage_; diff --git a/file/prefetch_test.cc b/file/prefetch_test.cc index 726cccf29d7..327362b45ae 100644 --- a/file/prefetch_test.cc +++ b/file/prefetch_test.cc @@ -3124,7 +3124,7 @@ TEST_F(FilePrefetchBufferTest, SeekWithoutAlignment) { readahead_params.num_buffers = 2; FilePrefetchBuffer fpb(readahead_params, /*enable=*/true, - /*track_min_offset=*/false, fs(), nullptr, nullptr, + /*track_min_offset=*/false, fs(), nullptr, nullptr, nullptr, nullptr, FilePrefetchBufferUsage::kUnknown); Slice result; @@ -3159,7 +3159,7 @@ TEST_F(FilePrefetchBufferTest, SeekWithoutAlignment) { readahead_params.num_file_reads_for_auto_readahead = 2; readahead_params.num_buffers = 2; FilePrefetchBuffer fpb(readahead_params, /*enable=*/true, - /*track_min_offset=*/false, fs(), nullptr, nullptr, + /*track_min_offset=*/false, fs(), nullptr, nullptr, nullptr, nullptr, FilePrefetchBufferUsage::kUnknown); Slice result; @@ -3198,7 +3198,7 @@ TEST_F(FilePrefetchBufferTest, NoSyncWithAsyncIO) { readahead_params.max_readahead_size = 16384; readahead_params.num_buffers = 2; FilePrefetchBuffer fpb(readahead_params, /*enable=*/true, - /*track_min_offset=*/false, fs(), nullptr, nullptr, + /*track_min_offset=*/false, fs(), nullptr, nullptr, nullptr, nullptr, FilePrefetchBufferUsage::kUnknown); int read_async_called = 0; @@ -3251,7 +3251,7 @@ TEST_F(FilePrefetchBufferTest, SyncReadaheadStats) { ReadaheadParams readahead_params; readahead_params.initial_readahead_size = 8192; readahead_params.max_readahead_size = 8192; - FilePrefetchBuffer fpb(readahead_params, true, false, fs(), nullptr, + FilePrefetchBuffer fpb(readahead_params, true, false, fs(), nullptr,nullptr, stats.get()); Slice result; // Simulate a seek of 4096 bytes at offset 0. Due to the readahead settings, @@ -3309,7 +3309,7 @@ TEST_F(FilePrefetchBufferTest, ForCompaction) { readahead_params.num_buffers = 1; FilePrefetchBuffer fpb(readahead_params, true /* enable */, - false /* track_min_offset */, fs(), nullptr, + false /* track_min_offset */, fs(), nullptr,nullptr, stats.get()); Slice result; @@ -3484,7 +3484,7 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchStatsInternals) { readahead_params.num_buffers = num_buffers; FilePrefetchBuffer fpb(readahead_params, true /* enable */, - false /* track_min_offset */, fs(), clock(), + false /* track_min_offset */, fs(), clock(),nullptr, stats.get()); int overlap_buffer_write_ct = 0; @@ -3680,7 +3680,7 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchUnalignedReads) { size_t num_buffers = use_async_prefetch ? 2 : 1; readahead_params.num_buffers = num_buffers; FilePrefetchBuffer fpb(readahead_params, true /* enable */, - false /* track_min_offset */, fs(), clock(), + false /* track_min_offset */, fs(), clock(),nullptr, stats.get()); int overlap_buffer_write_ct = 0; @@ -3836,7 +3836,7 @@ TEST_P(FSBufferPrefetchTest, FSBufferPrefetchRandomized) { readahead_params.num_buffers = num_buffers; FilePrefetchBuffer fpb(readahead_params, true /* enable */, - false /* track_min_offset */, fs(), clock(), + false /* track_min_offset */, fs(), clock(),nullptr, stats.get()); Slice result; diff --git a/fuzz/sst_file_writer_fuzzer.cc b/fuzz/sst_file_writer_fuzzer.cc index 676daf574fa..b4aa8bb5124 100644 --- a/fuzz/sst_file_writer_fuzzer.cc +++ b/fuzz/sst_file_writer_fuzzer.cc @@ -96,7 +96,7 @@ TableReader* NewTableReader(const std::string& sst_file_path, 0 /* block_protection_bytes_per_key */); t_opt.largest_seqno = kMaxSequenceNumber; s = options.table_factory->NewTableReader(t_opt, std::move(file_reader), - file_size, &table_reader, + file_size, &table_reader,/*internal_stats=*/nullptr, /*prefetch=*/false); } if (!s.ok()) { diff --git a/include/rocksdb/table.h b/include/rocksdb/table.h index e1f76fcd463..464d522cbfa 100644 --- a/include/rocksdb/table.h +++ b/include/rocksdb/table.h @@ -862,6 +862,7 @@ TableFactory* NewCuckooTableFactory( const CuckooTableOptions& table_options = CuckooTableOptions()); class RandomAccessFileReader; +class InternalStats; // A base class for table factories. class TableFactory : public Customizable { @@ -901,10 +902,11 @@ class TableFactory : public Customizable { const TableReaderOptions& table_reader_options, std::unique_ptr&& file, uint64_t file_size, std::unique_ptr* table_reader, + InternalStats* internal_stats, bool prefetch_index_and_filter_in_cache = true) const { ReadOptions ro; return NewTableReader(ro, table_reader_options, std::move(file), file_size, - table_reader, prefetch_index_and_filter_in_cache); + table_reader, internal_stats, prefetch_index_and_filter_in_cache); } // Overload of the above function that allows the caller to pass in a @@ -912,7 +914,7 @@ class TableFactory : public Customizable { virtual Status NewTableReader( const ReadOptions& ro, const TableReaderOptions& table_reader_options, std::unique_ptr&& file, uint64_t file_size, - std::unique_ptr* table_reader, + std::unique_ptr* table_reader, InternalStats* internal_stats, bool prefetch_index_and_filter_in_cache) const = 0; // Return a table builder to write to a file for this table type. diff --git a/options/options_test.cc b/options/options_test.cc index 46690403a61..24e04541242 100644 --- a/options/options_test.cc +++ b/options/options_test.cc @@ -54,7 +54,7 @@ class UnregisteredTableFactory : public TableFactory { using TableFactory::NewTableReader; Status NewTableReader(const ReadOptions&, const TableReaderOptions&, std::unique_ptr&&, uint64_t, - std::unique_ptr*, bool) const override { + std::unique_ptr*, InternalStats*, bool) const override { return Status::NotSupported(); } TableBuilder* NewTableBuilder(const TableBuilderOptions&, diff --git a/table/adaptive/adaptive_table_factory.cc b/table/adaptive/adaptive_table_factory.cc index f06b265328f..21f02755fd9 100644 --- a/table/adaptive/adaptive_table_factory.cc +++ b/table/adaptive/adaptive_table_factory.cc @@ -37,7 +37,7 @@ AdaptiveTableFactory::AdaptiveTableFactory( Status AdaptiveTableFactory::NewTableReader( const ReadOptions& ro, const TableReaderOptions& table_reader_options, std::unique_ptr&& file, uint64_t file_size, - std::unique_ptr* table, + std::unique_ptr* table,InternalStats* internal_stats, bool prefetch_index_and_filter_in_cache) const { Footer footer; IOOptions opts; @@ -50,15 +50,15 @@ Status AdaptiveTableFactory::NewTableReader( if (footer.table_magic_number() == kPlainTableMagicNumber || footer.table_magic_number() == kLegacyPlainTableMagicNumber) { return plain_table_factory_->NewTableReader( - table_reader_options, std::move(file), file_size, table); + table_reader_options, std::move(file), file_size, table, internal_stats); } else if (footer.table_magic_number() == kBlockBasedTableMagicNumber || footer.table_magic_number() == kLegacyBlockBasedTableMagicNumber) { return block_based_table_factory_->NewTableReader( - ro, table_reader_options, std::move(file), file_size, table, + ro, table_reader_options, std::move(file), file_size, table,internal_stats, prefetch_index_and_filter_in_cache); } else if (footer.table_magic_number() == kCuckooTableMagicNumber) { return cuckoo_table_factory_->NewTableReader( - table_reader_options, std::move(file), file_size, table); + table_reader_options, std::move(file), file_size, table,internal_stats); } else { return Status::NotSupported("Unidentified table format"); } diff --git a/table/adaptive/adaptive_table_factory.h b/table/adaptive/adaptive_table_factory.h index 072e00ec4e0..6d2ef41ab0d 100644 --- a/table/adaptive/adaptive_table_factory.h +++ b/table/adaptive/adaptive_table_factory.h @@ -36,7 +36,7 @@ class AdaptiveTableFactory : public TableFactory { Status NewTableReader( const ReadOptions& ro, const TableReaderOptions& table_reader_options, std::unique_ptr&& file, uint64_t file_size, - std::unique_ptr* table, + std::unique_ptr* table,InternalStats* internal_stats, bool prefetch_index_and_filter_in_cache = true) const override; TableBuilder* NewTableBuilder( diff --git a/table/block_based/block_based_table_factory.cc b/table/block_based/block_based_table_factory.cc index 7add9fb16fc..7900dfb9433 100644 --- a/table/block_based/block_based_table_factory.cc +++ b/table/block_based/block_based_table_factory.cc @@ -547,13 +547,13 @@ Status CheckCacheOptionCompatibility(const BlockBasedTableOptions& bbto) { Status BlockBasedTableFactory::NewTableReader( const ReadOptions& ro, const TableReaderOptions& table_reader_options, std::unique_ptr&& file, uint64_t file_size, - std::unique_ptr* table_reader, + std::unique_ptr* table_reader,InternalStats* internal_stats, bool prefetch_index_and_filter_in_cache) const { return BlockBasedTable::Open( ro, table_reader_options.ioptions, table_reader_options.env_options, table_options_, table_reader_options.internal_comparator, std::move(file), file_size, table_reader_options.block_protection_bytes_per_key, - table_reader, table_reader_options.tail_size, + table_reader, internal_stats, table_reader_options.tail_size, shared_state_->table_reader_cache_res_mgr, table_reader_options.prefix_extractor, prefetch_index_and_filter_in_cache, table_reader_options.skip_filters, table_reader_options.level, diff --git a/table/block_based/block_based_table_factory.h b/table/block_based/block_based_table_factory.h index b05b4566040..97a36f1c46f 100644 --- a/table/block_based/block_based_table_factory.h +++ b/table/block_based/block_based_table_factory.h @@ -63,7 +63,7 @@ class BlockBasedTableFactory : public TableFactory { Status NewTableReader( const ReadOptions& ro, const TableReaderOptions& table_reader_options, std::unique_ptr&& file, uint64_t file_size, - std::unique_ptr* table_reader, + std::unique_ptr* table_reader,InternalStats* internal_stats, bool prefetch_index_and_filter_in_cache = true) const override; TableBuilder* NewTableBuilder( diff --git a/table/block_based/block_based_table_reader.cc b/table/block_based/block_based_table_reader.cc index 3db08519735..ad2ab20232f 100644 --- a/table/block_based/block_based_table_reader.cc +++ b/table/block_based/block_based_table_reader.cc @@ -626,7 +626,7 @@ Status BlockBasedTable::Open( const InternalKeyComparator& internal_comparator, std::unique_ptr&& file, uint64_t file_size, uint8_t block_protection_bytes_per_key, - std::unique_ptr* table_reader, uint64_t tail_size, + std::unique_ptr* table_reader, InternalStats* /*internal_stats*/, uint64_t tail_size, std::shared_ptr table_reader_cache_res_mgr, const std::shared_ptr& prefix_extractor, const bool prefetch_index_and_filter_in_cache, const bool skip_filters, @@ -949,7 +949,7 @@ Status BlockBasedTable::PrefetchTail( // Use `FilePrefetchBuffer` prefetch_buffer->reset(new FilePrefetchBuffer( ReadaheadParams(), true /* enable */, true /* track_min_offset */, - ioptions.fs.get() /* fs */, nullptr /* clock */, stats, + ioptions.fs.get() /* fs */, nullptr /* clock */, nullptr /* internal_stats */, stats, /* readahead_cb */ nullptr, FilePrefetchBufferUsage::kTableOpenPrefetchTail)); @@ -2011,8 +2011,9 @@ bool BlockBasedTable::IsLastLevel() const { InternalIterator* BlockBasedTable::NewIterator( const ReadOptions& read_options, const SliceTransform* prefix_extractor, - Arena* arena, bool skip_filters, TableReaderCaller caller, + Arena* arena, InternalStats* internal_stats, bool skip_filters, TableReaderCaller caller, size_t compaction_readahead_size, bool allow_unprepared_value) { + (void) internal_stats; BlockCacheLookupContext lookup_context{caller}; bool need_upper_bound_check = read_options.auto_prefix_mode || PrefixExtractorChanged(prefix_extractor); diff --git a/table/block_based/block_based_table_reader.h b/table/block_based/block_based_table_reader.h index 513e517aa85..5754af32845 100644 --- a/table/block_based/block_based_table_reader.h +++ b/table/block_based/block_based_table_reader.h @@ -101,7 +101,7 @@ class BlockBasedTable : public TableReader { const InternalKeyComparator& internal_key_comparator, std::unique_ptr&& file, uint64_t file_size, uint8_t block_protection_bytes_per_key, - std::unique_ptr* table_reader, uint64_t tail_size, + std::unique_ptr* table_reader, InternalStats* internal_status, uint64_t tail_size, std::shared_ptr table_reader_cache_res_mgr = nullptr, const std::shared_ptr& prefix_extractor = nullptr, @@ -132,7 +132,7 @@ class BlockBasedTable : public TableReader { // kCompaction. InternalIterator* NewIterator(const ReadOptions&, const SliceTransform* prefix_extractor, - Arena* arena, bool skip_filters, + Arena* arena, InternalStats* internal_stats, bool skip_filters, TableReaderCaller caller, size_t compaction_readahead_size = 0, bool allow_unprepared_value = false) override; @@ -718,7 +718,7 @@ struct BlockBasedTable::Rep { fpb->reset(new FilePrefetchBuffer( readahead_params, !ioptions.allow_mmap_reads /* enable */, false /* track_min_offset */, ioptions.fs.get(), ioptions.clock, - ioptions.stats, readaheadsize_cb, usage)); + nullptr /*internal_stats */, ioptions.stats, readaheadsize_cb, usage)); } void CreateFilePrefetchBufferIfNotExists( diff --git a/table/block_based/block_based_table_reader_test.cc b/table/block_based/block_based_table_reader_test.cc index 4a18b6fcda8..46f7e486561 100644 --- a/table/block_based/block_based_table_reader_test.cc +++ b/table/block_based/block_based_table_reader_test.cc @@ -182,7 +182,7 @@ class BlockBasedTableReaderBaseTest : public testing::Test { std::unique_ptr general_table; Status s = options_.table_factory->NewTableReader( read_opts, table_reader_options, std::move(file), file_size, - &general_table, prefetch_index_and_filter_in_cache); + &general_table, /*internal_stats=*/nullptr, prefetch_index_and_filter_in_cache); if (s.ok()) { table->reset(static_cast(general_table.release())); @@ -494,7 +494,7 @@ TEST_P(BlockBasedTableReaderTest, NewIterator) { std::unique_ptr iter; iter.reset(table->NewIterator( - read_opts, options_.prefix_extractor.get(), /*arena=*/nullptr, + read_opts, options_.prefix_extractor.get(), /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized)); // Test forward scan. diff --git a/table/block_based/data_block_hash_index_test.cc b/table/block_based/data_block_hash_index_test.cc index 7970ca1d9f9..95760e03704 100644 --- a/table/block_based/data_block_hash_index_test.cc +++ b/table/block_based/data_block_hash_index_test.cc @@ -586,7 +586,7 @@ void TestBoundary(InternalKey& ik1, std::string& v1, InternalKey& ik2, internal_comparator, 0 /* block_protection_bytes_per_key */, !kSkipFilters, !kImmortal, level_), - std::move(file_reader), sink->contents().size(), &table_reader)); + std::move(file_reader), sink->contents().size(), &table_reader, /*internal_stats=*/nullptr)); // Search using Get() ReadOptions ro; diff --git a/table/block_fetcher_test.cc b/table/block_fetcher_test.cc index 17310edec6a..193bdcbea1b 100644 --- a/table/block_fetcher_test.cc +++ b/table/block_fetcher_test.cc @@ -282,7 +282,7 @@ class BlockFetcherTest : public testing::Test { ASSERT_OK(BlockBasedTable::Open(ro, ioptions, EnvOptions(), *table_options, comparator, std::move(file), file_size, 0 /* block_protection_bytes_per_key */, - &table_reader, 0 /* tail_size */)); + &table_reader, nullptr /*internal_stats*/, 0 /* tail_size */)); table->reset(static_cast(table_reader.release())); } diff --git a/table/cuckoo/cuckoo_table_factory.cc b/table/cuckoo/cuckoo_table_factory.cc index 774e00212d9..044f07a0efa 100644 --- a/table/cuckoo/cuckoo_table_factory.cc +++ b/table/cuckoo/cuckoo_table_factory.cc @@ -16,7 +16,7 @@ namespace ROCKSDB_NAMESPACE { Status CuckooTableFactory::NewTableReader( const ReadOptions& /*ro*/, const TableReaderOptions& table_reader_options, std::unique_ptr&& file, uint64_t file_size, - std::unique_ptr* table, + std::unique_ptr* table,InternalStats* /*internal_stats*/, bool /*prefetch_index_and_filter_in_cache*/) const { std::unique_ptr new_reader(new CuckooTableReader( table_reader_options.ioptions, std::move(file), file_size, diff --git a/table/cuckoo/cuckoo_table_factory.h b/table/cuckoo/cuckoo_table_factory.h index 64077217d83..76fb2634055 100644 --- a/table/cuckoo/cuckoo_table_factory.h +++ b/table/cuckoo/cuckoo_table_factory.h @@ -64,7 +64,7 @@ class CuckooTableFactory : public TableFactory { Status NewTableReader( const ReadOptions& ro, const TableReaderOptions& table_reader_options, std::unique_ptr&& file, uint64_t file_size, - std::unique_ptr* table, + std::unique_ptr* table,InternalStats* internal_stats, bool prefetch_index_and_filter_in_cache = true) const override; TableBuilder* NewTableBuilder( diff --git a/table/cuckoo/cuckoo_table_reader.cc b/table/cuckoo/cuckoo_table_reader.cc index 5be1ebc19ec..465e6e2cedb 100644 --- a/table/cuckoo/cuckoo_table_reader.cc +++ b/table/cuckoo/cuckoo_table_reader.cc @@ -395,6 +395,7 @@ Slice CuckooTableIterator::value() const { InternalIterator* CuckooTableReader::NewIterator( const ReadOptions& /*read_options*/, const SliceTransform* /* prefix_extractor */, Arena* arena, + InternalStats* /*internal_stats*/, bool /*skip_filters*/, TableReaderCaller /*caller*/, size_t /*compaction_readahead_size*/, bool /* allow_unprepared_value */) { if (!status().ok()) { diff --git a/table/cuckoo/cuckoo_table_reader.h b/table/cuckoo/cuckoo_table_reader.h index d17011ed83e..991535ec013 100644 --- a/table/cuckoo/cuckoo_table_reader.h +++ b/table/cuckoo/cuckoo_table_reader.h @@ -48,7 +48,7 @@ class CuckooTableReader : public TableReader { // true InternalIterator* NewIterator(const ReadOptions&, const SliceTransform* prefix_extractor, - Arena* arena, bool skip_filters, + Arena* arena, InternalStats* internal_stats,bool skip_filters, TableReaderCaller caller, size_t compaction_readahead_size = 0, bool allow_unprepared_value = false) override; diff --git a/table/cuckoo/cuckoo_table_reader_test.cc b/table/cuckoo/cuckoo_table_reader_test.cc index ebec20bdcd3..199acc38ae9 100644 --- a/table/cuckoo/cuckoo_table_reader_test.cc +++ b/table/cuckoo/cuckoo_table_reader_test.cc @@ -143,7 +143,7 @@ class CuckooReaderTest : public testing::Test { GetSliceHash); ASSERT_OK(reader.status()); InternalIterator* it = reader.NewIterator( - ReadOptions(), /*prefix_extractor=*/nullptr, /*arena=*/nullptr, + ReadOptions(), /*prefix_extractor=*/nullptr,/*arena=*/nullptr, /*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized); ASSERT_OK(it->status()); ASSERT_TRUE(!it->Valid()); @@ -184,6 +184,7 @@ class CuckooReaderTest : public testing::Test { Arena arena; it = reader.NewIterator(ReadOptions(), /*prefix_extractor=*/nullptr, &arena, + /*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized); ASSERT_OK(it->status()); diff --git a/table/mock_table.cc b/table/mock_table.cc index 934c7f54a7f..9f32efad608 100644 --- a/table/mock_table.cc +++ b/table/mock_table.cc @@ -162,7 +162,7 @@ class MockTableBuilder : public TableBuilder { InternalIterator* MockTableReader::NewIterator( const ReadOptions&, const SliceTransform* /* prefix_extractor */, - Arena* /*arena*/, bool /*skip_filters*/, TableReaderCaller /*caller*/, + Arena* /*arena*/, InternalStats* /*internal_stats*/, bool /*skip_filters*/, TableReaderCaller /*caller*/, size_t /*compaction_readahead_size*/, bool /* allow_unprepared_value */) { return new MockTableIterator(table_); } @@ -202,6 +202,7 @@ Status MockTableFactory::NewTableReader( const TableReaderOptions& /*table_reader_options*/, std::unique_ptr&& file, uint64_t /*file_size*/, std::unique_ptr* table_reader, + InternalStats* /*internal_stats*/, bool /*prefetch_index_and_filter_in_cache*/) const { uint32_t id; Status s = GetIDFromFile(file.get(), &id); diff --git a/table/mock_table.h b/table/mock_table.h index af3a4eb46cd..f8610258b60 100644 --- a/table/mock_table.h +++ b/table/mock_table.h @@ -56,6 +56,7 @@ class MockTableFactory : public TableFactory { const ReadOptions& ro, const TableReaderOptions& table_reader_options, std::unique_ptr&& file, uint64_t file_size, std::unique_ptr* table_reader, + InternalStats* internal_stats, bool prefetch_index_and_filter_in_cache = true) const override; TableBuilder* NewTableBuilder( const TableBuilderOptions& table_builder_options, @@ -104,7 +105,7 @@ class MockTableReader : public TableReader { : table_(table), tp_(tp) {} virtual InternalIterator* NewIterator( - const ReadOptions&, const SliceTransform* prefix_extractor, Arena* arena, + const ReadOptions&, const SliceTransform* prefix_extractor, Arena* arena, InternalStats* internal_stats, bool skip_filters, TableReaderCaller caller, size_t compaction_readahead_size = 0, bool allow_unprepared_value = false) override; diff --git a/table/plain/plain_table_factory.cc b/table/plain/plain_table_factory.cc index 7d01b07f303..c94a0d7d3b1 100644 --- a/table/plain/plain_table_factory.cc +++ b/table/plain/plain_table_factory.cc @@ -57,7 +57,7 @@ PlainTableFactory::PlainTableFactory(const PlainTableOptions& options) Status PlainTableFactory::NewTableReader( const ReadOptions& /*ro*/, const TableReaderOptions& table_reader_options, std::unique_ptr&& file, uint64_t file_size, - std::unique_ptr* table, + std::unique_ptr* table,InternalStats* /*internal_stats*/, bool /*prefetch_index_and_filter_in_cache*/) const { return PlainTableReader::Open( table_reader_options.ioptions, table_reader_options.env_options, diff --git a/table/plain/plain_table_factory.h b/table/plain/plain_table_factory.h index d6055ccbdb8..363c4dd48dd 100644 --- a/table/plain/plain_table_factory.h +++ b/table/plain/plain_table_factory.h @@ -163,7 +163,7 @@ class PlainTableFactory : public TableFactory { Status NewTableReader(const ReadOptions& ro, const TableReaderOptions& table_reader_options, std::unique_ptr&& file, - uint64_t file_size, std::unique_ptr* table, + uint64_t file_size, std::unique_ptr* table,InternalStats* internal_stats, bool prefetch_index_and_filter_in_cache) const override; TableBuilder* NewTableBuilder( diff --git a/table/plain/plain_table_reader.cc b/table/plain/plain_table_reader.cc index 578e92aa312..566ea7bbfd4 100644 --- a/table/plain/plain_table_reader.cc +++ b/table/plain/plain_table_reader.cc @@ -194,7 +194,7 @@ void PlainTableReader::SetupForCompaction() {} InternalIterator* PlainTableReader::NewIterator( const ReadOptions& options, const SliceTransform* /* prefix_extractor */, - Arena* arena, bool /*skip_filters*/, TableReaderCaller /*caller*/, + Arena* arena, InternalStats* /*internal_stats*/, bool /*skip_filters*/, TableReaderCaller /*caller*/, size_t /*compaction_readahead_size*/, bool /* allow_unprepared_value */) { // Not necessarily used here, but make sure this has been initialized assert(table_properties_); diff --git a/table/plain/plain_table_reader.h b/table/plain/plain_table_reader.h index b127e22c0f4..f9c69eb9a09 100644 --- a/table/plain/plain_table_reader.h +++ b/table/plain/plain_table_reader.h @@ -81,7 +81,7 @@ class PlainTableReader : public TableReader { // true InternalIterator* NewIterator(const ReadOptions&, const SliceTransform* prefix_extractor, - Arena* arena, bool skip_filters, + Arena* arena, InternalStats* internal_stats,bool skip_filters, TableReaderCaller caller, size_t compaction_readahead_size = 0, bool allow_unprepared_value = false) override; diff --git a/table/sst_file_dumper.cc b/table/sst_file_dumper.cc index 905eef7004a..4094a4a0e6c 100644 --- a/table/sst_file_dumper.cc +++ b/table/sst_file_dumper.cc @@ -162,7 +162,7 @@ Status SstFileDumper::GetTableReader(const std::string& file_path) { if (s.ok()) { s = NewTableReader(ioptions_, soptions_, internal_comparator_, file_size, - &table_reader_); + &table_reader_, /*internal_stats=*/nullptr); } return s; } @@ -170,7 +170,7 @@ Status SstFileDumper::GetTableReader(const std::string& file_path) { Status SstFileDumper::NewTableReader( const ImmutableOptions& /*ioptions*/, const EnvOptions& /*soptions*/, const InternalKeyComparator& /*internal_comparator*/, uint64_t file_size, - std::unique_ptr* /*table_reader*/) { + std::unique_ptr* /*table_reader*/, InternalStats* /*internal_stats*/) { auto t_opt = TableReaderOptions( ioptions_, moptions_.prefix_extractor, soptions_, internal_comparator_, 0 /* block_protection_bytes_per_key */, false /* skip_filters */, @@ -191,12 +191,13 @@ Status SstFileDumper::NewTableReader( TableFactory::kBlockBasedTableName())) { return options_.table_factory->NewTableReader(t_opt, std::move(file_), file_size, &table_reader_, + /*prefetch_buffer=*/nullptr, /*enable_prefetch=*/false); } // For all other factory implementation return options_.table_factory->NewTableReader(t_opt, std::move(file_), - file_size, &table_reader_); + file_size, &table_reader_, /*internal_stats=*/nullptr); } Status SstFileDumper::VerifyChecksum() { @@ -239,7 +240,7 @@ Status SstFileDumper::CalculateCompressedTableSize( table_builder.reset( block_based_tf.NewTableBuilder(tb_options, dest_writer.get())); std::unique_ptr iter(table_reader_->NewIterator( - read_options_, moptions_.prefix_extractor.get(), /*arena=*/nullptr, + read_options_, moptions_.prefix_extractor.get(), /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kSSTDumpTool)); for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { table_builder->Add(iter->key(), iter->value()); @@ -468,7 +469,7 @@ Status SstFileDumper::ReadSequential(bool print_kv, uint64_t read_num_limit, InternalIterator* iter = table_reader_->NewIterator( read_options_, moptions_.prefix_extractor.get(), - /*arena=*/nullptr, /*skip_filters=*/false, + /*arena=*/nullptr, /*internal_stats=*/nullptr,/*skip_filters=*/false, TableReaderCaller::kSSTDumpTool); const Comparator* ucmp = internal_comparator_.user_comparator(); diff --git a/table/sst_file_dumper.h b/table/sst_file_dumper.h index a1a857115a8..72341870e23 100644 --- a/table/sst_file_dumper.h +++ b/table/sst_file_dumper.h @@ -74,7 +74,7 @@ class SstFileDumper { const EnvOptions& soptions, const InternalKeyComparator& internal_comparator, uint64_t file_size, - std::unique_ptr* table_reader); + std::unique_ptr* table_reader, InternalStats* internal_stats); std::string file_name_; uint64_t read_num_; diff --git a/table/sst_file_reader.cc b/table/sst_file_reader.cc index 847497bad55..f881783c00a 100644 --- a/table/sst_file_reader.cc +++ b/table/sst_file_reader.cc @@ -75,7 +75,7 @@ Status SstFileReader::Open(const std::string& file_path) { // Allow open file with global sequence number for backward compatibility. t_opt.largest_seqno = kMaxSequenceNumber; s = r->options.table_factory->NewTableReader(t_opt, std::move(file_reader), - file_size, &r->table_reader); + file_size, &r->table_reader, /*internal_stats=*/nullptr); } return s; } @@ -94,7 +94,7 @@ Iterator* SstFileReader::NewIterator(const ReadOptions& roptions) { true /* expose_blob_index */, false /* allow_refresh */); auto internal_iter = r->table_reader->NewIterator( res->GetReadOptions(), r->moptions.prefix_extractor.get(), - res->GetArena(), false /* skip_filters */, + res->GetArena(), /*internal_stats=*/nullptr, false /* skip_filters */, TableReaderCaller::kSSTFileReader); res->SetIterUnderDBIter(internal_iter); return res; @@ -104,7 +104,7 @@ std::unique_ptr SstFileReader::NewTableIterator() { auto r = rep_.get(); InternalIterator* internal_iter = r->table_reader->NewIterator( r->roptions_for_table_iter, r->moptions.prefix_extractor.get(), - /*arena*/ nullptr, false /* skip_filters */, + /*arena*/ nullptr, /*internal_stats=*/nullptr, false /* skip_filters */, TableReaderCaller::kSSTFileReader); assert(internal_iter); if (internal_iter == nullptr) { @@ -129,7 +129,7 @@ Status SstFileReader::VerifyChecksum(const ReadOptions& read_options) { Status SstFileReader::VerifyNumEntries(const ReadOptions& read_options) { Rep* r = rep_.get(); std::unique_ptr internal_iter{r->table_reader->NewIterator( - read_options, r->moptions.prefix_extractor.get(), nullptr, + read_options, r->moptions.prefix_extractor.get(), nullptr, /*internal_stats=*/nullptr, false /* skip_filters */, TableReaderCaller::kSSTFileReader)}; internal_iter->SeekToFirst(); Status s = internal_iter->status(); diff --git a/table/table_reader.h b/table/table_reader.h index a9d46499bd0..986d86e4be3 100644 --- a/table/table_reader.h +++ b/table/table_reader.h @@ -31,6 +31,7 @@ struct ReadOptions; struct TableProperties; class GetContext; class MultiGetContext; +class InternalStats; // A Table (also referred to as SST) is a sorted map from strings to strings. // Tables are immutable and persistent. A Table may be safely accessed from @@ -56,7 +57,7 @@ class TableReader { // kCompaction virtual InternalIterator* NewIterator( const ReadOptions& read_options, const SliceTransform* prefix_extractor, - Arena* arena, bool skip_filters, TableReaderCaller caller, + Arena* arena, InternalStats* internal_stats, bool skip_filters, TableReaderCaller caller, size_t compaction_readahead_size = 0, bool allow_unprepared_value = false) = 0; diff --git a/table/table_test.cc b/table/table_test.cc index 6207a40ce20..f9be556a9eb 100644 --- a/table/table_test.cc +++ b/table/table_test.cc @@ -413,7 +413,7 @@ class TableConstructor : public Constructor { InternalIterator* NewIterator( const SliceTransform* prefix_extractor) const override { InternalIterator* iter = table_reader_->NewIterator( - read_options_, prefix_extractor, /*arena=*/nullptr, + read_options_, prefix_extractor, /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized); if (convert_to_internal_key_) { return new KeyConvertingIterator(iter); @@ -449,7 +449,7 @@ class TableConstructor : public Constructor { &block_cache_tracer_, moptions.write_buffer_size, "", file_num_, kNullUniqueId64x2, largest_seqno_), std::move(file_reader_), TEST_GetSink()->contents().size(), - &table_reader_); + &table_reader_, /*internal_stats=*/nullptr); } virtual TableReader* GetTableReader() { return table_reader_.get(); } @@ -2129,7 +2129,7 @@ TEST_P(BlockBasedTableTest, TotalOrderSeekOnHashIndex) { ReadOptions ro; ro.total_order_seek = true; std::unique_ptr iter(reader->NewIterator( - ro, moptions.prefix_extractor.get(), /*arena=*/nullptr, + ro, moptions.prefix_extractor.get(), /*arena=*/nullptr, /*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized)); iter->Seek(InternalKey("b", 0, kTypeValue).Encode()); @@ -2189,7 +2189,7 @@ TEST_P(BlockBasedTableTest, NoopTransformSeek) { ReadOptions ro; ro.total_order_seek = (i == 0); std::unique_ptr iter(reader->NewIterator( - ro, moptions.prefix_extractor.get(), /*arena=*/nullptr, + ro, moptions.prefix_extractor.get(), /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized)); iter->Seek(key.Encode()); @@ -2229,7 +2229,7 @@ TEST_P(BlockBasedTableTest, SkipPrefixBloomFilter) { auto reader = c.GetTableReader(); ReadOptions read_options; std::unique_ptr db_iter(reader->NewIterator( - read_options, new_moptions.prefix_extractor.get(), /*arena=*/nullptr, + read_options, new_moptions.prefix_extractor.get(), /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized)); // Test point lookup @@ -2483,7 +2483,7 @@ void TableTest::IndexTest(BlockBasedTableOptions table_options) { // TODO(Zhongyi): update test to use MutableCFOptions ReadOptions read_options; std::unique_ptr index_iter(reader->NewIterator( - read_options, moptions.prefix_extractor.get(), /*arena=*/nullptr, + read_options, moptions.prefix_extractor.get(), /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized)); // -- Find keys do not exist, but have common prefix. @@ -2578,7 +2578,7 @@ void TableTest::IndexTest(BlockBasedTableOptions table_options) { ReadOptions ro; ro.total_order_seek = true; std::unique_ptr index_iter2(reader->NewIterator( - ro, moptions.prefix_extractor.get(), /*arena=*/nullptr, + ro, moptions.prefix_extractor.get(), /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized)); // Things to cover in partitioned index: @@ -2695,7 +2695,7 @@ TEST_P(BlockBasedTableTest, IndexSeekOptimizationIncomplete) { ReadOptions ropt; ropt.read_tier = ReadTier::kBlockCacheTier; std::unique_ptr iter(reader->NewIterator( - ropt, /*prefix_extractor=*/nullptr, /*arena=*/nullptr, + ropt, /*prefix_extractor=*/nullptr, /*internal_stats=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized)); auto ikey = [](Slice user_key) { @@ -2799,7 +2799,7 @@ TEST_P(BlockBasedTableTest, BinaryIndexWithFirstKey2) { ASSERT_EQ(4u, props->num_data_blocks); ReadOptions read_options; std::unique_ptr iter(reader->NewIterator( - read_options, /*prefix_extractor=*/nullptr, /*arena=*/nullptr, + read_options, /*prefix_extractor=*/nullptr, /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized, /*compaction_readahead_size=*/0, /*allow_unprepared_value=*/true)); @@ -2984,7 +2984,7 @@ TEST_P(BlockBasedTableTest, BinaryIndexWithFirstKeyGlobalSeqno) { ASSERT_EQ(1u, props->num_data_blocks); ReadOptions read_options; std::unique_ptr iter(reader->NewIterator( - read_options, /*prefix_extractor=*/nullptr, /*arena=*/nullptr, + read_options, /*prefix_extractor=*/nullptr, /*arena=*/nullptr, /*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized, /*compaction_readahead_size=*/0, /*allow_unprepared_value=*/true)); @@ -3173,7 +3173,7 @@ void WarmUpCache(TableConstructor* c, const MutableCFOptions& moptions, const std::vector& warm_keys) { ReadOptions ro; std::unique_ptr iter(c->GetTableReader()->NewIterator( - ro, moptions.prefix_extractor.get(), nullptr, false, + ro, moptions.prefix_extractor.get(), nullptr, nullptr, false, TableReaderCaller::kUncategorized)); size_t i = 0; while (i < warm_keys.size()) { @@ -3237,7 +3237,7 @@ TEST_P(BlockBasedTableTest, BlockCacheLookupSeqScans) { ASSERT_OK(options.statistics->Reset()); std::unique_ptr iter(c.GetTableReader()->NewIterator( - read_options, moptions.prefix_extractor.get(), /*arena=*/nullptr, + read_options, moptions.prefix_extractor.get(), /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized)); // Seek key - @@ -3275,7 +3275,7 @@ TEST_P(BlockBasedTableTest, BlockCacheLookupSeqScans) { WarmUpCache(&c, moptions, warm_keys); std::unique_ptr iter(c.GetTableReader()->NewIterator( - read_options, moptions.prefix_extractor.get(), nullptr, false, + read_options, moptions.prefix_extractor.get(), nullptr, nullptr, false, TableReaderCaller::kUncategorized)); // Seek key - @@ -3384,7 +3384,7 @@ TEST_P(BlockBasedTableTest, BlockCacheLookupAsyncScansSeek) { ASSERT_OK(options.statistics->Reset()); std::unique_ptr iter(c.GetTableReader()->NewIterator( - read_options, moptions.prefix_extractor.get(), nullptr, false, + read_options, moptions.prefix_extractor.get(), nullptr, nullptr, false, TableReaderCaller::kUncategorized)); // Seek key - @@ -3423,7 +3423,7 @@ TEST_P(BlockBasedTableTest, BlockCacheLookupAsyncScansSeek) { WarmUpCache(&c, moptions, warm_keys); std::unique_ptr iter(c.GetTableReader()->NewIterator( - read_options, moptions.prefix_extractor.get(), nullptr, false, + read_options, moptions.prefix_extractor.get(), nullptr, nullptr, false, TableReaderCaller::kUncategorized)); // Seek key - @@ -3473,7 +3473,7 @@ TEST_P(BlockBasedTableTest, BlockCacheLookupAsyncScansSeek) { WarmUpCache(&c, moptions, warm_keys); std::unique_ptr iter(c.GetTableReader()->NewIterator( - read_options, moptions.prefix_extractor.get(), /*arena=*/nullptr, + read_options, moptions.prefix_extractor.get(), /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized)); // Seek key - @@ -3867,7 +3867,7 @@ TEST_P(BlockBasedTableTest, TracingIterator) { for (uint32_t i = 1; i <= 2; i++) { ReadOptions read_options; std::unique_ptr iter(c.GetTableReader()->NewIterator( - read_options, moptions.prefix_extractor.get(), /*arena=*/nullptr, + read_options, moptions.prefix_extractor.get(), /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUserIterator)); iter->SeekToFirst(); while (iter->Valid()) { @@ -5131,7 +5131,7 @@ TEST_P(IndexBlockRestartIntervalTest, IndexBlockRestartInterval) { ReadOptions read_options; std::unique_ptr db_iter(reader->NewIterator( - read_options, moptions.prefix_extractor.get(), /*arena=*/nullptr, + read_options, moptions.prefix_extractor.get(), /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized)); // Test point lookup @@ -5326,10 +5326,10 @@ TEST_P(BlockBasedTableTest, DISABLED_TableWithGlobalSeqno) { options.table_factory->NewTableReader( TableReaderOptions(ioptions, moptions.prefix_extractor, EnvOptions(), ikc, 0 /* block_protection_bytes_per_key */), - std::move(file_reader), ss_rw.contents().size(), &table_reader); + std::move(file_reader), ss_rw.contents().size(), &table_reader, /*internal_stats=*/nullptr); return table_reader->NewIterator( - read_options, moptions.prefix_extractor.get(), /*arena=*/nullptr, + read_options, moptions.prefix_extractor.get(), /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized); }; @@ -5502,10 +5502,10 @@ TEST_P(BlockBasedTableTest, BlockAlignTest) { TableReaderOptions(ioptions2, moptions2.prefix_extractor, EnvOptions(), GetPlainInternalComparator(options2.comparator), 0 /* block_protection_bytes_per_key */), - std::move(file_reader), sink->contents().size(), &table_reader)); + std::move(file_reader), sink->contents().size(), &table_reader, /*internal_stats=*/nullptr)); std::unique_ptr db_iter(table_reader->NewIterator( - read_options, moptions2.prefix_extractor.get(), /*arena=*/nullptr, + read_options, moptions2.prefix_extractor.get(), /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized)); int expected_key = 1; @@ -6054,7 +6054,7 @@ TEST_P(BlockBasedTableTest, DataBlockHashIndex) { std::unique_ptr seek_iter; ReadOptions read_options; seek_iter.reset(reader->NewIterator( - read_options, moptions.prefix_extractor.get(), /*arena=*/nullptr, + read_options, moptions.prefix_extractor.get(), /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized)); for (int i = 0; i < 2; ++i) { ReadOptions ro; @@ -6137,14 +6137,14 @@ TEST_P(BlockBasedTableTest, OutOfBoundOnSeek) { read_opt.iterate_upper_bound = &upper_bound_slice; std::unique_ptr iter; iter.reset(new KeyConvertingIterator(reader->NewIterator( - read_opt, /*prefix_extractor=*/nullptr, /*arena=*/nullptr, + read_opt, /*prefix_extractor=*/nullptr, /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized))); iter->SeekToFirst(); ASSERT_FALSE(iter->Valid()); ASSERT_OK(iter->status()); ASSERT_TRUE(iter->UpperBoundCheckResult() == IterBoundCheck::kOutOfBound); iter.reset(new KeyConvertingIterator(reader->NewIterator( - read_opt, /*prefix_extractor=*/nullptr, /*arena=*/nullptr, + read_opt, /*prefix_extractor=*/nullptr, /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized))); iter->Seek("foo"); ASSERT_FALSE(iter->Valid()); @@ -6177,7 +6177,7 @@ TEST_P(BlockBasedTableTest, OutOfBoundOnNext) { read_opt.iterate_upper_bound = &ub_slice1; std::unique_ptr iter; iter.reset(new KeyConvertingIterator(reader->NewIterator( - read_opt, /*prefix_extractor=*/nullptr, /*arena=*/nullptr, + read_opt, /*prefix_extractor=*/nullptr, /*arena=*/nullptr, /*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized))); iter->Seek("bar"); ASSERT_TRUE(iter->Valid()); @@ -6189,7 +6189,7 @@ TEST_P(BlockBasedTableTest, OutOfBoundOnNext) { Slice ub_slice2(ub2); read_opt.iterate_upper_bound = &ub_slice2; iter.reset(new KeyConvertingIterator(reader->NewIterator( - read_opt, /*prefix_extractor=*/nullptr, /*arena=*/nullptr, + read_opt, /*prefix_extractor=*/nullptr, /*arena=*/nullptr,/*internal_stats=*/nullptr, /*skip_filters=*/false, TableReaderCaller::kUncategorized))); iter->Seek("foo"); ASSERT_TRUE(iter->Valid()); diff --git a/utilities/options/options_util_test.cc b/utilities/options/options_util_test.cc index 193142d67c2..b8aeca609a0 100644 --- a/utilities/options/options_util_test.cc +++ b/utilities/options/options_util_test.cc @@ -160,7 +160,7 @@ class DummyTableFactory : public TableFactory { const ReadOptions& /*ro*/, const TableReaderOptions& /*table_reader_options*/, std::unique_ptr&& /*file*/, - uint64_t /*file_size*/, std::unique_ptr* /*table_reader*/, + uint64_t /*file_size*/, std::unique_ptr* /*table_reader*/, InternalStats* /*internal_stats*/, bool /*prefetch_index_and_filter_in_cache*/) const override { return Status::NotSupported(); }