[Rocksdb] Fix Crash on finding a db with no log files. Error out instead

Summary:
If the vector returned by GetUpdatesSince is empty, it is still returned to the
user. This causes it throw an std::range error.
The probable file list is checked and it returns an IOError status instead of OK now.

Test Plan: added a unit test.

Reviewers: dhruba, heyongqiang

Reviewed By: heyongqiang

CC: leveldb

Differential Revision: https://reviews.facebook.net/D9771
main
Abhishek Kona 12 years ago
parent 7fdd5f5b33
commit 8e9c781ae5
  1. 4
      db/db_impl.cc
  2. 7
      db/db_test.cc

@ -956,6 +956,10 @@ Status DBImpl::FindProbableWALFiles(std::vector<LogFile>* const allLogs,
for( size_t i = startIndex; i < allLogs->size(); ++i) {
result->push_back(allLogs->at(i));
}
if (result->empty()) {
return Status::IOError(
"No probable files. Check if the db contains log files");
}
return Status::OK();
}

@ -2681,6 +2681,13 @@ TEST(DBTest, TransactionLogIteratorStallAtLastRecord) {
ASSERT_TRUE(iter->Valid());
}
TEST(DBTest, TransactionLogIteratorJustEmptyFile) {
Options options = OptionsForLogIterTest();
DestroyAndReopen(&options);
unique_ptr<TransactionLogIterator> iter;
Status status = dbfull()->GetUpdatesSince(0, &iter);
ASSERT_TRUE(!status.ok());
}
TEST(DBTest, ReadCompaction) {
std::string value(4096, '4'); // a string of size 4K
{

Loading…
Cancel
Save