Skip to content

Minor token ring creation optimization + rebuild token rings on hosts refresh - #472

Open
toptobes wants to merge 1 commit into
apache:trunkfrom
toptobes:token-ring-fix
Open

Minor token ring creation optimization + rebuild token rings on hosts refresh#472
toptobes wants to merge 1 commit into
apache:trunkfrom
toptobes:token-ring-fix

Conversation

@toptobes

Copy link
Copy Markdown

Improves a couple aspects of token ring handling, namely:

  • Brings token ring initialization from O(N^2) -> O(N log N)
  • Always rebuilds token rings in _refreshHosts

The second is the more important change, this way token-aware routing isn't broken due to topology changes during the runtime of the session (plus, metadata.getTokenRanges() is also a public method, so users could technically be consuming stale information)

As a precedent, I checked Go's implementation which refreshes the ring on one of three conditions (see host_source.go):

  • Reconnection <- ✅ _refresh() calls _refreshHosts()
  • Topology events <- ✅ _nodeTopologyChangeHandler() puts _refreshHosts() in the debouncer
  • On NODE UP when the host is not recognized <- ❌ not sure how necessary this is; it seems on the defensive side

I believe Java is similar to Go here, though I didn't look too long/hard at it (its implementation was a little harder to follow)

This is definitely not my ideal implementation by any means, but it's the minimal fix. The topology events definitely should have their own dedicated debouncer, but that's out of scope for this PR.

Additional notes:

  • I did not write any tests for _refreshHosts() specifically as there were no existing tests for that method.
  • buildTokens() has to explicitly invalidates keyspaces[*].replicas now; this wasn't an issue before since there were never any replicas prior to the token ring being built during initialization

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