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=1b7014bab4524e9915daa682b89f850cbead3c6c;hp=bff21337de19efd081f7a6e4eb2c4b8ed14a10a9;hpb=fbc5ebe015150e6bc2750b194a8f5c47142b3afa;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 bff21337de..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 @@ -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()); } }