Add retry for ResourceSubStores
Change-Id: Ie7f05f4d34813618ee785697d34a0903183f3036
(cherry picked from commit 5a91f39cecb77333f7a7523490a5fcd4c23ef062)
diff --git a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentContinuousResourceSubStore.java b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentContinuousResourceSubStore.java
index e6282dc..be9d592 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentContinuousResourceSubStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentContinuousResourceSubStore.java
@@ -17,6 +17,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
+import org.onlab.util.Tools;
import org.onosproject.net.resource.ContinuousResource;
import org.onosproject.net.resource.ContinuousResourceId;
import org.onosproject.net.resource.DiscreteResourceId;
@@ -24,6 +25,7 @@
import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.resource.ResourceConsumerId;
import org.onosproject.store.service.ConsistentMap;
+import org.onosproject.store.service.StorageException;
import org.onosproject.store.service.StorageService;
import org.onosproject.store.service.TransactionContext;
import org.onosproject.store.service.Versioned;
@@ -55,7 +57,12 @@
.withSerializer(SERIALIZER)
.build();
- childMap.putIfAbsent(Resource.ROOT.id(), new LinkedHashSet<>());
+ Tools.retryable(
+ () -> childMap.putIfAbsent(Resource.ROOT.id(), new LinkedHashSet<>()),
+ StorageException.ConcurrentModification.class,
+ Integer.MAX_VALUE,
+ 50
+ ).get();
}
@Override
diff --git a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentDiscreteResourceSubStore.java b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentDiscreteResourceSubStore.java
index d70916e..9135230 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentDiscreteResourceSubStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentDiscreteResourceSubStore.java
@@ -17,6 +17,7 @@
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;
@@ -24,6 +25,7 @@
import org.onosproject.net.resource.ResourceConsumerId;
import org.onosproject.net.resource.Resources;
import org.onosproject.store.service.ConsistentMap;
+import org.onosproject.store.service.StorageException;
import org.onosproject.store.service.StorageService;
import org.onosproject.store.service.TransactionContext;
import org.onosproject.store.service.Versioned;
@@ -53,7 +55,12 @@
.withSerializer(SERIALIZER)
.build();
- childMap.putIfAbsent(Resource.ROOT.id(), DiscreteResources.empty());
+ Tools.retryable(
+ () -> childMap.putIfAbsent(Resource.ROOT.id(), DiscreteResources.empty()),
+ StorageException.ConcurrentModification.class,
+ Integer.MAX_VALUE,
+ 50
+ ).get();
}
@Override