@@ -108,7 +108,7 @@ ParentConsistentHash::getPathHash(HttpRequestData *hrdata, ATSHash64 *h)
108108// Helper function to abstract calling ATSConsistentHash lookup_by_hashval() vs lookup().
109109static pRecord *
110110chash_lookup (ATSConsistentHash *fhash, uint64_t path_hash, ATSConsistentHashIter *chashIter, bool *wrap_around,
111- ATSHash64Sip24 *hash, bool *chash_init)
111+ ATSHash64Sip24 *hash, bool *chash_init, bool *mapWrapped )
112112{
113113 pRecord *prtmp;
114114
@@ -118,6 +118,11 @@ chash_lookup(ATSConsistentHash *fhash, uint64_t path_hash, ATSConsistentHashIter
118118 } else {
119119 prtmp = (pRecord *)fhash->lookup (nullptr , chashIter, wrap_around, hash);
120120 }
121+ // Do not set wrap_around to true until we try all the parents atleast once.
122+ bool wrapped = *wrap_around;
123+ *wrap_around = (*mapWrapped && *wrap_around) ? true : false ;
124+ if (!*mapWrapped && wrapped)
125+ *mapWrapped = true ;
121126 return prtmp;
122127}
123128
@@ -188,7 +193,7 @@ ParentConsistentHash::selectParent(bool first_call, ParentResult *result, Reques
188193 fhash = chash[last_lookup];
189194 do { // search until we've selected a different parent if !firstCall
190195 prtmp = chash_lookup (fhash, path_hash, &result->chashIter [last_lookup], &wrap_around[last_lookup], &hash,
191- &result->chash_init [last_lookup]);
196+ &result->chash_init [last_lookup], &result-> mapWrapped [last_lookup] );
192197 lookups++;
193198 if (prtmp) {
194199 pRec = (parents[last_lookup] + prtmp->idx );
@@ -219,10 +224,6 @@ ParentConsistentHash::selectParent(bool first_call, ParentResult *result, Reques
219224 }
220225 }
221226 if (!pRec || (pRec && !pRec->available ) || host_stat == HOST_STATUS_DOWN) {
222- if (firstCall) {
223- result->chash_init [PRIMARY] = false ;
224- result->chash_init [SECONDARY] = false ;
225- }
226227 do {
227228 // check if the host is retryable. It's retryable if the retry window has elapsed
228229 // and the global host status is HOST_STATUS_UP
@@ -276,7 +277,7 @@ ParentConsistentHash::selectParent(bool first_call, ParentResult *result, Reques
276277 }
277278 fhash = chash[last_lookup];
278279 prtmp = chash_lookup (fhash, path_hash, &result->chashIter [last_lookup], &wrap_around[last_lookup], &hash,
279- &result->chash_init [last_lookup]);
280+ &result->chash_init [last_lookup], &result-> mapWrapped [last_lookup] );
280281 lookups++;
281282 if (prtmp) {
282283 pRec = (parents[last_lookup] + prtmp->idx );
0 commit comments