Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


com.tangosol.net.partition
Class BroadKeyPartitioningStrategy

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.util.BitHelper
          extended by com.tangosol.util.ExternalizableHelper
              extended by com.tangosol.net.partition.DefaultKeyPartitioningStrategy
                  extended by com.tangosol.net.partition.BroadKeyPartitioningStrategy

All Implemented Interfaces:
KeyPartitioningStrategy

public class BroadKeyPartitioningStrategy
extends DefaultKeyPartitioningStrategy

The BroadKeyPartitioningStrategy is a strategy that could be used in cases when the standard key association-based strategy produces very uneven partition distribution - some partitions having significantly larger amount of data than others. Another use case is a partitioned cache with relatively small number of logical groups of values, when using the standard association strategy would result in only a small number of partitions containing any data and large number of partitions being completely empty.
While using the BroadKeyPartitioningStrategy allows to spread data much more evenly across partitions and still have scalable parallel queries (based on the KeyAssociatedFilter), it comes with a trade-off - associated entries can no longer be assume to reside in the same JVM, though with a relatively high probaility they will.

If an application semantic allows to dynamically determine the desired span for different logically associated groups of entries, it is recommended to extend this strategy and override the getSpan() method.

Since:
Coherence 3.6
Author:
gg 2010.05.19

Nested Class Summary

 

Nested classes/interfaces inherited from interface com.tangosol.net.partition.KeyPartitioningStrategy
KeyPartitioningStrategy.PartitionAwareKey

 

Field Summary

 

Fields inherited from class com.tangosol.net.partition.DefaultKeyPartitioningStrategy
m_service

 

Constructor Summary
BroadKeyPartitioningStrategy(int nSpan)
          Construct the BroadKeyPartitioningStrategy based on the specified span.

 

Method Summary
 PartitionSet getAssociatedPartitions(java.lang.Object oKey)
          Determine the set of partitions that all keys associated with the specified key are assigned to.
 int getKeyPartition(java.lang.Object oKey)
          Determine the partition to which a particular key should be assigned.
protected  int getSpan(java.lang.Object oBaseKey)
          Caculate the partition span for a logical group of keys represented by the speficified "base" key.
 void init(PartitionedService service)
          Initialize the KeyPartitioningStrategy and bind it to the specified PartitionedService.

 

Methods inherited from class com.tangosol.net.partition.DefaultKeyPartitioningStrategy
calculateKeyPartition

 

Methods inherited from class com.tangosol.util.BitHelper
countBits, countBits, countBits, indexOfLSB, indexOfLSB, indexOfLSB, indexOfMSB, indexOfMSB, indexOfMSB, rotateLeft, rotateLeft, rotateLeft, rotateRight, rotateRight, rotateRight, toBitString, toBitString, toBitString

 

Constructor Detail

BroadKeyPartitioningStrategy

public BroadKeyPartitioningStrategy(int nSpan)
Construct the BroadKeyPartitioningStrategy based on the specified span. Span value of zero means that this strategy will behave identically to the DefaultKeyPartitioningStrategy. Span value of N will place associated entries into no more than (N+1) distinct partitions.
Parameters:
nSpan - the default span value

Method Detail

init

public void init(PartitionedService service)
Initialize the KeyPartitioningStrategy and bind it to the specified PartitionedService.
Specified by:
init in interface KeyPartitioningStrategy
Overrides:
init in class DefaultKeyPartitioningStrategy
Parameters:
service - the PartitionedService that this strategy is being bound to

getKeyPartition

public int getKeyPartition(java.lang.Object oKey)
Determine the partition to which a particular key should be assigned.

In general, implementations are expected to respect the associations provided by the service's KeyAssociator in such a way that keys that return the same associated key would be assigned to the same partition. Furthermore, implementations are also expected to respect explicit partition-assignments dictated by the KeyPartitioningStrategy.PartitionAwareKey interface. Naturally, those two interfaces should not be combined for a given key.

The resulting partition must be in the range [0..N-1], where N is the value returned from PartitionedService.getPartitionCount().

Specified by:
getKeyPartition in interface KeyPartitioningStrategy
Overrides:
getKeyPartition in class DefaultKeyPartitioningStrategy
Parameters:
oKey - a key in its Object form
Returns:
the partition ID that the specified key is assigned to
See Also:
PartitionedService.getPartitionOwner(int)

getAssociatedPartitions

public PartitionSet getAssociatedPartitions(java.lang.Object oKey)
Determine the set of partitions that all keys associated with the specified key are assigned to. Most commonly, this method returns a partition set containing a single partition returned by the getKeyPartition method.
Specified by:
getAssociatedPartitions in interface KeyPartitioningStrategy
Overrides:
getAssociatedPartitions in class DefaultKeyPartitioningStrategy
Parameters:
oKey - a key in its Object form
Returns:
the PartitionSet associated with the specified key

getSpan

protected int getSpan(java.lang.Object oBaseKey)
Caculate the partition span for a logical group of keys represented by the speficified "base" key. The passed in key no longer needs to be checked for the key association; in fact if there was any association, it is the one that was returned by the service's KeyAssociator.

The default implementation just returns the constant span value, but subclasses could implement this method based on additional application level sematics or construction-time configuration to dynamically assign greater span values to larger logical groups.

Parameters:
oBaseKey - the "base" key in Object format
Returns:
the partition span for the given key

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.