Search in sources :

Example 1 with MigrationEndpoint

use of com.hazelcast.spi.partition.MigrationEndpoint in project hazelcast by hazelcast.

the class MigrationManager method finalizeMigration.

private void finalizeMigration(MigrationInfo migrationInfo) {
    try {
        Address thisAddress = node.getThisAddress();
        int partitionId = migrationInfo.getPartitionId();
        boolean source = thisAddress.equals(migrationInfo.getSource());
        boolean destination = thisAddress.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) {
                internalMigrationListener.onMigrationCommit(participant, migrationInfo);
            } else {
                internalMigrationListener.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);
            nodeEngine.getOperationService().execute(op);
            removeActiveMigration(partitionId);
        } else {
            final Address partitionOwner = partitionStateManager.getPartitionImpl(partitionId).getOwnerOrNull();
            if (node.getThisAddress().equals(partitionOwner)) {
                removeActiveMigration(partitionId);
                partitionStateManager.clearMigratingFlag(partitionId);
            } else {
                logger.severe("Failed to finalize migration because this member " + thisAddress + " is not a participant of the migration: " + migrationInfo);
            }
        }
    } catch (Exception e) {
        logger.warning(e);
    } finally {
        migrationInfo.doneProcessing();
    }
}
Also used : Address(com.hazelcast.nio.Address) FinalizeMigrationOperation(com.hazelcast.internal.partition.operation.FinalizeMigrationOperation) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint) MigrationParticipant(com.hazelcast.internal.partition.impl.InternalMigrationListener.MigrationParticipant) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) PartitionStateVersionMismatchException(com.hazelcast.internal.partition.PartitionStateVersionMismatchException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) MemberLeftException(com.hazelcast.core.MemberLeftException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 MemberLeftException (com.hazelcast.core.MemberLeftException)1 PartitionStateVersionMismatchException (com.hazelcast.internal.partition.PartitionStateVersionMismatchException)1 MigrationParticipant (com.hazelcast.internal.partition.impl.InternalMigrationListener.MigrationParticipant)1 FinalizeMigrationOperation (com.hazelcast.internal.partition.operation.FinalizeMigrationOperation)1 Address (com.hazelcast.nio.Address)1 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)1 MigrationEndpoint (com.hazelcast.spi.partition.MigrationEndpoint)1 ExecutionException (java.util.concurrent.ExecutionException)1