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%2FLeaderFrontendState.java;h=b37e2d8bf1603f70338e98543b6b5a93fc642d8a;hb=27b168d3ca3807123b4877f1ad0662b2610f393d;hp=ba2bdb3c7bfc87ba0dcc479ec754d7ff8dd7a751;hpb=a7aab5b8d7692d12928944a0d3da818571e324cc;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderFrontendState.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderFrontendState.java index ba2bdb3c7b..b37e2d8bf1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderFrontendState.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LeaderFrontendState.java @@ -10,6 +10,7 @@ package org.opendaylight.controller.cluster.datastore; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; @@ -28,6 +29,7 @@ import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifie import org.opendaylight.controller.cluster.access.concepts.RequestEnvelope; import org.opendaylight.controller.cluster.access.concepts.RequestException; import org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException; +import org.opendaylight.controller.cluster.datastore.ShardDataTreeCohort.State; import org.opendaylight.controller.cluster.datastore.utils.UnsignedLongRangeSet; import org.opendaylight.yangtools.concepts.Identifiable; import org.slf4j.Logger; @@ -55,6 +57,8 @@ final class LeaderFrontendState implements Identifiable { private final ClientIdentifier clientId; private final String persistenceId; + private long lastConnectTicks; + private long lastSeenTicks; private long expectedTxSequence; private Long lastSeenHistory = null; @@ -81,6 +85,7 @@ final class LeaderFrontendState implements Identifiable { this.purgedHistories = Preconditions.checkNotNull(purgedHistories); this.standaloneHistory = Preconditions.checkNotNull(standaloneHistory); this.localHistories = Preconditions.checkNotNull(localHistories); + this.lastSeenTicks = tree.readTime(); } @Override @@ -212,15 +217,49 @@ final class LeaderFrontendState implements Identifiable { void reconnect() { expectedTxSequence = 0; + lastConnectTicks = tree.readTime(); } void retire() { - // FIXME: flush all state + // Hunt down any transactions associated with this frontend + final Iterator it = tree.cohortIterator(); + while (it.hasNext()) { + final SimpleShardDataTreeCohort cohort = it.next(); + if (clientId.equals(cohort.getIdentifier().getHistoryId().getClientId())) { + if (cohort.getState() != State.COMMIT_PENDING) { + LOG.debug("{}: Retiring transaction {}", persistenceId, cohort.getIdentifier()); + it.remove(); + } else { + LOG.debug("{}: Transaction {} already committing, not retiring it", persistenceId, + cohort.getIdentifier()); + } + } + } + + // Clear out all transaction chains + localHistories.values().forEach(AbstractFrontendHistory::retire); + localHistories.clear(); + standaloneHistory.retire(); + } + + long getLastConnectTicks() { + return lastConnectTicks; + } + + long getLastSeenTicks() { + return lastSeenTicks; + } + + void touch() { + this.lastSeenTicks = tree.readTime(); } @Override public String toString() { - return MoreObjects.toStringHelper(LeaderFrontendState.class).add("clientId", clientId) - .add("purgedHistories", purgedHistories).toString(); + return MoreObjects.toStringHelper(LeaderFrontendState.class) + .add("clientId", clientId) + .add("nanosAgo", tree.readTime() - lastSeenTicks) + .add("purgedHistories", purgedHistories) + .toString(); } }