Yuta HIGUCHI
Committed by Gerrit Code Review

Hazelcast based Stores: configure async backup on it's own

Change-Id: I0b777fb90dd63d292a65f02811452430055ad547
......@@ -17,7 +17,6 @@ package org.onlab.onos.store.hz;
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 @@ public class StoreManager implements StoreService {
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) {
......
......@@ -21,6 +21,8 @@ import com.google.common.base.Verify;
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 @@ public class HazelcastIntentStore
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 @@ public class HazelcastIntentStore
};
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");
......
......@@ -45,6 +45,8 @@ import org.onlab.onos.store.serializers.KryoSerializer;
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 @@ public class DistributedMastershipStore
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 @@ public class DistributedMastershipStore
}
};
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");
}
......
......@@ -52,6 +52,8 @@ import org.slf4j.Logger;
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 @@ public class HazelcastLinkResourceStore
@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");
}
......