From 8e37a29bfbc58928dc1a24f38c7e8b2714017c85 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Thu, 8 May 2014 13:48:39 -0700 Subject: [PATCH] Compaction with zero outputs Summary: We had a hypothesis in https://reviews.facebook.net/D18507 that empty-string internal keys might have been caused by compaction filter deleting all the entries. I added a unit test for that case. Unforutnately, everything works as expected. Test Plan: this is a test Reviewers: dhruba, haobo, sdong Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D18519 --- db/db_test.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/db/db_test.cc b/db/db_test.cc index 88637ef53..01153b6a1 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -3841,6 +3841,38 @@ TEST(DBTest, CompactionFilter) { delete iter; } +// Tests the edge case where compaction does not produce any output -- all +// entries are deleted. The compaction should create bunch of 'DeleteFile' +// entries in VersionEdit, but none of the 'AddFile's. +TEST(DBTest, CompactionFilterDeletesAll) { + Options options; + options.compaction_filter_factory = std::make_shared(); + options.disable_auto_compactions = true; + options.create_if_missing = true; + DestroyAndReopen(&options); + + // put some data + for (int table = 0; table < 4; ++table) { + for (int i = 0; i < 10 + table; ++i) { + Put(std::to_string(table * 100 + i), "val"); + } + Flush(); + } + + // this will produce empty file (delete compaction filter) + ASSERT_OK(db_->CompactRange(nullptr, nullptr)); + ASSERT_EQ(0, CountLiveFiles()); + + Reopen(&options); + + Iterator* itr = db_->NewIterator(ReadOptions()); + itr->SeekToFirst(); + // empty db + ASSERT_TRUE(!itr->Valid()); + + delete itr; +} + TEST(DBTest, CompactionFilterWithValueChange) { do { Options options; -- GitLab