Fix IntentPartition rebalance to work correctly after a network partition heals
Change-Id: Ie73598bc191fffb46d18fc3544f9d2b15d10feb7
(cherry picked from commit a4d2c72a05edc1fcfb9d9e9c076019061e2b4d55)
diff --git a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/IntentPartitionManager.java b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/IntentPartitionManager.java
index 0ac9647..3080143 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/IntentPartitionManager.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/IntentPartitionManager.java
@@ -179,6 +179,14 @@
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 @@
int relinquish = myPartitions.size() - myShare;
+
for (int i = 0; i < relinquish; i++) {
String topic = myPartitions.get(i);
leadershipService.withdraw(topic);