[ONOS-6239] Flows are missing after mastership change if 'backupEnabled' is set to false

Change-Id: Ibdd0262fc47ef01d03d21313a7334cd1cf7feeba
(cherry picked from commit 75830f01d96bde802dfaf7d88317cf253fc934b7)
diff --git a/core/store/dist/src/main/java/org/onosproject/store/flow/impl/DistributedFlowRuleStore.java b/core/store/dist/src/main/java/org/onosproject/store/flow/impl/DistributedFlowRuleStore.java
index f451712..af388bab 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/flow/impl/DistributedFlowRuleStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/flow/impl/DistributedFlowRuleStore.java
@@ -117,7 +117,6 @@
     private final Logger log = getLogger(getClass());
 
     private static final int MESSAGE_HANDLER_THREAD_POOL_SIZE = 8;
-    private static final boolean DEFAULT_BACKUP_ENABLED = true;
     private static final int DEFAULT_MAX_BACKUP_COUNT = 2;
     private static final boolean DEFAULT_PERSISTENCE_ENABLED = false;
     private static final int DEFAULT_BACKUP_PERIOD_MILLIS = 2000;
@@ -129,10 +128,6 @@
             label = "Number of threads in the message handler pool")
     private int msgHandlerPoolSize = MESSAGE_HANDLER_THREAD_POOL_SIZE;
 
-    @Property(name = "backupEnabled", boolValue = DEFAULT_BACKUP_ENABLED,
-            label = "Indicates whether backups are enabled or not")
-    private volatile boolean backupEnabled = DEFAULT_BACKUP_ENABLED;
-
     @Property(name = "backupPeriod", intValue = DEFAULT_BACKUP_PERIOD_MILLIS,
             label = "Delay in ms between successive backup runs")
     private int backupPeriod = DEFAULT_BACKUP_PERIOD_MILLIS;
@@ -210,14 +205,12 @@
 
         registerMessageHandlers(messageHandlingExecutor);
 
-        if (backupEnabled) {
-            replicaInfoManager.addListener(flowTable);
-            backupTask = backupSenderExecutor.scheduleWithFixedDelay(
-                    flowTable::backup,
-                    0,
-                    backupPeriod,
-                    TimeUnit.MILLISECONDS);
-        }
+        replicaInfoManager.addListener(flowTable);
+        backupTask = backupSenderExecutor.scheduleWithFixedDelay(
+                flowTable::backup,
+                0,
+                backupPeriod,
+                TimeUnit.MILLISECONDS);
 
         deviceTableStats = storageService.<DeviceId, List<TableStatisticsEntry>>eventuallyConsistentMapBuilder()
                 .withName("onos-flow-table-stats")
@@ -233,10 +226,8 @@
 
     @Deactivate
     public void deactivate(ComponentContext context) {
-        if (backupEnabled) {
-            replicaInfoManager.removeListener(flowTable);
-            backupTask.cancel(true);
-        }
+        replicaInfoManager.removeListener(flowTable);
+        backupTask.cancel(true);
         configService.unregisterProperties(getClass(), false);
         unregisterMessageHandlers();
         deviceTableStats.removeListener(tableStatsListener);
@@ -251,23 +242,18 @@
     @Modified
     public void modified(ComponentContext context) {
         if (context == null) {
-            backupEnabled = DEFAULT_BACKUP_ENABLED;
             logConfig("Default config");
             return;
         }
 
         Dictionary properties = context.getProperties();
         int newPoolSize;
-        boolean newBackupEnabled;
         int newBackupPeriod;
         int newBackupCount;
         try {
             String s = get(properties, "msgHandlerPoolSize");
             newPoolSize = isNullOrEmpty(s) ? msgHandlerPoolSize : Integer.parseInt(s.trim());
 
-            s = get(properties, "backupEnabled");
-            newBackupEnabled = isNullOrEmpty(s) ? backupEnabled : Boolean.parseBoolean(s.trim());
-
             s = get(properties, "backupPeriod");
             newBackupPeriod = isNullOrEmpty(s) ? backupPeriod : Integer.parseInt(s.trim());
 
@@ -275,28 +261,15 @@
             newBackupCount = isNullOrEmpty(s) ? backupCount : Integer.parseInt(s.trim());
         } catch (NumberFormatException | ClassCastException e) {
             newPoolSize = MESSAGE_HANDLER_THREAD_POOL_SIZE;
-            newBackupEnabled = DEFAULT_BACKUP_ENABLED;
             newBackupPeriod = DEFAULT_BACKUP_PERIOD_MILLIS;
             newBackupCount = DEFAULT_MAX_BACKUP_COUNT;
         }
 
         boolean restartBackupTask = false;
-        if (newBackupEnabled != backupEnabled) {
-            backupEnabled = newBackupEnabled;
-            if (!backupEnabled) {
-                replicaInfoManager.removeListener(flowTable);
-                if (backupTask != null) {
-                    backupTask.cancel(false);
-                    backupTask = null;
-                }
-            } else {
-                replicaInfoManager.addListener(flowTable);
-            }
-            restartBackupTask = backupEnabled;
-        }
+
         if (newBackupPeriod != backupPeriod) {
             backupPeriod = newBackupPeriod;
-            restartBackupTask = backupEnabled;
+            restartBackupTask = true;
         }
         if (restartBackupTask) {
             if (backupTask != null) {
@@ -350,8 +323,8 @@
     }
 
     private void logConfig(String prefix) {
-        log.info("{} with msgHandlerPoolSize = {}; backupEnabled = {}, backupPeriod = {}, backupCount = {}",
-                 prefix, msgHandlerPoolSize, backupEnabled, backupPeriod, backupCount);
+        log.info("{} with msgHandlerPoolSize = {}; backupPeriod = {}, backupCount = {}",
+                 prefix, msgHandlerPoolSize, backupPeriod, backupCount);
     }
 
     // This is not a efficient operation on a distributed sharded
@@ -710,7 +683,7 @@
 
         private void handleEvent(ReplicaInfoEvent event) {
             DeviceId deviceId = event.subject();
-            if (!backupEnabled || !mastershipService.isLocalMaster(deviceId)) {
+            if (!mastershipService.isLocalMaster(deviceId)) {
                 return;
             }
             if (event.type() == MASTER_CHANGED) {
@@ -888,9 +861,6 @@
         }
 
         private void backup() {
-            if (!backupEnabled) {
-                return;
-            }
             try {
                 // compute a mapping from node to the set of devices whose flow entries it should backup
                 Map<NodeId, Set<DeviceId>> devicesToBackupByNode = Maps.newHashMap();