Fix db_bench

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
main
Stanislau Hlebik 11 years ago
parent 80a94d0517
commit c1a90b0848
  1. 11
      table/plain_table_index.cc
  2. 2
      table/plain_table_index.h
  3. 9
      table/plain_table_reader.cc

@ -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(

@ -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 {

@ -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,
@ -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) {

Loading…
Cancel
Save