public class InternalPartitionServiceImpl extends Object implements InternalPartitionService, EventPublishingService<PartitionEvent,PartitionEventListener<PartitionEvent>>, PartitionAwareService, ClusterStateListener, ClusterVersionListener
InternalPartitionService
implementation.MIGRATION_EVENT_TOPIC, MIGRATION_RETRY_COUNT, MIGRATION_RETRY_PAUSE, PARTITION_LOST_EVENT_TOPIC
SERVICE_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) |
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 partitionEvent,
PartitionEventListener 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. |
InternalMigrationListener |
getInternalMigrationListener() |
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.
|
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 |
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
|
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(String registrationId) |
boolean |
removePartitionLostListener(String registrationId) |
void |
replaceMember(Member oldMember,
Member newMember) |
void |
reset()
Resets this service back to its 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 service.
|
String |
toString() |
public InternalPartitionServiceImpl(Node node)
public void init(NodeEngine nodeEngine, Properties properties)
ManagedService
init
in interface ManagedService
nodeEngine
- the NodeEngine that this service belongs toproperties
- the Properties (can be used to pass settings to the service)public Address getPartitionOwner(int partitionId)
IPartitionService
If the owner of the partition is not set yet, it will trigger partition assignment.
getPartitionOwner
in interface IPartitionService
partitionId
- the partitionIdnull
if it's not set yetpublic Address getPartitionOwnerOrWait(int partitionId)
IPartitionService
If none is set, it will wait till the owner is set.
getPartitionOwnerOrWait
in interface IPartitionService
partitionId
- the partitionIdpublic PartitionRuntimeState firstArrangement()
InternalPartitionService
ClusterState.ACTIVE
firstArrangement
in interface InternalPartitionService
PartitionRuntimeState
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()
InternalPartitionService
getMemberGroupsSize
in interface InternalPartitionService
MemberGroupFactory
,
PartitionGroupConfig
public int getMaxAllowedBackupCount()
IPartitionService
The returned number will be in the range of [0, IPartition.MAX_BACKUP_COUNT
].
getMaxAllowedBackupCount
in interface IPartitionService
public void memberAdded(Member member)
InternalPartitionService
memberAdded
in interface InternalPartitionService
member
- new memberpublic void memberRemoved(Member member)
InternalPartitionService
memberRemoved
in interface InternalPartitionService
member
- removed memberpublic void onClusterStateChange(ClusterState newState)
ClusterStateListener
onClusterStateChange
in interface ClusterStateListener
newState
- new cluster stateClusterState
public void onClusterVersionChange(Version newVersion)
ClusterVersionListener
ClusterStateManager#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 ClusterVersionListener
newVersion
- the new versionpublic PartitionRuntimeState createPartitionState()
InternalPartitionService
null
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 InternalPartitionService
isFetchMostRecentPartitionTableTaskRequired()
,
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()
IPartitionService
IPartition
instances.
Note: Creates a new array on each invocation, not recommended to use in high-loaded parts of code.
getPartitions
in interface IPartitionService
IPartition
instancespublic InternalPartition[] getInternalPartitions()
getInternalPartitions
in interface InternalPartitionService
public InternalPartition getPartition(int partitionId)
IPartitionService
IPartition
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 InternalPartitionService
getPartition
in interface IPartitionService
partitionId
- the partition IDpublic InternalPartition getPartition(int partitionId, boolean triggerOwnerAssignment)
IPartitionService
IPartition
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 InternalPartitionService
getPartition
in interface IPartitionService
partitionId
- the partition IDtriggerOwnerAssignment
- flag to trigger the partition assignmentpublic boolean onShutdown(long timeout, TimeUnit unit)
GracefulShutdownAwareService
onShutdown
in interface GracefulShutdownAwareService
timeout
- timeout for graceful shutdownunit
- time unitpublic void onShutdownRequest(Member member)
public void onShutdownResponse()
public boolean isMemberStateSafe()
IPartitionService
This method just checks for a safe state, it doesn't force this member to be in a safe state.
isMemberStateSafe
in interface IPartitionService
true
if this member in a safe state, otherwise false
public boolean hasOnGoingMigration()
IPartitionService
hasOnGoingMigration
in interface IPartitionService
true
if there are migrations, false
otherwise.public boolean hasOnGoingMigrationLocal()
IPartitionService
hasOnGoingMigrationLocal
in interface IPartitionService
true
if there are migrations, false
otherwise.public final int getPartitionId(Data key)
IPartitionService
Data
key.getPartitionId
in interface IPartitionService
key
- the Data
keypublic final int getPartitionId(Object key)
IPartitionService
getPartitionId
in interface IPartitionService
key
- the object keypublic final int getPartitionCount()
IPartitionService
getPartitionCount
in interface IPartitionService
public long getPartitionMigrationTimeout()
public PartitionReplicaVersionManager getPartitionReplicaVersionManager()
getPartitionReplicaVersionManager
in interface InternalPartitionService
public Map<Address,List<Integer>> getMemberPartitionsMap()
IPartitionService
Blocks until partitions are assigned.
getMemberPartitionsMap
in interface IPartitionService
public List<Integer> getMemberPartitions(Address target)
IPartitionService
If the owner of the partition is not set yet, it will trigger partition assignment.
getMemberPartitions
in interface IPartitionService
public List<Integer> getMemberPartitionsIfAssigned(Address target)
InternalPartitionService
getMemberPartitionsIfAssigned
in interface InternalPartitionService
public void reset()
ManagedService
TODO: what is the purpose of reset
reset
in interface ManagedService
public void pauseMigration()
InternalPartitionService
pauseMigration
in interface InternalPartitionService
public void resumeMigration()
InternalPartitionService
resumeMigration
in interface InternalPartitionService
public boolean areMigrationTasksAllowed()
public void shutdown(boolean terminate)
ManagedService
TODO: what is the purpose of the terminate variable
shutdown
in interface ManagedService
terminate
- true
to shut down this servicepublic long getMigrationQueueSize()
getMigrationQueueSize
in interface IPartitionService
public PartitionServiceProxy getPartitionServiceProxy()
InternalPartitionService
PartitionServiceProxy
of the partition service..getPartitionServiceProxy
in interface InternalPartitionService
PartitionServiceProxy
public String addMigrationListener(MigrationListener listener)
addMigrationListener
in interface IPartitionService
public boolean removeMigrationListener(String registrationId)
removeMigrationListener
in interface IPartitionService
public String addPartitionLostListener(PartitionLostListener listener)
addPartitionLostListener
in interface IPartitionService
public String addLocalPartitionLostListener(PartitionLostListener listener)
addLocalPartitionLostListener
in interface IPartitionService
public boolean removePartitionLostListener(String registrationId)
removePartitionLostListener
in interface IPartitionService
public void dispatchEvent(PartitionEvent partitionEvent, PartitionEventListener partitionEventListener)
EventPublishingService
dispatchEvent
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)
IPartitionService
isPartitionOwner
in interface IPartitionService
partitionId
- 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 IPartitionService
public void onPartitionLost(IPartitionLostEvent event)
PartitionAwareService
onPartitionLost
in interface PartitionAwareService
event
- 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()
getPartitionReplicaStateChecker
in interface InternalPartitionService
public PartitionEventManager getPartitionEventManager()
public PartitionTableView createPartitionTableView()
InternalPartitionService
createPartitionTableView
in interface InternalPartitionService
public boolean commitMigrationOnDestination(MigrationInfo migration, Address sender)
Copyright © 2019 Hazelcast, Inc.. All Rights Reserved.