Class SyncReplicatedConsistentHashFactory
java.lang.Object
org.infinispan.distribution.ch.impl.SyncReplicatedConsistentHashFactory
- All Implemented Interfaces:
ConsistentHashFactory<ReplicatedConsistentHash>
public class SyncReplicatedConsistentHashFactory
extends Object
implements ConsistentHashFactory<ReplicatedConsistentHash>
SyncConsistentHashFactory
adapted for replicated caches, so that the primary owner of a key
is the same in replicated and distributed caches.- Since:
- 8.2
- Author:
- Dan Berindei
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionCreate a new consistent hash instance.Recreates a ConsistentHash from a previously stored persistent state.rebalance
(ReplicatedConsistentHash baseCH) Create a new consistent hash instance, based on an existing instance, but balanced according to the implementation's rules.Creates a union of two compatible ConsistentHashes (use the same hashing function and have the same configuration parameters).updateMembers
(ReplicatedConsistentHash baseCH, List<Address> newMembers, Map<Address, Float> actualCapacityFactors) Updates an existing consistent hash instance to remove owners that are not in thenewMembers
list.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.infinispan.distribution.ch.ConsistentHashFactory
create
-
Constructor Details
-
SyncReplicatedConsistentHashFactory
public SyncReplicatedConsistentHashFactory()
-
-
Method Details
-
create
public ReplicatedConsistentHash create(int numOwners, int numSegments, List<Address> members, Map<Address, Float> capacityFactors) Description copied from interface:ConsistentHashFactory
Create a new consistent hash instance. The consistent hash will be balanced.- Specified by:
create
in interfaceConsistentHashFactory<ReplicatedConsistentHash>
- 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
Description copied from interface:ConsistentHashFactory
Recreates a ConsistentHash from a previously stored persistent state. The returned ConsistentHash will not have proper addresses, butPersistentUUID
s instead so they will need to be replaced- Specified by:
fromPersistentState
in interfaceConsistentHashFactory<ReplicatedConsistentHash>
- Parameters:
state
- the state to restore
-
updateMembers
public ReplicatedConsistentHash updateMembers(ReplicatedConsistentHash baseCH, List<Address> newMembers, Map<Address, Float> actualCapacityFactors) Description copied from interface:ConsistentHashFactory
Updates an existing consistent hash instance to remove owners that are not in thenewMembers
list.If a segment has at least one owner in
newMembers
, this method will not add another owner. This guarantees that the new consistent hash can be used immediately, without transferring any state.If a segment has no owners in
newMembers
and theConsistentHash
implementation (e.g.DefaultConsistentHash
) requires at least one owner for each segment, this method may add one or more owners for that segment. Since the data in that segment was lost, the new consistent hash can still be used without transferring state.- Specified by:
updateMembers
in interfaceConsistentHashFactory<ReplicatedConsistentHash>
- Parameters:
baseCH
- An existing consistent hash instance, should not benull
newMembers
- 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:
- A new
ConsistentHash
instance, orbaseCH
if the existing instance does not need any changes.
-
rebalance
Description copied from interface:ConsistentHashFactory
Create a new consistent hash instance, based on an existing instance, but balanced according to the implementation's rules.- Specified by:
rebalance
in interfaceConsistentHashFactory<ReplicatedConsistentHash>
- Parameters:
baseCH
- An existing consistent hash instance, should not benull
- Returns:
- A new
ConsistentHash
instance, orbaseCH
if the existing instance does not need any changes.
-
union
Description copied from interface:ConsistentHashFactory
Creates a union of two compatible ConsistentHashes (use the same hashing function and have the same configuration parameters).The owners of a segment
s
inunion(ch1, ch2)
will include both the owners ofs
inch1
and the owners ofs
inch2
, so a cache can switch from usingunion(ch1, ch2)
to usingch2
without transferring any state.- Specified by:
union
in interfaceConsistentHashFactory<ReplicatedConsistentHash>
-