Fix PingPong transaction race in EffectiveRibWriter. 03/24603/3
authorDana Kutenicsova <dkutenic@cisco.com>
Wed, 29 Jul 2015 12:35:10 +0000 (14:35 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 4 Aug 2015 06:24:55 +0000 (06:24 +0000)
To avoid race conditions between transactions, create one only when
we need one.

Change-Id: I1052adb326db68aeaac700a0f0169bba3f0b8999
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java

index 0b1a8d92e38ddffe2e1f8e18c817b6a0e4f01a4c..dfaaeea77f7c61ed3f16703f627b688c0fc8c727 100644 (file)
@@ -184,7 +184,10 @@ final class EffectiveRibInWriter implements AutoCloseable {
         @Override
         public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
             LOG.trace("Data changed called to effective RIB. Change : {}", changes);
-            final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction();
+
+            // we have a lot of transactions created for 'nothing' because a lot of changes
+            // are skipped, so ensure we only create one transaction when we really need it
+            DOMDataWriteTransaction tx = null;
             for (final DataTreeCandidate tc : changes) {
                 final YangInstanceIdentifier rootPath = tc.getRootPath();
 
@@ -210,10 +213,15 @@ final class EffectiveRibInWriter implements AutoCloseable {
                     continue;
                 }
                 for (final DataTreeCandidateNode table : tables.getChildNodes()) {
+                    if (tx == null) {
+                        tx = this.chain.newWriteOnlyTransaction();
+                    }
                     changeDataTree(tx, rootPath, root, peerKey, table);
                 }
             }
-            tx.submit();
+            if (tx != null) {
+                tx.submit();
+            }
         }
 
         private void changeDataTree(final DOMDataWriteTransaction tx, final YangInstanceIdentifier rootPath,