Class 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 probability they will.

If the semantics of an application allows dynamically determining 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
  • Constructor Details

    • 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 Details

    • 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(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:
    • getAssociatedPartitions

      public PartitionSet getAssociatedPartitions(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(Object oBaseKey)
      Calculate the partition span for a logical group of keys represented by the specified "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 semantics 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