public class SyncConsistentHashFactory extends Object implements ConsistentHashFactory<DefaultConsistentHash>
CacheTopologyControlCommand
for each cache
it wants to join and Infinispan can and does batch cache topology changes.
For example, if a rebalance is in progress, joins are queued and send in
one go when the rebalance has finished.
This ConsistentHashFactory
implementation avois any of the issues
mentioned and guarantees that multiple caches with the same members will
have the same consistent hash.
It has a drawback compared to DefaultConsistentHashFactory
though:
it can potentially move a lot more segments during a rebalance than
strictly necessary because it's not taking advantage of the optimisation
mentioned above.Modifier and Type | Class and Description |
---|---|
protected static class |
SyncConsistentHashFactory.Builder |
static class |
SyncConsistentHashFactory.Externalizer |
Modifier and Type | Field and Description |
---|---|
static float |
OWNED_SEGMENTS_ALLOWED_VARIATION |
static float |
PRIMARY_SEGMENTS_ALLOWED_VARIATION |
Constructor and Description |
---|
SyncConsistentHashFactory() |
Modifier and Type | Method and Description |
---|---|
protected void |
checkCapacityFactors(List<Address> members,
Map<Address,Float> capacityFactors) |
DefaultConsistentHash |
create(Hash hashFunction,
int numOwners,
int numSegments,
List<Address> members,
Map<Address,Float> capacityFactors)
Create a new consistent hash instance.
|
protected SyncConsistentHashFactory.Builder |
createBuilder(Hash hashFunction,
int numOwners,
int numSegments,
List<Address> members,
Map<Address,Float> capacityFactors) |
boolean |
equals(Object other) |
DefaultConsistentHash |
fromPersistentState(ScopedPersistentState state)
Recreates a ConsistentHash from a previously stored persistent state
|
int |
hashCode() |
DefaultConsistentHash |
rebalance(DefaultConsistentHash baseCH)
Create a new consistent hash instance, based on an existing instance, but "balanced" according to
the implementation's rules.
|
DefaultConsistentHash |
union(DefaultConsistentHash ch1,
DefaultConsistentHash ch2)
Creates a union of two compatible ConsistentHashes (use the same hashing function and have the same configuration
parameters).
|
DefaultConsistentHash |
updateMembers(DefaultConsistentHash baseCH,
List<Address> newMembers,
Map<Address,Float> actualCapacityFactors)
Create a new consistent hash instance, based on an existing instance, but with a new list of members.
|
public static final float OWNED_SEGMENTS_ALLOWED_VARIATION
public static final float PRIMARY_SEGMENTS_ALLOWED_VARIATION
public DefaultConsistentHash create(Hash hashFunction, int numOwners, int numSegments, List<Address> members, Map<Address,Float> capacityFactors)
ConsistentHashFactory
create
in interface ConsistentHashFactory<DefaultConsistentHash>
hashFunction
- The hash function to use on top of the keys' own hashCode()
implementation.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.
If null
, all the members are assumed to have a capacity factor of 1.public DefaultConsistentHash fromPersistentState(ScopedPersistentState state)
ConsistentHashFactory
fromPersistentState
in interface ConsistentHashFactory<DefaultConsistentHash>
protected SyncConsistentHashFactory.Builder createBuilder(Hash hashFunction, int numOwners, int numSegments, List<Address> members, Map<Address,Float> capacityFactors)
protected void checkCapacityFactors(List<Address> members, Map<Address,Float> capacityFactors)
public DefaultConsistentHash updateMembers(DefaultConsistentHash baseCH, List<Address> newMembers, Map<Address,Float> actualCapacityFactors)
ConsistentHashFactory
updateMembers
in interface ConsistentHashFactory<DefaultConsistentHash>
baseCH
- An existing consistent hash instance, should not be null
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.
If null
, all the members are assumed to have a capacity factor of 1.ConsistentHash
instance, or baseCH
if the existing instance
does not need any changes.public DefaultConsistentHash rebalance(DefaultConsistentHash baseCH)
ConsistentHashFactory
rebalance(rebalance(ch))
must be equivalent to rebalance(ch)
.rebalance
in interface ConsistentHashFactory<DefaultConsistentHash>
baseCH
- An existing consistent hash instance, should not be null
ConsistentHash
instance, or baseCH
if the existing instance
does not need any changes.public DefaultConsistentHash union(DefaultConsistentHash ch1, DefaultConsistentHash ch2)
ConsistentHashFactory
union
in interface ConsistentHashFactory<DefaultConsistentHash>
Copyright © 2017 JBoss, a division of Red Hat. All rights reserved.