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%2FAbstractFrontendHistory.java;h=01fc35c395656896ba59e668134429875cc13508;hb=546cd1fd100dbaa36908b22c2f422320dbd8c4b2;hp=c1d2db309410dd831a31b3ec4845f02534749c9b;hpb=64bc1360aedb83583edb354444ee3e4295c7a5e6;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java index c1d2db3094..01fc35c395 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java @@ -7,8 +7,9 @@ */ package org.opendaylight.controller.cluster.datastore; +import static java.util.Objects.requireNonNull; + import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Range; import com.google.common.collect.RangeSet; @@ -16,7 +17,8 @@ import com.google.common.primitives.UnsignedLong; import java.util.HashMap; import java.util.Map; import java.util.Optional; -import javax.annotation.Nullable; +import java.util.SortedSet; +import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.controller.cluster.access.commands.AbstractReadTransactionRequest; import org.opendaylight.controller.cluster.access.commands.ClosedTransactionException; import org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest; @@ -59,10 +61,10 @@ abstract class AbstractFrontendHistory implements Identifiable closedTransactions, final RangeSet purgedTransactions) { - this.persistenceId = Preconditions.checkNotNull(persistenceId); - this.tree = Preconditions.checkNotNull(tree); - this.closedTransactions = Preconditions.checkNotNull(closedTransactions); - this.purgedTransactions = Preconditions.checkNotNull(purgedTransactions); + this.persistenceId = requireNonNull(persistenceId); + this.tree = requireNonNull(tree); + this.closedTransactions = requireNonNull(closedTransactions); + this.purgedTransactions = requireNonNull(purgedTransactions); } final String persistenceId() { @@ -75,51 +77,12 @@ abstract class AbstractFrontendHistory implements Identifiable handleTransactionRequest(final TransactionRequest request, final RequestEnvelope envelope, final long now) throws RequestException { - final TransactionIdentifier id = request.getTarget(); - final UnsignedLong ul = UnsignedLong.fromLongBits(id.getTransactionId()); - if (request instanceof TransactionPurgeRequest) { - if (purgedTransactions.contains(ul)) { - // Retransmitted purge request: nothing to do - LOG.debug("{}: transaction {} already purged", persistenceId, id); - return new TransactionPurgeResponse(id, request.getSequence()); - } - - // We perform two lookups instead of a straight remove, because once the map becomes empty we switch it - // to an ImmutableMap, which does not allow remove(). - if (closedTransactions.containsKey(ul)) { - tree.purgeTransaction(id, () -> { - closedTransactions.remove(ul); - if (closedTransactions.isEmpty()) { - closedTransactions = ImmutableMap.of(); - } - - purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul))); - LOG.debug("{}: finished purging inherited transaction {}", persistenceId(), id); - envelope.sendSuccess(new TransactionPurgeResponse(id, request.getSequence()), readTime() - now); - }); - return null; - } - - final FrontendTransaction tx = transactions.get(id); - if (tx == null) { - // This should never happen because the purge callback removes the transaction and puts it into - // purged transactions in one go. If it does, we warn about the situation and - LOG.warn("{}: transaction {} not tracked in {}, but not present in active transactions", persistenceId, - id, purgedTransactions); - purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul))); - return new TransactionPurgeResponse(id, request.getSequence()); - } - - tree.purgeTransaction(id, () -> { - purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul))); - transactions.remove(id); - LOG.debug("{}: finished purging transaction {}", persistenceId(), id); - envelope.sendSuccess(new TransactionPurgeResponse(id, request.getSequence()), readTime() - now); - }); - return null; + return handleTransactionPurgeRequest(request, envelope, now); } + final TransactionIdentifier id = request.getTarget(); + final UnsignedLong ul = UnsignedLong.fromLongBits(id.getTransactionId()); if (purgedTransactions.contains(ul)) { LOG.warn("{}: Request {} is contained purged transactions {}", persistenceId, request, purgedTransactions); throw new DeadTransactionException(purgedTransactions); @@ -154,6 +117,52 @@ abstract class AbstractFrontendHistory implements Identifiable handleTransactionPurgeRequest(final TransactionRequest request, + final RequestEnvelope envelope, final long now) { + final TransactionIdentifier id = request.getTarget(); + final UnsignedLong ul = UnsignedLong.fromLongBits(id.getTransactionId()); + if (purgedTransactions.contains(ul)) { + // Retransmitted purge request: nothing to do + LOG.debug("{}: transaction {} already purged", persistenceId, id); + return new TransactionPurgeResponse(id, request.getSequence()); + } + + // We perform two lookups instead of a straight remove, because once the map becomes empty we switch it + // to an ImmutableMap, which does not allow remove(). + if (closedTransactions.containsKey(ul)) { + tree.purgeTransaction(id, () -> { + closedTransactions.remove(ul); + if (closedTransactions.isEmpty()) { + closedTransactions = ImmutableMap.of(); + } + + purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul))); + LOG.debug("{}: finished purging inherited transaction {}", persistenceId(), id); + envelope.sendSuccess(new TransactionPurgeResponse(id, request.getSequence()), readTime() - now); + }); + return null; + } + + final FrontendTransaction tx = transactions.get(id); + if (tx == null) { + // This should never happen because the purge callback removes the transaction and puts it into + // purged transactions in one go. If it does, we warn about the situation and + LOG.warn("{}: transaction {} not tracked in {}, but not present in active transactions", persistenceId, + id, purgedTransactions); + purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul))); + return new TransactionPurgeResponse(id, request.getSequence()); + } + + tree.purgeTransaction(id, () -> { + purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul))); + transactions.remove(id); + LOG.debug("{}: finished purging transaction {}", persistenceId(), id); + envelope.sendSuccess(new TransactionPurgeResponse(id, request.getSequence()), readTime() - now); + }); + + return null; + } + final void destroy(final long sequence, final RequestEnvelope envelope, final long now) { LOG.debug("{}: closing history {}", persistenceId(), getIdentifier()); tree.closeTransactionChain(getIdentifier(), @@ -171,19 +180,17 @@ abstract class AbstractFrontendHistory implements Identifiable request, final TransactionIdentifier id) - throws RequestException { + private FrontendTransaction createTransaction(final TransactionRequest request, final TransactionIdentifier id) { if (request instanceof CommitLocalTransactionRequest) { LOG.debug("{}: allocating new ready transaction {}", persistenceId(), id); tree.getStats().incrementReadWriteTransactionCount(); return createReadyTransaction(id, ((CommitLocalTransactionRequest) request).getModification()); } - if (request instanceof AbstractReadTransactionRequest) { - if (((AbstractReadTransactionRequest) request).isSnapshotOnly()) { - LOG.debug("{}: allocating new open snapshot {}", persistenceId(), id); - tree.getStats().incrementReadOnlyTransactionCount(); - return createOpenSnapshot(id); - } + if (request instanceof AbstractReadTransactionRequest + && ((AbstractReadTransactionRequest) request).isSnapshotOnly()) { + LOG.debug("{}: allocating new open snapshot {}", persistenceId(), id); + tree.getStats().incrementReadOnlyTransactionCount(); + return createOpenSnapshot(id); } LOG.debug("{}: allocating new open transaction {}", persistenceId(), id); @@ -191,17 +198,18 @@ abstract class AbstractFrontendHistory implements Identifiable> participatingShardNames); @Override public String toString() {