[VOL-4065] Fix race condition between mastership and local leadership
Change-Id: I265ea449355a5e74a43f03ca9416e31b9df84060
diff --git a/app/src/main/java/org/opencord/igmpproxy/impl/IgmpLeadershipManager.java b/app/src/main/java/org/opencord/igmpproxy/impl/IgmpLeadershipManager.java
index c40bca2..b31091b 100644
--- a/app/src/main/java/org/opencord/igmpproxy/impl/IgmpLeadershipManager.java
+++ b/app/src/main/java/org/opencord/igmpproxy/impl/IgmpLeadershipManager.java
@@ -58,17 +58,25 @@
log.info("Stopped.");
}
+ /**
+ * Checks for mastership or falls back to leadership on deviceId.
+ * If the device is available use mastership,
+ * otherwise fallback on leadership.
+ * Leadership on the device topic is needed because the master can be NONE
+ * in case the device went away, we still need to handle events
+ * consistently
+ */
@Override
public boolean isLocalLeader(DeviceId deviceId) {
- if (!mastershipService.isLocalMaster(deviceId)) {
- if (deviceService.isAvailable(deviceId)) {
- return false;
- }
+ if (deviceService.isAvailable(deviceId)) {
+ return mastershipService.isLocalMaster(deviceId);
+ } else {
+ // Fallback with Leadership service - device id is used as topic
NodeId leader = leadershipService.runForLeadership(
deviceId.toString()).leaderNodeId();
+ // Verify if this node is the leader
return clusterService.getLocalNode().id().equals(leader);
}
- return true;
}
@Override