Skip to content

xds: Wrap around the ring in RingHashLoadBalancer.getTargetIndex - #13054

Open
TimurRakhmatullin86 wants to merge 1 commit into
grpc:masterfrom
TimurRakhmatullin86:fix/ringhash-wrap-around
Open

xds: Wrap around the ring in RingHashLoadBalancer.getTargetIndex#13054
TimurRakhmatullin86 wants to merge 1 commit into
grpc:masterfrom
TimurRakhmatullin86:fix/ringhash-wrap-around

Conversation

@TimurRakhmatullin86

Copy link
Copy Markdown
Contributor

RingHashPicker.getTargetIndex binary-searches the Ketama ring for the smallest ring entry whose hash is >= the request hash. When the request hash is greater than every entry on the ring, the search stops at the last entry and returns it instead of wrapping clockwise back to the first entry as a ring requires.

As a result, requests whose hash falls in the gap above the largest ring point are routed to the last ring entry's host as the primary pick (and demote the first entry's host), diverging from the affinity Envoy and gRPC C-core produce for the same hash and skewing load onto the last host. That window is a deterministic slice of the 64-bit hash space and is always reachable, since the request hash is an independent 64-bit value.

Return index 0 when the request hash exceeds the largest ring entry so the ring wraps around; a hash equal to the largest entry still resolves to that entry (strict comparison). Add a test asserting that a hash above the maximum and a hash below the minimum select the same host.

RingHashPicker.getTargetIndex binary-searches the Ketama ring for the
smallest ring entry whose hash is >= the request hash. When the request
hash is greater than every entry on the ring, the search stops at the
last entry and returns it instead of wrapping clockwise back to the first
entry as a ring requires.

As a result, requests whose hash falls in the gap above the largest ring
point are routed to the last ring entry's host as the primary pick (and
demote the first entry's host), diverging from the affinity Envoy and
gRPC C-core produce for the same hash and skewing load onto the last host.
That window is a deterministic slice of the 64-bit hash space and is always
reachable, since the request hash is an independent 64-bit value.

Return index 0 when the request hash exceeds the largest ring entry so the
ring wraps around; a hash equal to the largest entry still resolves to that
entry (strict comparison). Add a test asserting that a hash above the
maximum and a hash below the minimum select the same host.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant