BUG-650: speedup DOMDataBrokerTransactionChainImpl 05/11105/3
authorRobert Varga <rovarga@cisco.com>
Fri, 12 Sep 2014 13:29:09 +0000 (15:29 +0200)
committerRobert Varga <rovarga@cisco.com>
Sat, 13 Sep 2014 00:49:59 +0000 (02:49 +0200)
The transaction chain implementation does not need to have
synchronization on submit, but rather it needs to check if the chain has
not been closed (implictly or explicitly). Same goes for the close path,
thus this patch speeds things up by downgrading the synchronized
sections to volatile reads and writes.

Change-Id: I57dec6dbfb1933005a9ee0718b666ee102ce7116
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMDataBrokerTransactionChainImpl.java

index d17b71e..7cd6afa 100644 (file)
@@ -11,7 +11,6 @@ import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.CheckedFuture;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicLong;
-import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
@@ -32,12 +31,12 @@ public class DOMDataBrokerTransactionChainImpl extends AbstractDOMForwardedTrans
         implements DOMTransactionChain, DOMDataCommitErrorListener {
 
     private static final Logger LOG = LoggerFactory.getLogger(DOMDataBrokerTransactionChainImpl.class);
+    private final AtomicLong txNum = new AtomicLong();
     private final DOMDataCommitExecutor coordinator;
     private final TransactionChainListener listener;
     private final long chainId;
-    private final AtomicLong txNum = new AtomicLong();
-    @GuardedBy("this")
-    private boolean failed = false;
+
+    private volatile boolean failed = false;
 
     /**
      *
@@ -69,26 +68,30 @@ public class DOMDataBrokerTransactionChainImpl extends AbstractDOMForwardedTrans
     }
 
     @Override
-    public synchronized CheckedFuture<Void,TransactionCommitFailedException> submit(
+    public CheckedFuture<Void,TransactionCommitFailedException> submit(
             final DOMDataWriteTransaction transaction, final Iterable<DOMStoreThreePhaseCommitCohort> cohorts) {
+        checkNotClosed();
+
         return coordinator.submit(transaction, cohorts, Optional.<DOMDataCommitErrorListener> of(this));
     }
 
     @Override
-    public synchronized void close() {
+    public void close() {
         super.close();
+
         for (DOMStoreTransactionChain subChain : getTxFactories().values()) {
             subChain.close();
         }
 
         if (!failed) {
             LOG.debug("Transaction chain {}¬†successfully finished.", this);
+            // FIXME: this event should be emitted once all operations complete
             listener.onTransactionChainSuccessful(this);
         }
     }
 
     @Override
-    public synchronized void onCommitFailed(final DOMDataWriteTransaction tx, final Throwable cause) {
+    public void onCommitFailed(final DOMDataWriteTransaction tx, final Throwable cause) {
         failed = true;
         LOG.debug("Transaction chain {}¬†failed.", this, cause);
         listener.onTransactionChainFailed(this, tx, cause);