From b0029bc7fa2348e9c897d7488d0d77304857b7b3 Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Tue, 24 Jan 2017 13:23:50 -0800 Subject: [PATCH] Test merge op covered by range deletion in memtable Summary: It's a test case for #1797. Also got rid of kTypeDeletion in the conditional since we treat it the same as kTypeRangeDeletion. Closes https://github.com/facebook/rocksdb/pull/1800 Differential Revision: D4451300 Pulled By: ajkr fbshipit-source-id: b39dda1 --- db/db_range_del_test.cc | 30 ++++++++++++++++++++++++++++++ db/memtable.cc | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/db/db_range_del_test.cc b/db/db_range_del_test.cc index cf7aa06af..d46ee2c7b 100644 --- a/db/db_range_del_test.cc +++ b/db/db_range_del_test.cc @@ -601,6 +601,36 @@ TEST_F(DBRangeDelTest, GetCoveredKeyFromSst) { db_->ReleaseSnapshot(snapshot); } +TEST_F(DBRangeDelTest, GetCoveredMergeOperandFromMemtable) { + const int kNumMergeOps = 10; + Options opts = CurrentOptions(); + opts.merge_operator = MergeOperators::CreateUInt64AddOperator(); + Reopen(opts); + + for (int i = 0; i < kNumMergeOps; ++i) { + std::string val; + PutFixed64(&val, i); + db_->Merge(WriteOptions(), "key", val); + if (i == kNumMergeOps / 2) { + // deletes [0, 5] + db_->DeleteRange(WriteOptions(), db_->DefaultColumnFamily(), "key", + "key_"); + } + } + + ReadOptions read_opts; + std::string expected, actual; + ASSERT_OK(db_->Get(read_opts, "key", &actual)); + PutFixed64(&expected, 30); // 6+7+8+9 + ASSERT_EQ(expected, actual); + + expected.clear(); + read_opts.ignore_range_deletions = true; + ASSERT_OK(db_->Get(read_opts, "key", &actual)); + PutFixed64(&expected, 45); // 0+1+2+...+9 + ASSERT_EQ(expected, actual); +} + TEST_F(DBRangeDelTest, GetIgnoresRangeDeletions) { Options opts = CurrentOptions(); opts.max_write_buffer_number = 4; diff --git a/db/memtable.cc b/db/memtable.cc index 9f939e4d3..6da600e82 100644 --- a/db/memtable.cc +++ b/db/memtable.cc @@ -560,7 +560,7 @@ static bool SaveValue(void* arg, const char* entry) { ValueType type; UnPackSequenceAndType(tag, &s->seq, &type); - if ((type == kTypeValue || type == kTypeDeletion || type == kTypeMerge) && + if ((type == kTypeValue || type == kTypeMerge) && range_del_agg->ShouldDelete(Slice(key_ptr, key_length))) { type = kTypeRangeDeletion; }