* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.controller.cluster.raft;
import akka.actor.ActorRef;
import org.opendaylight.yangtools.concepts.Identifier;
-public interface ClientRequestTracker {
- /**
- * Returns the client actor that should be sent a response when consensus is achieved.
- *
- * @return the client actor
- */
- ActorRef getClientActor();
-
- /**
- * Returns the identifier of the object that is to be replicated. For example a transaction identifier in the case
- * of a transaction.
- *
- * @return the identifier
- */
- Identifier getIdentifier();
-
- /**
- * Returns the index of the log entry that is to be replicated.
- *
- * @return the index
- */
- long getIndex();
+/**
+ * Consensus forwarding tracker.
+ *
+ * @param clientActor the client actor that should be sent a response when consensus is achieved
+ * @param identifier the identifier of the object that is to be replicated. For example a transaction identifier in the
+ * case of a transaction
+ * @param logIndex the index of the log entry that is to be replicated
+ */
+public record ClientRequestTracker(long logIndex, ActorRef clientActor, Identifier identifier) {
}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.controller.cluster.raft;
-
-import akka.actor.ActorRef;
-import org.opendaylight.yangtools.concepts.Identifier;
-
-public class ClientRequestTrackerImpl implements ClientRequestTracker {
-
- private final ActorRef clientActor;
- private final Identifier identifier;
- private final long logIndex;
-
- public ClientRequestTrackerImpl(ActorRef clientActor, Identifier identifier, long logIndex) {
-
- this.clientActor = clientActor;
-
- this.identifier = identifier;
-
- this.logIndex = logIndex;
- }
-
- @Override
- public ActorRef getClientActor() {
- return clientActor;
- }
-
- @Override
- public long getIndex() {
- return logIndex;
- }
-
- @Override
- public Identifier getIdentifier() {
- return identifier;
- }
-}
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.opendaylight.controller.cluster.messaging.MessageSlicer;
import org.opendaylight.controller.cluster.messaging.SliceOptions;
import org.opendaylight.controller.cluster.raft.ClientRequestTracker;
-import org.opendaylight.controller.cluster.raft.ClientRequestTrackerImpl;
import org.opendaylight.controller.cluster.raft.FollowerLogInformation;
import org.opendaylight.controller.cluster.raft.PeerInfo;
import org.opendaylight.controller.cluster.raft.RaftActorContext;
import org.opendaylight.controller.cluster.raft.messages.IdentifiablePayload;
import org.opendaylight.controller.cluster.raft.messages.InstallSnapshot;
import org.opendaylight.controller.cluster.raft.messages.InstallSnapshotReply;
-import org.opendaylight.controller.cluster.raft.messages.Payload;
import org.opendaylight.controller.cluster.raft.messages.RaftRPC;
import org.opendaylight.controller.cluster.raft.messages.RequestVote;
import org.opendaylight.controller.cluster.raft.messages.RequestVoteReply;
* @return the ClientRequestTracker or null if none available
*/
private ClientRequestTracker removeClientRequestTracker(final long logIndex) {
- final Iterator<ClientRequestTracker> it = trackers.iterator();
+ final var it = trackers.iterator();
while (it.hasNext()) {
- final ClientRequestTracker t = it.next();
- if (t.getIndex() == logIndex) {
+ final var tracker = it.next();
+ if (tracker.logIndex() == logIndex) {
it.remove();
- return t;
+ return tracker;
}
}
-
return null;
}
// If it does that means the leader wasn't dropped before the transaction applied.
// That means that this transaction can be safely applied as a local transaction since we
// have the ClientRequestTracker.
- final ClientRequestTracker tracker = removeClientRequestTracker(entry.getIndex());
+ final var tracker = removeClientRequestTracker(entry.getIndex());
if (tracker != null) {
- return new ApplyState(tracker.getClientActor(), tracker.getIdentifier(), entry);
+ return new ApplyState(tracker.clientActor(), tracker.identifier(), entry);
}
// Tracker is missing, this means that we switched behaviours between replicate and applystate
// and became the leader again,. We still want to apply this as a local modification because
// we have resumed leadership with that log entry having been committed.
- final Payload payload = entry.getData();
- if (payload instanceof IdentifiablePayload<?> identifiable) {
+ if (entry.getData() instanceof IdentifiablePayload<?> identifiable) {
return new ApplyState(null, identifiable.getIdentifier(), entry);
}
// client actor
final var clientActor = replicate.clientActor();
if (clientActor != null) {
- trackers.add(new ClientRequestTrackerImpl(clientActor, replicate.identifier(), logIndex));
+ trackers.add(new ClientRequestTracker(logIndex, clientActor, replicate.identifier()));
}
boolean applyModificationToState = !context.anyVotingPeers()