public Partition getPartition(UUID id) { return partitionService.getPartition(id); }
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); } }
private static void waitUntilClusterSafe() throws InterruptedException { while (!clusterB.getPartitionService().isClusterSafe()) { Thread.sleep(100); } }
@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)); } }
@Prepare public void prepare() { if (!isMemberNode(targetInstance)) { return; } int retry = 0; while (!partitionService.isClusterSafe() && retry++ < isClusterSafeRetries) { logger.info(name + ": isClusterSafe() " + partitionService.isClusterSafe()); sleepSeconds(1); } logger.info(name + ": isClusterSafe() " + partitionService.isClusterSafe()); logger.info(name + ": isLocalMemberSafe() " + partitionService.isLocalMemberSafe()); logger.info(name + ": getCluster().getMembers().size() " + targetInstance.getCluster().getMembers().size()); logPartitionStatistics(logger, name, map, false); }
public static void main(String[] args) { HazelcastInstance node = Hazelcast.newHazelcastInstance(); boolean safe = node.getPartitionService().isLocalMemberSafe(); System.out.printf("# Is local member safe for shutdown\t: %s\n", safe); } }
public static void main(String[] args) { HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(null); HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(null); // initialize partitions instance1.getMap("map1").put(0, 0); instance1.getPartitionService().addPartitionLostListener(new PartitionLostListener() { @Override public void partitionLost(PartitionLostEvent event) { System.out.println("Instance2 has lost a partition for data with 0 backup! " + event); } }); instance2.getLifecycleService().terminate(); } }
public HazelcastPartitionManager(PartitionService partitionService) { this.partitionService = partitionService; partitionService.addMigrationListener(new MigrationListener() { @Override public void migrationStarted(MigrationEvent migrationEvent) {} @Override public void migrationFailed(MigrationEvent migrationEvent) { migrationCompleted(migrationEvent); } @Override public void migrationCompleted(MigrationEvent migrationEvent) { if(migrationEvent.getOldOwner() == null) { for(PartitionLostListener listener : listeners) { try { listener.partitionLost(migrationEvent); } catch (Exception e) { //swallow log.error("An exception was thrown by our partitionLost event listener. I will ignore it. ", e); } } } } }); }
@Override public void run() { memberStateSafe = instance.getPartitionService().isLocalMemberSafe(); } }, INITIAL_PARTITION_SAFETY_CHECK_DELAY, PARTITION_SAFETY_CHECK_PERIOD, TimeUnit.SECONDS);
private void initialize(HazelcastInstance hzInstance) { this.hzInstance = hzInstance; ITopic<Counter> cTopic = hzInstance.getTopic(TPN_XDM_COUNTERS); cTopic.addMessageListener(this); ITopic<Long> pTopic = hzInstance.getTopic(TPN_XDM_POPULATION); pTopic.addMessageListener(new PopulationStateListener()); hTopic = hzInstance.getTopic(TPN_XDM_HEALTH); xddCache = hzInstance.getMap(CN_XDM_DOCUMENT); hzInstance.getPartitionService().addPartitionLostListener(this); }
@Override protected void doStart() { final HazelcastClusterMonitorListener clusterMonitorListener = new HazelcastClusterMonitorListener(); if (this.monitorTypes.contains(ClusterMonitorType.MEMBERSHIP.name())) { final String registrationId = this.hazelcastInstance.getCluster() .addMembershipListener(clusterMonitorListener); this.hazelcastRegisteredListenerIdMap.put(ClusterMonitorType.MEMBERSHIP, registrationId); } if (this.monitorTypes.contains(ClusterMonitorType.DISTRIBUTED_OBJECT.name())) { final String registrationId = this.hazelcastInstance .addDistributedObjectListener(clusterMonitorListener); this.hazelcastRegisteredListenerIdMap.put(ClusterMonitorType.DISTRIBUTED_OBJECT, registrationId); } if (this.monitorTypes.contains(ClusterMonitorType.MIGRATION.name())) { final String registrationId = this.hazelcastInstance.getPartitionService() .addMigrationListener(clusterMonitorListener); this.hazelcastRegisteredListenerIdMap.put(ClusterMonitorType.MIGRATION, registrationId); } if (this.monitorTypes.contains(ClusterMonitorType.LIFECYCLE.name())) { final String registrationId = this.hazelcastInstance.getLifecycleService() .addLifecycleListener(clusterMonitorListener); this.hazelcastRegisteredListenerIdMap.put(ClusterMonitorType.LIFECYCLE, registrationId); } if (this.monitorTypes.contains(ClusterMonitorType.CLIENT.name())) { final String registrationId = this.hazelcastInstance.getClientService() .addClientListener(clusterMonitorListener); this.hazelcastRegisteredListenerIdMap.put(ClusterMonitorType.CLIENT, registrationId); } }
private int partitionId(@Nonnull String sequencerName) { Partition partition = partitionService.getPartition(sequencerName); return partition.getPartitionId(); }
public Set<Partition> getPartitions() { return hazelcast.getPartitionService().getPartitions(); }
public static void main(String[] args) { HazelcastInstance node = Hazelcast.newHazelcastInstance(); boolean safe = node.getPartitionService().isClusterSafe(); System.out.printf("# Is cluster safe for shutdown\t: %s\n", safe); } }
@Override public void run() { memberStateSafe = instance.getPartitionService().isLocalMemberSafe(); } }, INITIAL_PARTITION_SAFETY_CHECK_DELAY, PARTITION_SAFETY_CHECK_PERIOD, TimeUnit.SECONDS);
@SuppressWarnings("checkstyle:magicnumber") @SuppressFBWarnings({"EI_EXPOSE_REP2"}) public ExpirationManager(ClearExpiredRecordsTask task, NodeEngine nodeEngine) { this.task = task; this.nodeEngine = nodeEngine; this.globalTaskScheduler = nodeEngine.getExecutionService().getGlobalTaskScheduler(); this.taskPeriodSeconds = checkPositive(task.getTaskPeriodSeconds(), "taskPeriodSeconds should be a positive number"); this.lifecycleService = getHazelcastInstance().getLifecycleService(); this.lifecycleListenerId = lifecycleService.addLifecycleListener(this); this.partitionService = getHazelcastInstance().getPartitionService(); this.partitionLostListenerId = partitionService.addPartitionLostListener(this); }
@Override public void onStart() { logger.info("Plugin:active: logPartitions:" + logPartitions); connectionObservable.addConnectionListener(new ConnectionListenerImpl()); hazelcastInstance.getCluster().addMembershipListener(new MembershipListenerImpl()); if (logPartitions) { hazelcastInstance.getPartitionService().addMigrationListener(new MigrationListenerImpl()); } hazelcastInstance.getLifecycleService().addLifecycleListener(new LifecycleListenerImpl()); if (nodeExtension != null) { nodeExtension.registerListener(new ClusterVersionListenerImpl()); } }
@Override public boolean apply(Map.Entry<K, V> mapEntry) { if (member.equals(partService.getPartition(mapEntry.getKey()).getOwner())) { return predicate.apply(mapEntry); } return false; }
@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>(); } }
private static void waitUntilClusterSafe() throws InterruptedException { while (!clusterA.getPartitionService().isClusterSafe()) { Thread.sleep(100); } }