PlainTable::Next() should pass the error message from ReadKey()

Summary:
PlainTable::Next() should pass the error message from ReadKey(). Now it would return a wrong error message.
Also improve the messages of status when failing to read

Test Plan: make all check

Reviewers: ljin, kailiu, haobo

Reviewed By: kailiu

CC: leveldb

Differential Revision: https://reviews.facebook.net/D16365
main
sdong 11 years ago
parent ccaedd16d4
commit a04dbf6e49
  1. 19
      table/plain_table_reader.cc

@ -527,13 +527,14 @@ Status PlainTableReader::ReadKey(const char* start, ParsedInternalKey* key,
key_ptr = key_ptr =
GetVarint32Ptr(start, file_data_.data() + data_end_offset_, &tmp_size); GetVarint32Ptr(start, file_data_.data() + data_end_offset_, &tmp_size);
if (key_ptr == nullptr) { if (key_ptr == nullptr) {
return Status::Corruption("Unable to read the next key"); return Status::Corruption(
"Unexpected EOF when reading the next key's size");
} }
user_key_size = (size_t)tmp_size; user_key_size = (size_t)tmp_size;
*bytes_read = key_ptr - start; *bytes_read = key_ptr - start;
} }
if (key_ptr + user_key_size + 1 >= file_data_.data() + data_end_offset_) { if (key_ptr + user_key_size + 1 >= file_data_.data() + data_end_offset_) {
return Status::Corruption("Unable to read the next key"); return Status::Corruption("Unexpected EOF when reading the next key");
} }
if (*(key_ptr + user_key_size) == PlainTableFactory::kValueTypeSeqId0) { if (*(key_ptr + user_key_size) == PlainTableFactory::kValueTypeSeqId0) {
@ -544,10 +545,12 @@ Status PlainTableReader::ReadKey(const char* start, ParsedInternalKey* key,
*bytes_read += user_key_size + 1; *bytes_read += user_key_size + 1;
} else { } else {
if (start + user_key_size + 8 >= file_data_.data() + data_end_offset_) { if (start + user_key_size + 8 >= file_data_.data() + data_end_offset_) {
return Status::Corruption("Unable to read the next key"); return Status::Corruption(
"Unexpected EOF when reading internal bytes of the next key");
} }
if (!ParseInternalKey(Slice(key_ptr, user_key_size + 8), key)) { if (!ParseInternalKey(Slice(key_ptr, user_key_size + 8), key)) {
return Status::Corruption(Slice()); return Status::Corruption(
Slice("Incorrect value type found when reading the next key"));
} }
*bytes_read += user_key_size + 8; *bytes_read += user_key_size + 8;
} }
@ -569,15 +572,19 @@ Status PlainTableReader::Next(uint32_t* offset, ParsedInternalKey* key,
const char* start = file_data_.data() + *offset; const char* start = file_data_.data() + *offset;
size_t bytes_for_key; size_t bytes_for_key;
Status s = ReadKey(start, key, &bytes_for_key); Status s = ReadKey(start, key, &bytes_for_key);
if (!s.ok()) {
return s;
}
uint32_t value_size; uint32_t value_size;
const char* value_ptr = GetVarint32Ptr( const char* value_ptr = GetVarint32Ptr(
start + bytes_for_key, file_data_.data() + data_end_offset_, &value_size); start + bytes_for_key, file_data_.data() + data_end_offset_, &value_size);
if (value_ptr == nullptr) { if (value_ptr == nullptr) {
return Status::Corruption("Error reading value length."); return Status::Corruption(
"Unexpected EOF when reading the next value's size.");
} }
*offset = *offset + (value_ptr - start) + value_size; *offset = *offset + (value_ptr - start) + value_size;
if (*offset > data_end_offset_) { if (*offset > data_end_offset_) {
return Status::Corruption("Reach end of file when reading value"); return Status::Corruption("Unexpected EOF when reading the next value. ");
} }
*value = Slice(value_ptr, value_size); *value = Slice(value_ptr, value_size);

Loading…
Cancel
Save