Infinispan Distribution 5.2.6.Final-redhat-2

org.infinispan.distribution.ch
Class SyncConsistentHashFactory

java.lang.Object
  extended by org.infinispan.distribution.ch.SyncConsistentHashFactory
All Implemented Interfaces:
ConsistentHashFactory<DefaultConsistentHash>
Direct Known Subclasses:
TopologyAwareSyncConsistentHashFactory

public class SyncConsistentHashFactory
extends Object
implements ConsistentHashFactory<DefaultConsistentHash>

A ConsistentHashFactory implementation that guarantees caches with the same members 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.

Since:
5.2
Author:
Dan Berindei

Nested Class Summary
protected static class SyncConsistentHashFactory.Builder
           
static class SyncConsistentHashFactory.Externalizer
           
 
Constructor Summary
SyncConsistentHashFactory()
           
 
Method Summary
 DefaultConsistentHash create(Hash hashFunction, int numOwners, int numSegments, List<Address> members)
          Create a new consistent hash instance.
protected  int normalizedHash(Hash hashFunction, int hashcode)
           
protected  void populateOwnersFewSegments(SyncConsistentHashFactory.Builder builder, SortedMap<Integer,Address> primarySegments)
           
protected  void populateOwnersManySegments(SyncConsistentHashFactory.Builder builder, SortedMap<Integer,Address> primarySegments)
           
 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)
          Create a new consistent hash instance, based on an existing instance, but with a new list of members.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SyncConsistentHashFactory

public SyncConsistentHashFactory()
Method Detail

create

public DefaultConsistentHash create(Hash hashFunction,
                                    int numOwners,
                                    int numSegments,
                                    List<Address> members)
Description copied from interface: ConsistentHashFactory
Create a new consistent hash instance.

Specified by:
create in interface ConsistentHashFactory<DefaultConsistentHash>
Parameters:
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.

populateOwnersFewSegments

protected void populateOwnersFewSegments(SyncConsistentHashFactory.Builder builder,
                                         SortedMap<Integer,Address> primarySegments)

normalizedHash

protected int normalizedHash(Hash hashFunction,
                             int hashcode)

populateOwnersManySegments

protected void populateOwnersManySegments(SyncConsistentHashFactory.Builder builder,
                                          SortedMap<Integer,Address> primarySegments)

updateMembers

public DefaultConsistentHash updateMembers(DefaultConsistentHash baseCH,
                                           List<Address> newMembers)
Description copied from interface: ConsistentHashFactory
Create a new consistent hash instance, based on an existing instance, but with a new list of members.

This method will not assign any new owners, so it will not require a state transfer. The only exception is if a segment doesn't have any owners in the new members list - but there isn't anyone to transfer that segment from, so that won't require a state transfer either.

Specified by:
updateMembers in interface ConsistentHashFactory<DefaultConsistentHash>
Parameters:
baseCH - An existing consistent hash instance, should not be null
newMembers - A list of addresses representing the new cache members.
Returns:
A new ConsistentHash instance, or baseCH if the existing instance does not need any changes.

rebalance

public DefaultConsistentHash rebalance(DefaultConsistentHash baseCH)
Description copied from interface: ConsistentHashFactory
Create a new consistent hash instance, based on an existing instance, but "balanced" according to the implementation's rules.

It must be possible to switch from the "intermediary" consistent hash that includes the old owners to the new consistent hash without any state transfer.

rebalance(rebalance(ch)) must be equivalent to rebalance(ch).

Specified by:
rebalance in interface ConsistentHashFactory<DefaultConsistentHash>
Parameters:
baseCH - An existing consistent hash instance, should not be null
Returns:
A new ConsistentHash instance, or baseCH if the existing instance does not need any changes.

union

public DefaultConsistentHash union(DefaultConsistentHash ch1,
                                   DefaultConsistentHash ch2)
Description copied from interface: ConsistentHashFactory
Creates a union of two compatible ConsistentHashes (use the same hashing function and have the same configuration parameters).

Specified by:
union in interface ConsistentHashFactory<DefaultConsistentHash>

Infinispan Distribution 5.2.6.Final-redhat-2

Copyright © 2013 JBoss, a division of Red Hat. All Rights Reserved.