Madan Jampani

Fix IntentPartition rebalance to work correctly after a network partition heals

Change-Id: Ie73598bc191fffb46d18fc3544f9d2b15d10feb7
......@@ -179,6 +179,14 @@ public class IntentPartitionManager implements IntentPartitionService {
int myShare = (int) Math.ceil((double) NUM_PARTITIONS / activeNodes);
// First make sure this node is a candidate for all partitions.
IntStream.range(0, NUM_PARTITIONS)
.mapToObj(this::getPartitionPath)
.map(leadershipService::getLeadership)
.filter(leadership -> !leadership.candidates().contains(localNodeId))
.map(Leadership::topic)
.forEach(leadershipService::runForLeadership);
List<String> myPartitions = IntStream.range(0, NUM_PARTITIONS)
.mapToObj(this::getPartitionPath)
.map(leadershipService::getLeadership)
......@@ -189,6 +197,7 @@ public class IntentPartitionManager implements IntentPartitionService {
int relinquish = myPartitions.size() - myShare;
for (int i = 0; i < relinquish; i++) {
String topic = myPartitions.get(i);
leadershipService.withdraw(topic);
......