public interface MigrationAwareService
MapService
starts moving its data around because partitions are moving
to a different machine.
Service itself must decide to keep or remove its data for specific partition according to number of backups
it's willing to keep and PartitionMigrationEvent
parameters; partitionId, migration-endpoint,
current replica index and new replica index.
SOURCE
or DESTINATION
On migration source, partition replica will be either removed completely or shifted down to a higher indexed replica. During commit, service should remove either all or some part of its data in this partition and run any other action needed. A sample commit on source will look like;
public void commitMigration(PartitionMigrationEvent event) {
if (event.getMigrationEndpoint() == MigrationEndpoint.SOURCE) {
if (event.getNewReplicaIndex() == -1 || event.getNewReplicaIndex() > configuredBackupCount) {
// remove data...
}
}
// run any other task needed
}
During rollback, source usually doesn't expected to perform any task. But service implementation may need
to execute custom tasks.
On migration destination, either a fresh partition replica will be received or current replica will be shifted up to a lower indexed replica. During rollback, service should remove either all or some part of its data in this partition and run any other action needed. A sample rollback on destination will look like;
public void rollbackMigration(PartitionMigrationEvent event) {
if (event.getMigrationEndpoint() == MigrationEndpoint.DESTINATION) {
if (event.getCurrentReplicaIndex() == -1 || event.getCurrentReplicaIndex() > configuredBackupCount) {
// remove data...
}
}
// run any other task needed
}
During commit, destination usually doesn't expected to perform any task. But service implementation may need to execute custom tasks.
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.
|
Operation |
prepareReplicationOperation(PartitionReplicationEvent event)
Returns an operation to replicate service data and/or state for a specific partition replica
on another cluster member.
|
void |
rollbackMigration(PartitionMigrationEvent event)
Rollback the migration process for this service, on both source and destination members.
|
Operation prepareReplicationOperation(PartitionReplicationEvent event)
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.
event
- replicationvoid beforeMigration(PartitionMigrationEvent event)
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.
event
- migration eventvoid commitMigration(PartitionMigrationEvent event)
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.
event
- migration eventvoid rollbackMigration(PartitionMigrationEvent event)
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.
event
- migration eventCopyright © 2022 Hazelcast, Inc.. All Rights Reserved.