private boolean isLinked(String src, String dst, Set<ConsumerPair> pairs, List<String> currentPath) { if (src.equals(dst)) return false; if (pairs.isEmpty()) return false; if (new ConsumerPair(src, dst).in(pairs)) { currentPath.add(src); currentPath.add(dst); return true; } for (ConsumerPair pair: pairs) if (pair.srcMemberId.equals(src)) { Set<ConsumerPair> reducedSet = new HashSet<>(pairs); reducedSet.remove(pair); currentPath.add(pair.srcMemberId); return isLinked(pair.dstMemberId, dst, reducedSet, currentPath); } return false; }
private TopicPartition getTheActualPartitionToBeMoved(TopicPartition partition, String oldConsumer, String newConsumer) { String topic = partition.topic(); if (!partitionMovementsByTopic.containsKey(topic)) return partition; if (partitionMovements.containsKey(partition)) { // this partition has previously moved assert oldConsumer.equals(partitionMovements.get(partition).dstMemberId); oldConsumer = partitionMovements.get(partition).srcMemberId; } Map<ConsumerPair, Set<TopicPartition>> partitionMovementsForThisTopic = partitionMovementsByTopic.get(topic); ConsumerPair reversePair = new ConsumerPair(newConsumer, oldConsumer); if (!partitionMovementsForThisTopic.containsKey(reversePair)) return partition; return partitionMovementsForThisTopic.get(reversePair).iterator().next(); }
private void movePartition(TopicPartition partition, String oldConsumer, String newConsumer) { ConsumerPair pair = new ConsumerPair(oldConsumer, newConsumer); if (partitionMovements.containsKey(partition)) { // this partition has previously moved ConsumerPair existingPair = removeMovementRecordOfPartition(partition); assert existingPair.dstMemberId.equals(oldConsumer); if (!existingPair.srcMemberId.equals(newConsumer)) { // the partition is not moving back to its previous consumer // return new ConsumerPair2(existingPair.src, newConsumer); addPartitionMovementRecord(partition, new ConsumerPair(existingPair.srcMemberId, newConsumer)); } } else addPartitionMovementRecord(partition, pair); }
private boolean in(Set<ConsumerPair> pairs) { for (ConsumerPair pair: pairs) if (this.equals(pair)) return true; return false; } }