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;
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;
private final ClientIdentifier clientId;
private final String persistenceId;
+ private long lastConnectTicks;
+ private long lastSeenTicks;
private long expectedTxSequence;
private Long lastSeenHistory = null;
this.purgedHistories = Preconditions.checkNotNull(purgedHistories);
this.standaloneHistory = Preconditions.checkNotNull(standaloneHistory);
this.localHistories = Preconditions.checkNotNull(localHistories);
+ this.lastSeenTicks = tree.readTime();
}
@Override
void reconnect() {
expectedTxSequence = 0;
+ lastConnectTicks = tree.readTime();
}
void retire() {
- // FIXME: flush all state
+ // Hunt down any transactions associated with this frontend
+ final Iterator<SimpleShardDataTreeCohort> 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();
}
}