Reduce the number of accesses to consistent map
Stop accessing the consistent map when the resource is discrete.
Now, access to the consistent map happens only when the resource
is continuous.
Change-Id: Ic1cb1d94d32a2097dfca891e1d2de7fdc5d4c00a
diff --git a/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java b/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
index 00ccd9d..5b669af 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
@@ -202,10 +202,18 @@
TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
- // Extract Discrete instances from resources
+ // Look up resources by resource IDs
List<Resource> resources = ids.stream()
.filter(x -> x.parent().isPresent())
- .flatMap(x -> Tools.stream(lookup(childTxMap, x)))
+ .map(x -> {
+ // avoid access to consistent map in the case of discrete resource
+ if (x instanceof DiscreteResourceId) {
+ return Optional.of(Resources.discrete((DiscreteResourceId) x).resource());
+ } else {
+ return lookup(childTxMap, x);
+ }
+ })
+ .flatMap(Tools::stream)
.collect(Collectors.toList());
// the order is preserved by LinkedHashMap
Map<DiscreteResourceId, List<Resource>> resourceMap = resources.stream()