use of com.hazelcast.partition.Partition in project hazelcast by hazelcast.
the class QueryUtils method createPartitionMap.
/**
* Create map from member ID to owned partitions.
*
* @param nodeEngine node engine
* @param localMemberVersion version of the local member. If any of partition owners have a different version, an exception
* is thrown. The check is ignored if passed version is {@code null}
* @param failOnUnassignedPartition whether the call should fail in case an unassigned partition is found; when set to
* {@code false} the missing partitions will not be included in the result
* @return partition mapping
*/
public static Map<UUID, PartitionIdSet> createPartitionMap(NodeEngine nodeEngine, @Nullable MemberVersion localMemberVersion, boolean failOnUnassignedPartition) {
Collection<Partition> parts = nodeEngine.getHazelcastInstance().getPartitionService().getPartitions();
int partCnt = parts.size();
Map<UUID, PartitionIdSet> partMap = new LinkedHashMap<>();
for (Partition part : parts) {
Member owner = part.getOwner();
if (owner == null) {
if (failOnUnassignedPartition) {
throw QueryException.error(SqlErrorCode.PARTITION_DISTRIBUTION, "Partition is not assigned to any member: " + part.getPartitionId());
} else {
continue;
}
}
if (localMemberVersion != null) {
if (!localMemberVersion.equals(owner.getVersion())) {
UUID localMemberId = nodeEngine.getLocalMember().getUuid();
throw QueryException.error("Cannot execute SQL query when members have different versions " + "(make sure that all members have the same version) {localMemberId=" + localMemberId + ", localMemberVersion=" + localMemberVersion + ", remoteMemberId=" + owner.getUuid() + ", remoteMemberVersion=" + owner.getVersion() + "}");
}
}
partMap.computeIfAbsent(owner.getUuid(), (key) -> new PartitionIdSet(partCnt)).add(part.getPartitionId());
}
return partMap;
}
use of com.hazelcast.partition.Partition in project hazelcast by hazelcast.
the class PartitionServiceProxyTest method testGetPartition.
@Test
public void testGetPartition() {
String key = "Key";
PartitionService clientPartitionService = client.getPartitionService();
Partition clientPartition = clientPartitionService.getPartition(key);
PartitionService serverPartitionService = server.getPartitionService();
Partition serverPartition = serverPartitionService.getPartition(key);
assertEquals(clientPartition.getPartitionId(), serverPartition.getPartitionId());
}
use of com.hazelcast.partition.Partition in project hazelcast by hazelcast.
the class PartitionServiceProxyTest method testGetPartitions.
@Test
public void testGetPartitions() {
PartitionService clientPartitionService = client.getPartitionService();
Set<Partition> clientPartitions = clientPartitionService.getPartitions();
PartitionService serverPartitionService = server.getPartitionService();
Set<Partition> serverPartitions = serverPartitionService.getPartitions();
assertEquals(clientPartitions.size(), serverPartitions.size());
}
use of com.hazelcast.partition.Partition in project hazelcast by hazelcast.
the class ConsoleApp method handlePartitions.
protected void handlePartitions(String[] args) {
Set<Partition> partitions = hazelcast.getPartitionService().getPartitions();
Map<Member, Integer> partitionCounts = new HashMap<>();
for (Partition partition : partitions) {
Member owner = partition.getOwner();
if (owner != null) {
Integer count = partitionCounts.get(owner);
int newCount = 1;
if (count != null) {
newCount = count + 1;
}
partitionCounts.put(owner, newCount);
}
println(partition);
}
Set<Map.Entry<Member, Integer>> entries = partitionCounts.entrySet();
for (Map.Entry<Member, Integer> entry : entries) {
println(entry.getKey() + ": " + entry.getValue());
}
}
use of com.hazelcast.partition.Partition in project hazelcast by hazelcast.
the class RingbufferStoreFailureConsistencyTest method getPrimaryInstance.
private HazelcastInstance getPrimaryInstance(HazelcastInstance instance, HazelcastInstance instance2) {
Partition primaryPartition = instance.getPartitionService().getPartition(RINGBUFFER_NAME);
UUID primaryInstanceUuid = primaryPartition.getOwner().getUuid();
UUID instanceOneUuid = instance.getCluster().getLocalMember().getUuid();
return primaryInstanceUuid.equals(instanceOneUuid) ? instance : instance2;
}
Aggregations