X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FRaftActorServerConfigurationSupport.java;h=db9088ebae7b78477f8a11ede661a49748dcf8d4;hb=224aa4f574c63576961dc9dc37e075e2e5096a5a;hp=f969e3d67d46b53920e2b41b5fa3078fe5efd5f1;hpb=388dd012c7b36177808ff5c5ad692b16dd58c944;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupport.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupport.java index f969e3d67d..db9088ebae 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupport.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupport.java @@ -11,7 +11,7 @@ import akka.actor.ActorRef; import akka.actor.ActorSelection; import akka.actor.Cancellable; import com.google.common.base.Preconditions; -import java.util.LinkedList; +import java.util.ArrayDeque; import java.util.Queue; import java.util.UUID; import javax.annotation.Nullable; @@ -43,7 +43,7 @@ class RaftActorServerConfigurationSupport { private final RaftActorContext raftContext; - private final Queue> pendingOperationsQueue = new LinkedList<>(); + private final Queue> pendingOperationsQueue = new ArrayDeque<>(); private OperationState currentOperationState = IDLE; @@ -77,15 +77,17 @@ class RaftActorServerConfigurationSupport { private void onRemoveServer(RemoveServer removeServer, ActorRef sender) { LOG.debug("{}: onRemoveServer: {}, state: {}", raftContext.getId(), removeServer, currentOperationState); - if(removeServer.getServerId().equals(raftActor.getLeaderId())){ - // Removing current leader is not supported yet - // TODO: To properly support current leader removal we need to first implement transfer of leadership - LOG.debug("Cannot remove {} replica because it is the Leader", removeServer.getServerId()); - sender.tell(new RemoveServerReply(ServerChangeStatus.NOT_SUPPORTED, raftActor.getLeaderId()), raftActor.getSelf()); - } else if(!raftContext.getPeerIds().contains(removeServer.getServerId())) { - sender.tell(new RemoveServerReply(ServerChangeStatus.DOES_NOT_EXIST, raftActor.getLeaderId()), raftActor.getSelf()); + boolean isSelf = removeServer.getServerId().equals(raftActor.getId()); + if(isSelf && !raftContext.hasFollowers()) { + sender.tell(new RemoveServerReply(ServerChangeStatus.NOT_SUPPORTED, raftActor.getLeaderId()), + raftActor.getSelf()); + } else if(!isSelf && !raftContext.getPeerIds().contains(removeServer.getServerId())) { + sender.tell(new RemoveServerReply(ServerChangeStatus.DOES_NOT_EXIST, raftActor.getLeaderId()), + raftActor.getSelf()); } else { - onNewOperation(new RemoveServerContext(removeServer, raftContext.getPeerAddress(removeServer.getServerId()), sender)); + String serverAddress = isSelf ? raftActor.self().path().toString() : + raftContext.getPeerAddress(removeServer.getServerId()); + onNewOperation(new RemoveServerContext(removeServer, serverAddress, sender)); } } @@ -199,7 +201,9 @@ class RaftActorServerConfigurationSupport { protected void persistNewServerConfiguration(ServerOperationContext operationContext){ raftContext.setDynamicServerConfigurationInUse(); - ServerConfigurationPayload payload = raftContext.getPeerServerInfo(); + + boolean includeSelf = !operationContext.getServerId().equals(raftActor.getId()); + ServerConfigurationPayload payload = raftContext.getPeerServerInfo(includeSelf); LOG.debug("{}: New server configuration : {}", raftContext.getId(), payload.getServerConfig()); raftActor.persistData(operationContext.getClientRequestor(), operationContext.getContextId(), payload); @@ -570,7 +574,10 @@ class RaftActorServerConfigurationSupport { @Override public void initiate() { - raftContext.removePeer(getRemoveServerContext().getOperation().getServerId()); + String serverId = getRemoveServerContext().getOperation().getServerId(); + raftContext.removePeer(serverId); + ((AbstractLeader)raftActor.getCurrentBehavior()).removeFollower(serverId); + persistNewServerConfiguration(getRemoveServerContext()); } }