3.2.5.2. Implementing a ConsistentHashFactory


JBoss Data Grid ships with four ConsistentHashFactory implementations:
  • DefaultConsistentHashFactory - keeps segments balanced evenly across all the nodes, however the key mapping is not guaranteed to be same across caches,as this depends on the history of each cache.
  • SyncConsistentHashFactory - guarantees that the key mapping is the same for each cache, provided the current membership is the same. This has a drawback in that a node joining the cache can cause the existing nodes to also exchange segments, resulting in either additional state transfer traffic, the distribution of the data becoming less even, or both.
  • TopologyAwareConsistentHashFactory - equivalent of DefaultConsistentHashFactory, but with server hinting enabled.
  • TopologyAwareSyncConsistentHashFactory - equivalent of SyncConsistentHashFactory, but with server hinting enabled.
In addition to these, a ConsistentHashFactory can be implemented manually. The custom ConsistentHashFactory must implement the following methods:
			
create(Hash hashFunction,
          int numOwners,
          int numSegments,
          List<Address> members)
// create a new consistent hash instance

updateMembers(ConsistentHash baseCH,
          List<Address> newMembers)
// update the list of members of an existing consistent hash instance; the implementation should not assign new segments to a node, unless that segments doesn't have any owners

rebalance(ConsistentHash baseCH)
// rebalance the segments between existing members (so a node joining requires both updateMembers and rebalance)

union(ConsistentHash ch1, ConsistentHash ch2)
// create a consistent hash instance which, for each segment, has the same owners as both consistent hash parameters. The result consistent hash is used for write operations during state transfer.


Copy to Clipboard Toggle word wrap
Consistent hash instances can be created with the following parameters:
  • The hashFunction parameter is used on top of the keys' own hashCode() implementation.
  • The numOwners parameter is the ideal number of owners for each key. The created consistent hash can have a greater or fewer number of owners, however each key will have at least one owner.
  • The numSegments defines the number of hash-space arguments. The implementation may either round up the number of segments for performance, or it may ignore the parameter altogether.
  • The members parameter provides a list of addresses representing the new cache members.
Currently it is not possible to pass custom parameters to ConsistentHashFactory implementations.
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2026 Red Hat
Back to top