]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Fix crash caused by opening an empty DB in readonly mode
authorVenkatesh Radhakrishnan <rven@fb.com>
Wed, 1 Apr 2015 23:55:08 +0000 (16:55 -0700)
committerVenkatesh Radhakrishnan <rven@fb.com>
Fri, 3 Apr 2015 18:05:19 +0000 (11:05 -0700)
Summary:
This diff fixes a crash found when an empty database is opened in readonly mode.
We now check the number of levels before we open the DB as a compacted DB.

Test Plan: DBTest.EmptyCompactedDB

Reviewers: igor, sdong

Reviewed By: sdong

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D36327

Conflicts:
db/db_test.cc

db/db_test.cc
utilities/compacted_db/compacted_db_impl.cc

index 57558dbf687b596fde4d0a45655dc8d51aa9152c..a27511cf53c81e10622ee613f8718dd57f1a7690 100644 (file)
@@ -11952,6 +11952,17 @@ TEST_F(DBTest, FilterCompactionTimeTest) {
   delete itr;
 }
 
+TEST_F(DBTest, EmptyCompactedDB) {
+  Options options;
+  options.max_open_files = -1;
+  options = CurrentOptions(options);
+  Close();
+  ASSERT_OK(ReadOnlyReopen(options));
+  Status s = Put("new", "value");
+  ASSERT_TRUE(s.IsNotSupported());
+  Close();
+}
+
 }  // namespace rocksdb
 
 int main(int argc, char** argv) {
index 102e357283980a8782336e6fdef32ad992b8bb25..55bcbca8a7412b273c98b6c0d3e628a80b9972e1 100644 (file)
@@ -107,6 +107,9 @@ Status CompactedDBImpl::Init(const Options& options) {
   version_ = cfd_->GetSuperVersion()->current;
   user_comparator_ = cfd_->user_comparator();
   auto* vstorage = version_->storage_info();
+  if (vstorage->num_non_empty_levels() == 0) {
+    return Status::NotSupported("no file exists");
+  }
   const LevelFilesBrief& l0 = vstorage->LevelFilesBrief(0);
   // L0 should not have files
   if (l0.num_files > 1) {