Search in sources :

Example 11 with InternalPartitionServiceImpl

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

the class FinalizePromotionOperation method shiftUpReplicaVersions.

private void shiftUpReplicaVersions() {
    final int partitionId = getPartitionId();
    try {
        final InternalPartitionServiceImpl partitionService = getService();
        // returns the internal array itself, not the copy
        final long[] versions = partitionService.getPartitionReplicaVersions(partitionId);
        final int lostReplicaIndex = currentReplicaIndex - 1;
        if (currentReplicaIndex > 1) {
            final long[] versionsCopy = Arrays.copyOf(versions, versions.length);
            final long version = versions[lostReplicaIndex];
            Arrays.fill(versions, 0, lostReplicaIndex, version);
            if (logger.isFinestEnabled()) {
                logger.finest("Partition replica is lost! partitionId=" + partitionId + " lost replicaIndex=" + lostReplicaIndex + " replica versions before shift up=" + Arrays.toString(versionsCopy) + " replica versions after shift up=" + Arrays.toString(versions));
            }
        } else if (logger.isFinestEnabled()) {
            logger.finest("PROMOTE partitionId=" + getPartitionId() + " from currentReplicaIndex=" + currentReplicaIndex);
        }
        PartitionEventManager partitionEventManager = partitionService.getPartitionEventManager();
        partitionEventManager.sendPartitionLostEvent(partitionId, lostReplicaIndex);
    } catch (Throwable e) {
        logger.warning("Promotion failed. partitionId=" + partitionId + " replicaIndex=" + currentReplicaIndex, e);
    }
}
Also used : InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) PartitionEventManager(com.hazelcast.internal.partition.impl.PartitionEventManager)

Example 12 with InternalPartitionServiceImpl

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

the class StaleReadDuringMigrationTest method invokeOperation.

private InternalCompletableFuture<Boolean> invokeOperation(final Config config) {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
    final HazelcastInstance instance = factory.newHazelcastInstance(config);
    warmUpPartitions(instance);
    final int partitionId = 0;
    final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) getPartitionService(instance);
    final InternalPartitionImpl partition = (InternalPartitionImpl) partitionService.getPartition(partitionId);
    partition.setMigrating(true);
    final InternalOperationService operationService = getOperationService(instance);
    final InvocationBuilder invocationBuilder = operationService.createInvocationBuilder(InternalPartitionService.SERVICE_NAME, new DummyOperation(), partitionId);
    return invocationBuilder.invoke();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) InvocationBuilder(com.hazelcast.spi.InvocationBuilder) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 13 with InternalPartitionServiceImpl

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

the class PartitionLostListenerTest method test_partitionLostListenerInvoked.

@Test
public void test_partitionLostListenerInvoked() {
    HazelcastInstance instance = instances[0];
    final EventCollectingPartitionLostListener listener = new EventCollectingPartitionLostListener();
    instance.getPartitionService().addPartitionLostListener(listener);
    final IPartitionLostEvent internalEvent = new IPartitionLostEvent(1, 0, null);
    NodeEngineImpl nodeEngine = getNode(instance).getNodeEngine();
    InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) nodeEngine.getPartitionService();
    partitionService.onPartitionLost(internalEvent);
    assertEventEventually(listener, internalEvent);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventCollectingPartitionLostListener(com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) IPartitionLostEvent(com.hazelcast.spi.partition.IPartitionLostEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with InternalPartitionServiceImpl

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

the class ClientPartitionLostListenerTest method test_partitionLostListener_invoked_fromOtherNode.

@Test
public void test_partitionLostListener_invoked_fromOtherNode() {
    final HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
    final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().setSmartRouting(false);
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    warmUpPartitions(instance1, instance2, client);
    final HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
    final Address clientOwnerAddress = clientInstanceImpl.getClientClusterService().getOwnerConnectionAddress();
    final HazelcastInstance other = getAddress(instance1).equals(clientOwnerAddress) ? instance2 : instance1;
    final EventCollectingPartitionLostListener listener = new EventCollectingPartitionLostListener();
    client.getPartitionService().addPartitionLostListener(listener);
    assertRegistrationsSizeEventually(instance1, 1);
    assertRegistrationsSizeEventually(instance2, 1);
    final InternalPartitionServiceImpl partitionService = getNode(other).getNodeEngine().getService(SERVICE_NAME);
    final int partitionId = 5;
    partitionService.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
    assertPartitionLostEventEventually(listener, partitionId);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) HazelcastTestSupport.getAddress(com.hazelcast.test.HazelcastTestSupport.getAddress) EventCollectingPartitionLostListener(com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ClientTestUtil.getHazelcastClientInstanceImpl(com.hazelcast.client.impl.ClientTestUtil.getHazelcastClientInstanceImpl) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientConfig(com.hazelcast.client.config.ClientConfig) IPartitionLostEvent(com.hazelcast.spi.partition.IPartitionLostEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with InternalPartitionServiceImpl

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

the class Node method initializeListeners.

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" })
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 InternalMigrationListener) {
            final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) nodeEngine.getPartitionService();
            partitionService.setInternalMigrationListener((InternalMigrationListener) 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 : InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalMigrationListener(com.hazelcast.internal.partition.impl.InternalMigrationListener) 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.core.ClientListener) ListenerConfig(com.hazelcast.config.ListenerConfig) PartitionLostListener(com.hazelcast.partition.PartitionLostListener) MembershipListener(com.hazelcast.core.MembershipListener) MigrationListener(com.hazelcast.core.MigrationListener) InternalMigrationListener(com.hazelcast.internal.partition.impl.InternalMigrationListener)

Aggregations

InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)35 Address (com.hazelcast.nio.Address)11 ILogger (com.hazelcast.logging.ILogger)10 PartitionStateManager (com.hazelcast.internal.partition.impl.PartitionStateManager)7 NodeEngine (com.hazelcast.spi.NodeEngine)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)5 IPartitionLostEvent (com.hazelcast.spi.partition.IPartitionLostEvent)5 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 InternalPartitionImpl (com.hazelcast.internal.partition.impl.InternalPartitionImpl)4 PartitionReplicaManager (com.hazelcast.internal.partition.impl.PartitionReplicaManager)4 EventCollectingPartitionLostListener (com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener)4 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)3 InternalMigrationListener (com.hazelcast.internal.partition.impl.InternalMigrationListener)3 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)3 MigrationEndpoint (com.hazelcast.spi.partition.MigrationEndpoint)3 ClusterService (com.hazelcast.internal.cluster.ClusterService)2 Operation (com.hazelcast.spi.Operation)2