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

laiyingchun 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 376dfc8  feat: add base classes for user-specified compaction (#731)
376dfc8 is described below

commit 376dfc88215e3654ec0ed7c61d9e18bfc7d597f4
Author: zhao liwei <[email protected]>
AuthorDate: Fri May 28 16:08:12 2021 +0800

    feat: add base classes for user-specified compaction (#731)
---
 src/server/compaction_filter_rule.h | 40 +++++++++++++++++++++++++
 src/server/compaction_operation.cpp | 43 ++++++++++++++++++++++++++
 src/server/compaction_operation.h   | 60 +++++++++++++++++++++++++++++++++++++
 3 files changed, 143 insertions(+)

diff --git a/src/server/compaction_filter_rule.h 
b/src/server/compaction_filter_rule.h
new file mode 100644
index 0000000..2c18209
--- /dev/null
+++ b/src/server/compaction_filter_rule.h
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <rocksdb/slice.h>
+
+namespace pegasus {
+namespace server {
+/** compaction_filter_rule represents the compaction rule to filter the keys 
which are stored in
+ * rocksdb. */
+class compaction_filter_rule
+{
+public:
+    virtual ~compaction_filter_rule() = default;
+
+    // TODO(zhaoliwei): we can use `value_filed` to replace existing_value in 
the later,
+    // after the refactor of value schema
+    virtual bool match(const std::string &hash_key,
+                       const std::string &sort_key,
+                       const rocksdb::Slice &existing_value) const = 0;
+};
+} // namespace server
+} // namespace pegasus
diff --git a/src/server/compaction_operation.cpp 
b/src/server/compaction_operation.cpp
new file mode 100644
index 0000000..5db9ade
--- /dev/null
+++ b/src/server/compaction_operation.cpp
@@ -0,0 +1,43 @@
+/*
+ * 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 "compaction_operation.h"
+
+namespace pegasus {
+namespace server {
+compaction_operation::~compaction_operation() = default;
+
+bool compaction_operation::all_rules_match(const std::string &hash_key,
+                                           const std::string &sort_key,
+                                           const rocksdb::Slice 
&existing_value) const
+{
+    if (rules.empty()) {
+        return false;
+    }
+
+    for (const auto &rule : rules) {
+        if (!rule->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
new file mode 100644
index 0000000..7c44c59
--- /dev/null
+++ b/src/server/compaction_operation.h
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <memory>
+#include <vector>
+#include "compaction_filter_rule.h"
+
+namespace pegasus {
+namespace server {
+
+typedef std::vector<std::unique_ptr<compaction_filter_rule>> filter_rules;
+/** compaction_operation represents the compaction operation. A compaction 
operation will be
+ * executed when all the corresponding compaction rules are matched. */
+class compaction_operation
+{
+public:
+    compaction_operation(filter_rules &&rules, uint32_t pegasus_data_version)
+        : rules(std::move(rules)), pegasus_data_version(pegasus_data_version)
+    {
+    }
+    virtual ~compaction_operation() = 0;
+
+    bool all_rules_match(const std::string &hash_key,
+                         const std::string &sort_key,
+                         const rocksdb::Slice &existing_value) const;
+    /**
+     * @return false indicates that this key-value should be removed
+     * If you want to modify the existing_value, you can pass it back through 
new_value and
+     * value_changed needs to be set to true in this case.
+     */
+    virtual 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 = 0;
+
+protected:
+    filter_rules rules;
+    uint32_t pegasus_data_version;
+};
+} // namespace server
+} // namespace pegasus

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to