Hazelcast based Stores: configure async backup on it's own
Change-Id: I0b777fb90dd63d292a65f02811452430055ad547
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/hz/StoreManager.java b/core/store/dist/src/main/java/org/onlab/onos/store/hz/StoreManager.java
index 6256364..6a3c9de 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/hz/StoreManager.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/hz/StoreManager.java
@@ -17,7 +17,6 @@
import com.hazelcast.config.Config;
import com.hazelcast.config.FileSystemXmlConfig;
-import com.hazelcast.config.MapConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
@@ -48,12 +47,6 @@
try {
Config config = new FileSystemXmlConfig(HAZELCAST_XML_FILE);
- MapConfig roles = config.getMapConfig("nodeRoles");
- roles.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - roles.getBackupCount());
-
- MapConfig terms = config.getMapConfig("terms");
- terms.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - terms.getBackupCount());
-
instance = Hazelcast.newHazelcastInstance(config);
log.info("Started");
} catch (FileNotFoundException e) {
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/intent/impl/HazelcastIntentStore.java b/core/store/dist/src/main/java/org/onlab/onos/store/intent/impl/HazelcastIntentStore.java
index c537a72..926686a 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/intent/impl/HazelcastIntentStore.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/intent/impl/HazelcastIntentStore.java
@@ -21,6 +21,8 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
+import com.hazelcast.config.Config;
+import com.hazelcast.config.MapConfig;
import com.hazelcast.core.EntryAdapter;
import com.hazelcast.core.EntryEvent;
import com.hazelcast.core.EntryListener;
@@ -82,12 +84,15 @@
private final Logger log = getLogger(getClass());
// Assumption: IntentId will not have synonyms
+ private static final String INTENTS_MAP_NAME = "intents";
private SMap<IntentId, Intent> intents;
+ private static final String INTENT_STATES_MAP_NAME = "intent-states";
private SMap<IntentId, IntentState> states;
// Map to store instance local intermediate state transition
private transient Map<IntentId, IntentState> transientStates = new ConcurrentHashMap<>();
+ private static final String INSTALLABLE_INTENTS_MAP_NAME = "installable-intents";
private SMap<IntentId, List<Intent>> installable;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -144,20 +149,29 @@
};
+ final Config config = theInstance.getConfig();
+
+ MapConfig intentsCfg = config.getMapConfig(INTENTS_MAP_NAME);
+ intentsCfg.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - intentsCfg.getBackupCount());
+
// TODO: enable near cache, allow read from backup for this IMap
- IMap<byte[], byte[]> rawIntents = super.theInstance.getMap("intents");
+ IMap<byte[], byte[]> rawIntents = super.theInstance.getMap(INTENTS_MAP_NAME);
intents = new SMap<>(rawIntents , super.serializer);
- // TODO: disable near cache, disable read from backup for this IMap
- IMap<byte[], byte[]> rawStates = super.theInstance.getMap("intent-states");
+ MapConfig statesCfg = config.getMapConfig(INTENT_STATES_MAP_NAME);
+ statesCfg.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - statesCfg.getBackupCount());
+
+ IMap<byte[], byte[]> rawStates = super.theInstance.getMap(INTENT_STATES_MAP_NAME);
states = new SMap<>(rawStates , super.serializer);
EntryListener<IntentId, IntentState> listener = new RemoteIntentStateListener();
listenerId = states.addEntryListener(listener , true);
transientStates.clear();
- // TODO: disable near cache, disable read from backup for this IMap
- IMap<byte[], byte[]> rawInstallables = super.theInstance.getMap("installable-intents");
+ MapConfig installableCfg = config.getMapConfig(INSTALLABLE_INTENTS_MAP_NAME);
+ installableCfg.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - installableCfg.getBackupCount());
+
+ IMap<byte[], byte[]> rawInstallables = super.theInstance.getMap(INSTALLABLE_INTENTS_MAP_NAME);
installable = new SMap<>(rawInstallables , super.serializer);
log.info("Started");
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/mastership/impl/DistributedMastershipStore.java b/core/store/dist/src/main/java/org/onlab/onos/store/mastership/impl/DistributedMastershipStore.java
index bf15ddc..acae21e 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/mastership/impl/DistributedMastershipStore.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/mastership/impl/DistributedMastershipStore.java
@@ -45,6 +45,8 @@
import org.onlab.util.KryoNamespace;
import com.google.common.base.Objects;
+import com.hazelcast.config.Config;
+import com.hazelcast.config.MapConfig;
import com.hazelcast.core.EntryEvent;
import com.hazelcast.core.EntryListener;
import com.hazelcast.core.MapEvent;
@@ -67,8 +69,10 @@
private static final Integer INIT = 1;
//device to node roles
+ private static final String NODE_ROLES_MAP_NAME = "nodeRoles";
protected SMap<DeviceId, RoleValue> roleMap;
//devices to terms
+ private static final String TERMS_MAP_NAME = "terms";
protected SMap<DeviceId, Integer> terms;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -92,9 +96,17 @@
}
};
- roleMap = new SMap<>(theInstance.<byte[], byte[]>getMap("nodeRoles"), this.serializer);
+ final Config config = theInstance.getConfig();
+
+ MapConfig nodeRolesCfg = config.getMapConfig(NODE_ROLES_MAP_NAME);
+ nodeRolesCfg.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - nodeRolesCfg.getBackupCount());
+
+ MapConfig termsCfg = config.getMapConfig(TERMS_MAP_NAME);
+ termsCfg.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - termsCfg.getBackupCount());
+
+ roleMap = new SMap<>(theInstance.<byte[], byte[]>getMap(NODE_ROLES_MAP_NAME), this.serializer);
listenerId = roleMap.addEntryListener((new RemoteMasterShipEventHandler()), true);
- terms = new SMap<>(theInstance.<byte[], byte[]>getMap("terms"), this.serializer);
+ terms = new SMap<>(theInstance.<byte[], byte[]>getMap(TERMS_MAP_NAME), this.serializer);
log.info("Started");
}
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/resource/impl/HazelcastLinkResourceStore.java b/core/store/dist/src/main/java/org/onlab/onos/store/resource/impl/HazelcastLinkResourceStore.java
index b40ec81..b2adc25 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/resource/impl/HazelcastLinkResourceStore.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/resource/impl/HazelcastLinkResourceStore.java
@@ -52,6 +52,8 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
+import com.hazelcast.config.Config;
+import com.hazelcast.config.MapConfig;
import com.hazelcast.core.TransactionalMap;
import com.hazelcast.transaction.TransactionContext;
import com.hazelcast.transaction.TransactionException;
@@ -104,6 +106,15 @@
@Activate
public void activate() {
super.activate();
+
+ final Config config = theInstance.getConfig();
+
+ MapConfig linkCfg = config.getMapConfig(LINK_RESOURCE_ALLOCATIONS);
+ linkCfg.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - linkCfg.getBackupCount());
+
+ MapConfig intentCfg = config.getMapConfig(INTENT_ALLOCATIONS);
+ intentCfg.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - intentCfg.getBackupCount());
+
log.info("Started");
}