You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by GitBox <gi...@apache.org> on 2021/05/07 19:36:26 UTC

[GitHub] [trafficserver] traeak commented on a change in pull request #6455: regex_revalidate c++, lifecycle messages, MISS support

traeak commented on a change in pull request #6455:
URL: https://github.com/apache/trafficserver/pull/6455#discussion_r628462980



##########
File path: plugins/regex_revalidate/regex_revalidate.cc
##########
@@ -0,0 +1,754 @@
+/** @file
+
+  ATS plugin to do (simple) regular expression remap rules
+
+  @section license License
+
+  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 "ts/ts.h"
+#include "ts/remap.h"
+#include "ts/experimental.h"
+#include "regex.h"
+
+#include <cinttypes>
+#include <cstring>
+#include <ctime>
+#include <getopt.h>
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <algorithm>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <set>
+#include <string>
+#include <string_view>
+#include <vector>
+
+#ifdef HAVE_PCRE_PCRE_H
+#include <pcre/pcre.h>
+#else
+#include <pcre.h>
+#endif
+
+namespace
+{
+constexpr char const *const PLUGIN_NAME = "regex_revalidate";
+constexpr char const *const RELOAD_TAG  = "config_reload";
+constexpr char const *const PRINT_TAG   = "config_print";
+
+constexpr char const *const RESULT_MISS  = "MISS";
+constexpr char const *const RESULT_STALE = "STALE";
+
+#define DEBUG_LOG(fmt, ...) TSDebug(PLUGIN_NAME, "%s:%d " fmt, __func__, __LINE__, ##__VA_ARGS__)
+
+#define ERROR_LOG(fmt, ...)                         \
+  TSError("(%s) " fmt, PLUGIN_NAME, ##__VA_ARGS__); \
+  DEBUG_LOG(fmt, ##__VA_ARGS__)
+
+constexpr TSHRTime const CONFIG_TMOUT = 60000; // ms, 60s
+constexpr int const OVECTOR_SIZE      = 30;
+constexpr int const LOG_ROLL_INTERVAL = 86400;
+constexpr int const LOG_ROLL_OFFSET   = 0;
+
+TSCont config_cont{nullptr};
+
+struct Invalidate {
+  static Regex config_re;
+
+  std::string regex_text{};
+  Regex regex{};
+  time_t epoch{0};
+  time_t expiry{0};
+  TSCacheLookupResult new_result{TS_CACHE_LOOKUP_HIT_STALE};
+
+  Invalidate() = default;
+
+  Invalidate(Invalidate const &orig)
+  {
+    regex_text = orig.regex_text;
+    regex.compile(regex_text.c_str());
+    epoch      = orig.epoch;
+    expiry     = orig.expiry;
+    new_result = orig.new_result;
+  }
+
+  Invalidate(Invalidate &&orig)
+  {
+    std::swap(regex_text, orig.regex_text);
+    std::swap(regex, orig.regex);
+    std::swap(epoch, orig.epoch);
+    std::swap(expiry, orig.expiry);
+    std::swap(new_result, orig.new_result);
+  }
+
+  Invalidate &
+  operator=(Invalidate &&rhs)
+  {
+    if (&rhs != this) {
+      std::swap(regex_text, rhs.regex_text);
+      std::swap(regex, rhs.regex);
+      std::swap(epoch, rhs.epoch);
+      std::swap(expiry, rhs.expiry);
+      std::swap(new_result, rhs.new_result);
+    }
+    return *this;
+  }
+
+  Invalidate &
+  operator=(Invalidate const &rhs)
+  {
+    if (&rhs != this) {
+      regex_text = rhs.regex_text;
+      regex.compile(regex_text.c_str());
+      epoch      = rhs.epoch;
+      expiry     = rhs.expiry;
+      new_result = rhs.new_result;

Review comment:
       thanks

##########
File path: plugins/regex_revalidate/regex_revalidate.cc
##########
@@ -0,0 +1,754 @@
+/** @file
+
+  ATS plugin to do (simple) regular expression remap rules
+
+  @section license License
+
+  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 "ts/ts.h"
+#include "ts/remap.h"
+#include "ts/experimental.h"
+#include "regex.h"
+
+#include <cinttypes>
+#include <cstring>
+#include <ctime>
+#include <getopt.h>
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <algorithm>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <set>
+#include <string>
+#include <string_view>
+#include <vector>
+
+#ifdef HAVE_PCRE_PCRE_H
+#include <pcre/pcre.h>
+#else
+#include <pcre.h>
+#endif
+
+namespace
+{
+constexpr char const *const PLUGIN_NAME = "regex_revalidate";
+constexpr char const *const RELOAD_TAG  = "config_reload";
+constexpr char const *const PRINT_TAG   = "config_print";
+
+constexpr char const *const RESULT_MISS  = "MISS";
+constexpr char const *const RESULT_STALE = "STALE";
+
+#define DEBUG_LOG(fmt, ...) TSDebug(PLUGIN_NAME, "%s:%d " fmt, __func__, __LINE__, ##__VA_ARGS__)
+
+#define ERROR_LOG(fmt, ...)                         \
+  TSError("(%s) " fmt, PLUGIN_NAME, ##__VA_ARGS__); \
+  DEBUG_LOG(fmt, ##__VA_ARGS__)
+
+constexpr TSHRTime const CONFIG_TMOUT = 60000; // ms, 60s
+constexpr int const OVECTOR_SIZE      = 30;
+constexpr int const LOG_ROLL_INTERVAL = 86400;
+constexpr int const LOG_ROLL_OFFSET   = 0;
+
+TSCont config_cont{nullptr};
+
+struct Invalidate {
+  static Regex config_re;
+
+  std::string regex_text{};
+  Regex regex{};
+  time_t epoch{0};
+  time_t expiry{0};
+  TSCacheLookupResult new_result{TS_CACHE_LOOKUP_HIT_STALE};
+
+  Invalidate() = default;
+
+  Invalidate(Invalidate const &orig)
+  {
+    regex_text = orig.regex_text;
+    regex.compile(regex_text.c_str());
+    epoch      = orig.epoch;
+    expiry     = orig.expiry;
+    new_result = orig.new_result;
+  }
+
+  Invalidate(Invalidate &&orig)
+  {
+    std::swap(regex_text, orig.regex_text);
+    std::swap(regex, orig.regex);
+    std::swap(epoch, orig.epoch);
+    std::swap(expiry, orig.expiry);
+    std::swap(new_result, orig.new_result);
+  }
+
+  Invalidate &
+  operator=(Invalidate &&rhs)
+  {
+    if (&rhs != this) {
+      std::swap(regex_text, rhs.regex_text);
+      std::swap(regex, rhs.regex);
+      std::swap(epoch, rhs.epoch);
+      std::swap(expiry, rhs.expiry);
+      std::swap(new_result, rhs.new_result);

Review comment:
       tahnks




-- 
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