X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShardDataTreeTransactionChain.java;h=312e11290c88e713827fe2b051d96b667eb633da;hp=183c2192e405e2a48a52c664ef90033f5da38597;hb=823bd74f34ee1c651f1f90daeef386a35c68d431;hpb=f16ea6ce80e6c0a47eae0cc1cf9d404c57d7880d diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeTransactionChain.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeTransactionChain.java index 183c2192e4..312e11290c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeTransactionChain.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeTransactionChain.java @@ -10,6 +10,10 @@ package org.opendaylight.controller.cluster.datastore; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import javax.annotation.concurrent.NotThreadSafe; +import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; +import org.opendaylight.yangtools.concepts.Identifiable; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,18 +22,19 @@ import org.slf4j.LoggerFactory; * A transaction chain attached to a Shard. */ @NotThreadSafe -final class ShardDataTreeTransactionChain extends ShardDataTreeTransactionParent { +final class ShardDataTreeTransactionChain extends ShardDataTreeTransactionParent + implements Identifiable { private static final Logger LOG = LoggerFactory.getLogger(ShardDataTreeTransactionChain.class); + private final LocalHistoryIdentifier chainId; private final ShardDataTree dataTree; - private final String chainId; private ReadWriteShardDataTreeTransaction previousTx; private ReadWriteShardDataTreeTransaction openTransaction; private boolean closed; - ShardDataTreeTransactionChain(final String chainId, final ShardDataTree dataTree) { + ShardDataTreeTransactionChain(final LocalHistoryIdentifier localHistoryIdentifier, final ShardDataTree dataTree) { + this.chainId = Preconditions.checkNotNull(localHistoryIdentifier); this.dataTree = Preconditions.checkNotNull(dataTree); - this.chainId = Preconditions.checkNotNull(chainId); } private DataTreeSnapshot getSnapshot() { @@ -37,20 +42,22 @@ final class ShardDataTreeTransactionChain extends ShardDataTreeTransactionParent Preconditions.checkState(openTransaction == null, "Transaction %s is open", openTransaction); if (previousTx == null) { - return dataTree.getDataTree().takeSnapshot(); - } else { - return previousTx.getSnapshot(); + LOG.debug("Opening an unchained snapshot in {}", chainId); + return dataTree.takeSnapshot(); } + + LOG.debug("Reusing a chained snapshot in {}", chainId); + return previousTx.getSnapshot(); } - ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(final String txId) { + ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(final TransactionIdentifier txId) { final DataTreeSnapshot snapshot = getSnapshot(); LOG.debug("Allocated read-only transaction {} snapshot {}", txId, snapshot); return new ReadOnlyShardDataTreeTransaction(txId, snapshot); } - ReadWriteShardDataTreeTransaction newReadWriteTransaction(final String txId) { + ReadWriteShardDataTreeTransaction newReadWriteTransaction(final TransactionIdentifier txId) { final DataTreeSnapshot snapshot = getSnapshot(); LOG.debug("Allocated read-write transaction {} snapshot {}", txId, snapshot); @@ -65,7 +72,8 @@ final class ShardDataTreeTransactionChain extends ShardDataTreeTransactionParent @Override protected void abortTransaction(final AbstractShardDataTreeTransaction transaction) { if (transaction instanceof ReadWriteShardDataTreeTransaction) { - Preconditions.checkState(openTransaction != null, "Attempted to abort transaction %s while none is outstanding", transaction); + Preconditions.checkState(openTransaction != null, + "Attempted to abort transaction %s while none is outstanding", transaction); LOG.debug("Aborted transaction {}", transaction); openTransaction = null; } @@ -73,7 +81,8 @@ final class ShardDataTreeTransactionChain extends ShardDataTreeTransactionParent @Override protected ShardDataTreeCohort finishTransaction(final ReadWriteShardDataTreeTransaction transaction) { - Preconditions.checkState(openTransaction != null, "Attempted to finish transaction %s while none is outstanding", transaction); + Preconditions.checkState(openTransaction != null, + "Attempted to finish transaction %s while none is outstanding", transaction); // dataTree is finalizing ready the transaction, we just record it for the next // transaction in chain @@ -90,9 +99,19 @@ final class ShardDataTreeTransactionChain extends ShardDataTreeTransactionParent return MoreObjects.toStringHelper(this).add("id", chainId).toString(); } - void clearTransaction(ReadWriteShardDataTreeTransaction transaction) { + void clearTransaction(final ReadWriteShardDataTreeTransaction transaction) { if (transaction.equals(previousTx)) { previousTx = null; } } + + @Override + public LocalHistoryIdentifier getIdentifier() { + return chainId; + } + + @Override + ShardDataTreeCohort createReadyCohort(final TransactionIdentifier txId, final DataTreeModification modification) { + return dataTree.createReadyCohort(txId, modification); + } }