Infinispan Distribution 5.2.6.Final-redhat-2

org.infinispan.distribution.ch
Class DefaultConsistentHashFactory

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

public class DefaultConsistentHashFactory
extends Object
implements ConsistentHashFactory<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
static class DefaultConsistentHashFactory.Builder
           
static class DefaultConsistentHashFactory.Externalizer
           
 
Constructor Summary
DefaultConsistentHashFactory()
           
 
Method Summary
protected  void addBackupOwners(DefaultConsistentHashFactory.Builder builder)
           
protected  void addPrimaryOwners(DefaultConsistentHashFactory.Builder builder)
           
 DefaultConsistentHash create(Hash hashFunction, int numOwners, int numSegments, List<Address> members)
          Create a new consistent hash instance.
protected  boolean doAddBackupOwners(DefaultConsistentHashFactory.Builder builder, int maxSegments)
           
protected  void doAddPrimaryOwners(DefaultConsistentHashFactory.Builder builder, int maxSegments, int maxOwners)
           
protected  boolean doRemoveExtraBackupOwners(DefaultConsistentHashFactory.Builder builder, int maxSegments)
           
protected  Address findNewBackupOwner(DefaultConsistentHashFactory.Builder builder, Collection<Address> excludes, int maxSegments)
           
protected  Address findNewPrimaryOwner(DefaultConsistentHashFactory.Builder builder, Collection<Address> candidates, int maxSegments)
           
 DefaultConsistentHash rebalance(DefaultConsistentHash baseCH)
          Create a new consistent hash instance, based on an existing instance, but "balanced" according to the implementation's rules.
protected  void rebalanceBuilder(DefaultConsistentHashFactory.Builder builder)
           
protected  void removeExtraBackupOwners(DefaultConsistentHashFactory.Builder builder, int minSegments)
           
protected  void replaceBackupOwners(DefaultConsistentHashFactory.Builder builder, int maxSegments)
           
protected  void swapPrimaryOwnersWithBackups(DefaultConsistentHashFactory.Builder builder, int maxSegments)
           
 DefaultConsistentHash union(DefaultConsistentHash dch1, DefaultConsistentHash dch2)
          Merges two consistent hash objects that have the same number of segments, numOwners and hash function.
 DefaultConsistentHash updateMembers(DefaultConsistentHash baseCH, List<Address> actualMembers)
          Leavers are removed and segments without owners are assigned new owners.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultConsistentHashFactory

public DefaultConsistentHashFactory()
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.

updateMembers

public DefaultConsistentHash updateMembers(DefaultConsistentHash baseCH,
                                           List<Address> actualMembers)
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).

Specified by:
updateMembers in interface ConsistentHashFactory<DefaultConsistentHash>
Parameters:
baseCH - An existing consistent hash instance, should not be null
actualMembers - A list of addresses representing the new cache members.
Returns:

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 dch1,
                                   DefaultConsistentHash dch2)
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.

Specified by:
union in interface ConsistentHashFactory<DefaultConsistentHash>

rebalanceBuilder

protected void rebalanceBuilder(DefaultConsistentHashFactory.Builder builder)

addPrimaryOwners

protected void addPrimaryOwners(DefaultConsistentHashFactory.Builder builder)

doAddPrimaryOwners

protected void doAddPrimaryOwners(DefaultConsistentHashFactory.Builder builder,
                                  int maxSegments,
                                  int maxOwners)

swapPrimaryOwnersWithBackups

protected void swapPrimaryOwnersWithBackups(DefaultConsistentHashFactory.Builder builder,
                                            int maxSegments)

addBackupOwners

protected void addBackupOwners(DefaultConsistentHashFactory.Builder builder)

removeExtraBackupOwners

protected void removeExtraBackupOwners(DefaultConsistentHashFactory.Builder builder,
                                       int minSegments)

doRemoveExtraBackupOwners

protected boolean doRemoveExtraBackupOwners(DefaultConsistentHashFactory.Builder builder,
                                            int maxSegments)

doAddBackupOwners

protected boolean doAddBackupOwners(DefaultConsistentHashFactory.Builder builder,
                                    int maxSegments)

replaceBackupOwners

protected void replaceBackupOwners(DefaultConsistentHashFactory.Builder builder,
                                   int maxSegments)

findNewBackupOwner

protected Address findNewBackupOwner(DefaultConsistentHashFactory.Builder builder,
                                     Collection<Address> excludes,
                                     int maxSegments)
Returns:
The member with the least owned segments that is also not in the excludes list.

findNewPrimaryOwner

protected Address findNewPrimaryOwner(DefaultConsistentHashFactory.Builder builder,
                                      Collection<Address> candidates,
                                      int maxSegments)
Returns:
The candidate with the least primary-owned segments that is also not in the excludes list.

Infinispan Distribution 5.2.6.Final-redhat-2

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