From e942d53d96b51006148cb02c2e9e31a2bb656820 Mon Sep 17 00:00:00 2001 From: keith2008 <56985076@qq.com> Date: Tue, 23 Aug 2016 08:51:44 +0800 Subject: [PATCH] TS-4744: ParentConsistentHash::selectParent may select the unavailable parent --- proxy/ParentConsistentHash.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/proxy/ParentConsistentHash.cc b/proxy/ParentConsistentHash.cc index 9e10307b632..e25823f1e4c 100644 --- a/proxy/ParentConsistentHash.cc +++ b/proxy/ParentConsistentHash.cc @@ -143,6 +143,9 @@ ParentConsistentHash::selectParent(const ParentSelectionPolicy *policy, bool fir if (prtmp) { pRec = (parents[last_lookup] + prtmp->idx); } + else { + pRec = NULL; + } } while (prtmp && strcmp(prtmp->hostname, result->hostname) == 0); } } @@ -166,7 +169,7 @@ ParentConsistentHash::selectParent(const ParentSelectionPolicy *policy, bool fir } Debug("parent_select", "wrap_around[PRIMARY]: %d, wrap_around[SECONDARY]: %d", wrap_around[PRIMARY], wrap_around[SECONDARY]); if (!wrap_around[PRIMARY] || (chash[SECONDARY] != NULL)) { - Debug("parent_select", "Selected parent %s is not available, looking up another parent.", pRec ? pRec->hostname:"[NULL]"); + Debug("parent_select", "Selected parent %s is not available, looking up another parent.", pRec->hostname); if (chash[SECONDARY] != NULL && !wrap_around[SECONDARY]) { fhash = chash[SECONDARY]; last_lookup = SECONDARY; @@ -185,6 +188,9 @@ ParentConsistentHash::selectParent(const ParentSelectionPolicy *policy, bool fir pRec = (parents[last_lookup] + prtmp->idx); Debug("parent_select", "Selected a new parent: %s.", pRec->hostname); } + else { + pRec = NULL; + } } if (wrap_around[PRIMARY] && chash[SECONDARY] == NULL) { Debug("parent_select", "No available parents.");