Search in sources :

Example 1 with MigrationInterceptor

use of com.hazelcast.internal.partition.impl.MigrationInterceptor in project hazelcast by hazelcast.

the class ClientExecutorServiceCancelTest method testCancel_submitToKeyOwner_Should_Not_Block_Migration.

@Test(expected = CancellationException.class)
public void testCancel_submitToKeyOwner_Should_Not_Block_Migration() throws IOException, ExecutionException, InterruptedException {
    server2.shutdown();
    HazelcastInstance client = createClient(true);
    warmUpPartitions(server1);
    IExecutorService executorService = client.getExecutorService(randomString());
    String key = ExecutorServiceTestSupport.generateKeyOwnedBy(server1);
    final Future<Boolean> future = executorService.submitToKeyOwner(new CancellationAwareTask(SLEEP_TIME), key);
    awaitTaskStartAtMember(server1, 1);
    InternalPartitionServiceImpl internalPartitionService = (InternalPartitionServiceImpl) TestUtil.getNode(server1).getPartitionService();
    final int partitionId = internalPartitionService.getPartitionId(key);
    // Simulate partition thread blockage as if the partition is migrating
    internalPartitionService.setMigrationInterceptor(new MigrationInterceptor() {

        @Override
        public void onMigrationCommit(MigrationInterceptor.MigrationParticipant participant, MigrationInfo migrationInfo) {
            int migratingPartitionId = migrationInfo.getPartitionId();
            if (migratingPartitionId == partitionId) {
                spawn(() -> {
                    future.cancel(true);
                });
                // sleep enough so that the ExecutorServiceCancelOnPartitionMessageTask actually starts
                // This test is time sensitive
                sleepSeconds(3);
            }
        }
    });
    // Start the second member to initiate migration
    server2 = hazelcastFactory.newHazelcastInstance();
    waitAllForSafeState(server1, server2);
    future.get();
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) IExecutorService(com.hazelcast.core.IExecutorService) MigrationInterceptor(com.hazelcast.internal.partition.impl.MigrationInterceptor) CancellationAwareTask(com.hazelcast.client.test.executor.tasks.CancellationAwareTask) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with MigrationInterceptor

use of com.hazelcast.internal.partition.impl.MigrationInterceptor in project hazelcast by hazelcast.

the class Node method initializeListeners.

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity", "checkstyle:methodlength" })
private void initializeListeners(Config config) {
    for (final ListenerConfig listenerCfg : config.getListenerConfigs()) {
        Object listener = listenerCfg.getImplementation();
        if (listener == null) {
            try {
                listener = ClassLoaderUtil.newInstance(configClassLoader, listenerCfg.getClassName());
            } catch (Exception e) {
                logger.severe(e);
            }
        }
        if (listener instanceof HazelcastInstanceAware) {
            ((HazelcastInstanceAware) listener).setHazelcastInstance(hazelcastInstance);
        }
        boolean known = false;
        if (listener instanceof DistributedObjectListener) {
            final ProxyServiceImpl proxyService = (ProxyServiceImpl) nodeEngine.getProxyService();
            proxyService.addProxyListener((DistributedObjectListener) listener);
            known = true;
        }
        if (listener instanceof MembershipListener) {
            clusterService.addMembershipListener((MembershipListener) listener);
            known = true;
        }
        if (listener instanceof MigrationListener) {
            partitionService.addMigrationListener((MigrationListener) listener);
            known = true;
        }
        if (listener instanceof PartitionLostListener) {
            partitionService.addPartitionLostListener((PartitionLostListener) listener);
            known = true;
        }
        if (listener instanceof LifecycleListener) {
            hazelcastInstance.lifecycleService.addLifecycleListener((LifecycleListener) listener);
            known = true;
        }
        if (listener instanceof ClientListener) {
            String serviceName = ClientEngineImpl.SERVICE_NAME;
            nodeEngine.getEventService().registerLocalListener(serviceName, serviceName, listener);
            known = true;
        }
        if (listener instanceof MigrationInterceptor) {
            partitionService.setMigrationInterceptor((MigrationInterceptor) listener);
            known = true;
        }
        if (listener instanceof CPMembershipListener) {
            hazelcastInstance.cpSubsystem.addMembershipListener((CPMembershipListener) listener);
            known = true;
        }
        if (listener instanceof CPGroupAvailabilityListener) {
            hazelcastInstance.cpSubsystem.addGroupAvailabilityListener((CPGroupAvailabilityListener) listener);
            known = true;
        }
        if (nodeExtension.registerListener(listener)) {
            known = true;
        }
        if (listener != null && !known) {
            final String error = "Unknown listener type: " + listener.getClass();
            Throwable t = new IllegalArgumentException(error);
            logger.warning(error, t);
        }
    }
}
Also used : LifecycleListener(com.hazelcast.core.LifecycleListener) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware) DistributedObjectListener(com.hazelcast.core.DistributedObjectListener) ProxyServiceImpl(com.hazelcast.spi.impl.proxyservice.impl.ProxyServiceImpl) ClientListener(com.hazelcast.client.ClientListener) ListenerConfig(com.hazelcast.config.ListenerConfig) PartitionLostListener(com.hazelcast.partition.PartitionLostListener) CPMembershipListener(com.hazelcast.cp.event.CPMembershipListener) MigrationInterceptor(com.hazelcast.internal.partition.impl.MigrationInterceptor) CPMembershipListener(com.hazelcast.cp.event.CPMembershipListener) MembershipListener(com.hazelcast.cluster.MembershipListener) MigrationListener(com.hazelcast.partition.MigrationListener) CPGroupAvailabilityListener(com.hazelcast.cp.event.CPGroupAvailabilityListener)

Example 3 with MigrationInterceptor

use of com.hazelcast.internal.partition.impl.MigrationInterceptor in project hazelcast by hazelcast.

the class BaseMigrationOperation method onMigrationStart.

void onMigrationStart() {
    InternalPartitionServiceImpl partitionService = getService();
    MigrationInterceptor migrationInterceptor = partitionService.getMigrationInterceptor();
    migrationInterceptor.onMigrationStart(getMigrationParticipantType(), migrationInfo);
}
Also used : InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) MigrationInterceptor(com.hazelcast.internal.partition.impl.MigrationInterceptor)

Example 4 with MigrationInterceptor

use of com.hazelcast.internal.partition.impl.MigrationInterceptor in project hazelcast by hazelcast.

the class BaseMigrationOperation method onMigrationComplete.

void onMigrationComplete() {
    InternalPartitionServiceImpl partitionService = getService();
    MigrationInterceptor migrationInterceptor = partitionService.getMigrationInterceptor();
    migrationInterceptor.onMigrationComplete(getMigrationParticipantType(), migrationInfo, success);
}
Also used : InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) MigrationInterceptor(com.hazelcast.internal.partition.impl.MigrationInterceptor)

Example 5 with MigrationInterceptor

use of com.hazelcast.internal.partition.impl.MigrationInterceptor in project hazelcast by hazelcast.

the class GracefulShutdownTest method shutdownMasterCandidate_whileMastershipClaimIsInProgress.

@Test
public void shutdownMasterCandidate_whileMastershipClaimIsInProgress() throws Exception {
    Config config = new Config();
    // setting a very graceful shutdown high timeout value
    // to guarantee instance.shutdown() not to timeout
    config.setProperty(ClusterProperty.GRACEFUL_SHUTDOWN_MAX_WAIT.getName(), "99999999999");
    final HazelcastInstance[] instances = factory.newInstances(config, 4);
    assertClusterSizeEventually(4, instances);
    warmUpPartitions(instances);
    // Drop mastership claim operation submitted from master candidate
    dropOperationsFrom(instances[1], ClusterDataSerializerHook.F_ID, singletonList(ClusterDataSerializerHook.FETCH_MEMBER_LIST_STATE));
    final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) getPartitionService(instances[1]);
    final AtomicReference<MigrationInfo> startedMigration = new AtomicReference<MigrationInfo>();
    partitionService.setMigrationInterceptor(new MigrationInterceptor() {

        @Override
        public void onMigrationStart(MigrationParticipant participant, MigrationInfo migrationInfo) {
            startedMigration.set(migrationInfo);
        }
    });
    final long partitionStateStamp = partitionService.getPartitionStateStamp();
    instances[0].getLifecycleService().terminate();
    // instance-1 starts mastership claim
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertTrue(getNode(instances[1]).isMaster());
        }
    });
    Future future = spawn(new Runnable() {

        @Override
        public void run() {
            instances[1].shutdown();
        }
    });
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() {
            // other members have not received/accepted mastership claim yet
            assertNotEquals(getAddress(instances[1]), getNode(instances[2]).getMasterAddress());
            assertNotEquals(getAddress(instances[1]), getNode(instances[3]).getMasterAddress());
            // no partition state version change
            assertEquals(partitionStateStamp, partitionService.getPartitionStateStamp());
            // no migrations has been submitted yet
            assertNull(startedMigration.get());
        }
    }, 5);
    assertFalse(future.isDone());
    resetPacketFiltersFrom(instances[1]);
    future.get();
}
Also used : Config(com.hazelcast.config.Config) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) AtomicReference(java.util.concurrent.atomic.AtomicReference) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) Future(java.util.concurrent.Future) MigrationInterceptor(com.hazelcast.internal.partition.impl.MigrationInterceptor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MigrationInterceptor (com.hazelcast.internal.partition.impl.MigrationInterceptor)6 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 Config (com.hazelcast.config.Config)2 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ClientListener (com.hazelcast.client.ClientListener)1 CancellationAwareTask (com.hazelcast.client.test.executor.tasks.CancellationAwareTask)1 MembershipListener (com.hazelcast.cluster.MembershipListener)1 ListenerConfig (com.hazelcast.config.ListenerConfig)1 DistributedObjectListener (com.hazelcast.core.DistributedObjectListener)1 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)1 IExecutorService (com.hazelcast.core.IExecutorService)1 LifecycleListener (com.hazelcast.core.LifecycleListener)1 CPGroupAvailabilityListener (com.hazelcast.cp.event.CPGroupAvailabilityListener)1 CPMembershipListener (com.hazelcast.cp.event.CPMembershipListener)1 MigrationStats (com.hazelcast.internal.partition.impl.MigrationStats)1