Improve SnapshotBackedReadTransaction.close() 96/10196/2
authorRobert Varga <rovarga@cisco.com>
Fri, 22 Aug 2014 22:18:26 +0000 (00:18 +0200)
committerRobert Varga <rovarga@cisco.com>
Mon, 25 Aug 2014 12:34:36 +0000 (14:34 +0200)
This improves visibility of close() operation, resulting in improved
close/read collision detection.

Change-Id: I7d3367c4d669a5c3dcd3f5c6583ce64b7690f1d9
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SnapshotBackedReadTransaction.java

index 44ee61c116a9a4c5f8f336890827fcfceea68075..2caa76d49dff02a34ad98232ccdc7db139f07f2c 100644 (file)
@@ -33,7 +33,7 @@ final class SnapshotBackedReadTransaction extends AbstractDOMStoreTransaction
                                           implements DOMStoreReadTransaction {
 
     private static final Logger LOG = LoggerFactory.getLogger(SnapshotBackedReadTransaction.class);
-    private DataTreeSnapshot stableSnapshot;
+    private volatile DataTreeSnapshot stableSnapshot;
 
     public SnapshotBackedReadTransaction(final Object identifier, final DataTreeSnapshot snapshot) {
         super(identifier);
@@ -52,19 +52,21 @@ final class SnapshotBackedReadTransaction extends AbstractDOMStoreTransaction
         LOG.debug("Tx: {} Read: {}", getIdentifier(), path);
         checkNotNull(path, "Path must not be null.");
 
-        if(stableSnapshot == null) {
+        final DataTreeSnapshot snapshot = stableSnapshot;
+        if (snapshot == null) {
             return Futures.immediateFailedCheckedFuture(new ReadFailedException("Transaction is closed"));
         }
 
         try {
-            return Futures.immediateCheckedFuture(stableSnapshot.readNode(path));
+            return Futures.immediateCheckedFuture(snapshot.readNode(path));
         } catch (Exception e) {
             LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e);
             return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read failed",e));
         }
     }
 
-    @Override public CheckedFuture<Boolean, ReadFailedException> exists(YangInstanceIdentifier path) {
+    @Override
+    public CheckedFuture<Boolean, ReadFailedException> exists(YangInstanceIdentifier path) {
         LOG.debug("Tx: {} Exists: {}", getIdentifier(), path);
         checkNotNull(path, "Path must not be null.");