use of com.hazelcast.internal.partition.MigrationEndpoint in project hazelcast by hazelcast.
the class MigrationManager method finalizeMigration.
/**
* Finalizes a migration that has finished with {@link MigrationStatus#SUCCESS}
* or {@link MigrationStatus#FAILED} by invoking {@link FinalizeMigrationOperation}
* locally if this is the source or destination. The finalization is asynchronous
* and there might be other ongoing migration finalizations.
* <p>
* It will also cleanup the migration state by removing the active migration and
* clearing the migration flag on the partition owner.
* <p>
* This method should not be called on a node which is not the source, destination
* or partition owner for this migration.
*
* @param migrationInfo the migration to be finalized
*/
void finalizeMigration(MigrationInfo migrationInfo) {
try {
PartitionReplica localReplica = PartitionReplica.from(node.getLocalMember());
int partitionId = migrationInfo.getPartitionId();
boolean source = localReplica.equals(migrationInfo.getSource());
boolean destination = localReplica.equals(migrationInfo.getDestination());
assert migrationInfo.getStatus() == MigrationStatus.SUCCESS || migrationInfo.getStatus() == MigrationStatus.FAILED : "Invalid migration: " + migrationInfo;
if (source || destination) {
boolean success = migrationInfo.getStatus() == MigrationStatus.SUCCESS;
MigrationParticipant participant = source ? MigrationParticipant.SOURCE : MigrationParticipant.DESTINATION;
if (success) {
migrationInterceptor.onMigrationCommit(participant, migrationInfo);
} else {
migrationInterceptor.onMigrationRollback(participant, migrationInfo);
}
MigrationEndpoint endpoint = source ? MigrationEndpoint.SOURCE : MigrationEndpoint.DESTINATION;
FinalizeMigrationOperation op = new FinalizeMigrationOperation(migrationInfo, endpoint, success);
op.setPartitionId(partitionId).setNodeEngine(nodeEngine).setValidateTarget(false).setService(partitionService);
registerFinalizingMigration(migrationInfo);
OperationServiceImpl operationService = nodeEngine.getOperationService();
if (logger.isFineEnabled()) {
logger.fine("Finalizing " + migrationInfo);
}
if (operationService.isRunAllowed(op)) {
// When migration finalization is triggered by subsequent migrations
// on partition thread, finalization may run directly on calling thread.
// Otherwise, if previously completed migration and newly submitted migration
// are on the same partition, then finalizing previous migration later will
// break the order, hence safety.
operationService.run(op);
} else {
operationService.execute(op);
}
removeActiveMigration(migrationInfo);
} else {
PartitionReplica partitionOwner = partitionStateManager.getPartitionImpl(partitionId).getOwnerReplicaOrNull();
if (localReplica.equals(partitionOwner)) {
// This is the primary owner of the partition and the migration was a backup replica migration.
// In this case, primary owner has nothing to do anymore,
// just remove the active migration and clear the migrating flag.
removeActiveMigration(migrationInfo);
partitionStateManager.clearMigratingFlag(partitionId);
} else {
logger.severe("Failed to finalize migration because " + localReplica + " is not a participant of the migration: " + migrationInfo);
}
}
} catch (Exception e) {
logger.warning(e);
}
}
use of com.hazelcast.internal.partition.MigrationEndpoint in project hazelcast by hazelcast.
the class MigrationEndpointTest method testReadFromSource.
@Test
public void testReadFromSource() throws Exception {
when(dataInput.readByte()).thenReturn((byte) 0);
MigrationEndpoint actual = MigrationEndpoint.readFrom(dataInput);
assertEquals(SOURCE, actual);
}
use of com.hazelcast.internal.partition.MigrationEndpoint in project hazelcast by hazelcast.
the class MigrationEndpointTest method testReadFromDestination.
@Test
public void testReadFromDestination() throws Exception {
when(dataInput.readByte()).thenReturn((byte) 1);
MigrationEndpoint actual = MigrationEndpoint.readFrom(dataInput);
assertEquals(DESTINATION, actual);
}
Aggregations