From 87551f3a44856d7494ffef678b63bb01a1b4ab2e Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 31 May 2017 19:49:52 +0200 Subject: [PATCH] BUG-8403: go through the DONE transition Third step of the fix: make make AbstractProxyTransaction go through the DONE state before retiring. This ends up also fixing breakage in local chain transactions, which could end up leaking because we never go back to just using the base data tree. Change-Id: I97ac1687eaf3ecd8f46a68c6170891ea06703e95 Signed-off-by: Robert Varga (cherry picked from commit 9b4c07ca27b2c3c7ca5d5e790aa1f121ce4857f3) --- .../actors/dds/AbstractProxyTransaction.java | 43 +++++++++++++++---- .../databroker/actors/dds/ProxyHistory.java | 12 +++++- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java index 549cab269f..ac91f2d041 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java @@ -119,11 +119,14 @@ abstract class AbstractProxyTransaction implements Identifiable> callback, final long enqueuedTicks) { - enqueueRequest(purgeRequest(), resp -> { - LOG.debug("Transaction {} purge completed", this); - parent.completeTransaction(this); + LOG.debug("{}: initiating purge", this); + + final State prev = state; + if (prev instanceof SuccessorState) { + ((SuccessorState) prev).setDone(); + } else { + final boolean success = STATE_UPDATER.compareAndSet(this, prev, DONE); + if (!success) { + LOG.warn("{}: moved from state {} while we were purging it", this, prev); + } + } + + successfulRequests.clear(); + + enqueueRequest(new TransactionPurgeRequest(getIdentifier(), nextSequence(), localActor()), resp -> { + LOG.debug("{}: purge completed", this); + parent.purgeTransaction(this); + if (callback != null) { callback.accept(resp); } }, enqueuedTicks); } - private TransactionPurgeRequest purgeRequest() { - successfulRequests.clear(); - return new TransactionPurgeRequest(getIdentifier(), nextSequence(), localActor()); - } - // Called with the connection unlocked final synchronized void startReconnect() { // At this point canCommit/directCommit are blocked, we assert a new successor state, retrieving the previous diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ProxyHistory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ProxyHistory.java index 4764f24d49..d66b748f5b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ProxyHistory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ProxyHistory.java @@ -384,7 +384,7 @@ abstract class ProxyHistory implements Identifiable { final void completeTransaction(final AbstractProxyTransaction tx) { lock.lock(); try { - proxies.remove(tx.getIdentifier()); + // Removal will be completed once purge completes LOG.debug("Proxy {} completing transaction {}", this, tx); onTransactionCompleted(tx); } finally { @@ -392,6 +392,16 @@ abstract class ProxyHistory implements Identifiable { } } + void purgeTransaction(final AbstractProxyTransaction tx) { + lock.lock(); + try { + proxies.remove(tx.getIdentifier()); + LOG.debug("Proxy {} purged transaction {}", this, tx); + } finally { + lock.unlock(); + } + } + final void close() { lock.lock(); try { -- 2.36.6