Rename BlockBasedTable::ReadMetaBlock (#6009)

Summary:
According to
https://github.com/facebook/rocksdb/wiki/Rocksdb-BlockBasedTable-Format,
the block read by BlockBasedTable::ReadMetaBlock is actually the meta index
block. Therefore, it is better to rename the function to ReadMetaIndexBlock.

This PR also applies some format change to existing code.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6009

Test Plan: make check

Differential Revision: D18333238

Pulled By: riversand963

fbshipit-source-id: 2c4340a29b3edba53d19c132cbfd04caf6242aed
This commit is contained in:
Yanqin Jin 2019-11-05 17:17:36 -08:00 committed by Facebook Github Bot
parent 230bcae7b6
commit 67e735dbf9
4 changed files with 55 additions and 49 deletions

View File

@ -166,7 +166,7 @@ class WriteBatchWithIndex : public WriteBatchBase {
// called.
Iterator* NewIteratorWithBase(ColumnFamilyHandle* column_family,
Iterator* base_iterator,
const ReadOptions *opts = nullptr);
const ReadOptions* opts = nullptr);
// default column family
Iterator* NewIteratorWithBase(Iterator* base_iterator);

View File

@ -1201,28 +1201,29 @@ Status BlockBasedTable::Open(
rep->compression_dict_handle = BlockHandle::NullBlockHandle();
// Read metaindex
std::unique_ptr<Block> meta;
std::unique_ptr<InternalIterator> meta_iter;
s = new_table->ReadMetaBlock(prefetch_buffer.get(), &meta, &meta_iter);
std::unique_ptr<Block> metaindex;
std::unique_ptr<InternalIterator> metaindex_iter;
s = new_table->ReadMetaIndexBlock(prefetch_buffer.get(), &metaindex,
&metaindex_iter);
if (!s.ok()) {
return s;
}
// Populates table_properties and some fields that depend on it,
// such as index_type.
s = new_table->ReadPropertiesBlock(prefetch_buffer.get(), meta_iter.get(),
largest_seqno);
s = new_table->ReadPropertiesBlock(prefetch_buffer.get(),
metaindex_iter.get(), largest_seqno);
if (!s.ok()) {
return s;
}
s = new_table->ReadRangeDelBlock(prefetch_buffer.get(), meta_iter.get(),
s = new_table->ReadRangeDelBlock(prefetch_buffer.get(), metaindex_iter.get(),
internal_comparator, &lookup_context);
if (!s.ok()) {
return s;
}
s = new_table->PrefetchIndexAndFilterBlocks(
prefetch_buffer.get(), meta_iter.get(), new_table.get(), prefetch_all,
table_options, level, &lookup_context);
prefetch_buffer.get(), metaindex_iter.get(), new_table.get(),
prefetch_all, table_options, level, &lookup_context);
if (s.ok()) {
// Update tail prefetch stats
@ -1634,17 +1635,19 @@ size_t BlockBasedTable::ApproximateMemoryUsage() const {
return usage;
}
// Load the meta-block from the file. On success, return the loaded meta block
// and its iterator.
Status BlockBasedTable::ReadMetaBlock(FilePrefetchBuffer* prefetch_buffer,
std::unique_ptr<Block>* meta_block,
std::unique_ptr<InternalIterator>* iter) {
// Load the meta-index-block from the file. On success, return the loaded
// metaindex
// block and its iterator.
Status BlockBasedTable::ReadMetaIndexBlock(
FilePrefetchBuffer* prefetch_buffer,
std::unique_ptr<Block>* metaindex_block,
std::unique_ptr<InternalIterator>* iter) {
// TODO(sanjay): Skip this if footer.metaindex_handle() size indicates
// it is an empty block.
std::unique_ptr<Block> meta;
std::unique_ptr<Block> metaindex;
Status s = ReadBlockFromFile(
rep_->file.get(), prefetch_buffer, rep_->footer, ReadOptions(),
rep_->footer.metaindex_handle(), &meta, rep_->ioptions,
rep_->footer.metaindex_handle(), &metaindex, rep_->ioptions,
true /* decompress */, true /*maybe_compressed*/, BlockType::kMetaIndex,
UncompressionDict::GetEmptyDict(), rep_->persistent_cache_options,
kDisableGlobalSequenceNumber, 0 /* read_amp_bytes_per_bit */,
@ -1659,10 +1662,10 @@ Status BlockBasedTable::ReadMetaBlock(FilePrefetchBuffer* prefetch_buffer,
return s;
}
*meta_block = std::move(meta);
*metaindex_block = std::move(metaindex);
// meta block uses bytewise comparator.
iter->reset(meta_block->get()->NewDataIterator(BytewiseComparator(),
BytewiseComparator()));
iter->reset(metaindex_block->get()->NewDataIterator(BytewiseComparator(),
BytewiseComparator()));
return Status::OK();
}
@ -3743,11 +3746,12 @@ Status BlockBasedTable::VerifyChecksum(const ReadOptions& read_options,
TableReaderCaller caller) {
Status s;
// Check Meta blocks
std::unique_ptr<Block> meta;
std::unique_ptr<InternalIterator> meta_iter;
s = ReadMetaBlock(nullptr /* prefetch buffer */, &meta, &meta_iter);
std::unique_ptr<Block> metaindex;
std::unique_ptr<InternalIterator> metaindex_iter;
s = ReadMetaIndexBlock(nullptr /* prefetch buffer */, &metaindex,
&metaindex_iter);
if (s.ok()) {
s = VerifyChecksumInMetaBlocks(meta_iter.get());
s = VerifyChecksumInMetaBlocks(metaindex_iter.get());
if (!s.ok()) {
return s;
}
@ -3938,11 +3942,12 @@ Status BlockBasedTable::CreateIndexReader(
index_reader);
}
case BlockBasedTableOptions::kHashSearch: {
std::unique_ptr<Block> meta_guard;
std::unique_ptr<InternalIterator> meta_iter_guard;
std::unique_ptr<Block> metaindex_guard;
std::unique_ptr<InternalIterator> metaindex_iter_guard;
auto meta_index_iter = preloaded_meta_index_iter;
if (meta_index_iter == nullptr) {
auto s = ReadMetaBlock(prefetch_buffer, &meta_guard, &meta_iter_guard);
auto s = ReadMetaIndexBlock(prefetch_buffer, &metaindex_guard,
&metaindex_iter_guard);
if (!s.ok()) {
// we simply fall back to binary search in case there is any
// problem with prefix hash index loading.
@ -3953,7 +3958,7 @@ Status BlockBasedTable::CreateIndexReader(
use_cache, prefetch, pin,
lookup_context, index_reader);
}
meta_index_iter = meta_iter_guard.get();
meta_index_iter = metaindex_iter_guard.get();
}
return HashIndexReader::Create(this, prefetch_buffer, meta_index_iter,
@ -4110,31 +4115,33 @@ Status BlockBasedTable::DumpTable(WritableFile* out_file) {
out_file->Append(
"Metaindex Details:\n"
"--------------------------------------\n");
std::unique_ptr<Block> meta;
std::unique_ptr<InternalIterator> meta_iter;
Status s = ReadMetaBlock(nullptr /* prefetch_buffer */, &meta, &meta_iter);
std::unique_ptr<Block> metaindex;
std::unique_ptr<InternalIterator> metaindex_iter;
Status s = ReadMetaIndexBlock(nullptr /* prefetch_buffer */, &metaindex,
&metaindex_iter);
if (s.ok()) {
for (meta_iter->SeekToFirst(); meta_iter->Valid(); meta_iter->Next()) {
s = meta_iter->status();
for (metaindex_iter->SeekToFirst(); metaindex_iter->Valid();
metaindex_iter->Next()) {
s = metaindex_iter->status();
if (!s.ok()) {
return s;
}
if (meta_iter->key() == rocksdb::kPropertiesBlock) {
if (metaindex_iter->key() == rocksdb::kPropertiesBlock) {
out_file->Append(" Properties block handle: ");
out_file->Append(meta_iter->value().ToString(true).c_str());
out_file->Append(metaindex_iter->value().ToString(true).c_str());
out_file->Append("\n");
} else if (meta_iter->key() == rocksdb::kCompressionDictBlock) {
} else if (metaindex_iter->key() == rocksdb::kCompressionDictBlock) {
out_file->Append(" Compression dictionary block handle: ");
out_file->Append(meta_iter->value().ToString(true).c_str());
out_file->Append(metaindex_iter->value().ToString(true).c_str());
out_file->Append("\n");
} else if (strstr(meta_iter->key().ToString().c_str(),
} else if (strstr(metaindex_iter->key().ToString().c_str(),
"filter.rocksdb.") != nullptr) {
out_file->Append(" Filter block handle: ");
out_file->Append(meta_iter->value().ToString(true).c_str());
out_file->Append(metaindex_iter->value().ToString(true).c_str());
out_file->Append("\n");
} else if (meta_iter->key() == rocksdb::kRangeDelBlock) {
} else if (metaindex_iter->key() == rocksdb::kRangeDelBlock) {
out_file->Append(" Range deletion block handle: ");
out_file->Append(meta_iter->value().ToString(true).c_str());
out_file->Append(metaindex_iter->value().ToString(true).c_str());
out_file->Append("\n");
}
}

View File

@ -413,9 +413,9 @@ class BlockBasedTable : public TableReader {
TailPrefetchStats* tail_prefetch_stats, const bool prefetch_all,
const bool preload_all,
std::unique_ptr<FilePrefetchBuffer>* prefetch_buffer);
Status ReadMetaBlock(FilePrefetchBuffer* prefetch_buffer,
std::unique_ptr<Block>* meta_block,
std::unique_ptr<InternalIterator>* iter);
Status ReadMetaIndexBlock(FilePrefetchBuffer* prefetch_buffer,
std::unique_ptr<Block>* metaindex_block,
std::unique_ptr<InternalIterator>* iter);
Status TryReadPropertiesWithGlobalSeqno(FilePrefetchBuffer* prefetch_buffer,
const Slice& handle_value,
TableProperties** table_properties);

View File

@ -42,9 +42,8 @@ class BaseDeltaIterator : public Iterator {
base_iterator_(base_iterator),
delta_iterator_(delta_iterator),
comparator_(comparator),
iterate_upper_bound_(read_options? read_options->iterate_upper_bound :
nullptr)
{}
iterate_upper_bound_(read_options ? read_options->iterate_upper_bound
: nullptr) {}
~BaseDeltaIterator() override {}
@ -284,8 +283,8 @@ class BaseDeltaIterator : public Iterator {
return;
}
if (iterate_upper_bound_) {
if (comparator_->Compare(delta_entry.key,
*iterate_upper_bound_) >= 0) {
if (comparator_->Compare(delta_entry.key, *iterate_upper_bound_) >=
0) {
// out of upper bound -> finished.
return;
}
@ -660,7 +659,7 @@ WBWIIterator* WriteBatchWithIndex::NewIterator(
Iterator* WriteBatchWithIndex::NewIteratorWithBase(
ColumnFamilyHandle* column_family, Iterator* base_iterator,
const ReadOptions *read_options) {
const ReadOptions* read_options) {
if (rep->overwrite_key == false) {
assert(false);
return nullptr;