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%2FLocalFrontendHistory.java;h=d7c30121bf8a9323a362814ee7449870900acb84;hp=8e32c76ba794679dc3cdd84004946f1b57087ade;hb=8f18717f60e58eebf726fe0611859311fa83df44;hpb=de64c6bbf2d5aeb51f4036f9dd606a9bf6f71afb diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalFrontendHistory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalFrontendHistory.java index 8e32c76ba7..d7c30121bf 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalFrontendHistory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalFrontendHistory.java @@ -8,15 +8,16 @@ package org.opendaylight.controller.cluster.datastore; import com.google.common.base.Preconditions; -import org.opendaylight.controller.cluster.access.commands.DeadTransactionException; -import org.opendaylight.controller.cluster.access.commands.LocalHistorySuccess; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.RangeSet; +import com.google.common.collect.TreeRangeSet; +import com.google.common.primitives.UnsignedLong; +import java.util.HashMap; +import java.util.Map; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; -import org.opendaylight.controller.cluster.access.concepts.RequestEnvelope; 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.slf4j.Logger; -import org.slf4j.LoggerFactory; /** @@ -25,18 +26,25 @@ import org.slf4j.LoggerFactory; * @author Robert Varga */ final class LocalFrontendHistory extends AbstractFrontendHistory { - private static final Logger LOG = LoggerFactory.getLogger(LocalFrontendHistory.class); - private final ShardDataTreeTransactionChain chain; - private final ShardDataTree tree; - private Long lastSeenTransaction; + private LocalFrontendHistory(final String persistenceId, final ShardDataTree tree, + final ShardDataTreeTransactionChain chain, final Map closedTransactions, + final RangeSet purgedTransactions) { + super(persistenceId, tree, closedTransactions, purgedTransactions); + this.chain = Preconditions.checkNotNull(chain); + } - LocalFrontendHistory(final String persistenceId, final ShardDataTree tree, + static LocalFrontendHistory create(final String persistenceId, final ShardDataTree tree, final ShardDataTreeTransactionChain chain) { - super(persistenceId, tree.ticker()); - this.tree = Preconditions.checkNotNull(tree); - this.chain = Preconditions.checkNotNull(chain); + return new LocalFrontendHistory(persistenceId, tree, chain, ImmutableMap.of(), TreeRangeSet.create()); + } + + static LocalFrontendHistory recreate(final String persistenceId, final ShardDataTree tree, + final ShardDataTreeTransactionChain chain, final Map closedTransactions, + final RangeSet purgedTransactions) { + return new LocalFrontendHistory(persistenceId, tree, chain, new HashMap<>(closedTransactions), + TreeRangeSet.create(purgedTransactions)); } @Override @@ -46,53 +54,28 @@ final class LocalFrontendHistory extends AbstractFrontendHistory { @Override FrontendTransaction createOpenSnapshot(final TransactionIdentifier id) throws RequestException { - checkDeadTransaction(id); - lastSeenTransaction = id.getTransactionId(); return FrontendReadOnlyTransaction.create(this, chain.newReadOnlyTransaction(id)); } @Override FrontendTransaction createOpenTransaction(final TransactionIdentifier id) throws RequestException { - checkDeadTransaction(id); - lastSeenTransaction = id.getTransactionId(); return FrontendReadWriteTransaction.createOpen(this, chain.newReadWriteTransaction(id)); } @Override FrontendTransaction createReadyTransaction(final TransactionIdentifier id, final DataTreeModification mod) throws RequestException { - checkDeadTransaction(id); - lastSeenTransaction = id.getTransactionId(); return FrontendReadWriteTransaction.createReady(this, id, mod); } @Override - ShardDataTreeCohort createReadyCohort(final TransactionIdentifier id, final DataTreeModification mod) { - return chain.createReadyCohort(id, mod); + ShardDataTreeCohort createFailedCohort(final TransactionIdentifier id, final DataTreeModification mod, + final Exception failure) { + return chain.createFailedCohort(id, mod, failure); } - void destroy(final long sequence, final RequestEnvelope envelope, final long now) - throws RequestException { - LOG.debug("{}: closing history {}", persistenceId(), getIdentifier()); - tree.closeTransactionChain(getIdentifier(), () -> { - envelope.sendSuccess(new LocalHistorySuccess(getIdentifier(), sequence), readTime() - now); - }); - } - - void purge(final long sequence, final RequestEnvelope envelope, final long now) { - LOG.debug("{}: purging history {}", persistenceId(), getIdentifier()); - tree.purgeTransactionChain(getIdentifier(), () -> { - envelope.sendSuccess(new LocalHistorySuccess(getIdentifier(), sequence), readTime() - now); - }); - } - - private void checkDeadTransaction(final TransactionIdentifier id) throws RequestException { - // FIXME: check if this history is still open - // FIXME: check if the last transaction has been submitted - - // Transaction identifiers within a local history have to have increasing IDs - if (lastSeenTransaction != null && Long.compareUnsigned(lastSeenTransaction, id.getTransactionId()) >= 0) { - throw new DeadTransactionException(lastSeenTransaction); - } + @Override + ShardDataTreeCohort createReadyCohort(final TransactionIdentifier id, final DataTreeModification mod) { + return chain.createReadyCohort(id, mod); } }