Check for rep_->table_properties being nullptr

Summary:
The very old sst formats do not have table_properties and rep_->table_properties is thus nullptr. The recent patch in https://github.com/facebook/rocksdb/pull/3894 does not check for nullptr and hence makes it backward incompatible. This patch adds the check.
Closes https://github.com/facebook/rocksdb/pull/3918

Differential Revision: D8188638

Pulled By: maysamyabandeh

fbshipit-source-id: b1d986665ecf0b4d1c442adfa8a193b97707d47b
main
Maysam Yabandeh 7 years ago committed by Facebook Github Bot
parent 1c1bafa668
commit 03cda531e4
  1. 25
      table/block_based_table_reader.cc

@ -1799,7 +1799,8 @@ bool BlockBasedTable::PrefixMayMatch(const Slice& internal_key,
// and we're not really sure that we're past the end // and we're not really sure that we're past the end
// of the file // of the file
may_match = iiter->status().IsIncomplete(); may_match = iiter->status().IsIncomplete();
} else if ((rep_->table_properties->index_key_is_user_key } else if ((rep_->table_properties &&
rep_->table_properties->index_key_is_user_key
? iiter->key() ? iiter->key()
: ExtractUserKey(iiter->key())) : ExtractUserKey(iiter->key()))
.starts_with(ExtractUserKey(internal_prefix))) { .starts_with(ExtractUserKey(internal_prefix))) {
@ -2278,7 +2279,8 @@ Status BlockBasedTable::Prefetch(const Slice* const begin,
for (begin ? iiter->Seek(*begin) : iiter->SeekToFirst(); iiter->Valid(); for (begin ? iiter->Seek(*begin) : iiter->SeekToFirst(); iiter->Valid();
iiter->Next()) { iiter->Next()) {
Slice block_handle = iiter->value(); Slice block_handle = iiter->value();
const bool is_user_key = rep_->table_properties->index_key_is_user_key > 0; const bool is_user_key = rep_->table_properties &&
rep_->table_properties->index_key_is_user_key > 0;
if (end && if (end &&
((!is_user_key && comparator.Compare(iiter->key(), *end) >= 0) || ((!is_user_key && comparator.Compare(iiter->key(), *end) >= 0) ||
(is_user_key && (is_user_key &&
@ -2436,13 +2438,15 @@ Status BlockBasedTable::CreateIndexReader(
this, file, prefetch_buffer, footer, footer.index_handle(), this, file, prefetch_buffer, footer, footer.index_handle(),
rep_->ioptions, icomparator, index_reader, rep_->ioptions, icomparator, index_reader,
rep_->persistent_cache_options, level, rep_->persistent_cache_options, level,
rep_->table_properties->index_key_is_user_key == 0); rep_->table_properties == nullptr ||
rep_->table_properties->index_key_is_user_key == 0);
} }
case BlockBasedTableOptions::kBinarySearch: { case BlockBasedTableOptions::kBinarySearch: {
return BinarySearchIndexReader::Create( return BinarySearchIndexReader::Create(
file, prefetch_buffer, footer, footer.index_handle(), rep_->ioptions, file, prefetch_buffer, footer, footer.index_handle(), rep_->ioptions,
icomparator, index_reader, rep_->persistent_cache_options, icomparator, index_reader, rep_->persistent_cache_options,
rep_->table_properties->index_key_is_user_key == 0); rep_->table_properties == nullptr ||
rep_->table_properties->index_key_is_user_key == 0);
} }
case BlockBasedTableOptions::kHashSearch: { case BlockBasedTableOptions::kHashSearch: {
std::unique_ptr<Block> meta_guard; std::unique_ptr<Block> meta_guard;
@ -2461,7 +2465,8 @@ Status BlockBasedTable::CreateIndexReader(
file, prefetch_buffer, footer, footer.index_handle(), file, prefetch_buffer, footer, footer.index_handle(),
rep_->ioptions, icomparator, index_reader, rep_->ioptions, icomparator, index_reader,
rep_->persistent_cache_options, rep_->persistent_cache_options,
rep_->table_properties->index_key_is_user_key == 0); rep_->table_properties == nullptr ||
rep_->table_properties->index_key_is_user_key == 0);
} }
meta_index_iter = meta_iter_guard.get(); meta_index_iter = meta_iter_guard.get();
} }
@ -2471,7 +2476,8 @@ Status BlockBasedTable::CreateIndexReader(
rep_->ioptions, icomparator, footer.index_handle(), meta_index_iter, rep_->ioptions, icomparator, footer.index_handle(), meta_index_iter,
index_reader, rep_->hash_index_allow_collision, index_reader, rep_->hash_index_allow_collision,
rep_->persistent_cache_options, rep_->persistent_cache_options,
rep_->table_properties->index_key_is_user_key == 0); rep_->table_properties == nullptr ||
rep_->table_properties->index_key_is_user_key == 0);
} }
default: { default: {
std::string error_message = std::string error_message =
@ -2758,11 +2764,12 @@ Status BlockBasedTable::DumpIndexBlock(WritableFile* out_file) {
Slice key = blockhandles_iter->key(); Slice key = blockhandles_iter->key();
Slice user_key; Slice user_key;
InternalKey ikey; InternalKey ikey;
if (rep_->table_properties->index_key_is_user_key == 0) { if (rep_->table_properties &&
rep_->table_properties->index_key_is_user_key != 0) {
user_key = key;
} else {
ikey.DecodeFrom(key); ikey.DecodeFrom(key);
user_key = ikey.user_key(); user_key = ikey.user_key();
} else {
user_key = key;
} }
out_file->Append(" HEX "); out_file->Append(" HEX ");

Loading…
Cancel
Save