public class CountingMigrationAwareService extends Object implements FragmentedMigrationAwareService
MigrationAwareService
that delegates to another MigrationAwareService
and keeps track of the number of
migrations concerning the partition owner (either as current or new replica index) currently in-flight.Constructor and Description |
---|
CountingMigrationAwareService(FragmentedMigrationAwareService migrationAwareService) |
Modifier and Type | Method and Description |
---|---|
void |
beforeMigration(PartitionMigrationEvent event)
Called before migration process starts, on both source and destination members.
|
void |
commitMigration(PartitionMigrationEvent event)
Commits the migration process for this service, on both source and destination members.
|
Collection<ServiceNamespace> |
getAllServiceNamespaces(PartitionReplicationEvent event)
Returns all known namespaces for given replication event.
|
int |
getMigrationStamp()
Returns a stamp to denote current migration state which can later be validated
using
validateMigrationStamp(int) . |
boolean |
isKnownServiceNamespace(ServiceNamespace namespace)
Returns true if namespace is known by this service, false otherwise
|
Operation |
prepareReplicationOperation(PartitionReplicationEvent event)
Returns an operation to replicate service data and/or state for a specific partition replica
on another cluster member.
|
Operation |
prepareReplicationOperation(PartitionReplicationEvent event,
Collection<ServiceNamespace> namespaces)
Returns an operation to replicate service data and/or state for a specific partition replica and namespaces
on another cluster member.
|
void |
rollbackMigration(PartitionMigrationEvent event)
Rollback the migration process for this service, on both source and destination members.
|
boolean |
validateMigrationStamp(int stamp)
Returns true if there's no primary replica migrations started and/or completed
since issuance of the given stamp.
|
public CountingMigrationAwareService(FragmentedMigrationAwareService migrationAwareService)
public Collection<ServiceNamespace> getAllServiceNamespaces(PartitionReplicationEvent event)
FragmentedMigrationAwareService
getAllServiceNamespaces
in interface FragmentedMigrationAwareService
event
- replication eventpublic boolean isKnownServiceNamespace(ServiceNamespace namespace)
FragmentedMigrationAwareService
isKnownServiceNamespace
in interface FragmentedMigrationAwareService
namespace
- namespacepublic Operation prepareReplicationOperation(PartitionReplicationEvent event)
MigrationAwareService
This method will be called on source member whenever partitioning system requires to copy/replicate a partition replica. Returned operation will be executed on destination member. If operation fails by throwing exception, migration process will fail and will be rolled back.
Returning null is allowed and means service does not have anything to replicate.
prepareReplicationOperation
in interface MigrationAwareService
event
- replicationpublic Operation prepareReplicationOperation(PartitionReplicationEvent event, Collection<ServiceNamespace> namespaces)
FragmentedMigrationAwareService
MigrationAwareService.prepareReplicationOperation(PartitionReplicationEvent)
,
instead of copying whole partition replica, allows copying only some portion of replica,
specified by given namespaces.
This method will be called on source member whenever partitioning system requires to copy/replicate a partition replica. Returned operation will be executed on destination member. If operation fails by throwing exception, migration process will fail and will be rolled back.
Returning null is allowed and means service does not have anything to replicate.
prepareReplicationOperation
in interface FragmentedMigrationAwareService
event
- replication eventnamespaces
- replica fragment namespaces to replicateMigrationAwareService.prepareReplicationOperation(PartitionReplicationEvent)
public void beforeMigration(PartitionMigrationEvent event)
MigrationAwareService
Service can take actions required before migration. Migration process will block until this method returns. If this method fails by throwing an exception, migration process for specific partition will fail and will be rolled back.
beforeMigration
in interface MigrationAwareService
event
- migration eventpublic void commitMigration(PartitionMigrationEvent event)
MigrationAwareService
Commit is not expected to fail at this point, all exceptions will be suppressed and logged. Implementations of this method must be thread safe as this method may be called concurrently for different migrations on different partitions.
commitMigration
in interface MigrationAwareService
event
- migration eventpublic void rollbackMigration(PartitionMigrationEvent event)
MigrationAwareService
Rollback is not expected to fail at this point, all exceptions will be suppressed and logged. Implementations of this method must be thread safe as this method may be called concurrently for different migrations on different partitions.
rollbackMigration
in interface MigrationAwareService
event
- migration eventpublic int getMigrationStamp()
validateMigrationStamp(int)
.public boolean validateMigrationStamp(int stamp)
stamp
- a stampCopyright © 2021 Hazelcast, Inc.. All Rights Reserved.