Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor cluster based dispatch and enable customizable routers #353

Merged
merged 10 commits into from
Aug 25, 2024

Conversation

whitfin
Copy link
Owner

@whitfin whitfin commented Aug 21, 2024

Fixes #246 and #344 and #345 :)

This PR introduces customizable routing modules for distributed caches and will also include documentation updates based on the comments in #246 (namely #246 (comment)). It should be noted that the next version of Cachex will be v4.0.0 so we are free to make breaking changes here.

There is a lot in here, but the gist is that you can now provide an implementation of Cachex.Router to dictate exactly how your keys are assigned to nodes in your cluster. Routers can either be synchronous state, or they can delegate to other linked processes. There are four routers included in this PR:

  • Cachex.Router.Local
    • Routes keys to the local node
    • Does not accept any options
    • This is the default router
  • Cachex.Router.Mod
    • Routes keys using basic hashing (i.e. hash(key) % len(nodes))
    • Included as reference and to add more test coverage
    • The quickest remote implementation
  • Cachex.Router.Jump
    • Routes keys using Jump Consistent hash
    • Accepts a list of nodes as options
    • Same logic as Cachex v3.x
  • Cachex.Router.Ring
    • Routes keys using a hash ring
    • Can dynamically scale to added/removed nodes
    • Delegates to libring
    • Accepts all of the same options as libring

Each of these routers (except Cachex.Router.Local) can be configured to use the currently connected nodes, rather than providing them. The way to do this differs per router, so make sure to visit them for docs (although I'll be writing a new "distribution" guide based on these prior to v4.x).

I previously wrote that I would add two functions to the Cachex API to allow addition/removal of nodes, but I don't think this makes sense now that we can configure routers independently. If we need additional APIs for this in future, happy to add them but they don't seem necessary.

The old Cachex.Router module was moved into a service in Cachex.Services.Conductor to better fit the new role, and to allow Cachex.Router to focus on behaviour.

The :nodes option has also been removed from Cachex's main API, because now it's an option on (some of) the Router implementations. This is also much cleaner, IMO.

@whitfin whitfin added this to the v4.0.0 milestone Aug 21, 2024
@whitfin whitfin self-assigned this Aug 21, 2024
@whitfin
Copy link
Owner Author

whitfin commented Aug 22, 2024

Just an FYI this is still WIP and design isn't settled so I wouldn't spend much time looking over this just yet...

@whitfin whitfin merged commit f66a6fa into main Aug 25, 2024
13 checks passed
@whitfin whitfin deleted the issue-345 branch August 25, 2024 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant