Search in sources :

Example 21 with InternalPartition

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

the class MapLoaderTest method findOwnerAndReplicas.

private HazelcastInstance[] findOwnerAndReplicas(HazelcastInstance[] instances, String name) {
    Node node = getNode(instances[0]);
    InternalPartitionService partitionService = node.getPartitionService();
    int partitionId = partitionService.getPartitionId(name);
    InternalPartition partition = partitionService.getPartition(partitionId);
    HazelcastInstance[] ownerAndReplicas = new HazelcastInstance[instances.length];
    for (int i = 0; i < instances.length; i++) {
        ownerAndReplicas[i] = getInstanceForAddress(instances, partition.getReplicaAddress(i));
    }
    return ownerAndReplicas;
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.Node) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

Example 22 with InternalPartition

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

the class AdvancedClusterStateTest method partitionTable_shouldBeFrozen_whenMemberLeaves_inFrozenState.

@Test
public void partitionTable_shouldBeFrozen_whenMemberLeaves_inFrozenState() {
    Config config = new Config();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance[] instances = factory.newInstances(config);
    HazelcastInstance hz1 = instances[0];
    HazelcastInstance hz2 = instances[1];
    HazelcastInstance hz3 = instances[2];
    warmUpPartitions(instances);
    waitAllForSafeState(instances);
    final Address owner = getNode(hz1).getThisAddress();
    int partitionId = getPartitionId(hz1);
    changeClusterStateEventually(hz2, ClusterState.FROZEN);
    terminateInstance(hz1);
    final InternalPartition partition = getNode(hz2).getPartitionService().getPartition(partitionId);
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(owner, partition.getOwnerOrNull());
        }
    }, 3);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) InternalPartition(com.hazelcast.internal.partition.InternalPartition) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) TransactionException(com.hazelcast.transaction.TransactionException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 23 with InternalPartition

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

the class AdvancedClusterStateTest method test_eitherClusterStateChange_orPartitionInitialization_shouldBeSuccessful.

@Test
public void test_eitherClusterStateChange_orPartitionInitialization_shouldBeSuccessful() throws Exception {
    Config config = new Config();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance[] instances = factory.newInstances(config);
    HazelcastInstance hz1 = instances[0];
    final HazelcastInstance hz2 = instances[1];
    HazelcastInstance hz3 = instances[2];
    final InternalPartitionService partitionService = getNode(hz1).getPartitionService();
    final int initialPartitionStateVersion = partitionService.getPartitionStateVersion();
    final ClusterState newState = ClusterState.PASSIVE;
    final Future future = spawn(new Runnable() {

        public void run() {
            try {
                changeClusterState(hz2, newState, initialPartitionStateVersion);
            } catch (Exception ignored) {
            }
        }
    });
    partitionService.firstArrangement();
    future.get(2, TimeUnit.MINUTES);
    final ClusterState currentState = hz2.getCluster().getClusterState();
    if (currentState == newState) {
        // if cluster state changed then partition state version should be equal to initial version
        assertEquals(initialPartitionStateVersion, partitionService.getPartitionStateVersion());
    } else {
        assertEquals(ClusterState.ACTIVE, currentState);
        final InternalPartition partition = partitionService.getPartition(0, false);
        if (partition.getOwnerOrNull() == null) {
            // if partition assignment failed then partition state version should be equal to initial version
            assertEquals(initialPartitionStateVersion, partitionService.getPartitionStateVersion());
        } else {
            // if cluster state change failed and partition assignment is done
            // then partition state version should be some positive number
            final int partitionStateVersion = partitionService.getPartitionStateVersion();
            assertTrue("Version should be positive: " + partitionService, partitionStateVersion > 0);
        }
    }
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Config(com.hazelcast.config.Config) Future(java.util.concurrent.Future) InternalPartition(com.hazelcast.internal.partition.InternalPartition) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) TransactionException(com.hazelcast.transaction.TransactionException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 24 with InternalPartition

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

the class PartitionReplicaStateChecker method hasMissingReplicaOwners.

private boolean hasMissingReplicaOwners() {
    if (!needsReplicaStateCheck()) {
        return false;
    }
    int memberGroupsSize = partitionStateManager.getMemberGroupsSize();
    int replicaCount = Math.min(InternalPartition.MAX_REPLICA_COUNT, memberGroupsSize);
    ClusterServiceImpl clusterService = node.getClusterService();
    ClusterState clusterState = clusterService.getClusterState();
    boolean isClusterNotActive = (clusterState == ClusterState.FROZEN || clusterState == ClusterState.PASSIVE);
    for (InternalPartition partition : partitionStateManager.getPartitions()) {
        for (int index = 0; index < replicaCount; index++) {
            Address address = partition.getReplicaAddress(index);
            if (address == null) {
                if (logger.isFinestEnabled()) {
                    logger.finest("Missing replica=" + index + " for partitionId=" + partition.getPartitionId());
                }
                return true;
            }
            if (clusterService.getMember(address) == null && (!isClusterNotActive || !clusterService.isMemberRemovedWhileClusterIsNotActive(address))) {
                if (logger.isFinestEnabled()) {
                    logger.finest("Unknown replica owner= " + address + ", partitionId=" + partition.getPartitionId() + ", replica=" + index);
                }
                return true;
            }
        }
    }
    return false;
}
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 25 with InternalPartition

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

the class CheckReplicaVersionTask method run.

@Override
public void run() {
    int partitionId = getPartitionId();
    int replicaIndex = this.replicaIndex;
    InternalPartition partition = partitionService.getPartition(partitionId);
    if (partition.isMigrating()) {
        notifyCallback(false);
        return;
    }
    Address target = partition.getReplicaAddress(replicaIndex);
    if (target == null) {
        notifyCallback(false);
        return;
    }
    invokeCheckReplicaVersion(partitionId, replicaIndex, target);
}
Also used : Address(com.hazelcast.nio.Address) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

Aggregations

InternalPartition (com.hazelcast.internal.partition.InternalPartition)26 ParallelTest (com.hazelcast.test.annotation.ParallelTest)13 QuickTest (com.hazelcast.test.annotation.QuickTest)13 Test (org.junit.Test)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)12 Address (com.hazelcast.nio.Address)12 Config (com.hazelcast.config.Config)8 ListenerConfig (com.hazelcast.config.ListenerConfig)6 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AssertTask (com.hazelcast.test.AssertTask)4 ClusterState (com.hazelcast.cluster.ClusterState)3 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)3 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 Node (com.hazelcast.instance.Node)2 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)2 PartitionRuntimeState (com.hazelcast.internal.partition.PartitionRuntimeState)2 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 TransactionException (com.hazelcast.transaction.TransactionException)2