Skip to content

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
  • Loading branch information
hx235 committed Sep 25, 2024
1 parent fbbb087 commit a79b65e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
5 changes: 5 additions & 0 deletions file/prefetch_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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));
Expand Down Expand Up @@ -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;
Expand All @@ -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<Iterator>(db_->NewIterator(ropts));
auto cmp_iter = std::unique_ptr<Iterator>(db_->NewIterator(cmp_ro));

Expand Down
8 changes: 8 additions & 0 deletions table/block_based/block_based_table_iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
37 changes: 31 additions & 6 deletions table/block_based/block_based_table_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ class BlockBasedTableIterator : public InternalIteratorBase<Slice> {
// 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.
Expand Down Expand Up @@ -411,12 +415,33 @@ class BlockBasedTableIterator : public InternalIteratorBase<Slice> {
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() {
Expand Down

0 comments on commit a79b65e

Please sign in to comment.