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; ...@@ -17,7 +17,6 @@ package org.onlab.onos.store.hz;
17 17
18 import com.hazelcast.config.Config; 18 import com.hazelcast.config.Config;
19 import com.hazelcast.config.FileSystemXmlConfig; 19 import com.hazelcast.config.FileSystemXmlConfig;
20 -import com.hazelcast.config.MapConfig;
21 import com.hazelcast.core.Hazelcast; 20 import com.hazelcast.core.Hazelcast;
22 import com.hazelcast.core.HazelcastInstance; 21 import com.hazelcast.core.HazelcastInstance;
23 22
...@@ -48,12 +47,6 @@ public class StoreManager implements StoreService { ...@@ -48,12 +47,6 @@ public class StoreManager implements StoreService {
48 try { 47 try {
49 Config config = new FileSystemXmlConfig(HAZELCAST_XML_FILE); 48 Config config = new FileSystemXmlConfig(HAZELCAST_XML_FILE);
50 49
51 - MapConfig roles = config.getMapConfig("nodeRoles");
52 - roles.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - roles.getBackupCount());
53 -
54 - MapConfig terms = config.getMapConfig("terms");
55 - terms.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - terms.getBackupCount());
56 -
57 instance = Hazelcast.newHazelcastInstance(config); 50 instance = Hazelcast.newHazelcastInstance(config);
58 log.info("Started"); 51 log.info("Started");
59 } catch (FileNotFoundException e) { 52 } catch (FileNotFoundException e) {
......
...@@ -21,6 +21,8 @@ import com.google.common.base.Verify; ...@@ -21,6 +21,8 @@ import com.google.common.base.Verify;
21 import com.google.common.collect.ImmutableList; 21 import com.google.common.collect.ImmutableList;
22 import com.google.common.collect.ImmutableSet; 22 import com.google.common.collect.ImmutableSet;
23 import com.google.common.collect.Lists; 23 import com.google.common.collect.Lists;
24 +import com.hazelcast.config.Config;
25 +import com.hazelcast.config.MapConfig;
24 import com.hazelcast.core.EntryAdapter; 26 import com.hazelcast.core.EntryAdapter;
25 import com.hazelcast.core.EntryEvent; 27 import com.hazelcast.core.EntryEvent;
26 import com.hazelcast.core.EntryListener; 28 import com.hazelcast.core.EntryListener;
...@@ -82,12 +84,15 @@ public class HazelcastIntentStore ...@@ -82,12 +84,15 @@ public class HazelcastIntentStore
82 private final Logger log = getLogger(getClass()); 84 private final Logger log = getLogger(getClass());
83 85
84 // Assumption: IntentId will not have synonyms 86 // Assumption: IntentId will not have synonyms
87 + private static final String INTENTS_MAP_NAME = "intents";
85 private SMap<IntentId, Intent> intents; 88 private SMap<IntentId, Intent> intents;
89 + private static final String INTENT_STATES_MAP_NAME = "intent-states";
86 private SMap<IntentId, IntentState> states; 90 private SMap<IntentId, IntentState> states;
87 91
88 // Map to store instance local intermediate state transition 92 // Map to store instance local intermediate state transition
89 private transient Map<IntentId, IntentState> transientStates = new ConcurrentHashMap<>(); 93 private transient Map<IntentId, IntentState> transientStates = new ConcurrentHashMap<>();
90 94
95 + private static final String INSTALLABLE_INTENTS_MAP_NAME = "installable-intents";
91 private SMap<IntentId, List<Intent>> installable; 96 private SMap<IntentId, List<Intent>> installable;
92 97
93 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 98 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -144,20 +149,29 @@ public class HazelcastIntentStore ...@@ -144,20 +149,29 @@ public class HazelcastIntentStore
144 149
145 }; 150 };
146 151
152 + final Config config = theInstance.getConfig();
153 +
154 + MapConfig intentsCfg = config.getMapConfig(INTENTS_MAP_NAME);
155 + intentsCfg.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - intentsCfg.getBackupCount());
156 +
147 // TODO: enable near cache, allow read from backup for this IMap 157 // TODO: enable near cache, allow read from backup for this IMap
148 - IMap<byte[], byte[]> rawIntents = super.theInstance.getMap("intents"); 158 + IMap<byte[], byte[]> rawIntents = super.theInstance.getMap(INTENTS_MAP_NAME);
149 intents = new SMap<>(rawIntents , super.serializer); 159 intents = new SMap<>(rawIntents , super.serializer);
150 160
151 - // TODO: disable near cache, disable read from backup for this IMap 161 + MapConfig statesCfg = config.getMapConfig(INTENT_STATES_MAP_NAME);
152 - IMap<byte[], byte[]> rawStates = super.theInstance.getMap("intent-states"); 162 + statesCfg.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - statesCfg.getBackupCount());
163 +
164 + IMap<byte[], byte[]> rawStates = super.theInstance.getMap(INTENT_STATES_MAP_NAME);
153 states = new SMap<>(rawStates , super.serializer); 165 states = new SMap<>(rawStates , super.serializer);
154 EntryListener<IntentId, IntentState> listener = new RemoteIntentStateListener(); 166 EntryListener<IntentId, IntentState> listener = new RemoteIntentStateListener();
155 listenerId = states.addEntryListener(listener , true); 167 listenerId = states.addEntryListener(listener , true);
156 168
157 transientStates.clear(); 169 transientStates.clear();
158 170
159 - // TODO: disable near cache, disable read from backup for this IMap 171 + MapConfig installableCfg = config.getMapConfig(INSTALLABLE_INTENTS_MAP_NAME);
160 - IMap<byte[], byte[]> rawInstallables = super.theInstance.getMap("installable-intents"); 172 + installableCfg.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - installableCfg.getBackupCount());
173 +
174 + IMap<byte[], byte[]> rawInstallables = super.theInstance.getMap(INSTALLABLE_INTENTS_MAP_NAME);
161 installable = new SMap<>(rawInstallables , super.serializer); 175 installable = new SMap<>(rawInstallables , super.serializer);
162 176
163 log.info("Started"); 177 log.info("Started");
......
...@@ -45,6 +45,8 @@ import org.onlab.onos.store.serializers.KryoSerializer; ...@@ -45,6 +45,8 @@ import org.onlab.onos.store.serializers.KryoSerializer;
45 import org.onlab.util.KryoNamespace; 45 import org.onlab.util.KryoNamespace;
46 46
47 import com.google.common.base.Objects; 47 import com.google.common.base.Objects;
48 +import com.hazelcast.config.Config;
49 +import com.hazelcast.config.MapConfig;
48 import com.hazelcast.core.EntryEvent; 50 import com.hazelcast.core.EntryEvent;
49 import com.hazelcast.core.EntryListener; 51 import com.hazelcast.core.EntryListener;
50 import com.hazelcast.core.MapEvent; 52 import com.hazelcast.core.MapEvent;
...@@ -67,8 +69,10 @@ public class DistributedMastershipStore ...@@ -67,8 +69,10 @@ public class DistributedMastershipStore
67 private static final Integer INIT = 1; 69 private static final Integer INIT = 1;
68 70
69 //device to node roles 71 //device to node roles
72 + private static final String NODE_ROLES_MAP_NAME = "nodeRoles";
70 protected SMap<DeviceId, RoleValue> roleMap; 73 protected SMap<DeviceId, RoleValue> roleMap;
71 //devices to terms 74 //devices to terms
75 + private static final String TERMS_MAP_NAME = "terms";
72 protected SMap<DeviceId, Integer> terms; 76 protected SMap<DeviceId, Integer> terms;
73 77
74 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 78 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -92,9 +96,17 @@ public class DistributedMastershipStore ...@@ -92,9 +96,17 @@ public class DistributedMastershipStore
92 } 96 }
93 }; 97 };
94 98
95 - roleMap = new SMap<>(theInstance.<byte[], byte[]>getMap("nodeRoles"), this.serializer); 99 + final Config config = theInstance.getConfig();
100 +
101 + MapConfig nodeRolesCfg = config.getMapConfig(NODE_ROLES_MAP_NAME);
102 + nodeRolesCfg.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - nodeRolesCfg.getBackupCount());
103 +
104 + MapConfig termsCfg = config.getMapConfig(TERMS_MAP_NAME);
105 + termsCfg.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - termsCfg.getBackupCount());
106 +
107 + roleMap = new SMap<>(theInstance.<byte[], byte[]>getMap(NODE_ROLES_MAP_NAME), this.serializer);
96 listenerId = roleMap.addEntryListener((new RemoteMasterShipEventHandler()), true); 108 listenerId = roleMap.addEntryListener((new RemoteMasterShipEventHandler()), true);
97 - terms = new SMap<>(theInstance.<byte[], byte[]>getMap("terms"), this.serializer); 109 + terms = new SMap<>(theInstance.<byte[], byte[]>getMap(TERMS_MAP_NAME), this.serializer);
98 110
99 log.info("Started"); 111 log.info("Started");
100 } 112 }
......
...@@ -52,6 +52,8 @@ import org.slf4j.Logger; ...@@ -52,6 +52,8 @@ import org.slf4j.Logger;
52 import com.google.common.collect.ImmutableList; 52 import com.google.common.collect.ImmutableList;
53 import com.google.common.collect.ImmutableSet; 53 import com.google.common.collect.ImmutableSet;
54 import com.google.common.collect.Sets; 54 import com.google.common.collect.Sets;
55 +import com.hazelcast.config.Config;
56 +import com.hazelcast.config.MapConfig;
55 import com.hazelcast.core.TransactionalMap; 57 import com.hazelcast.core.TransactionalMap;
56 import com.hazelcast.transaction.TransactionContext; 58 import com.hazelcast.transaction.TransactionContext;
57 import com.hazelcast.transaction.TransactionException; 59 import com.hazelcast.transaction.TransactionException;
...@@ -104,6 +106,15 @@ public class HazelcastLinkResourceStore ...@@ -104,6 +106,15 @@ public class HazelcastLinkResourceStore
104 @Activate 106 @Activate
105 public void activate() { 107 public void activate() {
106 super.activate(); 108 super.activate();
109 +
110 + final Config config = theInstance.getConfig();
111 +
112 + MapConfig linkCfg = config.getMapConfig(LINK_RESOURCE_ALLOCATIONS);
113 + linkCfg.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - linkCfg.getBackupCount());
114 +
115 + MapConfig intentCfg = config.getMapConfig(INTENT_ALLOCATIONS);
116 + intentCfg.setAsyncBackupCount(MapConfig.MAX_BACKUP_COUNT - intentCfg.getBackupCount());
117 +
107 log.info("Started"); 118 log.info("Started");
108 } 119 }
109 120
......