Merge ClientRequestTracker 08/109508/6
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 31 Dec 2023 03:31:50 +0000 (04:31 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 31 Dec 2023 11:47:14 +0000 (12:47 +0100)
The split between interface and implementation is completely
unnecessary, this is just a simple DTO.

Change-Id: Ie10a68b003b6ef82f59fb298cd433c8b876afcc3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ClientRequestTracker.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ClientRequestTrackerImpl.java [deleted file]
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java

index 0f14844d5666e5ee6f73f3d7cb005b607c41b3a7..c69decdd14d8578dcba92d608ca55018a8b34b21 100644 (file)
@@ -5,33 +5,19 @@
  * 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) {
 
 }
diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ClientRequestTrackerImpl.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ClientRequestTrackerImpl.java
deleted file mode 100644 (file)
index 6ffb922..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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;
-    }
-}
index b4d30c28b43f47a39cba70c08fb5765722e6300f..e1a32ecef8e7a0e9697cdd11a98cabf9ea21ce70 100644 (file)
@@ -20,7 +20,6 @@ import java.io.ObjectOutputStream;
 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;
@@ -34,7 +33,6 @@ import org.opendaylight.controller.cluster.io.SharedFileBackedOutputStream;
 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;
@@ -52,7 +50,6 @@ import org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply;
 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;
@@ -450,15 +447,14 @@ public abstract class AbstractLeader extends AbstractRaftActorBehavior {
      * @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;
     }
 
@@ -468,16 +464,15 @@ public abstract class AbstractLeader extends AbstractRaftActorBehavior {
         // 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);
         }
 
@@ -656,7 +651,7 @@ public abstract class AbstractLeader extends AbstractRaftActorBehavior {
         // 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()