This is an automated email from the ASF dual-hosted git repository. jrushford pushed a commit to branch master in repository https://git-dual.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push: new e5090a8 TS-4701: Add a new latched parent selection strategy. e5090a8 is described below commit e5090a83125046b7af0ad8c802b7408a431d9968 Author: John J. Rushford <jrushf...@apache.org> AuthorDate: Thu Oct 6 20:22:59 2016 +0000 TS-4701: Add a new latched parent selection strategy. --- doc/admin-guide/files/parent.config.en.rst | 7 ++++ proxy/ParentRoundRobin.cc | 11 ++++- proxy/ParentRoundRobin.h | 1 + proxy/ParentSelection.cc | 66 ++++++++++++++++++++++++++++++ proxy/ParentSelection.h | 1 + 5 files changed, 84 insertions(+), 2 deletions(-) diff --git a/doc/admin-guide/files/parent.config.en.rst b/doc/admin-guide/files/parent.config.en.rst index c3df065..93238d7 100644 --- a/doc/admin-guide/files/parent.config.en.rst +++ b/doc/admin-guide/files/parent.config.en.rst @@ -207,6 +207,13 @@ The following list shows the possible actions and their allowed values. The other traffic is unaffected. Once the downed parent becomes available, the traffic distribution returns to the pre-down state. + - ``latched`` - The first parent in the list is marked as primary and is + always chosen until connection errors cause it to be marked down. When + this occurs the next parent in the list then becomes primary. The primary + will wrap back to the first parent in the list when it is the last parent + in the list and is marked down due to a connection error. Newly chosen + primary parents marked as unavailable will then be restored if the failure + retry time has elapsed and the transaction using the primary succeeds. .. _parent-config-format-go-direct: diff --git a/proxy/ParentRoundRobin.cc b/proxy/ParentRoundRobin.cc index 93a3e5a..f7a40b8 100644 --- a/proxy/ParentRoundRobin.cc +++ b/proxy/ParentRoundRobin.cc @@ -25,6 +25,7 @@ ParentRoundRobin::ParentRoundRobin(ParentRecord *parent_record, ParentRR_t _round_robin_type) { round_robin_type = _round_robin_type; + latched_parent = 0; if (is_debug_tag_set("parent_select")) { switch (round_robin_type) { @@ -37,6 +38,9 @@ ParentRoundRobin::ParentRoundRobin(ParentRecord *parent_record, ParentRR_t _roun case P_HASH_ROUND_ROBIN: Debug("parent_select", "Using a round robin parent selection strategy of type P_HASH_ROUND_ROBIN."); break; + case P_LATCHED_ROUND_ROBIN: + Debug("parent_select", "Using a round robin parent selection strategy of type P_LATCHED_ROUND_ROBIN."); + break; default: // should never see this, there is a problem if you do. Debug("parent_select", "Using a round robin parent selection strategy of type UNKNOWN TYPE."); @@ -97,13 +101,16 @@ ParentRoundRobin::selectParent(const ParentSelectionPolicy *policy, bool first_c case P_NO_ROUND_ROBIN: cur_index = result->start_parent = 0; break; + case P_LATCHED_ROUND_ROBIN: + cur_index = result->start_parent = latched_parent; + break; default: ink_release_assert(0); } } } else { // Move to next parent due to failure - cur_index = (result->last_parent + 1) % result->rec->num_parents; + latched_parent = cur_index = (result->last_parent + 1) % result->rec->num_parents; // Check to see if we have wrapped around if ((unsigned int)cur_index == result->start_parent) { @@ -158,7 +165,7 @@ ParentRoundRobin::selectParent(const ParentSelectionPolicy *policy, bool first_c Debug("parent_select", "Chosen parent = %s.%d", result->hostname, result->port); return; } - cur_index = (cur_index + 1) % result->rec->num_parents; + latched_parent = cur_index = (cur_index + 1) % result->rec->num_parents; } while ((unsigned int)cur_index != result->start_parent); if (result->rec->go_direct == true && result->rec->parent_is_proxy == true) { diff --git a/proxy/ParentRoundRobin.h b/proxy/ParentRoundRobin.h index 57b6832..818e26c 100644 --- a/proxy/ParentRoundRobin.h +++ b/proxy/ParentRoundRobin.h @@ -35,6 +35,7 @@ class ParentRoundRobin : public ParentSelectionStrategy { ParentRR_t round_robin_type; + int latched_parent; public: ParentRoundRobin(ParentRecord *_parent_record, ParentRR_t _round_robin_type); diff --git a/proxy/ParentSelection.cc b/proxy/ParentSelection.cc index 91ae19e..332cdae 100644 --- a/proxy/ParentSelection.cc +++ b/proxy/ParentSelection.cc @@ -543,6 +543,8 @@ ParentRecord::Init(matcher_line *line_info) round_robin = P_NO_ROUND_ROBIN; } else if (strcasecmp(val, "consistent_hash") == 0) { round_robin = P_CONSISTENT_HASH; + } else if (strcasecmp(val, "latched") == 0) { + round_robin = P_LATCHED_ROUND_ROBIN; } else { round_robin = P_NO_ROUND_ROBIN; errPtr = "invalid argument to round_robin directive"; @@ -681,6 +683,7 @@ ParentRecord::Init(matcher_line *line_info) case P_NO_ROUND_ROBIN: case P_STRICT_ROUND_ROBIN: case P_HASH_ROUND_ROBIN: + case P_LATCHED_ROUND_ROBIN: TSDebug("parent_select", "allocating ParentRoundRobin() lookup strategy."); selection_strategy = new ParentRoundRobin(this, round_robin); break; @@ -1282,6 +1285,69 @@ EXCLUSIVE_REGRESSION_TEST(PARENTSELECTION)(RegressionTest * /* t ATS_UNUSED */, sleep(1); RE(verify(result, PARENT_FAIL, NULL, 80), 177); + // Test 178 + tbl[0] = '\0'; + ST(178); + T("dest_domain=rabbit.net parent=fuzzy:80|1.0;fluffy:80|1.0;furry:80|1.0;frisky:80|1.0 " + "round_robin=latched go_direct=false\n"); + REBUILD; + REINIT; + br(request, "i.am.rabbit.net"); + FP; + sleep(1); + RE(verify(result, PARENT_SPECIFIED, "fuzzy", 80), 178); + + params->markParentDown(result); // fuzzy is down + + // Test 179 + ST(179); + REINIT; + br(request, "i.am.rabbit.net"); + FP; + sleep(1); + RE(verify(result, PARENT_SPECIFIED, "fluffy", 80), 179); + + params->markParentDown(result); // fluffy is down + + // Test 180 + ST(180); + REINIT; + br(request, "i.am.rabbit.net"); + FP; + sleep(1); + RE(verify(result, PARENT_SPECIFIED, "furry", 80), 180); + + params->markParentDown(result); // furry is down + + // Test 181 + ST(181); + REINIT; + br(request, "i.am.rabbit.net"); + FP; + sleep(1); + RE(verify(result, PARENT_SPECIFIED, "frisky", 80), 181); + + params->markParentDown(result); // frisky is down and we should be back on fuzzy. + + // Test 182 + ST(182); + REINIT; + br(request, "i.am.rabbit.net"); + FP; + sleep(1); + RE(verify(result, PARENT_FAIL, NULL, 80), 182); + + // wait long enough so that fuzzy is retryable. + sleep(params->policy.ParentRetryTime - 1); + + // Test 183 + ST(183); + REINIT; + br(request, "i.am.rabbit.net"); + FP; + sleep(1); + RE(verify(result, PARENT_SPECIFIED, "fuzzy", 80), 183); + delete request; delete result; delete params; diff --git a/proxy/ParentSelection.h b/proxy/ParentSelection.h index 3fd2826..78c0942 100644 --- a/proxy/ParentSelection.h +++ b/proxy/ParentSelection.h @@ -64,6 +64,7 @@ enum ParentRR_t { P_STRICT_ROUND_ROBIN, P_HASH_ROUND_ROBIN, P_CONSISTENT_HASH, + P_LATCHED_ROUND_ROBIN, }; enum ParentRetry_t { -- To stop receiving notification emails like this one, please contact ['"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>'].