From a79b65ecd0460c4e8f4e8973ec6a78bdba07772b Mon Sep 17 00:00:00 2001 From: Hui Xiao Date: Tue, 24 Sep 2024 18:15:11 -0700 Subject: [PATCH] draft --- file/prefetch_test.cc | 5 +++ .../block_based/block_based_table_iterator.cc | 8 ++++ .../block_based/block_based_table_iterator.h | 37 ++++++++++++++++--- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/file/prefetch_test.cc b/file/prefetch_test.cc index 20d85a785d8..01a8b94a65c 100644 --- a/file/prefetch_test.cc +++ b/file/prefetch_test.cc @@ -1249,6 +1249,7 @@ TEST_P(PrefetchTest, PrefetchWhenReseekwithCache) { Close(); } +// Best UT integration for correctness coverage TEST_P(PrefetchTest, PrefetchWithBlockLookupAutoTuneTest) { if (mem_env_ || encrypted_env_) { ROCKSDB_GTEST_SKIP("Test requires non-mem or non-encrypted environment"); @@ -1262,6 +1263,7 @@ TEST_P(PrefetchTest, PrefetchWithBlockLookupAutoTuneTest) { Options options; SetGenericOptions(env.get(), /*use_direct_io=*/false, options); options.statistics = CreateDBStatistics(); + options.prefix_extractor.reset(NewFixedPrefixTransform(7)); BlockBasedTableOptions table_options; SetBlockBasedTableOptions(table_options); options.table_factory.reset(NewBlockBasedTableFactory(table_options)); @@ -1333,8 +1335,10 @@ TEST_P(PrefetchTest, PrefetchWithBlockLookupAutoTuneTest) { ReadOptions ropts; ropts.auto_readahead_size = true; + ropts.prefix_same_as_start = true; ReadOptions cmp_ro; cmp_ro.auto_readahead_size = false; + cmp_ro.prefix_same_as_start = true; if (std::get<0>(GetParam())) { ropts.readahead_size = cmp_ro.readahead_size = 32768; @@ -1354,6 +1358,7 @@ TEST_P(PrefetchTest, PrefetchWithBlockLookupAutoTuneTest) { cmp_ro.iterate_upper_bound = ub_ptr; ropts.iterate_upper_bound = ub_ptr; + auto iter = std::unique_ptr(db_->NewIterator(ropts)); auto cmp_iter = std::unique_ptr(db_->NewIterator(cmp_ro)); diff --git a/table/block_based/block_based_table_iterator.cc b/table/block_based/block_based_table_iterator.cc index 14db24d9b3c..f820fa0bca5 100644 --- a/table/block_based/block_based_table_iterator.cc +++ b/table/block_based/block_based_table_iterator.cc @@ -35,6 +35,14 @@ void BlockBasedTableIterator::SeekSecondPass(const Slice* target) { void BlockBasedTableIterator::SeekImpl(const Slice* target, bool async_prefetch) { + // Invalid transform + // Tranform user timestamp + // best place to set `prefix_for_same_as_start_` + if (prefix_extractor_) { + prefix_for_same_as_start_ = + prefix_extractor_->Transform(ExtractUserKey(*target)); + } + bool is_first_pass = !async_read_in_progress_; if (!is_first_pass) { diff --git a/table/block_based/block_based_table_iterator.h b/table/block_based/block_based_table_iterator.h index 2b562ef0679..f107f296cb8 100644 --- a/table/block_based/block_based_table_iterator.h +++ b/table/block_based/block_based_table_iterator.h @@ -353,6 +353,10 @@ class BlockBasedTableIterator : public InternalIteratorBase { // is used to disable the lookup. IterDirection direction_ = IterDirection::kForward; + // perf for stroing slice + // naming + Slice prefix_for_same_as_start_ = nullptr; + void SeekSecondPass(const Slice* target); // If `target` is null, seek to first. @@ -411,12 +415,33 @@ class BlockBasedTableIterator : public InternalIteratorBase { bool IsNextBlockOutOfBound() { // If curr block's index key >= iterate_upper_bound, it means all the keys // in next block or above are out of bound. - return (user_comparator_.CompareWithoutTimestamp( - index_iter_->user_key(), - /*a_has_ts=*/true, *read_options_.iterate_upper_bound, - /*b_has_ts=*/false) >= 0 - ? true - : false); + // return (user_comparator_.CompareWithoutTimestamp( + // index_iter_->user_key(), + // /*a_has_ts=*/true, *read_options_.iterate_upper_bound, + // /*b_has_ts=*/false) >= 0 + // ? true + // : false); + bool out_of_upper_bound = + (user_comparator_.CompareWithoutTimestamp( + index_iter_->user_key(), + /*a_has_ts=*/true, *read_options_.iterate_upper_bound, + /*b_has_ts=*/false) >= 0 + ? true + : false); + if (out_of_upper_bound) { + return true; + } + + bool out_of_prefix_bound = + (read_options_.prefix_same_as_start && + prefix_for_same_as_start_ != nullptr && + prefix_extractor_->Transform(index_iter_->user_key()) + .compare(prefix_for_same_as_start_) != 0); + if (out_of_prefix_bound) { + return true; + } + + return false; } void ClearBlockHandles() {