Skip to content

Commit f7affef

Browse files
committed
Set wrap after checking all the parents
1 parent e6cf1bf commit f7affef

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

proxy/ParentConsistentHash.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ ParentConsistentHash::getPathHash(HttpRequestData *hrdata, ATSHash64 *h)
108108
// Helper function to abstract calling ATSConsistentHash lookup_by_hashval() vs lookup().
109109
static pRecord *
110110
chash_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);

proxy/ParentSelection.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ struct ParentResult {
177177
reset()
178178
{
179179
ink_zero(*this);
180-
line_number = -1;
181-
result = PARENT_UNDEFINED;
180+
line_number = -1;
181+
result = PARENT_UNDEFINED;
182+
mapWrapped[0] = false;
183+
mapWrapped[1] = false;
182184
}
183185

184186
bool
@@ -274,6 +276,7 @@ struct ParentResult {
274276
uint32_t start_parent;
275277
uint32_t last_group;
276278
bool wrap_around;
279+
bool mapWrapped[2];
277280
// state for consistent hash.
278281
int last_lookup;
279282
ATSConsistentHashIter chashIter[MAX_GROUP_RINGS];

0 commit comments

Comments
 (0)