Mark couple of expensive LeadershipService methods as deprecated
Change-Id: Iff9207a917de5855153f641ddabe1afba0178d53
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 1db6534..0ac9647 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
@@ -43,6 +43,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
+import java.util.stream.IntStream;
/**
* Manages the assignment of intent keyspace partitions to instances.
@@ -135,7 +136,8 @@
@Override
public boolean isMine(Key intentKey) {
- return Objects.equals(leadershipService.getLeader(getPartitionPath(getPartitionForKey(intentKey))),
+ return Objects.equals(leadershipService.getLeadership(getPartitionPath(getPartitionForKey(intentKey)))
+ .leaderNodeId(),
localNodeId);
}
@@ -177,24 +179,20 @@
int myShare = (int) Math.ceil((double) NUM_PARTITIONS / activeNodes);
- List<Leadership> myPartitions = leadershipService.getLeaderBoard().values()
- .stream()
- .filter(l -> localNodeId.equals(l.leaderNodeId()))
- .filter(l -> l.topic().startsWith(ELECTION_PREFIX))
- .collect(Collectors.toList());
+ List<String> myPartitions = IntStream.range(0, NUM_PARTITIONS)
+ .mapToObj(this::getPartitionPath)
+ .map(leadershipService::getLeadership)
+ .filter(Objects::nonNull)
+ .filter(leadership -> localNodeId.equals(leadership.leaderNodeId()))
+ .map(Leadership::topic)
+ .collect(Collectors.toList());
int relinquish = myPartitions.size() - myShare;
- if (relinquish <= 0) {
- return;
- }
-
for (int i = 0; i < relinquish; i++) {
- String topic = myPartitions.get(i).topic();
+ String topic = myPartitions.get(i);
leadershipService.withdraw(topic);
-
- executor.schedule(() -> recontest(topic),
- BACKOFF_TIME, TimeUnit.SECONDS);
+ executor.schedule(() -> recontest(topic), BACKOFF_TIME, TimeUnit.SECONDS);
}
}