Committed by
Gerrit Code Review
Added retry to the config store, to recover from CM timeout exception.
Change-Id: I602cbf5a09fa353ea57aecf9bb511b3f9453aca8
Showing
1 changed file
with
12 additions
and
1 deletions
| ... | @@ -33,6 +33,7 @@ import org.apache.felix.scr.annotations.Reference; | ... | @@ -33,6 +33,7 @@ import org.apache.felix.scr.annotations.Reference; |
| 33 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 33 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 34 | import org.apache.felix.scr.annotations.Service; | 34 | import org.apache.felix.scr.annotations.Service; |
| 35 | import org.onlab.util.KryoNamespace; | 35 | import org.onlab.util.KryoNamespace; |
| 36 | +import org.onlab.util.Tools; | ||
| 36 | import org.onosproject.incubator.net.config.Config; | 37 | import org.onosproject.incubator.net.config.Config; |
| 37 | import org.onosproject.incubator.net.config.ConfigApplyDelegate; | 38 | import org.onosproject.incubator.net.config.ConfigApplyDelegate; |
| 38 | import org.onosproject.incubator.net.config.ConfigFactory; | 39 | import org.onosproject.incubator.net.config.ConfigFactory; |
| ... | @@ -42,6 +43,7 @@ import org.onosproject.incubator.net.config.NetworkConfigStoreDelegate; | ... | @@ -42,6 +43,7 @@ import org.onosproject.incubator.net.config.NetworkConfigStoreDelegate; |
| 42 | import org.onosproject.store.AbstractStore; | 43 | import org.onosproject.store.AbstractStore; |
| 43 | import org.onosproject.store.serializers.KryoNamespaces; | 44 | import org.onosproject.store.serializers.KryoNamespaces; |
| 44 | import org.onosproject.store.service.ConsistentMap; | 45 | import org.onosproject.store.service.ConsistentMap; |
| 46 | +import org.onosproject.store.service.ConsistentMapException; | ||
| 45 | import org.onosproject.store.service.MapEvent; | 47 | import org.onosproject.store.service.MapEvent; |
| 46 | import org.onosproject.store.service.MapEventListener; | 48 | import org.onosproject.store.service.MapEventListener; |
| 47 | import org.onosproject.store.service.Serializer; | 49 | import org.onosproject.store.service.Serializer; |
| ... | @@ -66,6 +68,8 @@ public class DistributedNetworkConfigStore | ... | @@ -66,6 +68,8 @@ public class DistributedNetworkConfigStore |
| 66 | extends AbstractStore<NetworkConfigEvent, NetworkConfigStoreDelegate> | 68 | extends AbstractStore<NetworkConfigEvent, NetworkConfigStoreDelegate> |
| 67 | implements NetworkConfigStore { | 69 | implements NetworkConfigStore { |
| 68 | 70 | ||
| 71 | + private static final int MAX_BACKOFF = 10; | ||
| 72 | + | ||
| 69 | private final Logger log = LoggerFactory.getLogger(getClass()); | 73 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 70 | 74 | ||
| 71 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 75 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| ... | @@ -160,7 +164,14 @@ public class DistributedNetworkConfigStore | ... | @@ -160,7 +164,14 @@ public class DistributedNetworkConfigStore |
| 160 | 164 | ||
| 161 | @Override | 165 | @Override |
| 162 | public <S, T extends Config<S>> T getConfig(S subject, Class<T> configClass) { | 166 | public <S, T extends Config<S>> T getConfig(S subject, Class<T> configClass) { |
| 163 | - Versioned<ObjectNode> json = configs.get(key(subject, configClass)); | 167 | + // FIXME: There has to be a better way to absorb the timeout exceptions. |
| 168 | + Versioned<ObjectNode> json = null; | ||
| 169 | + try { | ||
| 170 | + json = configs.get(key(subject, configClass)); | ||
| 171 | + } catch (ConsistentMapException.Timeout e) { | ||
| 172 | + Tools.randomDelay(MAX_BACKOFF); | ||
| 173 | + json = configs.get(key(subject, configClass)); | ||
| 174 | + } | ||
| 164 | return json != null ? createConfig(subject, configClass, json.value()) : null; | 175 | return json != null ? createConfig(subject, configClass, json.value()) : null; |
| 165 | } | 176 | } |
| 166 | 177 | ... | ... |
-
Please register or login to post a comment