diff --git a/table/block_based_table_builder.cc b/table/block_based_table_builder.cc index 17e9367aa..3dd51cd65 100644 --- a/table/block_based_table_builder.cc +++ b/table/block_based_table_builder.cc @@ -159,9 +159,6 @@ IndexBuilder* CreateIndexBuilder(IndexType type, const Comparator* comparator) { case BlockBasedTableOptions::kBinarySearch: { return new ShortenedIndexBuilder(comparator); } - case BlockBasedTableOptions::kHashSearch: { - return new ShortenedIndexBuilder(comparator); - } default: { assert(!"Do not recognize the index type "); return nullptr; @@ -324,13 +321,16 @@ struct BlockBasedTableBuilder::Rep { } }; +// TODO(sdong): Currently only write out binary search index. In +// BlockBasedTableReader, Hash index will be built using binary search index. BlockBasedTableBuilder::BlockBasedTableBuilder( const Options& options, const BlockBasedTableOptions& table_options, const InternalKeyComparator& internal_comparator, WritableFile* file, CompressionType compression_type) : rep_(new Rep(options, internal_comparator, file, table_options.flush_block_policy_factory.get(), - compression_type, table_options.index_type)) { + compression_type, + BlockBasedTableOptions::IndexType::kBinarySearch)) { if (rep_->filter_block != nullptr) { rep_->filter_block->StartBlock(0); } diff --git a/table/block_based_table_reader.cc b/table/block_based_table_reader.cc index 656a3c79e..b44fab155 100644 --- a/table/block_based_table_reader.cc +++ b/table/block_based_table_reader.cc @@ -1030,14 +1030,29 @@ bool BlockBasedTable::TEST_KeyInCache(const ReadOptions& options, Status BlockBasedTable::CreateIndexReader(IndexReader** index_reader) { // Some old version of block-based tables don't have index type present in // table properties. If that's the case we can safely use the kBinarySearch. - auto index_type = rep_->index_type; + auto index_type_on_file = BlockBasedTableOptions::kBinarySearch; + if (rep_->table_properties) { + auto& props = rep_->table_properties->user_collected_properties; + auto pos = props.find(BlockBasedTablePropertyNames::kIndexType); + if (pos != props.end()) { + index_type_on_file = static_cast( + DecodeFixed32(pos->second.c_str())); + } + } + + // TODO(sdong): Currently binary index is the only index type we support in + // files. Hash index is built on top of binary index too. + if (index_type_on_file != BlockBasedTableOptions::kBinarySearch) { + return Status::NotSupported("File Contains not supported index type: ", + std::to_string(index_type_on_file)); + } auto file = rep_->file.get(); const auto& index_handle = rep_->index_handle; auto env = rep_->options.env; auto comparator = &rep_->internal_comparator; - switch (index_type) { + switch (rep_->index_type) { case BlockBasedTableOptions::kBinarySearch: { return BinarySearchIndexReader::Create(file, index_handle, env, comparator, index_reader);