diff --git a/db/db_test.cc b/db/db_test.cc index 21ba736be..d2f455c15 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -12270,6 +12270,17 @@ TEST_F(DBTest, TestLogCleanup) { } } +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) { diff --git a/utilities/compacted_db/compacted_db_impl.cc b/utilities/compacted_db/compacted_db_impl.cc index 102e35728..55bcbca8a 100644 --- a/utilities/compacted_db/compacted_db_impl.cc +++ b/utilities/compacted_db/compacted_db_impl.cc @@ -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) {