Search in sources :

Example 11 with ClusterState

use of com.hazelcast.cluster.ClusterState in project hazelcast by hazelcast.

the class InternalPartitionServiceImpl method isMemberAllowedToJoin.

@Override
public boolean isMemberAllowedToJoin(Address address) {
    lock.lock();
    try {
        ClusterState clusterState = node.getClusterService().getClusterState();
        if (clusterState == ClusterState.FROZEN || clusterState == ClusterState.PASSIVE) {
            logger.fine(address + " can join since cluster state is " + clusterState);
            return true;
        }
        if (partitionStateManager.isPresentInPartitionTable(address)) {
            logger.fine(address + " is in partition table");
            return false;
        }
        final MigrationRunnable activeTask = migrationManager.getActiveTask();
        if (activeTask instanceof MigrationManager.MigrateTask) {
            final MigrationManager.MigrateTask migrateTask = (MigrationManager.MigrateTask) activeTask;
            final MigrationInfo migrationInfo = migrateTask.migrationInfo;
            if (address.equals(migrationInfo.getSource()) || address.equals(migrationInfo.getDestination())) {
                logger.fine(address + " cannot join since " + migrationInfo);
                return false;
            }
        }
        return true;
    } finally {
        lock.unlock();
    }
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) MigrationInfo(com.hazelcast.internal.partition.MigrationInfo)

Example 12 with ClusterState

use of com.hazelcast.cluster.ClusterState in project hazelcast by hazelcast.

the class PartitionReplicaStateChecker method invokeReplicaSyncOperations.

@SuppressWarnings("checkstyle:npathcomplexity")
private int invokeReplicaSyncOperations(int maxBackupCount, Semaphore semaphore, AtomicBoolean result) {
    Address thisAddress = node.getThisAddress();
    ExecutionCallback<Object> callback = new ReplicaSyncResponseCallback(result, semaphore);
    ClusterServiceImpl clusterService = node.getClusterService();
    ClusterState clusterState = clusterService.getClusterState();
    boolean isClusterActive = clusterState == ClusterState.ACTIVE || clusterState == ClusterState.IN_TRANSITION;
    int ownedCount = 0;
    for (InternalPartition partition : partitionStateManager.getPartitions()) {
        Address owner = partition.getOwnerOrNull();
        if (owner == null) {
            result.set(false);
            continue;
        }
        if (!thisAddress.equals(owner)) {
            continue;
        }
        ownedCount++;
        if (maxBackupCount == 0) {
            if (partition.isMigrating()) {
                result.set(false);
            }
            continue;
        }
        for (int index = 1; index <= maxBackupCount; index++) {
            Address replicaAddress = partition.getReplicaAddress(index);
            if (replicaAddress == null) {
                result.set(false);
                semaphore.release();
                continue;
            }
            if (!isClusterActive && clusterService.isMemberRemovedWhileClusterIsNotActive(replicaAddress)) {
                semaphore.release();
                continue;
            }
            CheckReplicaVersionTask task = new CheckReplicaVersionTask(nodeEngine, partitionService, partition.getPartitionId(), index, callback);
            nodeEngine.getOperationService().execute(task);
        }
    }
    return ownedCount;
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) Address(com.hazelcast.nio.Address) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

Example 13 with ClusterState

use of com.hazelcast.cluster.ClusterState in project hazelcast by hazelcast.

the class BaseMigrationOperation method verifyClusterState.

private void verifyClusterState() {
    final NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    ClusterState clusterState = nodeEngine.getClusterService().getClusterState();
    if (clusterState != ClusterState.ACTIVE) {
        throw new IllegalStateException("Cluster state is not active! " + clusterState);
    }
    final Node node = nodeEngine.getNode();
    if (!node.getNodeExtension().isStartCompleted()) {
        throw new IllegalStateException("Migration operation is received before startup is completed. " + "Caller: " + getCallerAddress());
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ClusterState(com.hazelcast.cluster.ClusterState) Node(com.hazelcast.instance.Node)

Example 14 with ClusterState

use of com.hazelcast.cluster.ClusterState in project hazelcast by hazelcast.

the class MemberStateImplTest method testSerialization.

@Test
public void testSerialization() {
    HazelcastInstance hazelcastInstance = createHazelcastInstance();
    LocalReplicatedMapStatsImpl replicatedMapStats = new LocalReplicatedMapStatsImpl();
    replicatedMapStats.incrementPuts(30);
    CacheStatisticsImpl cacheStatistics = new CacheStatisticsImpl(Clock.currentTimeMillis());
    cacheStatistics.increaseCacheHits(5);
    Collection<ClientEndPointDTO> clients = new ArrayList<ClientEndPointDTO>();
    ClientEndPointDTO client = new ClientEndPointDTO();
    client.uuid = "abc123456";
    client.address = "localhost";
    client.clientType = "undefined";
    clients.add(client);
    Map<String, Long> runtimeProps = new HashMap<String, Long>();
    runtimeProps.put("prop1", 598123L);
    ClusterState clusterState = ClusterState.ACTIVE;
    com.hazelcast.instance.NodeState nodeState = com.hazelcast.instance.NodeState.PASSIVE;
    Version clusterVersion = Version.of("3.8.0");
    MemberVersion memberVersion = MemberVersion.of("3.9.0");
    NodeState state = new NodeStateImpl(clusterState, nodeState, clusterVersion, memberVersion);
    final BackupTaskStatus backupTaskStatus = new BackupTaskStatus(BackupTaskState.IN_PROGRESS, 5, 10);
    final HotRestartStateImpl hotRestartState = new HotRestartStateImpl(backupTaskStatus, false);
    final WanSyncState wanSyncState = new WanSyncStateImpl(WanSyncStatus.IN_PROGRESS, 86, "atob", "B");
    TimedMemberStateFactory factory = new TimedMemberStateFactory(getHazelcastInstanceImpl(hazelcastInstance));
    TimedMemberState timedMemberState = factory.createTimedMemberState();
    MemberStateImpl memberState = timedMemberState.getMemberState();
    memberState.setAddress("memberStateAddress:Port");
    memberState.putLocalMapStats("mapStats", new LocalMapStatsImpl());
    memberState.putLocalMultiMapStats("multiMapStats", new LocalMultiMapStatsImpl());
    memberState.putLocalQueueStats("queueStats", new LocalQueueStatsImpl());
    memberState.putLocalTopicStats("topicStats", new LocalTopicStatsImpl());
    memberState.putLocalExecutorStats("executorStats", new LocalExecutorStatsImpl());
    memberState.putLocalReplicatedMapStats("replicatedMapStats", replicatedMapStats);
    memberState.putLocalCacheStats("cacheStats", new LocalCacheStatsImpl(cacheStatistics));
    memberState.setRuntimeProps(runtimeProps);
    memberState.setLocalMemoryStats(new LocalMemoryStatsImpl());
    memberState.setOperationStats(new LocalOperationStatsImpl());
    memberState.setClients(clients);
    memberState.setNodeState(state);
    memberState.setHotRestartState(hotRestartState);
    memberState.setWanSyncState(wanSyncState);
    MemberStateImpl deserialized = new MemberStateImpl();
    deserialized.fromJson(memberState.toJson());
    assertEquals("memberStateAddress:Port", deserialized.getAddress());
    assertNotNull(deserialized.getLocalMapStats("mapStats").toString());
    assertNotNull(deserialized.getLocalMultiMapStats("multiMapStats").toString());
    assertNotNull(deserialized.getLocalQueueStats("queueStats").toString());
    assertNotNull(deserialized.getLocalTopicStats("topicStats").toString());
    assertNotNull(deserialized.getLocalExecutorStats("executorStats").toString());
    assertNotNull(deserialized.getLocalReplicatedMapStats("replicatedMapStats").toString());
    assertEquals(1, deserialized.getLocalReplicatedMapStats("replicatedMapStats").getPutOperationCount());
    assertNotNull(deserialized.getLocalCacheStats("cacheStats").toString());
    assertEquals(5, deserialized.getLocalCacheStats("cacheStats").getCacheHits());
    assertNotNull(deserialized.getRuntimeProps());
    assertEquals(Long.valueOf(598123L), deserialized.getRuntimeProps().get("prop1"));
    assertNotNull(deserialized.getLocalMemoryStats());
    assertNotNull(deserialized.getOperationStats());
    assertNotNull(deserialized.getMXBeans());
    client = deserialized.getClients().iterator().next();
    assertEquals("abc123456", client.uuid);
    assertEquals("localhost", client.address);
    assertEquals("undefined", client.clientType);
    NodeState deserializedState = deserialized.getNodeState();
    assertEquals(clusterState, deserializedState.getClusterState());
    assertEquals(nodeState, deserializedState.getNodeState());
    assertEquals(clusterVersion, deserializedState.getClusterVersion());
    assertEquals(memberVersion, deserializedState.getMemberVersion());
    final HotRestartState deserializedHotRestartState = deserialized.getHotRestartState();
    assertEquals(backupTaskStatus, deserializedHotRestartState.getBackupTaskStatus());
    final WanSyncState deserializedWanSyncState = deserialized.getWanSyncState();
    assertEquals(WanSyncStatus.IN_PROGRESS, deserializedWanSyncState.getStatus());
    assertEquals(86, deserializedWanSyncState.getSyncedPartitionCount());
    assertEquals("atob", deserializedWanSyncState.getActiveWanConfigName());
    assertEquals("B", deserializedWanSyncState.getActivePublisherName());
    ClusterHotRestartStatusDTO clusterHotRestartStatus = deserialized.getClusterHotRestartStatus();
    assertEquals(FULL_RECOVERY_ONLY, clusterHotRestartStatus.getDataRecoveryPolicy());
    assertEquals(ClusterHotRestartStatusDTO.ClusterHotRestartStatus.UNKNOWN, clusterHotRestartStatus.getHotRestartStatus());
    assertEquals(-1, clusterHotRestartStatus.getRemainingValidationTimeMillis());
    assertEquals(-1, clusterHotRestartStatus.getRemainingDataLoadTimeMillis());
    assertTrue(clusterHotRestartStatus.getMemberHotRestartStatusMap().isEmpty());
}
Also used : NodeState(com.hazelcast.monitor.NodeState) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WanSyncState(com.hazelcast.monitor.WanSyncState) MemberVersion(com.hazelcast.version.MemberVersion) Version(com.hazelcast.version.Version) MemberVersion(com.hazelcast.version.MemberVersion) ClusterHotRestartStatusDTO(com.hazelcast.internal.management.dto.ClusterHotRestartStatusDTO) TimedMemberState(com.hazelcast.monitor.TimedMemberState) ClusterState(com.hazelcast.cluster.ClusterState) TimedMemberStateFactory(com.hazelcast.internal.management.TimedMemberStateFactory) ClientEndPointDTO(com.hazelcast.internal.management.dto.ClientEndPointDTO) CacheStatisticsImpl(com.hazelcast.cache.impl.CacheStatisticsImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) BackupTaskStatus(com.hazelcast.hotrestart.BackupTaskStatus) HotRestartState(com.hazelcast.monitor.HotRestartState) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with ClusterState

use of com.hazelcast.cluster.ClusterState in project hazelcast by hazelcast.

the class GetClusterStateRequestTest method testGetClusterState.

@Test
public void testGetClusterState() throws Exception {
    GetClusterStateRequest request = new GetClusterStateRequest();
    ClusterState clusterState = cluster.getClusterState();
    JsonObject jsonObject = new JsonObject();
    request.writeResponse(managementCenterService, jsonObject);
    JsonObject result = (JsonObject) jsonObject.get("result");
    assertEquals(clusterState.name(), request.readResponse(result));
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) GetClusterStateRequest(com.hazelcast.internal.management.request.GetClusterStateRequest) JsonObject(com.eclipsesource.json.JsonObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ClusterState (com.hazelcast.cluster.ClusterState)26 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)6 Address (com.hazelcast.nio.Address)6 Node (com.hazelcast.instance.Node)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 InternalPartition (com.hazelcast.internal.partition.InternalPartition)3 Version (com.hazelcast.version.Version)3 JsonObject (com.eclipsesource.json.JsonObject)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)2 ILogger (com.hazelcast.logging.ILogger)2 NodeState (com.hazelcast.monitor.NodeState)2 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 TransactionException (com.hazelcast.transaction.TransactionException)2 MemberVersion (com.hazelcast.version.MemberVersion)2 ExecutionException (java.util.concurrent.ExecutionException)2