Handle race-conditions in BGP shutdown code 61/88661/5
authorAjay Lele <ajayslele@gmail.com>
Tue, 24 Mar 2020 22:43:48 +0000 (15:43 -0700)
committerAjay Lele <ajayslele@gmail.com>
Fri, 10 Apr 2020 05:20:46 +0000 (22:20 -0700)
JIRA: BGPCEP-900
Signed-off-by: Ajay Lele <ajayslele@gmail.com>
Change-Id: Id50c83cd226f6786c9830b3b10d7e0eddda9653e

bgp/openconfig-state/src/main/java/org/opendaylight/protocol/bgp/state/StateProviderImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/BGPClusterSingletonService.java

index b2c0db760ad026f523ffcbcfb8dcb5cf7f428659..30eebed46b6f4987f1e7d5ad31200b3d03a7a4bd 100644 (file)
@@ -172,8 +172,9 @@ public final class StateProviderImpl implements TransactionChainListener, AutoCl
             this.scheduleTask.cancel(true);
             if (!this.instanceIdentifiersCache.keySet().isEmpty()) {
                 final WriteTransaction wTx = this.transactionChain.newWriteOnlyTransaction();
-                this.instanceIdentifiersCache.keySet().iterator()
-                .forEachRemaining(ribId -> removeStoredOperationalState(ribId, wTx));
+                this.instanceIdentifiersCache.values()
+                        .forEach(bgpIID -> wTx.delete(LogicalDatastoreType.OPERATIONAL, bgpIID));
+                this.instanceIdentifiersCache.clear();
                 wTx.commit().addCallback(new FutureCallback<CommitInfo>() {
                     @Override
                     public void onSuccess(final CommitInfo result) {
index 7665fb10eda7219ff1f6e53f7268ae51a32e1400..563d97562c1146356aa19142a680a93a6da3cf7d 100644 (file)
@@ -71,6 +71,7 @@ public final class BGPClusterSingletonService implements ClusterSingletonService
     private final ServiceGroupIdentifier serviceGroupIdentifier;
     private final AtomicBoolean instantiated = new AtomicBoolean(false);
     private final PeerGroupConfigLoader peerGroupLoader;
+    @GuardedBy("this")
     private RibImpl ribImpl;
 
 
@@ -116,8 +117,15 @@ public final class BGPClusterSingletonService implements ClusterSingletonService
         Futures.addCallback(futureResult, new FutureCallback<List<? extends CommitInfo>>() {
             @Override
             public void onSuccess(final List<? extends CommitInfo> result) {
-                done.setFuture(Futures.transform(BGPClusterSingletonService.this.ribImpl.closeServiceInstance(),
-                    input -> null, MoreExecutors.directExecutor()));
+                synchronized (BGPClusterSingletonService.this) {
+                    if (BGPClusterSingletonService.this.ribImpl != null) {
+                        done.setFuture(Futures.transform(BGPClusterSingletonService.this.ribImpl.closeServiceInstance(),
+                            input -> null, MoreExecutors.directExecutor()));
+                    } else {
+                        done.setFuture(Futures.transform(CommitInfo.emptyFluentFuture(),
+                            input -> null, MoreExecutors.directExecutor()));
+                    }
+                }
             }
 
             @Override
@@ -179,6 +187,7 @@ public final class BGPClusterSingletonService implements ClusterSingletonService
         LOG.debug("RIB instance created: {}", this.ribImpl);
     }
 
+    @Holding("this")
     @SuppressWarnings("checkstyle:illegalCatch")
     private void closeRibService() {
         try {
@@ -221,7 +230,7 @@ public final class BGPClusterSingletonService implements ClusterSingletonService
     }
 
     @Override
-    public void close() {
+    public synchronized void close() {
         LOG.info("BGPClusterSingletonService {} close", this.serviceGroupIdentifier.getName());
         this.peers.values().iterator().forEachRemaining(PeerBean::close);
         this.ribImpl.close();