public class InternalPartitionServiceImpl extends Object implements InternalPartitionService, EventPublishingService<PartitionEvent,PartitionEventListener<PartitionEvent>>, PartitionAwareService, ClusterStateListener
InternalPartitionService implementation.MIGRATION_EVENT_TOPIC, MIGRATION_RETRY_COUNT, MIGRATION_RETRY_PAUSE, PARTITION_LOST_EVENT_TOPICSERVICE_NAME| Constructor and Description |
|---|
InternalPartitionServiceImpl(Node node) |
| Modifier and Type | Method and Description |
|---|---|
UUID |
addLocalPartitionLostListener(PartitionLostListener listener) |
UUID |
addMigrationListener(MigrationListener listener) |
UUID |
addPartitionLostListener(PartitionLostListener listener) |
boolean |
applyCompletedMigrations(Collection<MigrationInfo> migrations,
Address sender) |
boolean |
areMigrationTasksAllowed() |
boolean |
commitMigrationOnDestination(MigrationInfo migration,
Address sender) |
PartitionRuntimeState |
createPartitionState()
Creates the current partition runtime state.
|
PartitionRuntimeState |
createPartitionStateInternal()
Returns a copy of the partition table or
null if not initialized. |
PartitionTableView |
createPartitionTableView()
Creates an immutable/readonly view of partition table.
|
void |
dispatchEvent(PartitionEvent event,
PartitionEventListener<PartitionEvent> partitionEventListener)
Notifies the service of a published event.
|
PartitionRuntimeState |
firstArrangement()
Causes the partition table to be arranged and published to members if :
this instance has started
this instance is the master
the cluster is
ClusterState.ACTIVE
if the partition table has not already been arranged
if there is no cluster membership change
If this instance is not the master, it will trigger the master to assign the partitions. |
InternalPartition[] |
getInternalPartitions() |
int |
getMaxAllowedBackupCount()
Returns maximum allowed backup count according to current
cluster formation and partition group configuration.
|
int |
getMemberGroupsSize()
Number of the member groups to be used in partition assignments.
|
List<Integer> |
getMemberPartitions(Address target)
Returns partition ID list assigned to given target.
|
List<Integer> |
getMemberPartitionsIfAssigned(Address target)
Returns partition ID list assigned to given target if partitions are assigned when method is called.
|
Map<Address,List<Integer>> |
getMemberPartitionsMap()
Gets member partition IDs.
|
MigrationInterceptor |
getMigrationInterceptor() |
MigrationManager |
getMigrationManager() |
long |
getMigrationQueueSize() |
List<ReplicaFragmentSyncInfo> |
getOngoingReplicaSyncRequests() |
InternalPartition |
getPartition(int partitionId)
Returns the
IPartition for a given partition ID. |
InternalPartition |
getPartition(int partitionId,
boolean triggerOwnerAssignment)
Returns the
IPartition for a given partition ID. |
int |
getPartitionCount()
Returns the number of partitions.
|
PartitionEventManager |
getPartitionEventManager() |
int |
getPartitionId(Data key)
Returns the partition ID for a
Data key. |
int |
getPartitionId(Object key)
Returns the partition ID for a given object.
|
long |
getPartitionMigrationTimeout() |
Address |
getPartitionOwner(int partitionId)
Gets the owner of the partition if it's set.
|
Address |
getPartitionOwnerOrWait(int partitionId)
Gets the owner of the partition.
|
PartitionReplicaStateChecker |
getPartitionReplicaStateChecker() |
PartitionReplicaVersionManager |
getPartitionReplicaVersionManager() |
IPartition[] |
getPartitions()
Returns an array of
IPartition instances. |
PartitionServiceProxy |
getPartitionServiceProxy()
Returns the
PartitionServiceProxy of the partition service.. |
PartitionStateManager |
getPartitionStateManager() |
int |
getPartitionStateVersion() |
PartitionReplicaManager |
getReplicaManager() |
List<ScheduledEntry<ReplicaFragmentSyncInfo,Void>> |
getScheduledReplicaSyncRequests() |
boolean |
hasOnGoingMigration()
Checks if there are any cluster-wide migrations.
|
boolean |
hasOnGoingMigrationLocal()
Checks if there are any local migrations.
|
void |
init(NodeEngine nodeEngine,
Properties properties)
Initializes this service.
|
boolean |
isMemberStateSafe()
Queries and returns if this member in a safe state or not.
|
boolean |
isPartitionOwner(int partitionId)
Check if this node is the owner of a partition.
|
void |
memberAdded(Member member)
Called when a member is added to the cluster.
|
void |
memberRemoved(Member member)
Called when a member is removed from the cluster.
|
void |
onClusterStateChange(ClusterState newState)
Called when cluster state is changed
|
void |
onPartitionLost(IPartitionLostEvent event)
Invoked when a partition lost is detected
|
boolean |
onShutdown(long timeout,
TimeUnit unit)
A hook method that's called during graceful shutdown to provide safety for data managed by this service.
|
void |
onShutdownRequest(Member member) |
void |
onShutdownResponse() |
void |
pauseMigration()
Pause all migrations
|
boolean |
processPartitionRuntimeState(PartitionRuntimeState partitionState)
Sets the
partitionState if the node is started and the state is sent by the master known by this node. |
boolean |
removeMigrationListener(UUID registrationId) |
boolean |
removePartitionLostListener(UUID registrationId) |
void |
replaceMember(Member oldMember,
Member newMember) |
void |
reset()
Resets this service back to its initial state.
|
void |
resetMigrationInterceptor() |
void |
resumeMigration()
Resume all migrations
|
void |
setInitialState(PartitionTableView partitionTable)
Sets the initial partition table and state version.
|
void |
setMigrationInterceptor(MigrationInterceptor listener) |
void |
shutdown(boolean terminate)
Shuts down this service.
|
String |
toString() |
public InternalPartitionServiceImpl(Node node)
public void init(NodeEngine nodeEngine, Properties properties)
ManagedServiceinit in interface ManagedServicenodeEngine - the NodeEngine that this service belongs toproperties - the Properties (can be used to pass settings to the service)public Address getPartitionOwner(int partitionId)
IPartitionServiceIf the owner of the partition is not set yet, it will trigger partition assignment.
getPartitionOwner in interface IPartitionServicepartitionId - the partitionIdnull if it's not set yetpublic Address getPartitionOwnerOrWait(int partitionId)
IPartitionServiceIf none is set, it will wait till the owner is set.
getPartitionOwnerOrWait in interface IPartitionServicepartitionId - the partitionIdpublic PartitionRuntimeState firstArrangement()
InternalPartitionServiceClusterState.ACTIVEfirstArrangement in interface InternalPartitionServicePartitionRuntimeState if this node is the master and the partition table is initializedPartitionStateManager.initializePartitionAssignments(java.util.Set)public void setInitialState(PartitionTableView partitionTable)
PartitionStateManager.isInitialized() stays uninitialized but the current state
will be updated nevertheless.
This method acquires the partition service lock.partitionTable - the initial partition tableIllegalStateException - if the partition manager has already been initializedpublic int getMemberGroupsSize()
InternalPartitionServicegetMemberGroupsSize in interface InternalPartitionServiceMemberGroupFactory,
PartitionGroupConfigpublic int getMaxAllowedBackupCount()
IPartitionService
The returned number will be in the range of [0, IPartition.MAX_BACKUP_COUNT].
getMaxAllowedBackupCount in interface IPartitionServicepublic void memberAdded(Member member)
InternalPartitionServicememberAdded in interface InternalPartitionServicemember - new memberpublic void memberRemoved(Member member)
InternalPartitionServicememberRemoved in interface InternalPartitionServicemember - removed memberpublic void onClusterStateChange(ClusterState newState)
ClusterStateListeneronClusterStateChange in interface ClusterStateListenernewState - new cluster stateClusterStatepublic PartitionRuntimeState createPartitionState()
InternalPartitionServicenull if the node should fetch the most recent partition
table (e.g. this node is a newly appointed master) or if the partition state manager is not initialized.createPartitionState in interface InternalPartitionServiceisFetchMostRecentPartitionTableTaskRequired(),
FetchPartitionStateOperation,
PartitionStateManager.isInitialized()public PartitionRuntimeState createPartitionStateInternal()
null if not initialized. This method will acquire the partition service
lock.public boolean processPartitionRuntimeState(PartitionRuntimeState partitionState)
partitionState if the node is started and the state is sent by the master known by this node.partitionState - the new partition statetrue if the partition state was appliedpublic boolean applyCompletedMigrations(Collection<MigrationInfo> migrations, Address sender)
public IPartition[] getPartitions()
IPartitionServiceIPartition instances.
Note: Creates a new array on each invocation, not recommended to use in high-loaded parts of code.
getPartitions in interface IPartitionServiceIPartition instancespublic InternalPartition[] getInternalPartitions()
getInternalPartitions in interface InternalPartitionServicepublic InternalPartition getPartition(int partitionId)
IPartitionServiceIPartition for a given partition ID.
If the owner of the partition is not set yet, it will trigger partition assignment.
The IPartition for a given partition ID will never change, so the result can be cached safely.
getPartition in interface InternalPartitionServicegetPartition in interface IPartitionServicepartitionId - the partition IDpublic InternalPartition getPartition(int partitionId, boolean triggerOwnerAssignment)
IPartitionServiceIPartition for a given partition ID.
If the owner of the partition is not set yet and triggerOwnerAssignment is true,
it will trigger partition assignment.
The IPartition for a given partition ID will never change, so the result can be cached safely.
getPartition in interface InternalPartitionServicegetPartition in interface IPartitionServicepartitionId - the partition IDtriggerOwnerAssignment - flag to trigger the partition assignmentpublic boolean onShutdown(long timeout,
TimeUnit unit)
GracefulShutdownAwareServiceonShutdown in interface GracefulShutdownAwareServicetimeout - timeout for graceful shutdownunit - time unitpublic void onShutdownRequest(Member member)
public void onShutdownResponse()
public boolean isMemberStateSafe()
IPartitionServiceThis method just checks for a safe state, it doesn't force this member to be in a safe state.
isMemberStateSafe in interface IPartitionServicetrue if this member in a safe state, otherwise falsepublic boolean hasOnGoingMigration()
IPartitionServicehasOnGoingMigration in interface IPartitionServicetrue if there are migrations, false otherwise.public boolean hasOnGoingMigrationLocal()
IPartitionServicehasOnGoingMigrationLocal in interface IPartitionServicetrue if there are migrations, false otherwise.public final int getPartitionId(Data key)
IPartitionServiceData key.getPartitionId in interface IPartitionServicekey - the Data keypublic final int getPartitionId(Object key)
IPartitionServicegetPartitionId in interface IPartitionServicekey - the object keypublic final int getPartitionCount()
IPartitionServicegetPartitionCount in interface IPartitionServicepublic long getPartitionMigrationTimeout()
public PartitionReplicaVersionManager getPartitionReplicaVersionManager()
getPartitionReplicaVersionManager in interface InternalPartitionServicepublic Map<Address,List<Integer>> getMemberPartitionsMap()
IPartitionServiceBlocks until partitions are assigned.
getMemberPartitionsMap in interface IPartitionServicepublic List<Integer> getMemberPartitions(Address target)
IPartitionServiceIf the owner of the partition is not set yet, it will trigger partition assignment.
getMemberPartitions in interface IPartitionServicepublic List<Integer> getMemberPartitionsIfAssigned(Address target)
InternalPartitionServicegetMemberPartitionsIfAssigned in interface InternalPartitionServicepublic void reset()
ManagedServiceTODO: what is the purpose of reset
reset in interface ManagedServicepublic void pauseMigration()
InternalPartitionServicepauseMigration in interface InternalPartitionServicepublic void resumeMigration()
InternalPartitionServiceresumeMigration in interface InternalPartitionServicepublic boolean areMigrationTasksAllowed()
public void shutdown(boolean terminate)
ManagedServiceTODO: what is the purpose of the terminate variable
shutdown in interface ManagedServiceterminate - true to shut down this servicepublic long getMigrationQueueSize()
getMigrationQueueSize in interface IPartitionServicepublic PartitionServiceProxy getPartitionServiceProxy()
InternalPartitionServicePartitionServiceProxy of the partition service..getPartitionServiceProxy in interface InternalPartitionServicePartitionServiceProxypublic UUID addMigrationListener(MigrationListener listener)
addMigrationListener in interface IPartitionServicepublic boolean removeMigrationListener(UUID registrationId)
removeMigrationListener in interface IPartitionServicepublic UUID addPartitionLostListener(PartitionLostListener listener)
addPartitionLostListener in interface IPartitionServicepublic UUID addLocalPartitionLostListener(PartitionLostListener listener)
addLocalPartitionLostListener in interface IPartitionServicepublic boolean removePartitionLostListener(UUID registrationId)
removePartitionLostListener in interface IPartitionServicepublic void dispatchEvent(PartitionEvent event, PartitionEventListener<PartitionEvent> partitionEventListener)
EventPublishingServicedispatchEvent in interface EventPublishingService<PartitionEvent,PartitionEventListener<PartitionEvent>>event - the published eventpartitionEventListener - the listener registered for this eventpublic boolean isPartitionOwner(int partitionId)
IPartitionServiceisPartitionOwner in interface IPartitionServicepartitionId - the partition IDtrue if the node owns the partition,
false if the node doesn't own the partition or if the partition hasn't been assigned yetpublic int getPartitionStateVersion()
getPartitionStateVersion in interface IPartitionServicepublic void onPartitionLost(IPartitionLostEvent event)
PartitionAwareServiceonPartitionLost in interface PartitionAwareServiceevent - The event object that contains the partition ID and the number of replicas that is lostpublic void setMigrationInterceptor(MigrationInterceptor listener)
public MigrationInterceptor getMigrationInterceptor()
public void resetMigrationInterceptor()
public List<ReplicaFragmentSyncInfo> getOngoingReplicaSyncRequests()
public List<ScheduledEntry<ReplicaFragmentSyncInfo,Void>> getScheduledReplicaSyncRequests()
public PartitionStateManager getPartitionStateManager()
public MigrationManager getMigrationManager()
public PartitionReplicaManager getReplicaManager()
public PartitionReplicaStateChecker getPartitionReplicaStateChecker()
getPartitionReplicaStateChecker in interface InternalPartitionServicepublic PartitionEventManager getPartitionEventManager()
public PartitionTableView createPartitionTableView()
InternalPartitionServicecreatePartitionTableView in interface InternalPartitionServicepublic boolean commitMigrationOnDestination(MigrationInfo migration, Address sender)
Copyright © 2019 Hazelcast, Inc.. All rights reserved.