Use single counter for host probe index to avoid unnecessary Raft session creation
Change-Id: I59829879e291caf33fc3abd4b5bbb69f0be92261
diff --git a/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java b/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java
index 9cf9856..bc7f197 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java
@@ -47,6 +47,7 @@
import org.onosproject.net.provider.ProviderId;
import org.onosproject.store.AbstractStore;
import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.AtomicCounter;
import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.MapEvent;
import org.onosproject.store.service.MapEventListener;
@@ -94,6 +95,7 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected StorageService storageService;
+ private AtomicCounter hostProbeIndex;
private ConsistentMap<HostId, DefaultHost> hostsConsistentMap;
private Map<HostId, DefaultHost> hosts;
private Map<IpAddress, Set<Host>> hostsByIp;
@@ -158,6 +160,11 @@
pendingHostsConsistentMap.addListener(pendingHostListener);
pendingHosts = pendingHostsConsistentMap.asJavaMap();
+ hostProbeIndex = storageService.atomicCounterBuilder()
+ .withName("onos-hosts-probe-index")
+ .build()
+ .asAtomicCounter();
+
cacheCleaner.scheduleAtFixedRate(pendingHostsCache::cleanUp, 0,
PROBE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
@@ -412,7 +419,7 @@
@Override
public MacAddress addPendingHostLocation(HostId hostId, ConnectPoint connectPoint, ProbeMode probeMode) {
// Use ONLab OUI (3 bytes) + atomic counter (3 bytes) as the source MAC of the probe
- long nextIndex = storageService.getAtomicCounter("onos-hosts-probe-index").getAndIncrement();
+ long nextIndex = hostProbeIndex.getAndIncrement();
MacAddress probeMac = MacAddress.valueOf(MacAddress.NONE.toLong() + nextIndex);
PendingHostLocation phl = new PendingHostLocation(hostId, connectPoint, probeMode);