Adding retry to id block store.

Change-Id: I274a928a13d2999ccfeb79fc45caf292dbb81f5b
diff --git a/core/store/dist/src/main/java/org/onosproject/store/core/impl/ConsistentIdBlockStore.java b/core/store/dist/src/main/java/org/onosproject/store/core/impl/ConsistentIdBlockStore.java
index 2dc3129..1c9e44d 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/core/impl/ConsistentIdBlockStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/core/impl/ConsistentIdBlockStore.java
@@ -13,6 +13,7 @@
 import org.onosproject.core.IdBlock;
 import org.onosproject.core.IdBlockStore;
 import org.onosproject.store.service.AtomicCounter;
+import org.onosproject.store.service.StorageException;
 import org.onosproject.store.service.StorageService;
 import org.slf4j.Logger;
 
@@ -25,6 +26,8 @@
 @Service
 public class ConsistentIdBlockStore implements IdBlockStore {
 
+    private static final int MAX_TRIES = 3;
+
     private final Logger log = getLogger(getClass());
     private final Map<String, AtomicCounter> topicCounters = Maps.newConcurrentMap();
 
@@ -45,11 +48,23 @@
 
     @Override
     public IdBlock getIdBlock(String topic) {
-        AtomicCounter counter = topicCounters.computeIfAbsent(topic,
-                                    name -> storageService.atomicCounterBuilder()
-                                              .withName(name)
-                                              .build());
-        Long blockBase = counter.getAndAdd(DEFAULT_BLOCK_SIZE);
-        return new IdBlock(blockBase, DEFAULT_BLOCK_SIZE);
+        AtomicCounter counter = topicCounters
+                .computeIfAbsent(topic,
+                                 name -> storageService.atomicCounterBuilder()
+                                         .withName(name)
+                                         .build());
+        Throwable exc = null;
+        for (int i = 0; i < MAX_TRIES; i++) {
+            try {
+                Long blockBase = counter.getAndAdd(DEFAULT_BLOCK_SIZE);
+                return new IdBlock(blockBase, DEFAULT_BLOCK_SIZE);
+            } catch (StorageException e) {
+                log.warn("Unable to allocate ID block due to {}; retrying...",
+                         e.getMessage());
+                exc = e;
+            }
+        }
+        throw new IllegalStateException("Unable to allocate ID block", exc);
     }
+
 }