Madan Jampani
Committed by Gerrit Code Review

Removed operation retry wrappers around various consistent map/atomic counter operations

Change-Id: Ie6c22a983a01bf3488eff51a493554319c5d15f8
......@@ -36,7 +36,6 @@ import org.apache.felix.scr.annotations.Reference;
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.net.config.Config;
import org.onosproject.net.config.ConfigApplyDelegate;
import org.onosproject.net.config.ConfigFactory;
......@@ -47,7 +46,6 @@ import org.onosproject.net.config.NetworkConfigStoreDelegate;
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;
......@@ -79,7 +77,6 @@ public class DistributedNetworkConfigStore
private final Logger log = LoggerFactory.getLogger(getClass());
private static final int MAX_BACKOFF = 10;
private static final String INVALID_CONFIG_JSON =
"JSON node does not contain valid configuration";
private static final String INVALID_JSON_LIST =
......@@ -216,9 +213,7 @@ public class DistributedNetworkConfigStore
@Override
public <S, T extends Config<S>> T getConfig(S subject, Class<T> configClass) {
// TODO: need to identify and address the root cause for timeouts.
Versioned<JsonNode> json = Tools.retryable(configs::get, ConsistentMapException.class, 1, MAX_BACKOFF)
.apply(key(subject, configClass));
Versioned<JsonNode> json = configs.get(key(subject, configClass));
return json != null ? createConfig(subject, configClass, json.value()) : null;
}
......
......@@ -28,7 +28,6 @@ import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onlab.util.KryoNamespace;
import org.onlab.util.Tools;
import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
......@@ -45,12 +44,10 @@ import org.onosproject.net.provider.ProviderId;
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;
import org.onosproject.store.service.StorageService;
import org.onosproject.store.service.Versioned;
import org.slf4j.Logger;
import java.util.Collection;
......@@ -60,7 +57,6 @@ import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
......@@ -83,7 +79,7 @@ public class DistributedHostStore
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected StorageService storageService;
private ConsistentMap<HostId, DefaultHost> host;
private ConsistentMap<HostId, DefaultHost> hostsConsistentMap;
private Map<HostId, DefaultHost> hosts;
private final ConcurrentHashMap<HostId, DefaultHost> prevHosts =
......@@ -97,24 +93,24 @@ public class DistributedHostStore
KryoNamespace.Builder hostSerializer = KryoNamespace.newBuilder()
.register(KryoNamespaces.API);
host = storageService.<HostId, DefaultHost>consistentMapBuilder()
hostsConsistentMap = storageService.<HostId, DefaultHost>consistentMapBuilder()
.withName("onos-hosts")
.withRelaxedReadConsistency()
.withSerializer(Serializer.using(hostSerializer.build()))
.build();
hosts = host.asJavaMap();
hosts = hostsConsistentMap.asJavaMap();
prevHosts.putAll(hosts);
host.addListener(hostLocationTracker);
hostsConsistentMap.addListener(hostLocationTracker);
log.info("Started");
}
@Deactivate
public void deactivate() {
host.removeListener(hostLocationTracker);
hostsConsistentMap.removeListener(hostLocationTracker);
prevHosts.clear();
log.info("Stopped");
......@@ -162,8 +158,7 @@ public class DistributedHostStore
HostId hostId,
HostDescription hostDescription,
boolean replaceIPs) {
Supplier<Versioned<DefaultHost>> supplier =
() -> host.computeIf(hostId,
hostsConsistentMap.computeIf(hostId,
existingHost -> shouldUpdate(existingHost, providerId, hostId,
hostDescription, replaceIPs),
(id, existingHost) -> {
......@@ -193,12 +188,6 @@ public class DistributedHostStore
addresses,
annotations);
});
Tools.retryable(supplier,
ConsistentMapException.ConcurrentModification.class,
Integer.MAX_VALUE,
50).get();
return null;
}
......
......@@ -42,7 +42,6 @@ import org.onosproject.store.cluster.messaging.MessageSubject;
import org.onosproject.store.serializers.KryoNamespaces;
import org.onosproject.store.serializers.StoreSerializer;
import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.ConsistentMapException;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageService;
import org.osgi.service.component.ComponentContext;
......@@ -60,7 +59,6 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.onlab.util.Tools.get;
import static org.onlab.util.Tools.groupedThreads;
import static org.onlab.util.Tools.retryable;
import static org.slf4j.LoggerFactory.getLogger;
/**
......@@ -206,9 +204,7 @@ public class DistributedPacketStore
}
private void add(PacketRequest request) {
AtomicBoolean firstRequest =
retryable(this::addInternal, ConsistentMapException.ConcurrentModification.class,
Integer.MAX_VALUE, MAX_BACKOFF).apply(request);
AtomicBoolean firstRequest = addInternal(request);
if (firstRequest.get() && delegate != null) {
// The instance that makes the first request will push to all devices
delegate.requestPackets(request);
......@@ -234,9 +230,7 @@ public class DistributedPacketStore
}
private void remove(PacketRequest request) {
AtomicBoolean removedLast =
retryable(this::removeInternal, ConsistentMapException.ConcurrentModification.class,
Integer.MAX_VALUE, MAX_BACKOFF).apply(request);
AtomicBoolean removedLast = removeInternal(request);
if (removedLast.get() && delegate != null) {
// The instance that removes the last request will remove from all devices
delegate.cancelPackets(request);
......
......@@ -18,7 +18,6 @@ package org.onosproject.store.resource.impl;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.onlab.util.GuavaCollectors;
import org.onlab.util.Tools;
import org.onosproject.net.resource.ContinuousResource;
import org.onosproject.net.resource.ContinuousResourceId;
import org.onosproject.net.resource.DiscreteResourceId;
......@@ -26,7 +25,6 @@ import org.onosproject.net.resource.Resource;
import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.resource.ResourceConsumerId;
import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.ConsistentMapException;
import org.onosproject.store.service.StorageService;
import org.onosproject.store.service.TransactionContext;
import org.onosproject.store.service.Versioned;
......@@ -36,8 +34,6 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Stream;
import static org.onosproject.store.resource.impl.ConsistentResourceStore.MAX_RETRIES;
import static org.onosproject.store.resource.impl.ConsistentResourceStore.RETRY_DELAY;
import static org.onosproject.store.resource.impl.ConsistentResourceStore.SERIALIZER;
class ConsistentContinuousResourceSubStore {
......@@ -54,8 +50,7 @@ class ConsistentContinuousResourceSubStore {
.withSerializer(SERIALIZER)
.build();
Tools.retryable(() -> childMap.put(Resource.ROOT.id(), new LinkedHashSet<>()),
ConsistentMapException.class, MAX_RETRIES, RETRY_DELAY);
childMap.put(Resource.ROOT.id(), new LinkedHashSet<>());
}
TransactionalContinuousResourceSubStore transactional(TransactionContext tx) {
......
......@@ -17,7 +17,6 @@ package org.onosproject.store.resource.impl;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.onlab.util.Tools;
import org.onosproject.net.resource.DiscreteResource;
import org.onosproject.net.resource.DiscreteResourceId;
import org.onosproject.net.resource.Resource;
......@@ -25,7 +24,6 @@ import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.resource.ResourceConsumerId;
import org.onosproject.net.resource.Resources;
import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.ConsistentMapException;
import org.onosproject.store.service.StorageService;
import org.onosproject.store.service.TransactionContext;
import org.onosproject.store.service.Versioned;
......@@ -35,8 +33,6 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
import static org.onosproject.store.resource.impl.ConsistentResourceStore.MAX_RETRIES;
import static org.onosproject.store.resource.impl.ConsistentResourceStore.RETRY_DELAY;
import static org.onosproject.store.resource.impl.ConsistentResourceStore.SERIALIZER;
class ConsistentDiscreteResourceSubStore {
......@@ -53,8 +49,7 @@ class ConsistentDiscreteResourceSubStore {
.withSerializer(SERIALIZER)
.build();
Tools.retryable(() -> childMap.put(Resource.ROOT.id(), DiscreteResources.empty()),
ConsistentMapException.class, MAX_RETRIES, RETRY_DELAY);
childMap.put(Resource.ROOT.id(), DiscreteResources.empty());
}
TransactionalDiscreteResourceSubStore transactional(TransactionContext tx) {
......
......@@ -33,7 +33,6 @@ import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.packet.Ethernet;
import org.onlab.util.Tools;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.cluster.ClusterMetadataService;
import org.onosproject.cluster.ClusterService;
......@@ -70,7 +69,6 @@ import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.provider.lldpcommon.LinkDiscovery;
import org.onosproject.provider.lldpcommon.LinkDiscoveryContext;
import org.onosproject.store.service.ConsistentMapException;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
......@@ -252,14 +250,10 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv
cfgRegistry.addListener(cfgListener);
factories.forEach(cfgRegistry::registerConfigFactory);
SuppressionConfig cfg =
Tools.retryable(() -> cfgRegistry.getConfig(appId, SuppressionConfig.class),
ConsistentMapException.class, MAX_RETRIES, RETRY_DELAY).get();
SuppressionConfig cfg = cfgRegistry.getConfig(appId, SuppressionConfig.class);
if (cfg == null) {
// If no configuration is found, register default.
cfg = Tools.retryable(this::setDefaultSuppressionConfig,
ConsistentMapException.class,
MAX_RETRIES, RETRY_DELAY).get();
cfg = this.setDefaultSuppressionConfig();
}
cfgListener.reconfigureSuppressionRules(cfg);
......