ONOS-1883: Fix for lost flow rules on CLI directed mastership changes.
- Made all mastership role change operations asynchronous, which they are.
- In flowrule store we now check to see if any new backups need to be made when a device backup location (standby) changes
- In device mastership store we now wait briefly before we step down from mastership after promoting a new candidate as highest standy
Change-Id: Icb76cf4d0d23403053a3fd5a458a940b847da49f
diff --git a/core/net/src/main/java/org/onosproject/cluster/impl/MastershipManager.java b/core/net/src/main/java/org/onosproject/cluster/impl/MastershipManager.java
index e34790d..cb2fd18 100644
--- a/core/net/src/main/java/org/onosproject/cluster/impl/MastershipManager.java
+++ b/core/net/src/main/java/org/onosproject/cluster/impl/MastershipManager.java
@@ -17,6 +17,7 @@
import com.codahale.metrics.Timer;
import com.codahale.metrics.Timer.Context;
+
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -50,6 +51,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Lists.newArrayList;
import static org.onlab.metrics.MetricsUtil.startTimer;
@@ -111,26 +114,28 @@
checkNotNull(deviceId, DEVICE_ID_NULL);
checkNotNull(role, ROLE_NULL);
- MastershipEvent event = null;
+ CompletableFuture<MastershipEvent> eventFuture = null;
switch (role) {
case MASTER:
- event = store.setMaster(nodeId, deviceId);
+ eventFuture = store.setMaster(nodeId, deviceId);
break;
case STANDBY:
- event = store.setStandby(nodeId, deviceId);
+ eventFuture = store.setStandby(nodeId, deviceId);
break;
case NONE:
- event = store.relinquishRole(nodeId, deviceId);
+ eventFuture = store.relinquishRole(nodeId, deviceId);
break;
default:
log.info("Unknown role; ignoring");
return;
}
- if (event != null) {
- post(event);
- }
+ eventFuture.whenComplete((event, error) -> {
+ if (event != null) {
+ post(event);
+ }
+ });
}
@Override
@@ -141,12 +146,12 @@
@Override
public void relinquishMastership(DeviceId deviceId) {
- MastershipEvent event = null;
- event = store.relinquishRole(
- clusterService.getLocalNode().id(), deviceId);
- if (event != null) {
- post(event);
- }
+ store.relinquishRole(clusterService.getLocalNode().id(), deviceId)
+ .whenComplete((event, error) -> {
+ if (event != null) {
+ post(event);
+ }
+ });
}
@Override