public final class Partition extends java.lang.Object
Note that partitions are only visible on their active and replica nodes, not all nodes in the cluster.
Modifier and Type | Class and Description |
---|---|
static class |
Partition.Properties
The Partition properties used when defining a partition
|
static class |
Partition.State
The Partition states
|
static class |
Partition.Statistics
Partition statistics
|
static class |
Partition.Status
The Partition status
|
Modifier and Type | Field and Description |
---|---|
static int |
ActiveNodeIndex
Index to the active node in the nodes array
|
static long |
DefaultNumberOfThreads
The default number of threads to use when performing a migrate.
|
static long |
DefaultObjectsLockedPerTransaction
The default number of objects locked per transaction when
performing a migrate or update.
|
static Partition.Properties.RemoteEnableAction |
DefaultRemoteEnableAction
The default action used for remote partition enables.
|
static Partition.Properties.ReplicaAudit |
DefaultReplicaAudit
The default audit used for replicas.
|
static Partition.Properties.SparseAudit |
DefaultSparseAudit
The default audit used for sparse partitions.
|
Modifier and Type | Method and Description |
---|---|
long |
cardinality()
Returns the number of instances in this partition.
|
void |
clearStatistics()
Clear the statistics for the partition.
|
void |
disable(PartitionManager.DisableAction disableAction)
Disable high availability for this partition.
|
void |
enable(PartitionManager.EnableAction enableAction)
Enable high availability for this partition.
|
java.lang.String |
getActiveNode()
Get the active node for the partition.
|
Partition.State |
getCurrentState()
Get the current state for the partition.
|
Partition.Status |
getCurrentStatus()
Get the current status for the partition.
|
java.util.Date |
getLastStateChangeTime()
Get the last time the state for the partition was updated
|
java.lang.String |
getName()
Get the partition name.
|
java.lang.String[] |
getNodeList()
Get the complete node list for the partition.
|
Partition.Properties |
getProperties()
Get the properties currently defined for the partition.
|
ReplicaNode |
getReplicaNode(int idx)
Get the ReplicaNode instance for the given replica node index.
|
ReplicaNode |
getReplicaNode(java.lang.String nodeName)
Get the ReplicaNode instance for the given replica node name.
|
java.lang.String[] |
getReplicaNodes()
Get the replica node list for the partition.
|
Partition.Statistics |
getStatistics()
Get the statistics for the partition.
|
void |
migrate(Partition.Properties partitionProperties,
java.lang.String activeNode,
ReplicaNode[] replicas)
Migrate the partition.
|
void |
migrate(java.lang.String[] nodes)
Deprecated.
|
void |
setNotifier(PartitionNotifier partitionNotifier)
Associated a notifier with the partition.
|
void |
update()
Deprecated.
|
void |
update(Partition.Properties partitionProperties)
Update the partition.
|
public static final int ActiveNodeIndex
public static final long DefaultObjectsLockedPerTransaction
public static final long DefaultNumberOfThreads
public static final Partition.Properties.SparseAudit DefaultSparseAudit
Partition.Properties.SparseAudit.VERIFY_NODE_LIST
public static final Partition.Properties.ReplicaAudit DefaultReplicaAudit
Partition.Properties.ReplicaAudit.WAIT_ACTIVE
public static final Partition.Properties.RemoteEnableAction DefaultRemoteEnableAction
Partition.Properties.RemoteEnableAction.ENABLE_PARTITION
public final java.lang.String getName()
public final java.lang.String getActiveNode()
public final java.lang.String[] getReplicaNodes()
public final java.lang.String[] getNodeList()
The node list is a String array of node names, with the active node being at ActiveNodeIndex, followed by a prioritized list of replica nodes.
public final Partition.State getCurrentState()
public final Partition.Status getCurrentStatus()
public final ReplicaNode getReplicaNode(int idx) throws java.lang.IndexOutOfBoundsException
idx
- Index into the ReplicaNode array.java.lang.IndexOutOfBoundsException
- The idx isn't valid.public final ReplicaNode getReplicaNode(java.lang.String nodeName) throws java.lang.IllegalArgumentException
nodeName
- Name of replica node.java.lang.IllegalArgumentException
- The nodeName was invalid.public final java.util.Date getLastStateChangeTime()
public final Partition.Properties getProperties()
The restoreFromNode property is not stored in the runtime since it has no meaning outside of the initial definePartition(). So this method will return a Properties instance with a null restoreFromNode value.
public final Partition.Statistics getStatistics()
public final void clearStatistics()
@Deprecated public final void update() throws NodeMismatch, NotActiveNode
update(Properties)
instead.NodeMismatch
NotActiveNode
public final void update(Partition.Properties partitionProperties) throws NodeMismatch, NotActiveNode
This method is used to re-partition all instances that exist in a
partition. For each instance in the partition, the PartitionMapper
defined for that type is accessed, and the
instance re-assigned to the partition that the PartitionMapper.getPartition(java.lang.Object)
method returns. The update() method
must be called on the current active node for the partition.
To split a partition, the applications should create the new partition, install a new PartitionMapper for all types managed by the partition, and call the update() method for the existing partition.
To merge two or more partitions, the applications should install a new PartitionMapper for all types managed by the partition(s), and call the update() method for all the partitions that need to be merged.
It is important that all partitions returned when executing the PartitionMapper's getPartition() call for a type all contain identical node lists. If the partition returned contains a different node list than this partition, a NodeMismatch exception is thrown, and the update() terminates. To fix this, perform a migrate() on all partitions that will be split or merged to insure that they have identical node lists before performing an update().
partitionProperties
- Optional properties for the partition.
If null, the default property values are used.NodeMismatch
- The re-partitioning of instances was done using partitions that
have different node lists.NotActiveNode
- The current node is not the active node for the partition.@Deprecated public final void migrate(java.lang.String[] nodes) throws NotActiveNode, java.lang.IllegalArgumentException
migrate(Properties, String, ReplicaNode [])
instead.nodes
- An ordered list of nodes for the partition.NotActiveNode
java.lang.IllegalArgumentException
public final void migrate(Partition.Properties partitionProperties, java.lang.String activeNode, ReplicaNode[] replicas) throws NotActiveNode, java.lang.IllegalArgumentException
This method is used to migrate all instances that exist in a partition. For each instance in the partition, the object is migrated as needed to all nodes in the replicas array, and to the new activeNode if it is different from the current active node. This method must be called on the currently active node for the partition.
Any properties passed in only apply to the current migrate() command, properties passed into definePartition() are saved and used during failover.
partitionProperties
- Optional properties for the partition.
If null, the default property values are used.activeNode
- Active node after migrate completes.replicas
- An ordered list of replica nodes for the partition.
Should be passed in as a null instance or a zero length array if
no replicas exists.NotActiveNode
- The current node is not the active node for the partition.java.lang.IllegalArgumentException
- The activeNode or replica array was invalid.public final void enable(PartitionManager.EnableAction enableAction) throws NodeMismatch, ResourceUnavailableException
This method is used to enable this partition. If the partition is already in the ACTIVE state, no action is taken. This method blocks until all required object migration is complete.
enableAction
- The action to take when enabling partitions.ResourceUnavailableException
- The minimum number of nodes needed to establish a quorum has not been
seen, or the partition has not been defined.NodeMismatch
- The partition does not have the local node in the node list, and the
active node for the partition has a different node list.PartitionManager.enablePartitions(PartitionManager.EnableAction)
public final void disable(PartitionManager.DisableAction disableAction) throws ResourceUnavailableException
This method is used to remove the local node from the node list of this partition, and move the partition state to UNAVAILABLE. If called multiple times, the additional calls have no effect.
If the local node does not exist in the partition, no action is taken.
disableAction
- The action to take when disabling partitions.ResourceUnavailableException
- The partition would be in the UNAVAILABLE state after the
disable executes, not thrown if LEAVE_CLUSTER_FORCE is used.PartitionManager.disablePartitions(PartitionManager.DisableAction)
public final void setNotifier(PartitionNotifier partitionNotifier)
This method is used to associate a user defined PartitionNotifier
instance with a partition.
PartitionNotifier instances are local to a node, this method should be executed on all nodes which need to determine if a partition state change occurs.
The same PartitionNotifier instance can be associated with multiple partitions. Multiple PartitionNotifier instances can be installed for a given Partition. When a state change occurs, all instances are executed, no order is guaranteed when executing the notifiers. To remove a notifier, the PartitionNotifier instance should be deleted.
partitionNotifier
- User defined notifier instance.public final long cardinality()
This method does not establish transaction locks on the partition or any of the individual objects in the partition. This means the number returned by cardinality() may change even as observed within a single transaction.
Warning: This method requires a scan of all objects for each class in the partition to determine the count, which is computationally expensive.