You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2022/03/10 00:12:26 UTC

[trafficserver] branch 9.2.x updated: Port #7837 from core strategy to plugin (#8573)

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

zwoop pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/9.2.x by this push:
     new 3127f3e  Port #7837 from core strategy to plugin (#8573)
3127f3e is described below

commit 3127f3e9c28a1764eee8e08477e5a4086d341e1a
Author: Robert O Butts <ro...@users.noreply.github.com>
AuthorDate: Wed Jan 5 11:43:03 2022 -0700

    Port #7837 from core strategy to plugin (#8573)
    
    Ports #7837 from core strategies to parent_select plugin.
    
    Adds unavailable_server_retries and markdown to strategies.
    
    (cherry picked from commit cc117d2c07b5d73df720345b98899f6967dd1942)
---
 plugins/experimental/parent_select/strategy.cc | 31 ++++++++++++++++++++++----
 plugins/experimental/parent_select/strategy.h  | 17 ++++++++------
 2 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/plugins/experimental/parent_select/strategy.cc b/plugins/experimental/parent_select/strategy.cc
index 4816acd..a8991a2 100644
--- a/plugins/experimental/parent_select/strategy.cc
+++ b/plugins/experimental/parent_select/strategy.cc
@@ -130,6 +130,10 @@ PLNextHopSelectionStrategy::Init(const YAML::Node &n)
         max_simple_retries = failover_node["max_simple_retries"].as<int>();
       }
 
+      if (failover_node["max_unavailable_retries"]) {
+        max_unavailable_retries = failover_node["max_unavailable_retries"].as<int>();
+      }
+
       YAML::Node resp_codes_node;
       // connection failures are always failure and retryable (pending retries)
       resp_codes.add(STATUS_CONNECTION_FAILURE);
@@ -150,6 +154,24 @@ PLNextHopSelectionStrategy::Init(const YAML::Node &n)
           resp_codes.sort();
         }
       }
+      YAML::Node markdown_codes_node;
+      if (failover_node["markdown_codes"]) {
+        markdown_codes_node = failover_node["markdown_codes"];
+        if (markdown_codes_node.Type() != YAML::NodeType::Sequence) {
+          PL_NH_Error("Error in the markdown_codes definition for the strategy named '%s', skipping markdown_codes.",
+                      strategy_name.c_str());
+        } else {
+          for (auto &&k : markdown_codes_node) {
+            auto code = k.as<int>();
+            if (code > 300 && code < 599) {
+              markdown_codes.add(code);
+            } else {
+              PL_NH_Note("Skipping invalid markdown response code '%d' for the strategy named '%s'.", code, strategy_name.c_str());
+            }
+          }
+          markdown_codes.sort();
+        }
+      }
       YAML::Node health_check_node;
       if (failover_node["health_check"]) {
         health_check_node = failover_node["health_check"];
@@ -279,20 +301,21 @@ PLNextHopSelectionStrategy::nextHopExists(TSHttpTxn txnp)
 bool
 PLNextHopSelectionStrategy::codeIsFailure(TSHttpStatus response_code)
 {
-  return this->resp_codes.contains(response_code);
+  return this->resp_codes.contains(response_code) || this->markdown_codes.contains(response_code);
 }
 
 bool
 PLNextHopSelectionStrategy::responseIsRetryable(unsigned int current_retry_attempts, TSHttpStatus response_code)
 {
-  return this->codeIsFailure(response_code) && current_retry_attempts < this->max_simple_retries &&
-         current_retry_attempts < this->num_parents;
+  return (current_retry_attempts < this->num_parents) &&
+         ((this->resp_codes.contains(response_code) && current_retry_attempts < this->max_simple_retries) ||
+          (this->markdown_codes.contains(response_code) && current_retry_attempts < this->max_unavailable_retries));
 }
 
 bool
 PLNextHopSelectionStrategy::onFailureMarkParentDown(TSHttpStatus response_code)
 {
-  return static_cast<int>(response_code) >= 500 && static_cast<int>(response_code) <= 599;
+  return this->markdown_codes.contains(response_code);
 }
 
 bool
diff --git a/plugins/experimental/parent_select/strategy.h b/plugins/experimental/parent_select/strategy.h
index 072be43..6a8a6b6 100644
--- a/plugins/experimental/parent_select/strategy.h
+++ b/plugins/experimental/parent_select/strategy.h
@@ -272,14 +272,17 @@ protected:
   bool cache_peer_result  = true;
   PLNHSchemeType scheme   = PL_NH_SCHEME_NONE;
   PLNHRingMode ring_mode  = PL_NH_ALTERNATE_RING;
-  PLResponseCodes resp_codes;
+  PLResponseCodes resp_codes;     // simple retry codes
+  PLResponseCodes markdown_codes; // unavailable server retry and markdown codes
+
   PLHealthChecks health_checks;
   PLNextHopHealthStatus passive_health;
   std::vector<std::vector<std::shared_ptr<PLHostRecord>>> host_groups;
-  uint32_t max_simple_retries = 1;
-  uint32_t groups             = 0;
-  uint32_t grp_index          = 0;
-  uint32_t hst_index          = 0;
-  uint32_t num_parents        = 0;
-  uint32_t distance           = 0; // index into the strategies list.
+  uint32_t max_simple_retries      = 1;
+  uint32_t max_unavailable_retries = 1;
+  uint32_t groups                  = 0;
+  uint32_t grp_index               = 0;
+  uint32_t hst_index               = 0;
+  uint32_t num_parents             = 0;
+  uint32_t distance                = 0; // index into the strategies list.
 };