Avoid unnecessary reads of uncompression dictionary in MultiGet (#6906)
Summary: We may sometimes read the uncompression dictionary when its not necessary, when we lookup a key in an SST file but the index indicates the key is not present. This can happen with index_type 3. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6906 Test Plan: make check Reviewed By: cheng-chang Differential Revision: D21828944 Pulled By: anand1976 fbshipit-source-id: 7aef4f0a39548d0874eafefd2687006d2652f9bb
This commit is contained in:
parent
02f59ed669
commit
66942e8158
@ -2441,18 +2441,7 @@ void BlockBasedTable::MultiGet(const ReadOptions& read_options,
|
|||||||
|
|
||||||
CachableEntry<UncompressionDict> uncompression_dict;
|
CachableEntry<UncompressionDict> uncompression_dict;
|
||||||
Status uncompression_dict_status;
|
Status uncompression_dict_status;
|
||||||
if (rep_->uncompression_dict_reader) {
|
bool uncompression_dict_inited = false;
|
||||||
uncompression_dict_status =
|
|
||||||
rep_->uncompression_dict_reader->GetOrReadUncompressionDictionary(
|
|
||||||
nullptr /* prefetch_buffer */, no_io,
|
|
||||||
sst_file_range.begin()->get_context, &lookup_context,
|
|
||||||
&uncompression_dict);
|
|
||||||
}
|
|
||||||
|
|
||||||
const UncompressionDict& dict = uncompression_dict.GetValue()
|
|
||||||
? *uncompression_dict.GetValue()
|
|
||||||
: UncompressionDict::GetEmptyDict();
|
|
||||||
|
|
||||||
size_t total_len = 0;
|
size_t total_len = 0;
|
||||||
ReadOptions ro = read_options;
|
ReadOptions ro = read_options;
|
||||||
ro.read_tier = kBlockCacheTier;
|
ro.read_tier = kBlockCacheTier;
|
||||||
@ -2481,6 +2470,15 @@ void BlockBasedTable::MultiGet(const ReadOptions& read_options,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!uncompression_dict_inited && rep_->uncompression_dict_reader) {
|
||||||
|
uncompression_dict_status =
|
||||||
|
rep_->uncompression_dict_reader->GetOrReadUncompressionDictionary(
|
||||||
|
nullptr /* prefetch_buffer */, no_io,
|
||||||
|
sst_file_range.begin()->get_context, &lookup_context,
|
||||||
|
&uncompression_dict);
|
||||||
|
uncompression_dict_inited = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!uncompression_dict_status.ok()) {
|
if (!uncompression_dict_status.ok()) {
|
||||||
assert(!uncompression_dict_status.IsNotFound());
|
assert(!uncompression_dict_status.IsNotFound());
|
||||||
*(miter->s) = uncompression_dict_status;
|
*(miter->s) = uncompression_dict_status;
|
||||||
@ -2504,6 +2502,9 @@ void BlockBasedTable::MultiGet(const ReadOptions& read_options,
|
|||||||
BlockHandle handle = v.handle;
|
BlockHandle handle = v.handle;
|
||||||
BlockCacheLookupContext lookup_data_block_context(
|
BlockCacheLookupContext lookup_data_block_context(
|
||||||
TableReaderCaller::kUserMultiGet);
|
TableReaderCaller::kUserMultiGet);
|
||||||
|
const UncompressionDict& dict = uncompression_dict.GetValue()
|
||||||
|
? *uncompression_dict.GetValue()
|
||||||
|
: UncompressionDict::GetEmptyDict();
|
||||||
Status s = RetrieveBlock(
|
Status s = RetrieveBlock(
|
||||||
nullptr, ro, handle, dict, &(results.back()), BlockType::kData,
|
nullptr, ro, handle, dict, &(results.back()), BlockType::kData,
|
||||||
miter->get_context, &lookup_data_block_context,
|
miter->get_context, &lookup_data_block_context,
|
||||||
@ -2523,6 +2524,11 @@ void BlockBasedTable::MultiGet(const ReadOptions& read_options,
|
|||||||
|
|
||||||
if (total_len) {
|
if (total_len) {
|
||||||
char* scratch = nullptr;
|
char* scratch = nullptr;
|
||||||
|
const UncompressionDict& dict = uncompression_dict.GetValue()
|
||||||
|
? *uncompression_dict.GetValue()
|
||||||
|
: UncompressionDict::GetEmptyDict();
|
||||||
|
assert(uncompression_dict_inited || !rep_->uncompression_dict_reader);
|
||||||
|
assert(uncompression_dict_status.ok());
|
||||||
// If using direct IO, then scratch is not used, so keep it nullptr.
|
// If using direct IO, then scratch is not used, so keep it nullptr.
|
||||||
// If the blocks need to be uncompressed and we don't need the
|
// If the blocks need to be uncompressed and we don't need the
|
||||||
// compressed blocks, then we can use a contiguous block of
|
// compressed blocks, then we can use a contiguous block of
|
||||||
|
Loading…
Reference in New Issue
Block a user