From 9eca6d651d84542f0098d34eca104b51cbc42093 Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Mon, 13 Apr 2020 11:15:20 -0700 Subject: [PATCH] fix comparison count for format_version=3 indexes (#6650) Summary: In index blocks since `format_version=3`, user keys are written rather than internal keys. When reading such blocks, the comparator is obtained via `InternalKeyComparator::user_comparator()`. That function must not return an unwrapped result as the wrapper class provides accounting logic to populate `PerfContext::user_key_comparison_count`. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6650 Test Plan: ran db_bench and verified `PerfContext::user_key_comparison_count` became larger. Reviewed By: cheng-chang Differential Revision: D20866325 Pulled By: ajkr fbshipit-source-id: ad755d46bda31157dacc5b66e532279f19ad538c --- HISTORY.md | 1 + table/block_based/block.h | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index bbe3e61a2..145525668 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -9,6 +9,7 @@ ### Bug Fixes * Fix a bug when making options.bottommost_compression, options.compression_opts and options.bottommost_compression_opts dynamically changeable: the modified values are not written to option files or returned back to users when being queried. +* Fix a bug where index key comparisons were unaccounted in `PerfContext::user_key_comparison_count` for lookups in files written with `format_version >= 3`. ## 6.9.0 (03/29/2020) ### Behavior changes diff --git a/table/block_based/block.h b/table/block_based/block.h index 1e0440491..f3efe611c 100644 --- a/table/block_based/block.h +++ b/table/block_based/block.h @@ -502,9 +502,14 @@ class IndexBlockIter final : public BlockIter { SequenceNumber global_seqno, BlockPrefixIndex* prefix_index, bool have_first_key, bool key_includes_seq, bool value_is_full, bool block_contents_pinned) { - InitializeBase(key_includes_seq ? comparator : user_comparator, data, - restarts, num_restarts, kDisableGlobalSequenceNumber, - block_contents_pinned); + if (!key_includes_seq) { + user_comparator_wrapper_ = std::unique_ptr( + new UserComparatorWrapper(user_comparator)); + } + InitializeBase( + key_includes_seq ? comparator : user_comparator_wrapper_.get(), data, + restarts, num_restarts, kDisableGlobalSequenceNumber, + block_contents_pinned); key_includes_seq_ = key_includes_seq; key_.SetIsUserKey(!key_includes_seq_); prefix_index_ = prefix_index; @@ -573,6 +578,7 @@ class IndexBlockIter final : public BlockIter { } private: + std::unique_ptr user_comparator_wrapper_; // Key is in InternalKey format bool key_includes_seq_; bool value_delta_encoded_;