From 53fe636c7e44c4dcd98ec7d4c3dc23553a9144f4 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 31 Dec 2023 04:31:50 +0100 Subject: [PATCH] Merge ClientRequestTracker The split between interface and implementation is completely unnecessary, this is just a simple DTO. Change-Id: Ie10a68b003b6ef82f59fb298cd433c8b876afcc3 Signed-off-by: Robert Varga --- .../cluster/raft/ClientRequestTracker.java | 32 ++++---------- .../raft/ClientRequestTrackerImpl.java | 43 ------------------- .../raft/behaviors/AbstractLeader.java | 21 ++++----- 3 files changed, 17 insertions(+), 79 deletions(-) delete mode 100644 opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ClientRequestTrackerImpl.java diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ClientRequestTracker.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ClientRequestTracker.java index 0f14844d56..c69decdd14 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ClientRequestTracker.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ClientRequestTracker.java @@ -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 index 6ffb9228dc..0000000000 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/ClientRequestTrackerImpl.java +++ /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; - } -} diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java index b4d30c28b4..e1a32ecef8 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java @@ -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 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() -- 2.36.6