private void verifyHasPartitions(Set<Integer> targetPartitions) { if (targetPartitions.isEmpty()) { Map<Member, Integer> partitionsPerMember = new HashMap<Member, Integer>(); for (Partition partition : partitionService.getPartitions()) { Member owner = partition.getOwner(); if (owner == null) { throw new IllegalStateException("Owner is null for partition: " + partition); } Integer value = partitionsPerMember.get(owner); Integer result = value == null ? 1 : value + 1; partitionsPerMember.put(owner, result); } throw new IllegalStateException("No partitions found, partitionsPerMember: " + partitionsPerMember); } }
public Set<Partition> getPartitions() { return hazelcast.getPartitionService().getPartitions(); }
@SuppressWarnings("unchecked") BalancedKeyGenerator(HazelcastInstance hz, KeyLocality keyLocality, int keyCount) { this.hz = hz; this.keyLocality = keyLocality; this.keyCount = keyCount; this.partitionService = hz.getPartitionService(); Set<Integer> targetPartitions = getTargetPartitions(); this.maxKeysPerPartition = (int) Math.ceil(keyCount / (float) targetPartitions.size()); int partitionCount = partitionService.getPartitions().size(); this.keysPerPartition = new Set[partitionCount]; for (Integer partitionId : targetPartitions) { keysPerPartition[partitionId] = new HashSet<K>(); } }
public static String getPartitionDistributionInformation(HazelcastInstance hz) { Map<Member, Integer> partitionCountMap = new HashMap<Member, Integer>(); int totalPartitions = 0; for (Partition partition : hz.getPartitionService().getPartitions()) { totalPartitions++; Member member = partition.getOwner(); Integer count = partitionCountMap.get(member); if (count == null) { count = 0; } count++; partitionCountMap.put(member, count); } StringBuilder sb = new StringBuilder(); sb.append("total partitions: ").append(totalPartitions).append(NEW_LINE); for (Map.Entry<Member, Integer> entry : partitionCountMap.entrySet()) { Member member = entry.getKey(); long count = entry.getValue(); double percentage = count * 100d / totalPartitions; sb.append(member).append(" total: ").append(count) .append(" percentage: ").append(percentage).append('%').append(NEW_LINE); } return sb.toString(); }
public static String getPartitionDistributionInformation(HazelcastInstance hz) { Map<Member, Integer> partitionCountMap = new HashMap<Member, Integer>(); int totalPartitions = 0; for (Partition partition : hz.getPartitionService().getPartitions()) { totalPartitions++; Member member = partition.getOwner(); Integer count = partitionCountMap.get(member); if (count == null) { count = 0; } count++; partitionCountMap.put(member, count); } StringBuilder sb = new StringBuilder(); sb.append("total partitions: ").append(totalPartitions).append(NEW_LINE); for (Map.Entry<Member, Integer> entry : partitionCountMap.entrySet()) { Member member = entry.getKey(); long count = entry.getValue(); double percentage = count * 100d / totalPartitions; sb.append(member).append(" total: ").append(count) .append(" percentage: ").append(percentage).append('%').append(NEW_LINE); } return sb.toString(); }
public static String getPartitionDistributionInformation(HazelcastInstance hz) { Map<Member, Integer> partitionCountMap = new HashMap<Member, Integer>(); int totalPartitions = 0; for (Partition partition : hz.getPartitionService().getPartitions()) { totalPartitions++; Member member = partition.getOwner(); Integer count = partitionCountMap.get(member); if (count == null) { count = 0; } count++; partitionCountMap.put(member, count); } StringBuilder sb = new StringBuilder(); sb.append("total partitions: ").append(totalPartitions).append(NEW_LINE); for (Map.Entry<Member, Integer> entry : partitionCountMap.entrySet()) { Member member = entry.getKey(); long count = entry.getValue(); double percentage = count * 100d / totalPartitions; sb.append(member).append(" total: ").append(count) .append(" percentage: ").append(percentage).append('%').append(NEW_LINE); } return sb.toString(); }
public static void warmupPartitions(HazelcastInstance hazelcastInstance) { LOGGER.info("Waiting for partition warmup"); PartitionService partitionService = hazelcastInstance.getPartitionService(); long started = System.nanoTime(); for (Partition partition : partitionService.getPartitions()) { if (System.nanoTime() - started > PARTITION_WARMUP_TIMEOUT_NANOS) { throw new IllegalStateException("Partition warmup timeout. Partitions didn't get an owner in time"); } while (partition.getOwner() == null) { LOGGER.debug("Partition owner is not yet set for partitionId: " + partition.getPartitionId()); sleepMillisThrowException(PARTITION_WARMUP_SLEEP_INTERVAL_MILLIS); } } LOGGER.info("Partitions are warmed up successfully"); }
protected void handlePartitions(String[] args) { Set<Partition> partitions = hazelcast.getPartitionService().getPartitions(); Map<Member, Integer> partitionCounts = new HashMap<Member, Integer>(); 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()); } }
@Override public void init(@Nonnull Context context) { addrToPartitions = context.jetInstance().getHazelcastInstance().getPartitionService().getPartitions() .stream() .collect(groupingBy(p -> p.getOwner().getAddress(), mapping(Partition::getPartitionId, toList()))); }
protected void handlePartitions(String[] args) { Set<Partition> partitions = hazelcast.getPartitionService().getPartitions(); Map<Member, Integer> partitionCounts = new HashMap<Member, Integer>(); 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()); } }
protected void handlePartitions(String[] args) { Set<Partition> partitions = hazelcast.getPartitionService().getPartitions(); Map<Member, Integer> partitionCounts = new HashMap<Member, Integer>(); 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<Entry<Member, Integer>> entries = partitionCounts.entrySet(); for (Entry<Member, Integer> entry : entries) { println(entry.getKey() + ":" + entry.getValue()); } }
public void warmUpPartitions(HazelcastInstance...instances) throws InterruptedException { for (HazelcastInstance instance : instances) { final PartitionService ps = instance.getPartitionService(); for (Partition partition : ps.getPartitions()) { while (partition.getOwner() == null) { Thread.sleep(10); } } } for (int i = 0; i < 100000; i++) { map.get(i); } }
protected void handlePartitions(String[] args) { Set<Partition> partitions = hazelcast.getPartitionService().getPartitions(); Map<Member, Integer> partitionCounts = new HashMap<Member, Integer>(); 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<Entry<Member, Integer>> entries = partitionCounts.entrySet(); for (Entry<Member, Integer> entry : entries) { println(entry.getKey() + ":" + entry.getValue()); } }
private Set<Integer> getTargetPartitions() { Set<Integer> targetPartitions = new HashSet<Integer>(); Member localMember = getLocalMember(hz); switch (keyLocality) { case LOCAL: for (Partition partition : partitionService.getPartitions()) { if (localMember == null || localMember.equals(partition.getOwner())) { targetPartitions.add(partition.getPartitionId()); } } break; case REMOTE: for (Partition partition : partitionService.getPartitions()) { if (localMember == null || !localMember.equals(partition.getOwner())) { targetPartitions.add(partition.getPartitionId()); } } break; case RANDOM: for (Partition partition : partitionService.getPartitions()) { targetPartitions.add(partition.getPartitionId()); } break; default: throw new IllegalArgumentException("Unsupported keyLocality: " + keyLocality); } verifyHasPartitions(targetPartitions); return targetPartitions; }
@Override public void init(@Nonnull Context context) { if (clientXml != null) { initRemote(); } else { initLocal(context.jetInstance().getHazelcastInstance().getPartitionService().getPartitions()); } }
private MapConfig convertAndStoreMapConfig(String mapName, CacheSettings newSettings, Config config, MapConfig baseConfig) { MapConfig newConfig = new MapConfig(baseConfig); newConfig.setName(mapName); newConfig.setStatisticsEnabled(true); new HazelcastMapConfigConfigurator().configureMapConfig(newSettings, newConfig, hazelcast.getPartitionService().getPartitions().size()); config.addMapConfig(newConfig); return newConfig; }
@Setup public void setup() { integrityMap = targetInstance.getMap(name + "Integrity"); stressMap = targetInstance.getMap(name + "Stress"); integrityThreads = new MapIntegrityThread[mapIntegrityThreadCount]; value = new byte[valueSize]; Random random = new Random(); random.nextBytes(value); if (mapLoad && isMemberNode(targetInstance)) { PartitionService partitionService = targetInstance.getPartitionService(); final Set<Partition> partitionSet = partitionService.getPartitions(); for (Partition partition : partitionSet) { while (partition.getOwner() == null) { sleepSeconds(1); } } logger.info(format("%s: %d partitions", name, partitionSet.size())); Member localMember = targetInstance.getCluster().getLocalMember(); for (int i = 0; i < totalIntegrityKeys; i++) { Partition partition = partitionService.getPartition(i); if (localMember.equals(partition.getOwner())) { integrityMap.put(i, value); } } logger.info(format("%s: integrityMap=%s size=%d", name, integrityMap.getName(), integrityMap.size())); Config config = targetInstance.getConfig(); MapConfig mapConfig = config.getMapConfig(integrityMap.getName()); logger.info(format("%s: %s", name, mapConfig)); } }