diff --git a/HISTORY.md b/HISTORY.md index f7249818e..bcccc546c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -10,6 +10,9 @@ ### New Features * Marked the Ribbon filter and optimize_filters_for_memory features as production-ready, each enabling memory savings for Bloom-like filters. Use `NewRibbonFilterPolicy` in place of `NewBloomFilterPolicy` to use Ribbon filters instead of Bloom, or `ribbonfilter` in place of `bloomfilter` in configuration string. +### New Features +* Allow `DBWithTTL` to use `DeleteRange` api just like other DBs. `DeleteRangeCF()` which executes `WriteBatchInternal::DeleteRange()` has been added to the handler in `DBWithTTLImpl::Write()` to implement it. + ## 6.21.0 (2021-05-21) ### Bug Fixes * Fixed a bug in handling file rename error in distributed/network file systems when the server succeeds but client returns error. The bug can cause CURRENT file to point to non-existing MANIFEST file, thus DB cannot be opened. diff --git a/utilities/ttl/db_ttl_impl.cc b/utilities/ttl/db_ttl_impl.cc index 0463025f8..917130ca1 100644 --- a/utilities/ttl/db_ttl_impl.cc +++ b/utilities/ttl/db_ttl_impl.cc @@ -304,6 +304,11 @@ Status DBWithTTLImpl::Write(const WriteOptions& opts, WriteBatch* updates) { Status DeleteCF(uint32_t column_family_id, const Slice& key) override { return WriteBatchInternal::Delete(&updates_ttl, column_family_id, key); } + Status DeleteRangeCF(uint32_t column_family_id, const Slice& begin_key, + const Slice& end_key) override { + return WriteBatchInternal::DeleteRange(&updates_ttl, column_family_id, + begin_key, end_key); + } void LogData(const Slice& blob) override { updates_ttl.PutLogData(blob); } private: diff --git a/utilities/ttl/ttl_test.cc b/utilities/ttl/ttl_test.cc index 099ed6859..8e60fbc76 100644 --- a/utilities/ttl/ttl_test.cc +++ b/utilities/ttl/ttl_test.cc @@ -186,6 +186,18 @@ class TtlTest : public testing::Test { } } + // Runs a DeleteRange + void MakeDeleteRange(std::string start, std::string end, + ColumnFamilyHandle* cf = nullptr) { + ASSERT_TRUE(db_ttl_); + static WriteOptions wops; + WriteBatch wb; + ASSERT_OK(cf == nullptr + ? wb.DeleteRange(db_ttl_->DefaultColumnFamily(), start, end) + : wb.DeleteRange(cf, start, end)); + ASSERT_OK(db_ttl_->Write(wops, &wb)); + } + // checks the whole kvmap_ to return correct values using KeyMayExist void SimpleKeyMayExistCheck() { static ReadOptions ropts; @@ -684,6 +696,29 @@ TEST_F(TtlTest, ChangeTtlOnOpenDb) { CloseTtl(); } +// Test DeleteRange for DBWithTtl +TEST_F(TtlTest, DeleteRangeTest) { + OpenTtl(); + ASSERT_OK(db_ttl_->Put(WriteOptions(), "a", "val")); + MakeDeleteRange("a", "b"); + ASSERT_OK(db_ttl_->Put(WriteOptions(), "c", "val")); + MakeDeleteRange("b", "d"); + ASSERT_OK(db_ttl_->Put(WriteOptions(), "e", "val")); + MakeDeleteRange("d", "e"); + // first iteration verifies query correctness in memtable, second verifies + // query correctness for a single SST file + for (int i = 0; i < 2; i++) { + if (i > 0) { + ASSERT_OK(db_ttl_->Flush(FlushOptions())); + } + std::string value; + ASSERT_TRUE(db_ttl_->Get(ReadOptions(), "a", &value).IsNotFound()); + ASSERT_TRUE(db_ttl_->Get(ReadOptions(), "c", &value).IsNotFound()); + ASSERT_OK(db_ttl_->Get(ReadOptions(), "e", &value)); + } + CloseTtl(); +} + } // namespace ROCKSDB_NAMESPACE // A black-box test for the ttl wrapper around rocksdb