X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fbroker%2Fimpl%2FPingPongTransactionChain.java;fp=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fbroker%2Fimpl%2FPingPongTransactionChain.java;h=9895ff9ad5e87af9901b7ffe03b4a2e82726b307;hb=6051cbabfe99c494b4f3b75aca516fb6f27338ad;hp=961b6c7b9312948ad862fa5236f7ab66ed834534;hpb=e3998d55e33da9f6ecb69da75ecc71a047b6362b;p=controller.git diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/PingPongTransactionChain.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/PingPongTransactionChain.java index 961b6c7b93..9895ff9ad5 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/PingPongTransactionChain.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/PingPongTransactionChain.java @@ -158,13 +158,16 @@ public final class PingPongTransactionChain implements DOMTransactionChain { /* * This forces allocateTransaction() on a slow path, which has to happen after - * this method has completed executing. + * this method has completed executing. Also inflightTx may be updated outside + * the lock, hence we need to re-check. */ @GuardedBy("this") private void processIfReady() { - final PingPongTransaction tx = READY_UPDATER.getAndSet(this, null); - if (tx != null) { - processTransaction(tx); + if (inflightTx == null) { + final PingPongTransaction tx = READY_UPDATER.getAndSet(this, null); + if (tx != null) { + processTransaction(tx); + } } } @@ -251,14 +254,27 @@ public final class PingPongTransactionChain implements DOMTransactionChain { } @Override - public void close() { + public synchronized void close() { final PingPongTransaction notLocked = lockedTx; Preconditions.checkState(notLocked == null, "Attempted to close chain with outstanding transaction %s", notLocked); - synchronized (this) { - processIfReady(); - delegate.close(); + // Force allocations on slow path. We will complete the rest + final PingPongTransaction tx = READY_UPDATER.getAndSet(this, null); + + // Make sure no transaction is outstanding. Otherwise sleep a bit and retry + while (inflightTx != null) { + LOG.debug("Busy-waiting for in-flight transaction {} to complete", inflightTx); + Thread.yield(); + continue; } + + // If we have an outstanding transaction, send it down + if (tx != null) { + processTransaction(tx); + } + + // All done, close the delegate. All new allocations should fail. + delegate.close(); } @Override