org.infinispan.distribution
Class RebalanceTask

java.lang.Object
  extended by org.infinispan.distribution.RehashTask
      extended by org.infinispan.distribution.RebalanceTask
All Implemented Interfaces:
Callable<Void>

public class RebalanceTask
extends RehashTask

Task which handles view changes (joins, merges or leaves) and rebalances keys using a push based approach. Essentially, every member gets the old and new consistent hash (CH) on a view change. Then for each key K, it gets the target servers S-old for the old CH and S-new for the new CH. If S-old == S-new, it does nothing. If there is a change, it either pushes K to the new location (if it is the owner), or invalidates K (if we're not the owner any longer).

Example:

 - The membership is {A,B,C,D}
 - The new view is {A,B,C,D,E,F}
 - For K, the old CH is A,B and the new CH is A,C
 - A (since it is K's owner) now pushes K to C
 - B invalidates K
 - For K2, the old CH is A,B and the new CH is B,C
 - B (since it is the backup owner and A left) pushes K2 to C
 

Since:
4.2
Author:
Bela Ban

Field Summary
 
Fields inherited from class org.infinispan.distribution.RehashTask
cf, configuration, dataContainer, distributionManager, log, rpcManager, self, trace
 
Constructor Summary
RebalanceTask(RpcManager rpcManager, CommandsFactory commandsFactory, Configuration conf, DataContainer dataContainer, DistributionManagerImpl dmi, InvocationContextContainer icc, CacheNotifier notifier, InterceptorChain interceptorChain, int newViewId)
           
 
Method Summary
 Address getMyAddress()
           
protected  void performRehash()
           
protected  void rebalance(Object key, InternalCacheEntry value, int numOwners, ConsistentHash chOld, ConsistentHash chNew, CacheStore cacheStore, Map<Address,Map<Object,InternalCacheValue>> states, List<Object> keysToRemove)
          Computes the list of old and new servers for a given key K and value V.
 
Methods inherited from class org.infinispan.distribution.RehashTask
call, coordinator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RebalanceTask

public RebalanceTask(RpcManager rpcManager,
                     CommandsFactory commandsFactory,
                     Configuration conf,
                     DataContainer dataContainer,
                     DistributionManagerImpl dmi,
                     InvocationContextContainer icc,
                     CacheNotifier notifier,
                     InterceptorChain interceptorChain,
                     int newViewId)
Method Detail

performRehash

protected void performRehash()
                      throws Exception
Specified by:
performRehash in class RehashTask
Throws:
Exception

rebalance

protected void rebalance(Object key,
                         InternalCacheEntry value,
                         int numOwners,
                         ConsistentHash chOld,
                         ConsistentHash chNew,
                         CacheStore cacheStore,
                         Map<Address,Map<Object,InternalCacheValue>> states,
                         List<Object> keysToRemove)
Computes the list of old and new servers for a given key K and value V. Adds (K, V) to the states map if K should be pushed to other servers. Adds K to the keysToRemove list if this node is no longer an owner for K.

Parameters:
key - The key
value - The value; null if the value is not in the data container
numOwners - The number of owners (grabbed from the configuration)
chOld - The old (current) consistent hash
chNew - The new consistent hash
cacheStore - If the value is null, try to load it from this cache store
states - The result hashmap. Keys are servers, values are states (hashmaps) to be pushed to them
keysToRemove - A list that the keys that we need to remove will be added to

getMyAddress

public Address getMyAddress()

-->

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