private int partitionId(@Nonnull String sequencerName) { Partition partition = partitionService.getPartition(sequencerName); return partition.getPartitionId(); }
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 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"); }
private String getServiceInfo(DistributedObject obj) { final Partition partition = instance.getPartitionService().getPartition(obj.getPartitionKey()); return String.format("serviceName=%s, partitionId=%d, owner=%s", obj.getServiceName(), partition.getPartitionId(), partition.getOwner()); }
private void initLocal(Set<Partition> partitions) { addrToPartitions = partitions.stream() .collect(groupingBy(p -> p.getOwner().getAddress(), mapping(Partition::getPartitionId, toList()))); }
@Override public boolean apply(Map.Entry<K, V> mapEntry) { if (partitions.contains(partService.getPartition(mapEntry.getKey()).getPartitionId())) { return predicate.apply(mapEntry); } return false; }
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 boolean apply(Map.Entry<K, V> mapEntry) { if (member.equals(partService.getPartition(mapEntry.getKey()).getOwner())) { return predicate.apply(mapEntry); } return false; }
@Override public final K next() { for (; ; ) { K key = generateKey(); Partition partition = partitionService.getPartition(key); Set<K> keys = keysPerPartition[partition.getPartitionId()]; if (keys == null) { continue; } if (keys.contains(key)) { continue; } if (keys.size() == maxKeysPerPartition) { continue; } keys.add(key); return key; } }
@ManagedOperation(description="Return Document Location Info") @ManagedOperationParameters({ @ManagedOperationParameter(name = "uri", description = "Document identifier")}) public CompositeData getDocumentLocation(String uri) { try { Properties props = new Properties(); props.setProperty("bdb.document.headers", String.valueOf(DocumentAccessor.HDR_URI)); DocumentAccessor doc = docManager.getDocument(uri, props); CompositeData result = null; if (doc != null) { int hash = schemaManager.getRepository().getDistributionStrategy().getDistributionHash(uri); Partition part = hzClient.getPartitionService().getPartition(hash); Map<String, Object> location = new HashMap<>(2); location.put("partition", part.getPartitionId()); location.put("owner", part.getOwner().toString()); result = JMXUtils.mapToComposite("document", "Document Location", location); } logger.debug("getDocumentLocation; returning: {}", result); return result; } catch (BagriException ex) { logger.error("getDocumentLocation.error: {}", ex.getMessage(), ex); throw new RuntimeException(ex.getMessage()); } }
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(); }
@BeforeRun public void beforeRun(ThreadState state) { if (isClient(targetInstance)) { throw new IllegalArgumentException("SyntheticTest doesn't support clients at the moment"); } state.operationService = HazelcastTestUtils.getOperationService(targetInstance); int[] keys = KeyUtils.generateIntKeys(keyCount, keyLocality, targetInstance); for (int key : keys) { Partition partition = targetInstance.getPartitionService().getPartition(key); state.partitionSequence.add(partition.getPartitionId()); } Collections.shuffle(state.partitionSequence); }
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(); }
@BeforeRun public void beforeRun(ThreadState state) { if (isClient(targetInstance)) { throw new IllegalArgumentException("SyntheticTest doesn't support clients at the moment"); } state.operationService = HazelcastTestUtils.getOperationService(targetInstance); int[] keys = KeyUtils.generateIntKeys(keyCount, keyLocality, targetInstance); for (int key : keys) { Partition partition = targetInstance.getPartitionService().getPartition(key); state.partitionSequence.add(partition.getPartitionId()); } Collections.shuffle(state.partitionSequence); }
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(); }
@BeforeRun public void beforeRun(ThreadState state) { if (isClient(targetInstance)) { throw new IllegalArgumentException("SyntheticTest doesn't support clients at the moment"); } state.operationService = HazelcastTestUtils.getOperationService(targetInstance); int[] keys = KeyUtils.generateIntKeys(keyCount, keyLocality, targetInstance); for (int key : keys) { Partition partition = targetInstance.getPartitionService().getPartition(key); state.partitionSequence.add(partition.getPartitionId()); } Collections.shuffle(state.partitionSequence); }
private static boolean isLocalKey(HazelcastInstance instance, String key) { PartitionService partitionService = instance.getPartitionService(); Partition partition = partitionService.getPartition(key); Member owner = partition.getOwner(); return owner.equals(instance.getLocalEndpoint()); }
@BeforeRun public void beforeRun(ThreadState state) { if (isClient(targetInstance)) { throw new IllegalArgumentException("SyntheticTest doesn't support clients at the moment"); } state.operationService = HazelcastTestUtils.getOperationService(targetInstance); int[] keys = KeyUtils.generateIntKeys(keyCount, keyLocality, targetInstance); for (int key : keys) { Partition partition = targetInstance.getPartitionService().getPartition(key); state.partitionSequence.add(partition.getPartitionId()); } Collections.shuffle(state.partitionSequence); }
@Override public void init(@Nonnull Context context) { addrToPartitions = context.jetInstance().getHazelcastInstance().getPartitionService().getPartitions() .stream() .collect(groupingBy(p -> p.getOwner().getAddress(), mapping(Partition::getPartitionId, toList()))); }
@BeforeRun public void beforeRun(ThreadState state) { if (isClient(targetInstance)) { throw new IllegalArgumentException("SyntheticTest doesn't support clients at the moment"); } state.operationService = HazelcastTestUtils.getOperationService(targetInstance); int[] keys = KeyUtils.generateIntKeys(keyCount, keyLocality, targetInstance); for (int key : keys) { Partition partition = targetInstance.getPartitionService().getPartition(key); state.partitionSequence.add(partition.getPartitionId()); } Collections.shuffle(state.partitionSequence); }