Search in sources :

Example 16 with ClusterServiceImpl

use of com.hazelcast.internal.cluster.impl.ClusterServiceImpl in project hazelcast by hazelcast.

the class Invocation_NetworkSplitTest method testWaitNotifyService_whenNodeSplitFromCluster.

private void testWaitNotifyService_whenNodeSplitFromCluster(SplitAction action) throws Exception {
    Config config = createConfig();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(5);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    HazelcastInstance hz3 = factory.newHazelcastInstance(config);
    final Node node1 = TestUtil.getNode(hz1);
    Node node2 = TestUtil.getNode(hz2);
    Node node3 = TestUtil.getNode(hz3);
    warmUpPartitions(hz1, hz2, hz3);
    int partitionId = getPartitionId(hz3);
    NodeEngineImpl nodeEngine1 = node1.getNodeEngine();
    OperationService operationService1 = nodeEngine1.getOperationService();
    operationService1.invokeOnPartition("", new AlwaysBlockingOperation(), partitionId);
    final OperationParkerImpl waitNotifyService3 = (OperationParkerImpl) node3.getNodeEngine().getOperationParker();
    assertEqualsEventually(new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            return waitNotifyService3.getTotalParkedOperationCount();
        }
    }, 1);
    action.run(node1, node2, node3);
    // create a new node to prevent same partition assignments
    // after node3 rejoins
    factory.newHazelcastInstance(config);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Assert.assertEquals(0, node1.partitionService.getMigrationQueueSize());
        }
    });
    // Let node3 detect the split and merge it back to other two.
    ClusterServiceImpl clusterService3 = node3.getClusterService();
    clusterService3.merge(node1.address);
    assertEquals(4, node1.getClusterService().getSize());
    assertEquals(4, node2.getClusterService().getSize());
    assertEquals(4, node3.getClusterService().getSize());
    assertEquals(0, waitNotifyService3.getTotalParkedOperationCount());
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) TimeoutException(java.util.concurrent.TimeoutException) MemberLeftException(com.hazelcast.core.MemberLeftException) OperationParkerImpl(com.hazelcast.spi.impl.operationparker.impl.OperationParkerImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 17 with ClusterServiceImpl

use of com.hazelcast.internal.cluster.impl.ClusterServiceImpl in project hazelcast by hazelcast.

the class MultiMapService method createStats.

public LocalMultiMapStats createStats(String name) {
    LocalMultiMapStatsImpl stats = getLocalMultiMapStatsImpl(name);
    long ownedEntryCount = 0;
    long backupEntryCount = 0;
    long hits = 0;
    long lockedEntryCount = 0;
    ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngine.getClusterService();
    Address thisAddress = clusterService.getThisAddress();
    for (int i = 0; i < nodeEngine.getPartitionService().getPartitionCount(); i++) {
        IPartition partition = nodeEngine.getPartitionService().getPartition(i);
        MultiMapPartitionContainer partitionContainer = getPartitionContainer(i);
        MultiMapContainer multiMapContainer = partitionContainer.getCollectionContainer(name);
        if (multiMapContainer == null) {
            continue;
        }
        Address owner = partition.getOwnerOrNull();
        if (owner != null) {
            if (owner.equals(thisAddress)) {
                lockedEntryCount += multiMapContainer.getLockedCount();
                for (MultiMapValue multiMapValue : multiMapContainer.getMultiMapValues().values()) {
                    hits += multiMapValue.getHits();
                    ownedEntryCount += multiMapValue.getCollection(false).size();
                }
            } else {
                int backupCount = multiMapContainer.getConfig().getTotalBackupCount();
                for (int j = 1; j <= backupCount; j++) {
                    Address replicaAddress = partition.getReplicaAddress(j);
                    int memberSize = nodeEngine.getClusterService().getMembers().size();
                    int tryCount = REPLICA_ADDRESS_TRY_COUNT;
                    // wait if the partition table is not updated yet
                    while (memberSize > backupCount && replicaAddress == null && tryCount-- > 0) {
                        try {
                            Thread.sleep(REPLICA_ADDRESS_SLEEP_WAIT_MILLIS);
                        } catch (InterruptedException e) {
                            throw ExceptionUtil.rethrow(e);
                        }
                        replicaAddress = partition.getReplicaAddress(j);
                    }
                    if (replicaAddress != null && replicaAddress.equals(thisAddress)) {
                        for (MultiMapValue multiMapValue : multiMapContainer.getMultiMapValues().values()) {
                            backupEntryCount += multiMapValue.getCollection(false).size();
                        }
                    }
                }
            }
        }
    }
    stats.setOwnedEntryCount(ownedEntryCount);
    stats.setBackupEntryCount(backupEntryCount);
    stats.setHits(hits);
    stats.setLockedEntryCount(lockedEntryCount);
    return stats;
}
Also used : Address(com.hazelcast.nio.Address) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) LocalMultiMapStatsImpl(com.hazelcast.monitor.impl.LocalMultiMapStatsImpl) IPartition(com.hazelcast.spi.partition.IPartition) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint)

Example 18 with ClusterServiceImpl

use of com.hazelcast.internal.cluster.impl.ClusterServiceImpl in project hazelcast by hazelcast.

the class PhoneHome method phoneHome.

public Map<String, String> phoneHome(Node hazelcastNode, String version, boolean isEnterprise) {
    String downloadId = "source";
    InputStream is = null;
    try {
        is = getClass().getClassLoader().getResourceAsStream("hazelcast-download.properties");
        if (is != null) {
            final Properties properties = new Properties();
            properties.load(is);
            downloadId = properties.getProperty("hazelcastDownloadId");
        }
    } catch (IOException ignored) {
        EmptyStatement.ignore(ignored);
    } finally {
        IOUtil.closeResource(is);
    }
    //Calculate native memory usage from native memory config
    NativeMemoryConfig memoryConfig = hazelcastNode.getConfig().getNativeMemoryConfig();
    final ClusterServiceImpl clusterService = hazelcastNode.getClusterService();
    long totalNativeMemorySize = clusterService.getSize(DATA_MEMBER_SELECTOR) * memoryConfig.getSize().bytes();
    String nativeMemoryParameter = (isEnterprise) ? Long.toString(MemoryUnit.BYTES.toGigaBytes(totalNativeMemorySize)) : "0";
    //Calculate connected clients to the cluster.
    Map<ClientType, Integer> clusterClientStats = hazelcastNode.clientEngine.getConnectedClientStats();
    RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
    OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
    Long clusterUpTime = clusterService.getClusterClock().getClusterUpTime();
    PhoneHomeParameterCreator parameterCreator = new PhoneHomeParameterCreator();
    parameterCreator.addParam("version", version);
    parameterCreator.addParam("m", hazelcastNode.getThisUuid());
    parameterCreator.addParam("e", Boolean.toString(isEnterprise));
    parameterCreator.addParam("l", MD5Util.toMD5String(hazelcastNode.getConfig().getLicenseKey()));
    parameterCreator.addParam("p", downloadId);
    parameterCreator.addParam("c", clusterService.getClusterId());
    parameterCreator.addParam("crsz", convertToLetter(clusterService.getMembers().size()));
    parameterCreator.addParam("cssz", convertToLetter(hazelcastNode.clientEngine.getClientEndpointCount()));
    parameterCreator.addParam("hdgb", nativeMemoryParameter);
    parameterCreator.addParam("ccpp", Integer.toString(clusterClientStats.get(ClientType.CPP)));
    parameterCreator.addParam("cdn", Integer.toString(clusterClientStats.get(ClientType.CSHARP)));
    parameterCreator.addParam("cjv", Integer.toString(clusterClientStats.get(ClientType.JAVA)));
    parameterCreator.addParam("cnjs", Integer.toString(clusterClientStats.get(ClientType.NODEJS)));
    parameterCreator.addParam("cpy", Integer.toString(clusterClientStats.get(ClientType.PYTHON)));
    parameterCreator.addParam("cuptm", Long.toString(clusterUpTime));
    parameterCreator.addParam("nuptm", Long.toString(runtimeMxBean.getUptime()));
    parameterCreator.addParam("jvmn", runtimeMxBean.getVmName());
    parameterCreator.addParam("jvmv", System.getProperty("java.version"));
    JetBuildInfo jetBuildInfo = hazelcastNode.getBuildInfo().getJetBuildInfo();
    parameterCreator.addParam("jetv", jetBuildInfo == null ? "" : jetBuildInfo.getVersion());
    try {
        parameterCreator.addParam("osn", osMxBean.getName());
        parameterCreator.addParam("osa", osMxBean.getArch());
        parameterCreator.addParam("osv", osMxBean.getVersion());
    } catch (SecurityException e) {
        parameterCreator.addParam("osn", "N/A");
        parameterCreator.addParam("osa", "N/A");
        parameterCreator.addParam("osv", "N/A");
    }
    String urlStr = BASE_PHONE_HOME_URL + parameterCreator.build();
    fetchWebService(urlStr);
    return parameterCreator.getParameters();
}
Also used : ClientType(com.hazelcast.core.ClientType) JetBuildInfo(com.hazelcast.instance.JetBuildInfo) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) IOException(java.io.IOException) RuntimeMXBean(java.lang.management.RuntimeMXBean) Properties(java.util.Properties) NativeMemoryConfig(com.hazelcast.config.NativeMemoryConfig) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 19 with ClusterServiceImpl

use of com.hazelcast.internal.cluster.impl.ClusterServiceImpl in project hazelcast by hazelcast.

the class Invocation_NetworkSplitTest method testWaitingInvocations_whenNodeSplitFromCluster.

private void testWaitingInvocations_whenNodeSplitFromCluster(SplitAction splitAction) throws Exception {
    Config config = createConfig();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    HazelcastInstance hz3 = factory.newHazelcastInstance(config);
    Node node1 = TestUtil.getNode(hz1);
    Node node2 = TestUtil.getNode(hz2);
    Node node3 = TestUtil.getNode(hz3);
    warmUpPartitions(hz1, hz2, hz3);
    int partitionId = getPartitionId(hz2);
    NodeEngineImpl nodeEngine3 = node3.getNodeEngine();
    OperationService operationService3 = nodeEngine3.getOperationService();
    Operation op = new AlwaysBlockingOperation();
    Future<Object> future = operationService3.invokeOnPartition("", op, partitionId);
    // just wait a little to make sure
    // operation is landed on wait-queue
    sleepSeconds(1);
    // execute the given split action
    splitAction.run(node1, node2, node3);
    // Let node3 detect the split and merge it back to other two.
    ClusterServiceImpl clusterService3 = node3.getClusterService();
    clusterService3.merge(node1.address);
    assertClusterSizeEventually(3, hz1);
    assertClusterSizeEventually(3, hz2);
    assertClusterSizeEventually(3, hz3);
    try {
        future.get(1, TimeUnit.MINUTES);
        fail("Future.get() should fail with a MemberLeftException!");
    } catch (MemberLeftException e) {
        // expected
        EmptyStatement.ignore(e);
    } catch (Exception e) {
        fail(e.getClass().getName() + ": " + e.getMessage());
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) BlockingOperation(com.hazelcast.spi.BlockingOperation) Operation(com.hazelcast.spi.Operation) TimeoutException(java.util.concurrent.TimeoutException) MemberLeftException(com.hazelcast.core.MemberLeftException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 20 with ClusterServiceImpl

use of com.hazelcast.internal.cluster.impl.ClusterServiceImpl in project hazelcast by hazelcast.

the class AddMembershipListenerMessageTask method call.

@Override
protected Object call() {
    String serviceName = ClusterServiceImpl.SERVICE_NAME;
    ClusterServiceImpl service = getService(serviceName);
    ClientEndpoint endpoint = getEndpoint();
    String registrationId = service.addMembershipListener(new MembershipListenerImpl(endpoint));
    endpoint.addListenerDestroyAction(serviceName, serviceName, registrationId);
    return registrationId;
}
Also used : ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) ClientEndpoint(com.hazelcast.client.ClientEndpoint)

Aggregations

ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)41 Node (com.hazelcast.instance.Node)13 Address (com.hazelcast.nio.Address)13 ILogger (com.hazelcast.logging.ILogger)9 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)8 ClusterState (com.hazelcast.cluster.ClusterState)6 MemberImpl (com.hazelcast.instance.MemberImpl)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 OperationService (com.hazelcast.spi.OperationService)4 Member (com.hazelcast.core.Member)3 MemberLeftException (com.hazelcast.core.MemberLeftException)3 ClusterStateManager (com.hazelcast.internal.cluster.impl.ClusterStateManager)3 Config (com.hazelcast.config.Config)2 InternalPartition (com.hazelcast.internal.partition.InternalPartition)2 Connection (com.hazelcast.nio.Connection)2 Operation (com.hazelcast.spi.Operation)2 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2