Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions proxy/http/remap/NextHopConsistentHash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ constexpr std::string_view hash_key_cache = "cache_key";

static HostRecord *
chash_lookup(std::shared_ptr<ATSConsistentHash> ring, uint64_t hash_key, ATSConsistentHashIter *iter, bool *wrapped,
ATSHash64Sip24 *hash, bool *hash_init, uint64_t sm_id)
ATSHash64Sip24 *hash, bool *hash_init, bool *mapWrapped, uint64_t sm_id)
{
HostRecord *host_rec = nullptr;

Expand All @@ -46,6 +46,11 @@ chash_lookup(std::shared_ptr<ATSConsistentHash> ring, uint64_t hash_key, ATSCons
} else {
host_rec = static_cast<HostRecord *>(ring->lookup(nullptr, iter, wrapped, hash));
}
bool wrap_around = *wrapped;
*wrapped = (*mapWrapped && *wrapped) ? true : false;
if (!*mapWrapped && wrap_around) {
*mapWrapped = true;
}

return host_rec;
}
Expand Down Expand Up @@ -261,7 +266,8 @@ NextHopConsistentHash::findNextHop(const uint64_t sm_id, ParentResult &result, R

do { // search until we've selected a different parent if !firstcall
std::shared_ptr<ATSConsistentHash> r = rings[cur_ring];
hostRec = chash_lookup(r, hash_key, &result.chashIter[cur_ring], &wrapped, &hash, &result.chash_init[cur_ring], sm_id);
hostRec = chash_lookup(r, hash_key, &result.chashIter[cur_ring], &wrapped, &hash, &result.chash_init[cur_ring],
&result.mapWrapped[cur_ring], sm_id);
wrap_around[cur_ring] = wrapped;
lookups++;
// the 'available' flag is maintained in 'host_groups' and not the hash ring.
Expand Down Expand Up @@ -322,7 +328,8 @@ NextHopConsistentHash::findNextHop(const uint64_t sm_id, ParentResult &result, R
break;
}
std::shared_ptr<ATSConsistentHash> r = rings[cur_ring];
hostRec = chash_lookup(r, hash_key, &result.chashIter[cur_ring], &wrapped, &hash, &result.chash_init[cur_ring], sm_id);
hostRec = chash_lookup(r, hash_key, &result.chashIter[cur_ring], &wrapped, &hash, &result.chash_init[cur_ring],
&result.mapWrapped[cur_ring], sm_id);
wrap_around[cur_ring] = wrapped;
lookups++;
if (hostRec) {
Expand Down
8 changes: 4 additions & 4 deletions proxy/http/remap/unit-tests/test_NextHopConsistentHash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,17 @@ SCENARIO("Testing NextHopConsistentHash class (all firstcalls), using policy 'co
result.reset();
strategy->findNextHop(20004, result, request, fail_threshold, retry_time);
CHECK(result.result == ParentResultType::PARENT_SPECIFIED);
CHECK(strcmp(result.hostname, "q1.bar.com") == 0);
CHECK(strcmp(result.hostname, "s1.bar.com") == 0);

// mark down q1.bar.com
// mark down s1.bar.com
strategy->markNextHopDown(20004, result, 1, fail_threshold);

// fifth request
br(&request, "rabbit.net/asset1");
result.reset();
strategy->findNextHop(20005, result, request, fail_threshold, retry_time);
CHECK(result.result == ParentResultType::PARENT_DIRECT);
CHECK(result.hostname == nullptr);
CHECK(result.result == ParentResultType::PARENT_SPECIFIED);
CHECK(strcmp(result.hostname, "q1.bar.com") == 0);

// sixth request - wait and p1 should now become available
time_t now = time(nullptr) + 5;
Expand Down