Fix transaction leak in BridgeConfigReconciliationTask 69/65569/2
authorMichael Vorburger <vorburger@redhat.com>
Wed, 15 Nov 2017 16:59:01 +0000 (17:59 +0100)
committerAnil Vishnoi <vishnoianil@gmail.com>
Wed, 15 Nov 2017 20:30:06 +0000 (20:30 +0000)
see https://jira.opendaylight.org/browse/OVSDB-425

Change-Id: I9d89cb72768cff137b91773ac8ab0e1d5fce7a04
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/reconciliation/configuration/BridgeConfigReconciliationTask.java

index 239ef8c5beb3e4ce286bc6de1473978a5ce84c1a..09d74b527db93693794ba4af904c87a94bbd0361 100644 (file)
@@ -69,15 +69,15 @@ public class BridgeConfigReconciliationTask extends ReconciliationTask {
 
     @Override
     public boolean reconcileConfiguration(final OvsdbConnectionManager connectionManagerOfDevice) {
+        CheckedFuture<Optional<Topology>, ReadFailedException> readTopologyFuture;
         InstanceIdentifier<Topology> topologyInstanceIdentifier = SouthboundMapper.createTopologyInstanceIdentifier();
-        ReadOnlyTransaction tx = reconciliationManager.getDb().newReadOnlyTransaction();
-
-        // find all bridges of the specific device in the config data store
-        // TODO: this query is not efficient. It retrieves all the Nodes in the datastore, loop over them and look for
-        // the bridges of specific device. It is mre efficient if MDSAL allows query nodes using wildcard on node id
-        // (ie: ovsdb://uuid/<device uuid>/bridge/*) r attributes
-        CheckedFuture<Optional<Topology>, ReadFailedException> readTopologyFuture =
-                tx.read(CONFIGURATION, topologyInstanceIdentifier);
+        try (ReadOnlyTransaction tx = reconciliationManager.getDb().newReadOnlyTransaction()) {
+            // find all bridges of the specific device in the config data store
+            // TODO: this query is not efficient. It retrieves all the Nodes in the datastore, loop over them and look
+            // for the bridges of specific device. It is mre efficient if MDSAL allows query nodes using wildcard on
+            // node id (ie: ovsdb://uuid/<device uuid>/bridge/*) r attributes
+            readTopologyFuture = tx.read(CONFIGURATION, topologyInstanceIdentifier);
+        }
         Futures.addCallback(readTopologyFuture, new FutureCallback<Optional<Topology>>() {
             @Override
             public void onSuccess(@Nullable Optional<Topology> optionalTopology) {