Search in sources :

Example 16 with PartitionReplica

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

the class ClusterViewListenerService method getPartitions.

/**
 * If any partition does not have an owner, this method returns empty collection
 *
 * @param partitionTableView will be converted to address->partitions mapping
 * @return address->partitions mapping, where address is the client address of the member
 */
public Map<UUID, List<Integer>> getPartitions(PartitionTableView partitionTableView) {
    Map<UUID, List<Integer>> partitionsMap = new HashMap<>();
    int partitionCount = partitionTableView.length();
    for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        PartitionReplica owner = partitionTableView.getReplica(partitionId, 0);
        if (owner == null || owner.uuid() == null) {
            partitionsMap.clear();
            return partitionsMap;
        }
        partitionsMap.computeIfAbsent(owner.uuid(), k -> new LinkedList<>()).add(partitionId);
    }
    return partitionsMap;
}
Also used : Address(com.hazelcast.cluster.Address) CancelledKeyException(java.nio.channels.CancelledKeyException) Member(com.hazelcast.cluster.Member) MembershipManager(com.hazelcast.internal.cluster.impl.MembershipManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) EmptyStatement(com.hazelcast.internal.util.EmptyStatement) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) ArrayList(java.util.ArrayList) PartitionTableView(com.hazelcast.internal.partition.PartitionTableView) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Map(java.util.Map) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) MembersView(com.hazelcast.internal.cluster.impl.MembersView) LinkedList(java.util.LinkedList) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CoalescingDelayedTrigger(com.hazelcast.internal.util.scheduler.CoalescingDelayedTrigger) NodeEngine(com.hazelcast.spi.impl.NodeEngine) Connection(com.hazelcast.internal.nio.Connection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClientAddClusterViewListenerCodec(com.hazelcast.client.impl.protocol.codec.ClientAddClusterViewListenerCodec) UUID(java.util.UUID) TimeUnit(java.util.concurrent.TimeUnit) CLIENT(com.hazelcast.instance.EndpointQualifier.CLIENT) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) UUID(java.util.UUID) LinkedList(java.util.LinkedList)

Example 17 with PartitionReplica

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

the class InternalPartitionImplConstructorTest method testConstructor.

@Test
public void testConstructor() throws Exception {
    PartitionReplica local = new PartitionReplica(new Address("172.16.16.1", 4223), UuidUtil.newUnsecureUUID());
    PartitionReplica[] replicas = new PartitionReplica[] { new PartitionReplica(new Address("127.0.0.1", 2342), UuidUtil.newUnsecureUUID()) };
    InternalPartition partition = new InternalPartitionImpl(42, local, replicas, 1, null);
    InternalPartitionImplConstructor constructor = new InternalPartitionImplConstructor(InternalPartitionImpl.class);
    InternalPartition clonedPartition = (InternalPartition) constructor.createNew(partition);
    assertEquals(partition.getPartitionId(), clonedPartition.getPartitionId());
    assertEquals(partition.version(), clonedPartition.version());
    assertEquals(partition.getOwnerOrNull(), clonedPartition.getOwnerOrNull());
    assertEquals(partition.getReplicaAddress(0), clonedPartition.getReplicaAddress(0));
    assertEquals(partition.getReplica(0), clonedPartition.getReplica(0));
    assertEquals(partition.getReplicaIndex(replicas[0]), clonedPartition.getReplicaIndex(replicas[0]));
}
Also used : Address(com.hazelcast.cluster.Address) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) InternalPartition(com.hazelcast.internal.partition.InternalPartition) InternalPartitionImplConstructor(com.hazelcast.test.starter.constructor.InternalPartitionImplConstructor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with PartitionReplica

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

the class PartitionReplicaConstructorTest method testConstructor.

@Test
public void testConstructor() {
    HazelcastInstance hz = createHazelcastInstance();
    warmUpPartitions(hz);
    InternalPartitionService partitionService = getNode(hz).getPartitionService();
    InternalPartition[] partitions = partitionService.getInternalPartitions();
    InternalPartitionImpl partition = (InternalPartitionImpl) partitions[0];
    PartitionReplica replica = partition.getReplica(0);
    PartitionReplicaConstructor constructor = new PartitionReplicaConstructor(PartitionReplica.class);
    PartitionReplica clonedReplica = (PartitionReplica) constructor.createNew(replica);
    assertEquals(replica.address(), clonedReplica.address());
    assertEquals(replica.uuid(), clonedReplica.uuid());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) PartitionReplicaConstructor(com.hazelcast.test.starter.constructor.PartitionReplicaConstructor) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) InternalPartition(com.hazelcast.internal.partition.InternalPartition) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with PartitionReplica

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

the class InternalPartitionImplTest method testVersion_setReplicas.

@Test
public void testVersion_setReplicas() {
    replicaOwners[0] = localReplica;
    partition.setReplicas(replicaOwners);
    assertEquals(1, partition.version());
    PartitionReplica[] newReplicas = Arrays.copyOf(replicaOwners, replicaOwners.length);
    newReplicas[0] = new PartitionReplica(newAddress(6000), UuidUtil.newUnsecureUUID());
    newReplicas[1] = localReplica;
    partition.setReplicas(newReplicas);
    assertEquals(3, partition.version());
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with PartitionReplica

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

the class InternalPartitionImplTest method testIsOwnerOrBackup.

@Test
public void testIsOwnerOrBackup() {
    replicaOwners[0] = localReplica;
    Address otherAddress = newAddress(5001);
    replicaOwners[1] = new PartitionReplica(otherAddress, UuidUtil.newUnsecureUUID());
    partition.setReplicas(replicaOwners);
    assertTrue(partition.isOwnerOrBackup(replicaOwners[0]));
    assertTrue(partition.isOwnerOrBackup(localReplica));
    assertTrue(partition.isOwnerOrBackup(replicaOwners[1]));
    assertTrue(partition.isOwnerOrBackup(otherAddress));
    assertFalse(partition.isOwnerOrBackup(new PartitionReplica(newAddress(6000), UuidUtil.newUnsecureUUID())));
    assertFalse(partition.isOwnerOrBackup(newAddress(6000)));
}
Also used : Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)103 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)51 QuickTest (com.hazelcast.test.annotation.QuickTest)51 Test (org.junit.Test)51 Address (com.hazelcast.cluster.Address)44 InternalPartition (com.hazelcast.internal.partition.InternalPartition)17 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)17 ArrayList (java.util.ArrayList)10 Member (com.hazelcast.cluster.Member)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)7 PartitionTableView (com.hazelcast.internal.partition.PartitionTableView)6 ReadonlyInternalPartition (com.hazelcast.internal.partition.ReadonlyInternalPartition)6 ClusterState (com.hazelcast.cluster.ClusterState)5 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 NodeEngine (com.hazelcast.spi.impl.NodeEngine)4 Operation (com.hazelcast.spi.impl.operationservice.Operation)4 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)3 MemberLeftException (com.hazelcast.core.MemberLeftException)3 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)3