X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FStandaloneFrontendHistory.java;h=df13cd1368243ac8c128bc2eccf9c5ba14617bca;hb=f70fb5eaee514ffa5963049ac12286c2dee4ff80;hp=fe2588d5772289419664126f69fe0726902fbfbc;hpb=5cb0787412ab63a3aa5dcc044511e1ce569662cf;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/StandaloneFrontendHistory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/StandaloneFrontendHistory.java index fe2588d577..df13cd1368 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/StandaloneFrontendHistory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/StandaloneFrontendHistory.java @@ -7,13 +7,20 @@ */ package org.opendaylight.controller.cluster.datastore; -import com.google.common.base.Preconditions; -import com.google.common.base.Ticker; +import static java.util.Objects.requireNonNull; + +import com.google.common.collect.ImmutableMap; +import com.google.common.primitives.UnsignedLong; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.SortedSet; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; -import org.opendaylight.controller.cluster.access.concepts.RequestException; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; +import org.opendaylight.controller.cluster.datastore.utils.MutableUnsignedLongSet; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification; /** * Standalone transaction specialization of {@link AbstractFrontendHistory}. There can be multiple open transactions @@ -22,14 +29,28 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification * @author Robert Varga */ final class StandaloneFrontendHistory extends AbstractFrontendHistory { - private final LocalHistoryIdentifier identifier; - private final ShardDataTree tree; + private final @NonNull LocalHistoryIdentifier identifier; + private final @NonNull ShardDataTree tree; + + private StandaloneFrontendHistory(final String persistenceId, final ClientIdentifier clientId, + final ShardDataTree tree, final Map closedTransactions, + final MutableUnsignedLongSet purgedTransactions) { + super(persistenceId, tree, closedTransactions, purgedTransactions); + identifier = new LocalHistoryIdentifier(clientId, 0); + this.tree = requireNonNull(tree); + } - StandaloneFrontendHistory(final String persistenceId, final Ticker ticker, final ClientIdentifier clientId, + static @NonNull StandaloneFrontendHistory create(final String persistenceId, final ClientIdentifier clientId, final ShardDataTree tree) { - super(persistenceId, ticker); - this.identifier = new LocalHistoryIdentifier(clientId, 0); - this.tree = Preconditions.checkNotNull(tree); + return new StandaloneFrontendHistory(persistenceId, clientId, tree, ImmutableMap.of(), + MutableUnsignedLongSet.of()); + } + + static @NonNull StandaloneFrontendHistory recreate(final String persistenceId, final ClientIdentifier clientId, + final ShardDataTree tree, final Map closedTransactions, + final MutableUnsignedLongSet purgedTransactions) { + return new StandaloneFrontendHistory(persistenceId, clientId, tree, new HashMap<>(closedTransactions), + purgedTransactions.mutableCopy()); } @Override @@ -38,23 +59,31 @@ final class StandaloneFrontendHistory extends AbstractFrontendHistory { } @Override - FrontendTransaction createOpenSnapshot(final TransactionIdentifier id) throws RequestException { - return FrontendReadOnlyTransaction.create(this, tree.newReadOnlyTransaction(id)); + FrontendTransaction createOpenSnapshot(final TransactionIdentifier id) { + return FrontendReadOnlyTransaction.create(this, + new ReadOnlyShardDataTreeTransaction(tree, id, tree.takeSnapshot())); } @Override - FrontendTransaction createOpenTransaction(final TransactionIdentifier id) throws RequestException { - return FrontendReadWriteTransaction.createOpen(this, tree.newReadWriteTransaction(id)); + FrontendTransaction createOpenTransaction(final TransactionIdentifier id) { + return FrontendReadWriteTransaction.createOpen(this, + new ReadWriteShardDataTreeTransaction(tree, id, tree.takeSnapshot().newModification())); } @Override - FrontendTransaction createReadyTransaction(final TransactionIdentifier id, final DataTreeModification mod) - throws RequestException { + FrontendTransaction createReadyTransaction(final TransactionIdentifier id, final DataTreeModification mod) { return FrontendReadWriteTransaction.createReady(this, id, mod); } @Override - ShardDataTreeCohort createReadyCohort(final TransactionIdentifier id, final DataTreeModification mod) { - return tree.createReadyCohort(id, mod); + ShardDataTreeCohort createFailedCohort(final TransactionIdentifier id, final DataTreeModification mod, + final Exception failure) { + return tree.createFailedCohort(id, mod, failure); + } + + @Override + ShardDataTreeCohort createReadyCohort(final TransactionIdentifier id, final DataTreeModification mod, + final Optional> participatingShardNames) { + return tree.createReadyCohort(id, mod, participatingShardNames); } }