Skip to content

Commit

Permalink
Fix db_bench
Browse files Browse the repository at this point in the history
Summary: Adding check for zero size index

Test Plan: ./build_tools/regression_build_test.sh

Reviewers: yhchiang, sdong

Reviewed By: sdong

Subscribers: leveldb

Differential Revision: https://reviews.facebook.net/D20259
  • Loading branch information
StanislavGlebik committed Jul 21, 2014
1 parent 80a94d0 commit c1a90b0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
11 changes: 8 additions & 3 deletions table/plain_table_index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ inline uint32_t GetBucketIdFromHash(uint32_t hash, uint32_t num_buckets) {
}
}

void PlainTableIndex::InitFromRawData(Slice data) {
assert(GetVarint32(&data, &index_size_));
Status PlainTableIndex::InitFromRawData(Slice data) {
if (!GetVarint32(&data, &index_size_)) {
return Status::Corruption("Couldn't read the index size!");
}
assert(index_size_ > 0);
assert(GetVarint32(&data, &num_prefixes_));
if (!GetVarint32(&data, &num_prefixes_)) {
return Status::Corruption("Couldn't read the index size!");
}
sub_index_size_ = data.size() - index_size_ * kOffsetLen;

char* index_data_begin = const_cast<char*>(data.data());
index_ = reinterpret_cast<uint32_t*>(index_data_begin);
sub_index_ = reinterpret_cast<char*>(index_ + index_size_);
return Status::OK();
}

PlainTableIndex::IndexSearchResult PlainTableIndex::GetOffset(
Expand Down
2 changes: 1 addition & 1 deletion table/plain_table_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class PlainTableIndex {
IndexSearchResult GetOffset(uint32_t prefix_hash,
uint32_t* bucket_value) const;

void InitFromRawData(Slice data);
Status InitFromRawData(Slice data);

const char* GetSubIndexBasePtrAndUpperBound(uint32_t offset,
uint32_t* upper_bound) const {
Expand Down
9 changes: 6 additions & 3 deletions table/plain_table_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ Status PlainTableReader::PopulateIndexRecordList(
}

prefix_hashes->push_back(GetSliceHash(key_prefix_slice));
index_.InitFromRawData(index_builder->Finish());
return Status::OK();
auto s = index_.InitFromRawData(index_builder->Finish());
return s;
}

void PlainTableReader::AllocateAndFillBloom(int bloom_bits_per_key,
Expand Down Expand Up @@ -357,7 +357,10 @@ Status PlainTableReader::PopulateIndex(TableProperties* props,
return s;
}
} else {
index_.InitFromRawData(*index_block);
Status s = index_.InitFromRawData(*index_block);
if (!s.ok()) {
return s;
}
}

if (!index_in_file) {
Expand Down

0 comments on commit c1a90b0

Please sign in to comment.