public class InternalPartitionServiceImpl extends Object implements InternalPartitionService, ManagedService, EventPublishingService<PartitionEvent,PartitionEventListener<PartitionEvent>>, PartitionAwareService, ClusterStateListener, ClusterVersionListener
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 |
|---|---|
String |
addLocalPartitionLostListener(PartitionLostListener listener) |
String |
addMigrationListener(MigrationListener listener) |
void |
addPartitionListener(PartitionListener listener) |
String |
addPartitionLostListener(PartitionLostListener listener) |
PartitionRuntimeState |
createPartitionState()
Creates the current partition runtime state.
|
PartitionRuntimeState |
createPartitionStateInternal()
Returns a copy of the partition table or
null if not initialized. |
PartitionTableView |
createPartitionTableView() |
void |
dispatchEvent(PartitionEvent partitionEvent,
PartitionEventListener partitionEventListener)
Notifies the service of a published event.
|
void |
firstArrangement()
Causes the partition table to be arranged and published to members if :
the instance has started
the cluster is
ClusterState.ACTIVE
if it has not already been arranged
if there is no cluster membership change
If this node is not the master, it will trigger the master to assign the partitions. |
InternalMigrationListener |
getInternalMigrationListener() |
InternalPartition[] |
getInternalPartitions() |
int |
getMaxAllowedBackupCount()
Returns maximum allowed backup count according to current
cluster formation and partition group configuration.
|
int |
getMemberGroupsSize() |
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.
|
MigrationManager |
getMigrationManager() |
long |
getMigrationQueueSize() |
List<ReplicaFragmentSyncInfo> |
getOngoingReplicaSyncRequests() |
InternalPartition |
getPartition(int partitionId)
Returns the IPartition for a given partitionId.
|
InternalPartition |
getPartition(int partitionId,
boolean triggerOwnerAssignment)
Returns the IPartition for a given partitionId.
|
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() |
PartitionServiceProxy |
getPartitionServiceProxy() |
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 ManagedService
|
boolean |
isMemberAllowedToJoin(Address address) |
boolean |
isMemberStateSafe()
Query and return if this member in a safe state or not.
|
boolean |
isMigrationAllowed() |
boolean |
isPartitionOwner(int partitionId)
Check if this node is the owner of a partition
|
void |
memberAdded(MemberImpl member) |
void |
memberRemoved(MemberImpl member) |
void |
onClusterStateChange(ClusterState newState)
Called when cluster state is changed
|
void |
onClusterVersionChange(Version newVersion)
Invoked on registered listeners after the new cluster version has been applied.
|
void |
onPartitionLost(IPartitionLostEvent event)
Invoked when a partition lost is detected
|
void |
onShutdownRequest(Address address) |
void |
onShutdownResponse() |
void |
pauseMigration()
Pause all migrations
|
boolean |
prepareToSafeShutdown(long timeout,
TimeUnit unit) |
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(String registrationId) |
boolean |
removePartitionLostListener(String registrationId) |
void |
replaceAddress(Address oldAddress,
Address newAddress) |
void |
reset()
reset this ManagedService back to initial state.
|
void |
resetInternalMigrationListener() |
void |
resumeMigration()
Resume all migrations
|
void |
setInitialState(PartitionTableView partitionTable)
Sets the initial partition table and state version.
|
void |
setInternalMigrationListener(InternalMigrationListener listener) |
void |
shutdown(boolean terminate)
Shuts down this ManagedService.
|
String |
toString() |
public InternalPartitionServiceImpl(Node node)
public void init(NodeEngine nodeEngine, Properties properties)
ManagedServiceinit in interface ManagedServicenodeEngine - the NodeEngine that this ManagedService belongs to.properties - the Properties. Can be used to pass settings to the service.public Address getPartitionOwner(int partitionId)
IPartitionServicegetPartitionOwner in interface IPartitionServicepartitionId - the partitionIdpublic Address getPartitionOwnerOrWait(int partitionId)
IPartitionServicegetPartitionOwnerOrWait in interface IPartitionServicepartitionId - the partitionIdpublic void firstArrangement()
InternalPartitionServiceClusterState.ACTIVEfirstArrangement in interface InternalPartitionServicePartitionStateManager.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()
getMemberGroupsSize in interface InternalPartitionServicepublic int getMaxAllowedBackupCount()
IPartitionServiceIPartition.MAX_BACKUP_COUNT].getMaxAllowedBackupCount in interface IPartitionServicepublic boolean isMemberAllowedToJoin(Address address)
isMemberAllowedToJoin in interface InternalPartitionServicepublic void memberAdded(MemberImpl member)
memberAdded in interface InternalPartitionServicepublic void memberRemoved(MemberImpl member)
memberRemoved in interface InternalPartitionServicepublic void onClusterStateChange(ClusterState newState)
ClusterStateListeneronClusterStateChange in interface ClusterStateListenernewState - new cluster stateClusterStatepublic void onClusterVersionChange(Version newVersion)
ClusterVersionListenerClusterStateManager#version has been updated and while the cluster service lock
ClusterServiceImpl#lock is still locked, as part of the commit phase of the transaction changing
the cluster version. Unhandled exceptions from listeners implementation will break the new version commit and a slow
implementation will stall the system and may cause a transaction timeout.
If new cluster version is null and property
GroupProperty.INIT_CLUSTER_VERSION is set, the version set by this property
will be provided as argument to the listener. If neither are set, running node's codebase version will be used.onClusterVersionChange in interface ClusterVersionListenernewVersion - the new versionpublic 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 IPartition[] getPartitions()
getPartitions in interface IPartitionServicepublic InternalPartition[] getInternalPartitions()
getInternalPartitions in interface InternalPartitionServicepublic InternalPartition getPartition(int partitionId)
IPartitionServicegetPartition in interface InternalPartitionServicegetPartition in interface IPartitionServicepartitionId - the partitionIdpublic InternalPartition getPartition(int partitionId, boolean triggerOwnerAssignment)
IPartitionServicetriggerOwnerAssignment is true,
it will trigger partition assignment.
The IPartition for a given partitionId will never change, so it can be cached safely.getPartition in interface InternalPartitionServicegetPartition in interface IPartitionServicepartitionId - the partitionIdtriggerOwnerAssignment - flag to trigger partition assignmentpublic boolean prepareToSafeShutdown(long timeout,
TimeUnit unit)
prepareToSafeShutdown in interface InternalPartitionServicepublic void onShutdownRequest(Address address)
public void onShutdownResponse()
public boolean isMemberStateSafe()
IPartitionServiceisMemberStateSafe in interface IPartitionServicetrue if this member in a safe state, otherwise falsepublic boolean hasOnGoingMigration()
IPartitionServicehasOnGoingMigration in interface IPartitionServicepublic boolean hasOnGoingMigrationLocal()
IPartitionServicehasOnGoingMigrationLocal in interface IPartitionServicepublic final int getPartitionId(Data key)
IPartitionServicegetPartitionId in interface IPartitionServicekey - the Data key.public final int getPartitionId(Object key)
IPartitionServicegetPartitionId in interface IPartitionServicekey - the object key.public final int getPartitionCount()
IPartitionServicegetPartitionCount in interface IPartitionServicepublic long getPartitionMigrationTimeout()
public PartitionReplicaVersionManager getPartitionReplicaVersionManager()
getPartitionReplicaVersionManager in interface InternalPartitionServicepublic Map<Address,List<Integer>> getMemberPartitionsMap()
IPartitionServicegetMemberPartitionsMap in interface IPartitionServicepublic List<Integer> getMemberPartitions(Address target)
IPartitionServicegetMemberPartitions in interface IPartitionServicepublic List<Integer> getMemberPartitionsIfAssigned(Address target)
InternalPartitionServicegetMemberPartitionsIfAssigned in interface InternalPartitionServicepublic void reset()
ManagedServicereset in interface ManagedServicepublic void pauseMigration()
InternalPartitionServicepauseMigration in interface InternalPartitionServicepublic void resumeMigration()
InternalPartitionServiceresumeMigration in interface InternalPartitionServicepublic boolean isMigrationAllowed()
public void shutdown(boolean terminate)
ManagedServiceshutdown in interface ManagedServiceterminate - true to shut down the ManagedServicepublic long getMigrationQueueSize()
getMigrationQueueSize in interface IPartitionServicepublic PartitionServiceProxy getPartitionServiceProxy()
public String addMigrationListener(MigrationListener listener)
addMigrationListener in interface IPartitionServicepublic boolean removeMigrationListener(String registrationId)
removeMigrationListener in interface IPartitionServicepublic String addPartitionLostListener(PartitionLostListener listener)
addPartitionLostListener in interface IPartitionServicepublic String addLocalPartitionLostListener(PartitionLostListener listener)
addLocalPartitionLostListener in interface IPartitionServicepublic boolean removePartitionLostListener(String registrationId)
removePartitionLostListener in interface IPartitionServicepublic void dispatchEvent(PartitionEvent partitionEvent, PartitionEventListener partitionEventListener)
EventPublishingServicedispatchEvent in interface EventPublishingService<PartitionEvent,PartitionEventListener<PartitionEvent>>partitionEvent - the published eventpartitionEventListener - the listener registered for this eventpublic void addPartitionListener(PartitionListener listener)
public boolean isPartitionOwner(int partitionId)
IPartitionServiceisPartitionOwner in interface IPartitionServicepublic 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 setInternalMigrationListener(InternalMigrationListener listener)
public InternalMigrationListener getInternalMigrationListener()
public void resetInternalMigrationListener()
public List<ReplicaFragmentSyncInfo> getOngoingReplicaSyncRequests()
public List<ScheduledEntry<ReplicaFragmentSyncInfo,Void>> getScheduledReplicaSyncRequests()
public PartitionStateManager getPartitionStateManager()
public MigrationManager getMigrationManager()
public PartitionReplicaManager getReplicaManager()
public PartitionReplicaStateChecker getPartitionReplicaStateChecker()
public PartitionEventManager getPartitionEventManager()
public PartitionTableView createPartitionTableView()
createPartitionTableView in interface InternalPartitionServiceCopyright © 2017 Hazelcast, Inc.. All Rights Reserved.