You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pegasus.apache.org by zh...@apache.org on 2021/06/08 08:03:54 UTC

[incubator-pegasus] branch master updated: feat: add delete key compact operation (#751)

This is an automated email from the ASF dual-hosted git repository.

zhaoliwei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new d7ee8bd  feat: add delete key compact operation (#751)
d7ee8bd is described below

commit d7ee8bda9af82cba6ecbf9e3f1c9cfd6515bfb5c
Author: zhao liwei <zl...@163.com>
AuthorDate: Tue Jun 8 16:03:47 2021 +0800

    feat: add delete key compact operation (#751)
---
 src/server/compaction_filter_rule.h           |  1 +
 src/server/compaction_operation.cpp           | 16 ++++++++
 src/server/compaction_operation.h             | 15 ++++++++
 src/server/test/CMakeLists.txt                |  1 +
 src/server/test/compaction_operation_test.cpp | 55 +++++++++++++++++++++++++++
 5 files changed, 88 insertions(+)

diff --git a/src/server/compaction_filter_rule.h b/src/server/compaction_filter_rule.h
index 165b4c6..8927839 100644
--- a/src/server/compaction_filter_rule.h
+++ b/src/server/compaction_filter_rule.h
@@ -66,6 +66,7 @@ private:
     string_match_type match_type;
 
     FRIEND_TEST(hashkey_pattern_rule_test, match);
+    FRIEND_TEST(delete_key_test, filter);
 };
 
 class sortkey_pattern_rule : public compaction_filter_rule
diff --git a/src/server/compaction_operation.cpp b/src/server/compaction_operation.cpp
index 5db9ade..bb86e0c 100644
--- a/src/server/compaction_operation.cpp
+++ b/src/server/compaction_operation.cpp
@@ -39,5 +39,21 @@ bool compaction_operation::all_rules_match(const std::string &hash_key,
     return true;
 }
 
+delete_key::delete_key(filter_rules &&rules, uint32_t pegasus_data_version)
+    : compaction_operation(std::move(rules), pegasus_data_version)
+{
+}
+
+bool delete_key::filter(const std::string &hash_key,
+                        const std::string &sort_key,
+                        const rocksdb::Slice &existing_value,
+                        std::string *new_value,
+                        bool *value_changed) const
+{
+    if (!all_rules_match(hash_key, sort_key, existing_value)) {
+        return false;
+    }
+    return true;
+}
 } // namespace server
 } // namespace pegasus
diff --git a/src/server/compaction_operation.h b/src/server/compaction_operation.h
index 7c44c59..a4e6305 100644
--- a/src/server/compaction_operation.h
+++ b/src/server/compaction_operation.h
@@ -56,5 +56,20 @@ protected:
     filter_rules rules;
     uint32_t pegasus_data_version;
 };
+
+class delete_key : public compaction_operation
+{
+public:
+    delete_key(filter_rules &&rules, uint32_t pegasus_data_version);
+
+    bool filter(const std::string &hash_key,
+                const std::string &sort_key,
+                const rocksdb::Slice &existing_value,
+                std::string *new_value,
+                bool *value_changed) const;
+
+private:
+    FRIEND_TEST(delete_key_test, filter);
+};
 } // namespace server
 } // namespace pegasus
diff --git a/src/server/test/CMakeLists.txt b/src/server/test/CMakeLists.txt
index 1beddd4..ec68275 100644
--- a/src/server/test/CMakeLists.txt
+++ b/src/server/test/CMakeLists.txt
@@ -30,6 +30,7 @@ set(MY_PROJ_SRC "../pegasus_server_impl.cpp"
                 "../hotkey_collector.cpp"
                 "../rocksdb_wrapper.cpp"
                 "../compaction_filter_rule.cpp"
+                "../compaction_operation.cpp"
         )
 
 set(MY_SRC_SEARCH_MODE "GLOB")
diff --git a/src/server/test/compaction_operation_test.cpp b/src/server/test/compaction_operation_test.cpp
new file mode 100644
index 0000000..b7140aa
--- /dev/null
+++ b/src/server/test/compaction_operation_test.cpp
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <gtest/gtest.h>
+#include "server/compaction_operation.h"
+#include "server/compaction_filter_rule.h"
+#include <dsn/utility/smart_pointers.h>
+
+namespace pegasus {
+namespace server {
+
+TEST(delete_key_test, filter)
+{
+    struct test_case
+    {
+        bool filter;
+        std::string hashkey;
+        // hashkey_rule
+        std::string hashkey_pattern;
+        string_match_type hashkey_match_type;
+    } tests[] = {
+        {true, "hashkey", "hashkey", SMT_MATCH_ANYWHERE},
+        {false, "hashkey", "hashkey111", SMT_MATCH_ANYWHERE},
+    };
+
+    uint32_t data_version = 1;
+    filter_rules rules;
+    rules.push_back(dsn::make_unique<hashkey_pattern_rule>());
+    delete_key delete_operation(std::move(rules), data_version);
+    for (const auto &test : tests) {
+        auto hash_rule = static_cast<hashkey_pattern_rule *>(delete_operation.rules.begin()->get());
+        hash_rule->pattern = test.hashkey_pattern;
+        hash_rule->match_type = test.hashkey_match_type;
+        ASSERT_EQ(test.filter,
+                  delete_operation.filter(test.hashkey, "", rocksdb::Slice(), nullptr, nullptr));
+    }
+}
+} // namespace server
+} // namespace pegasus

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pegasus.apache.org
For additional commands, e-mail: commits-help@pegasus.apache.org