Added retry to the config store, to recover from CM timeout exception.
Change-Id: I602cbf5a09fa353ea57aecf9bb511b3f9453aca8
diff --git a/incubator/store/src/main/java/org/onosproject/incubator/store/config/impl/DistributedNetworkConfigStore.java b/incubator/store/src/main/java/org/onosproject/incubator/store/config/impl/DistributedNetworkConfigStore.java
index 390f517..e2a4b4f 100644
--- a/incubator/store/src/main/java/org/onosproject/incubator/store/config/impl/DistributedNetworkConfigStore.java
+++ b/incubator/store/src/main/java/org/onosproject/incubator/store/config/impl/DistributedNetworkConfigStore.java
@@ -33,6 +33,7 @@
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.util.KryoNamespace;
+import org.onlab.util.Tools;
import org.onosproject.incubator.net.config.Config;
import org.onosproject.incubator.net.config.ConfigApplyDelegate;
import org.onosproject.incubator.net.config.ConfigFactory;
@@ -42,6 +43,7 @@
import org.onosproject.store.AbstractStore;
import org.onosproject.store.serializers.KryoNamespaces;
import org.onosproject.store.service.ConsistentMap;
+import org.onosproject.store.service.ConsistentMapException;
import org.onosproject.store.service.MapEvent;
import org.onosproject.store.service.MapEventListener;
import org.onosproject.store.service.Serializer;
@@ -66,6 +68,8 @@
extends AbstractStore<NetworkConfigEvent, NetworkConfigStoreDelegate>
implements NetworkConfigStore {
+ private static final int MAX_BACKOFF = 10;
+
private final Logger log = LoggerFactory.getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -160,7 +164,14 @@
@Override
public <S, T extends Config<S>> T getConfig(S subject, Class<T> configClass) {
- Versioned<ObjectNode> json = configs.get(key(subject, configClass));
+ // FIXME: There has to be a better way to absorb the timeout exceptions.
+ Versioned<ObjectNode> json = null;
+ try {
+ json = configs.get(key(subject, configClass));
+ } catch (ConsistentMapException.Timeout e) {
+ Tools.randomDelay(MAX_BACKOFF);
+ json = configs.get(key(subject, configClass));
+ }
return json != null ? createConfig(subject, configClass, json.value()) : null;
}