From 4d7d88d74ee1177774fad5bd31ceaec2cee3056c Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 20 Apr 2017 16:37:02 +0200 Subject: [PATCH] BUG-8159: fix local transaction history tracking ShardCommitCoordinator needs to make sure ShardDataTree tracks the histories involved with local transaction being submitted via ReadyLocalTransaction. This is consistent with what we are doing for the BatchedModifications message. Change-Id: I02cc61476b5e02fb45f1482c4a9693bc77335793 Signed-off-by: Robert Varga (cherry picked from commit 5f0f7152dedbed437bdfb055e9bc80c0a1edaa15) --- .../datastore/ShardCommitCoordinator.java | 6 ++--- .../cluster/datastore/ShardDataTree.java | 25 +++++++++++++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardCommitCoordinator.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardCommitCoordinator.java index 691a4da66c..bf5d271bfc 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardCommitCoordinator.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardCommitCoordinator.java @@ -186,13 +186,13 @@ final class ShardCommitCoordinator { * @param shard the transaction's shard actor */ void handleReadyLocalTransaction(final ReadyLocalTransaction message, final ActorRef sender, final Shard shard) { - final ShardDataTreeCohort cohort = dataTree.createReadyCohort(message.getTransactionId(), - message.getModification()); + final TransactionIdentifier txId = message.getTransactionId(); + final ShardDataTreeCohort cohort = dataTree.newReadyCohort(txId, message.getModification()); final CohortEntry cohortEntry = CohortEntry.createReady(cohort, DataStoreVersions.CURRENT_VERSION); cohortCache.put(cohortEntry.getTransactionId(), cohortEntry); cohortEntry.setDoImmediateCommit(message.isDoCommitOnReady()); - log.debug("{}: Applying local modifications for Tx {}", name, message.getTransactionId()); + log.debug("{}: Applying local modifications for Tx {}", name, txId); if (message.isDoCommitOnReady()) { cohortEntry.setReplySender(sender); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java index f7d98276ca..1460982bf3 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java @@ -594,10 +594,10 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { replicatePayload(id, PurgeLocalHistoryPayload.create(id), callback); } - void registerDataChangeListener(YangInstanceIdentifier path, - AsyncDataChangeListener> listener, DataChangeScope scope, - Optional initialState, - Consumer>>> + void registerDataChangeListener(final YangInstanceIdentifier path, + final AsyncDataChangeListener> listener, + final DataChangeScope scope, final Optional initialState, + final Consumer>>> onRegistration) { dataChangeListenerPublisher.registerDataChangeListener(path, listener, scope, initialState, onRegistration); } @@ -609,9 +609,9 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { YangInstanceIdentifier.EMPTY, currentState.get())) : Optional.absent(); } - public void registerTreeChangeListener(YangInstanceIdentifier path, DOMDataTreeChangeListener listener, - Optional initialState, - Consumer> onRegistration) { + public void registerTreeChangeListener(final YangInstanceIdentifier path, final DOMDataTreeChangeListener listener, + final Optional initialState, + final Consumer> onRegistration) { treeChangeListenerPublisher.registerTreeChangeListener(path, listener, initialState, onRegistration); } @@ -923,7 +923,6 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { cohortRegistry.process(sender, message); } - @Override ShardDataTreeCohort createFailedCohort(final TransactionIdentifier txId, final DataTreeModification mod, final Exception failure) { @@ -941,6 +940,16 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { return cohort; } + // Exposed for ShardCommitCoordinator so it does not have deal with local histories (it does not care), this mimics + // the newReadWriteTransaction() + ShardDataTreeCohort newReadyCohort(final TransactionIdentifier txId, final DataTreeModification mod) { + if (txId.getHistoryId().getHistoryId() == 0) { + return createReadyCohort(txId, mod); + } + + return ensureTransactionChain(txId.getHistoryId()).createReadyCohort(txId, mod); + } + @SuppressFBWarnings(value = "DB_DUPLICATE_SWITCH_CLAUSES", justification = "See inline comments below.") void checkForExpiredTransactions(final long transactionCommitTimeoutMillis) { final long timeout = TimeUnit.MILLISECONDS.toNanos(transactionCommitTimeoutMillis); -- 2.36.6