Class GridClientPartitionAffinity
- java.lang.Object
-
- org.apache.ignite.internal.client.GridClientPartitionAffinity
-
- All Implemented Interfaces:
GridClientDataAffinity,GridClientTopologyListener
public class GridClientPartitionAffinity extends Object implements GridClientDataAffinity, GridClientTopologyListener
Affinity function for partitioned cache. This function supports the following configuration:-
backupFilter- Optional filter for back up nodes. If provided, then only nodes that pass this filter will be selected as backup nodes and only nodes that don't pass this filter will be selected as primary nodes. If not provided, then primary and backup nodes will be selected out of all nodes available for this cache.NOTE: In situations where there are no primary nodes at all, i.e. no nodes for which backup filter returns
false, first backup node for the key will be considered primary.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceGridClientPartitionAffinity.HashIdResolverThis resolver is used to provide alternate hash ID, other than node ID.
-
Field Summary
Fields Modifier and Type Field Description static intDFLT_PARTITION_CNTDefault number of partitions.
-
Constructor Summary
Constructors Constructor Description GridClientPartitionAffinity()Empty constructor with all defaults.GridClientPartitionAffinity(Integer parts, GridClientPredicate<UUID> backupFilter)Initializes optional counts for replicas and backups.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GridClientPredicate<UUID>getBackupFilter()Gets optional backup filter.GridClientPartitionAffinity.HashIdResolvergetHashIdResolver()Gets hash ID resolver for nodes.intgetPartitions()Gets total number of key partitions.GridClientNodenode(Object key, Collection<? extends GridClientNode> nodes)Gets primary affinity node for a key.voidonNodeAdded(GridClientNode node)Callback for new nodes joining the remote grid.voidonNodeRemoved(GridClientNode node)Callback for nodes leaving the remote grid.GridClientPartitionAffinitysetBackupFilter(GridClientPredicate<UUID> backupFilter)Sets optional backup filter.GridClientPartitionAffinitysetHashIdResolver(GridClientPartitionAffinity.HashIdResolver hashIdRslvr)Sets hash ID resolver for nodes.GridClientPartitionAffinitysetPartitions(int parts)Sets total number of partitions.StringtoString()
-
-
-
Field Detail
-
DFLT_PARTITION_CNT
public static final int DFLT_PARTITION_CNT
Default number of partitions.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GridClientPartitionAffinity
public GridClientPartitionAffinity()
Empty constructor with all defaults.
-
GridClientPartitionAffinity
public GridClientPartitionAffinity(Integer parts, GridClientPredicate<UUID> backupFilter)
Initializes optional counts for replicas and backups.Note that
excludeNeighborsparameter is ignored ifbackupFilteris set.- Parameters:
parts- Total number of partitions. IfnullthanDFLT_PARTITION_CNTwill be used.backupFilter- Optional back up filter for nodes. If provided, then primary nodes will be selected from all nodes outside of this filter, and backups will be selected from all nodes inside it.
-
-
Method Detail
-
getPartitions
public int getPartitions()
Gets total number of key partitions. To ensure that all partitions are equally distributed across all nodes, please make sure that this number is significantly larger than a number of nodes. Also, partition size should be relatively small. Try to avoid having partitions with more than quarter million keys.Note that for fully replicated caches this method should always return
1.- Returns:
- Total partition count.
-
setPartitions
public GridClientPartitionAffinity setPartitions(int parts)
Sets total number of partitions.- Parameters:
parts- Total number of partitions.- Returns:
thisfor chaining.
-
getHashIdResolver
public GridClientPartitionAffinity.HashIdResolver getHashIdResolver()
Gets hash ID resolver for nodes. This resolver is used to provide alternate hash ID, other than node ID.Node IDs constantly change when nodes get restarted, which causes them to be placed on different locations in the hash ring, and hence causing repartitioning. Providing an alternate hash ID, which survives node restarts, puts node on the same location on the hash ring, hence minimizing required repartitioning.
- Returns:
- Hash ID resolver.
-
setHashIdResolver
public GridClientPartitionAffinity setHashIdResolver(GridClientPartitionAffinity.HashIdResolver hashIdRslvr)
Sets hash ID resolver for nodes. This resolver is used to provide alternate hash ID, other than node ID.Node IDs constantly change when nodes get restarted, which causes them to be placed on different locations in the hash ring, and hence causing repartitioning. Providing an alternate hash ID, which survives node restarts, puts node on the same location on the hash ring, hence minimizing required repartitioning.
- Parameters:
hashIdRslvr- Hash ID resolver.- Returns:
thisfor chaining.
-
getBackupFilter
public GridClientPredicate<UUID> getBackupFilter()
Gets optional backup filter. If notnull, then primary nodes will be selected from all nodes outside of this filter, and backups will be selected from all nodes inside it.Note that
excludeNeighborsparameter is ignored ifbackupFilteris set.- Returns:
- Optional backup filter.
-
setBackupFilter
public GridClientPartitionAffinity setBackupFilter(GridClientPredicate<UUID> backupFilter)
Sets optional backup filter. If provided, then primary nodes will be selected from all nodes outside of this filter, and backups will be selected from all nodes inside it.Note that
excludeNeighborsparameter is ignored ifbackupFilteris set.- Parameters:
backupFilter- Optional backup filter.- Returns:
thisfor chaining.
-
node
public GridClientNode node(Object key, Collection<? extends GridClientNode> nodes)
Gets primary affinity node for a key. In case of replicated cache all nodes are equal and can be considered primary, so it may return any node. In case of partitioned cache primary node is returned.- Specified by:
nodein interfaceGridClientDataAffinity- Parameters:
key- Key to get affinity for.nodes- Nodes to choose from.- Returns:
- Affinity nodes for the given partition.
-
onNodeAdded
public void onNodeAdded(GridClientNode node)
Callback for new nodes joining the remote grid.- Specified by:
onNodeAddedin interfaceGridClientTopologyListener- Parameters:
node- New remote node.
-
onNodeRemoved
public void onNodeRemoved(GridClientNode node)
Callback for nodes leaving the remote grid.- Specified by:
onNodeRemovedin interfaceGridClientTopologyListener- Parameters:
node- Left node.
-
-