qinzuoyan commented on a change in pull request #688:
URL: https://github.com/apache/incubator-pegasus/pull/688#discussion_r566785486
##########
File path: src/server/key_ttl_compaction_filter.h
##########
@@ -23,12 +23,38 @@
#include <atomic>
#include <rocksdb/compaction_filter.h>
#include <rocksdb/merge_operator.h>
+#include <base/pegasus_key_schema.h>
#include "base/pegasus_utils.h"
#include "base/pegasus_value_schema.h"
namespace pegasus {
namespace server {
+inline bool need_clean_key(const rocksdb::Slice &key, uint32_t expire_ts,
uint32_t now_ts)
+{
+ std::vector<std::string> cleaned_hash_key_prefix = {"raw_tts_audio:",
"stored_tts_url_info:"};
Review comment:
每次调用need_clean_key都要构造一次vector
##########
File path: src/server/key_ttl_compaction_filter.h
##########
@@ -58,7 +84,13 @@ class KeyWithTTLCompactionFilter : public
rocksdb::CompactionFilter
*value_changed = true;
return false;
}
- return check_if_ts_expired(utils::epoch_now(), expire_ts);
+
+ uint32_t now_ts = utils::epoch_now();
+ if (check_if_ts_expired(now_ts, expire_ts)) {
+ return true;
+ }
+
+ return need_clean_key(key, expire_ts, now_ts);
Review comment:
实际上我只需要对一个表做这个清理数据操作,有没有办法获取到表ID,只对这个表ID执行这个函数?
##########
File path: src/server/test/key_ttl_compaction_filter_test.cpp
##########
@@ -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.
+ */
+
+#include <gtest/gtest.h>
+#include "server/key_ttl_compaction_filter.h"
+
+namespace pegasus {
+namespace server {
+
+TEST(key_ttl_compaction_filter_test, need_clean_key)
+{
+ int32_t oneday_sec = 24 * 60 * 60;
+
+ struct
+ {
+ std::string hash_key;
+ int32_t expire_sec_from_now;
+ bool need_clean;
+ } tests[] = {{"raw_tts_audio:", 100, false},
+ {"raw_tts_audio:xxx", 100, false},
+ {"raw_tts_audio:xxx", 3 * oneday_sec - 1, false},
+ {"raw_tts_audio:xxx", 3 * oneday_sec, true},
+ {"raw_tts_audio", 4 * oneday_sec, false},
+ {"stored_tts_url_info:", 100, false},
+ {"stored_tts_url_info:xxx", 100, false},
+ {"stored_tts_url_info:xxx", 3 * oneday_sec - 1, false},
+ {"stored_tts_url_info:xxx", 3 * oneday_sec, true},
+ {"stored_tts_url_info", 4 * oneday_sec, false},
+ {"donot_clean_key", 100, false},
+ {"donot_clean_key", 4 * oneday_sec, false}};
Review comment:
没有测试到 tts = 0 的场景
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]