You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pegasus.apache.org by GitBox <gi...@apache.org> on 2021/05/31 08:56:23 UTC
[GitHub] [incubator-pegasus] acelyc111 commented on a change in pull request #741: feat: add hashkey pattern rule
acelyc111 commented on a change in pull request #741:
URL: https://github.com/apache/incubator-pegasus/pull/741#discussion_r642326764
##########
File path: src/server/compaction_filter_rule.cpp
##########
@@ -0,0 +1,62 @@
+/*
+ * 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_filter_rule.h"
+
+#include <dsn/dist/fmt_logging.h>
+#include <dsn/utility/string_view.h>
+#include <dsn/c/api_utilities.h>
+
+namespace pegasus {
+namespace server {
+bool string_pattern_match(const std::string &value,
+ string_match_type type,
+ const std::string &filter_pattern)
+{
+ if (filter_pattern.length() == 0)
+ return false;
+ if (value.length() < filter_pattern.length())
+ return false;
Review comment:
```suggestion
if (filter_pattern.empty()) {
return false;
}
if (value.length() < filter_pattern.length()) {
return false;
}
```
##########
File path: src/server/compaction_filter_rule.cpp
##########
@@ -0,0 +1,62 @@
+/*
+ * 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_filter_rule.h"
+
+#include <dsn/dist/fmt_logging.h>
+#include <dsn/utility/string_view.h>
+#include <dsn/c/api_utilities.h>
+
+namespace pegasus {
+namespace server {
+bool string_pattern_match(const std::string &value,
+ string_match_type type,
+ const std::string &filter_pattern)
+{
+ if (filter_pattern.length() == 0)
+ return false;
+ if (value.length() < filter_pattern.length())
+ return false;
Review comment:
UT doesn't cover this case.
##########
File path: src/server/compaction_filter_rule.cpp
##########
@@ -0,0 +1,62 @@
+/*
+ * 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_filter_rule.h"
+
+#include <dsn/dist/fmt_logging.h>
+#include <dsn/utility/string_view.h>
+#include <dsn/c/api_utilities.h>
+
+namespace pegasus {
+namespace server {
+bool string_pattern_match(const std::string &value,
+ string_match_type type,
+ const std::string &filter_pattern)
+{
+ if (filter_pattern.length() == 0)
+ return false;
+ if (value.length() < filter_pattern.length())
+ return false;
+
+ switch (type) {
+ case string_match_type::SMT_MATCH_ANYWHERE:
+ return dsn::string_view(value).find(filter_pattern) != dsn::string_view::npos;
+ case string_match_type::SMT_MATCH_PREFIX:
+ return memcmp(value.data(), filter_pattern.data(), filter_pattern.length()) == 0;
+ case string_match_type::SMT_MATCH_POSTFIX:
+ return memcmp(value.data() + value.length() - filter_pattern.length(),
+ filter_pattern.data(),
+ filter_pattern.length()) == 0;
+ default:
+ derror_f("invalid match type {}", type);
Review comment:
UT doesn't cover this case.
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org