Search in sources :

Example 1 with MigrationAwareService

use of com.hazelcast.internal.partition.MigrationAwareService in project hazelcast by hazelcast.

the class FinalizeMigrationOperation method notifyServices.

/**
 * Notifies all {@link MigrationAwareService}s that the migration finished. The services can then execute the commit or
 * rollback logic. If this node was the source and backup replica for a partition, the services will first be notified that
 * the migration is starting.
 */
private void notifyServices() {
    PartitionMigrationEvent event = getPartitionMigrationEvent();
    Collection<MigrationAwareService> migrationAwareServices = getMigrationAwareServices();
    // knows replica is moved away from itself.
    if (isOldBackupReplicaOwner()) {
        // execute beforeMigration on old backup before commit/rollback
        for (MigrationAwareService service : migrationAwareServices) {
            beforeMigration(event, service);
        }
    }
    for (MigrationAwareService service : migrationAwareServices) {
        finishMigration(event, service);
    }
}
Also used : PartitionMigrationEvent(com.hazelcast.internal.partition.PartitionMigrationEvent) MigrationAwareService(com.hazelcast.internal.partition.MigrationAwareService)

Example 2 with MigrationAwareService

use of com.hazelcast.internal.partition.MigrationAwareService in project hazelcast by hazelcast.

the class AbstractPartitionOperation method createReplicationOperations.

private Collection<Operation> createReplicationOperations(PartitionReplicationEvent event, boolean nonFragmentedOnly) {
    Collection<Operation> operations = new ArrayList<>();
    NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    Collection<ServiceInfo> services = nodeEngine.getServiceInfos(MigrationAwareService.class);
    for (ServiceInfo serviceInfo : services) {
        MigrationAwareService service = serviceInfo.getService();
        if (nonFragmentedOnly && service instanceof FragmentedMigrationAwareService) {
            // skip fragmented services
            continue;
        }
        Operation op = service.prepareReplicationOperation(event);
        if (op != null) {
            op.setServiceName(serviceInfo.getName());
            operations.add(op);
        }
    }
    return operations;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ServiceInfo(com.hazelcast.spi.impl.servicemanager.ServiceInfo) ArrayList(java.util.ArrayList) MigrationAwareService(com.hazelcast.internal.partition.MigrationAwareService) ChunkedMigrationAwareService(com.hazelcast.internal.partition.ChunkedMigrationAwareService) FragmentedMigrationAwareService(com.hazelcast.internal.partition.FragmentedMigrationAwareService) Operation(com.hazelcast.spi.impl.operationservice.Operation) FragmentedMigrationAwareService(com.hazelcast.internal.partition.FragmentedMigrationAwareService)

Example 3 with MigrationAwareService

use of com.hazelcast.internal.partition.MigrationAwareService in project hazelcast by hazelcast.

the class BeforePromotionOperation method run.

@Override
public void run() {
    ILogger logger = getLogger();
    if (logger.isFinestEnabled()) {
        logger.finest("Running before promotion for " + getPartitionMigrationEvent());
    }
    PartitionMigrationEvent event = getPartitionMigrationEvent();
    for (MigrationAwareService service : getMigrationAwareServices()) {
        try {
            service.beforeMigration(event);
        } catch (Throwable e) {
            logger.warning("While promoting " + getPartitionMigrationEvent(), e);
        }
    }
}
Also used : PartitionMigrationEvent(com.hazelcast.internal.partition.PartitionMigrationEvent) MigrationAwareService(com.hazelcast.internal.partition.MigrationAwareService) ILogger(com.hazelcast.logging.ILogger)

Example 4 with MigrationAwareService

use of com.hazelcast.internal.partition.MigrationAwareService in project hazelcast by hazelcast.

the class BaseMigrationOperation method executeBeforeMigrations.

/**
 * Notifies all {@link MigrationAwareService}s that the migration is starting.
 */
void executeBeforeMigrations() throws Exception {
    PartitionMigrationEvent event = getMigrationEvent();
    Throwable t = null;
    for (MigrationAwareService service : getMigrationAwareServices()) {
        // we need to make sure all beforeMigration() methods are executed
        try {
            service.beforeMigration(event);
        } catch (Throwable e) {
            getLogger().warning("Error while executing beforeMigration()", e);
            t = e;
        }
    }
    if (t != null) {
        throw ExceptionUtil.rethrow(t);
    }
}
Also used : PartitionMigrationEvent(com.hazelcast.internal.partition.PartitionMigrationEvent) MigrationAwareService(com.hazelcast.internal.partition.MigrationAwareService)

Aggregations

MigrationAwareService (com.hazelcast.internal.partition.MigrationAwareService)4 PartitionMigrationEvent (com.hazelcast.internal.partition.PartitionMigrationEvent)3 ChunkedMigrationAwareService (com.hazelcast.internal.partition.ChunkedMigrationAwareService)1 FragmentedMigrationAwareService (com.hazelcast.internal.partition.FragmentedMigrationAwareService)1 ILogger (com.hazelcast.logging.ILogger)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 Operation (com.hazelcast.spi.impl.operationservice.Operation)1 ServiceInfo (com.hazelcast.spi.impl.servicemanager.ServiceInfo)1 ArrayList (java.util.ArrayList)1