Class DefaultConsistentHashFactory
java.lang.Object
org.infinispan.distribution.ch.impl.AbstractConsistentHashFactory<DefaultConsistentHash>
org.infinispan.distribution.ch.impl.DefaultConsistentHashFactory
- All Implemented Interfaces:
ConsistentHashFactory<DefaultConsistentHash>
- Direct Known Subclasses:
TopologyAwareConsistentHashFactory
@ProtoTypeId(1068)
public class DefaultConsistentHashFactory
extends AbstractConsistentHashFactory<DefaultConsistentHash>
Default implementation of
ConsistentHashFactory.
All methods except union(DefaultConsistentHash, DefaultConsistentHash) return a consistent hash
with floor(numOwners*numSegments/numNodes) <= segments per owner <= ceil(numOwners*numSegments/numNodes).- Since:
- 5.2
- Author:
- Dan Berindei, anistor@redhat.com
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidCreate a new consistent hash instance.protected voidbooleanprotected AddressfindNewBackupOwner(DefaultConsistentHashFactory.Builder builder, Collection<Address> excludes, Address owner) fromPersistentState(ScopedPersistentState state, Function<UUID, Address> addressMapper) Recreates aConsistentHashfrom a previously stored persistent state.static DefaultConsistentHashFactoryinthashCode()rebalance(DefaultConsistentHash baseCH) Create a new consistent hash instance, based on an existing instance, but balanced according to the implementation's rules.protected voidprotected voidprotected voidprotected voidreplacePrimaryOwners(DefaultConsistentHashFactory.Builder builder, int maxOwners) protected voidunion(DefaultConsistentHash dch1, DefaultConsistentHash dch2) Merges two consistent hash objects that have the same number of segments, numOwners and hash function.updateMembers(DefaultConsistentHash baseCH, List<Address> actualMembers, Map<Address, Float> actualCapacityFactors) Leavers are removed and segments without owners are assigned new owners.Methods inherited from class org.infinispan.distribution.ch.impl.AbstractConsistentHashFactory
checkCapacityFactors, findNewPrimaryOwner, findWorstPrimaryOwner
-
Constructor Details
-
DefaultConsistentHashFactory
protected DefaultConsistentHashFactory()
-
-
Method Details
-
getInstance
-
create
public DefaultConsistentHash create(int numOwners, int numSegments, List<Address> members, Map<Address, Float> capacityFactors) Description copied from interface:ConsistentHashFactoryCreate a new consistent hash instance. The consistent hash will be balanced.- Parameters:
numOwners- The ideal number of owners for each key. The created consistent hash can have more or less owners, but each key will have at least one owner.numSegments- Number of hash-space segments. The implementation may round up the number of segments for performance, or may ignore the parameter altogether.members- A list of addresses representing the new cache members.capacityFactors- The capacity factor of each member. Determines the relative capacity of each node compared to the others. The implementation may ignore this parameter. Ifnull, all the members are assumed to have a capacity factor of 1.
-
fromPersistentState
public PersistedConsistentHash<DefaultConsistentHash> fromPersistentState(ScopedPersistentState state, Function<UUID, Address> addressMapper) Description copied from interface:ConsistentHashFactoryRecreates aConsistentHashfrom a previously stored persistent state.The stored state typically contains a collection of
UUIDs representing the members. If a member is not present when reading from the state, itsUUIDmust be added to thePersistedConsistentHash.missingUuids()list. ThePersistedConsistentHash.consistentHash()may have incomplete ownership when there are missing UUIDs.- Parameters:
state- the state to restore, containing memberUUIDs.addressMapper- A function to map theUUIDtoAddress.- Returns:
- A
PersistedConsistentHashwith theConsistentHashand with the missingUUIDif any.
-
updateMembers
public DefaultConsistentHash updateMembers(DefaultConsistentHash baseCH, List<Address> actualMembers, Map<Address, Float> actualCapacityFactors) Leavers are removed and segments without owners are assigned new owners. Joiners might get some of the un-owned segments but otherwise they are not taken into account (that should happen during a rebalance).- Parameters:
baseCH- An existing consistent hash instance, should not benullactualMembers- A list of addresses representing the new cache members.actualCapacityFactors- The capacity factor of each member. Determines the relative capacity of each node compared to the others. The implementation may ignore this parameter. Ifnull, all the members are assumed to have a capacity factor of 1.- Returns:
-
rebalance
Description copied from interface:ConsistentHashFactoryCreate a new consistent hash instance, based on an existing instance, but balanced according to the implementation's rules.- Parameters:
baseCH- An existing consistent hash instance, should not benull- Returns:
- A new
ConsistentHashinstance, orbaseCHif the existing instance does not need any changes.
-
union
Merges two consistent hash objects that have the same number of segments, numOwners and hash function. For each segment, the primary owner of the first CH has priority, the other primary owners become backups. -
rebalanceBuilder
-
addPrimaryOwners
-
replacePrimaryOwners
-
swapPrimaryOwnersWithBackups
-
addBackupOwners
-
removeExtraBackupOwners
-
doAddBackupOwners
-
replaceBackupOwners
-
findNewBackupOwner
protected Address findNewBackupOwner(DefaultConsistentHashFactory.Builder builder, Collection<Address> excludes, Address owner) - Returns:
- The member with the worst owned segments/capacity ratio that is also not in the excludes list.
-
equals
-
hashCode
-