use of com.hazelcast.internal.partition.PartitionTableView 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;
}
use of com.hazelcast.internal.partition.PartitionTableView in project hazelcast by hazelcast.
the class ClusterViewListenerService method getPartitionViewMessageOrNull.
private ClientMessage getPartitionViewMessageOrNull() {
InternalPartitionService partitionService = (InternalPartitionService) nodeEngine.getPartitionService();
PartitionTableView partitionTableView = partitionService.createPartitionTableView();
Map<UUID, List<Integer>> partitions = getPartitions(partitionTableView);
if (partitions.size() == 0) {
return null;
}
int version;
long currentStamp = partitionTableView.stamp();
long latestStamp = latestPartitionStamp.get();
if (currentStamp != latestStamp && latestPartitionStamp.compareAndSet(latestStamp, currentStamp)) {
partitionTableVersion.incrementAndGet();
}
version = partitionTableVersion.get();
return ClientAddClusterViewListenerCodec.encodePartitionsViewEvent(version, partitions.entrySet());
}
use of com.hazelcast.internal.partition.PartitionTableView in project hazelcast by hazelcast.
the class FrozenPartitionTableTest method testPartitionTableIsFrozenDuring.
private void testPartitionTableIsFrozenDuring(final ClusterState clusterState) {
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance[] instances = factory.newInstances();
warmUpPartitions(instances);
changeClusterStateEventually(instances[0], clusterState);
List<HazelcastInstance> instancesList = new ArrayList<HazelcastInstance>(asList(instances));
Collections.shuffle(instancesList);
final PartitionTableView partitionTable = getPartitionTable(instances[0]);
while (instancesList.size() > 1) {
final HazelcastInstance instanceToShutdown = instancesList.remove(0);
instanceToShutdown.shutdown();
for (HazelcastInstance instance : instancesList) {
assertClusterSizeEventually(instancesList.size(), instance);
assertEquals(partitionTable, getPartitionTable(instance));
}
}
}
use of com.hazelcast.internal.partition.PartitionTableView in project hazelcast by hazelcast.
the class FrozenPartitionTableTest method partitionTable_isFrozen_whenMemberReJoins_duringClusterStateIs.
private void partitionTable_isFrozen_whenMemberReJoins_duringClusterStateIs(ClusterState state) {
Config config = new Config();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(4);
HazelcastInstance[] instances = factory.newInstances(config, 3);
HazelcastInstance hz1 = instances[0];
HazelcastInstance hz2 = instances[1];
HazelcastInstance hz3 = instances[2];
Address hz3Address = getNode(hz3).getThisAddress();
warmUpPartitions(instances);
final PartitionTableView partitionTable = getPartitionTable(hz1);
changeClusterStateEventually(hz2, state);
final Member member3 = getClusterService(hz3).getLocalMember();
terminateInstance(hz2);
terminateInstance(hz3);
hz3 = factory.newHazelcastInstance(hz3Address);
final Member newMember3 = getClusterService(hz3).getLocalMember();
assertClusterSizeEventually(2, hz1, hz3);
final List<HazelcastInstance> instanceList = asList(hz1, hz3);
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() {
for (HazelcastInstance instance : instanceList) {
PartitionTableView newPartitionTable = getPartitionTable(instance);
for (int i = 0; i < newPartitionTable.length(); i++) {
for (int j = 0; j < InternalPartition.MAX_REPLICA_COUNT; j++) {
PartitionReplica replica = partitionTable.getReplica(i, j);
PartitionReplica newReplica = newPartitionTable.getReplica(i, j);
if (replica == null) {
assertNull(newReplica);
} else if (replica.equals(PartitionReplica.from(member3))) {
assertEquals(PartitionReplica.from(newMember3), newReplica);
} else {
assertEquals(replica, newReplica);
}
}
}
}
}
}, 5);
}
use of com.hazelcast.internal.partition.PartitionTableView in project hazelcast by hazelcast.
the class InternalPartitionServiceImplTest method test_setInitialState_multipleTimes.
@Test(expected = IllegalStateException.class)
public void test_setInitialState_multipleTimes() {
InternalPartition[] partitions = new InternalPartition[partitionCount];
for (int i = 0; i < partitionCount; i++) {
PartitionReplica[] replicas = new PartitionReplica[MAX_REPLICA_COUNT];
replicas[0] = PartitionReplica.from(localMember);
partitions[i] = new ReadonlyInternalPartition(replicas, i, RandomPicker.getInt(1, 10));
}
partitionService.setInitialState(new PartitionTableView(partitions));
partitionService.setInitialState(new PartitionTableView(partitions));
}
Aggregations