Do not assert seal transition on forward path
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / SimpleShardBackendResolver.java
index 056a1ea7e226deb49a6ee12e916769bf7e6dbb0c..7c301e77a076466ac595e29fa3492aa11659f034 100644 (file)
@@ -41,18 +41,33 @@ final class SimpleShardBackendResolver extends AbstractShardBackendResolver {
     private CompletionStage<ShardBackendInfo> getBackendInfo(final long cookie) {
         Preconditions.checkArgument(cookie == 0);
 
-        ShardState local = state;
-        if (local == null) {
-            synchronized (this) {
-                local = state;
-                if (local == null) {
-                    local = resolveBackendInfo(shardName, 0);
-                    state = local;
-                }
-            }
+        final ShardState existing = state;
+        if (existing != null) {
+            return existing.getStage();
         }
 
-        return local.getStage();
+        synchronized (this) {
+            final ShardState recheck = state;
+            if (recheck != null) {
+                return recheck.getStage();
+            }
+
+            final ShardState newState = resolveBackendInfo(shardName, 0);
+            state = newState;
+
+            final CompletionStage<ShardBackendInfo> stage = newState.getStage();
+            stage.whenComplete((info, failure) -> {
+                if (failure != null) {
+                    synchronized (SimpleShardBackendResolver.this) {
+                        if (state == newState) {
+                            state = null;
+                        }
+                    }
+                }
+            });
+
+            return stage;
+        }
     }
 
     @Override
@@ -73,11 +88,16 @@ final class SimpleShardBackendResolver extends AbstractShardBackendResolver {
             synchronized (this) {
                 LOG.debug("Invalidating backend information {}", staleInfo);
                 flushCache(shardName);
-                LOG.trace("Invalidated cache %s", staleInfo);
+                LOG.trace("Invalidated cache {}", staleInfo);
                 state = null;
             }
         }
 
         return getBackendInfo(cookie);
     }
+
+    @Override
+    public String resolveCookieName(Long cookie) {
+        return shardName;
+    }
 }