2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.raft.behaviors;
10 import akka.actor.ActorRef;
11 import org.eclipse.jdt.annotation.Nullable;
12 import org.opendaylight.controller.cluster.raft.RaftActorContext;
13 import org.opendaylight.controller.cluster.raft.RaftState;
14 import org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply;
17 * Leader which is termed as isolated.
20 * If the reply from the majority of the followers is not received then the leader changes its behavior
21 * to IsolatedLeader. An isolated leader may have followers and they would continue to receive replicated messages.
24 * A schedule is run, at an interval of (10 * Heartbeat-time-interval), in the Leader
25 * to check if its isolated or not.
28 * In the Isolated Leader , on every AppendEntriesReply, we aggressively check if the leader is isolated.
29 * If no, then the state is switched back to Leader.
31 public class IsolatedLeader extends AbstractLeader {
32 IsolatedLeader(RaftActorContext context, @Nullable AbstractLeader initializeFromLeader) {
33 super(context, RaftState.IsolatedLeader, initializeFromLeader);
36 public IsolatedLeader(RaftActorContext context) {
40 // we received an Append Entries reply, we should switch the Behavior to Leader
42 protected RaftActorBehavior handleAppendEntriesReply(ActorRef sender,
43 AppendEntriesReply appendEntriesReply) {
44 RaftActorBehavior ret = super.handleAppendEntriesReply(sender, appendEntriesReply);
46 // it can happen that this isolated leader interacts with a new leader in the cluster and
47 // changes its state to Follower, hence we only need to switch to Leader if the state is still Isolated
48 if (ret.state() == RaftState.IsolatedLeader && !isLeaderIsolated()) {
49 log.info("IsolatedLeader {} switching from IsolatedLeader to Leader", getLeaderId());
50 return internalSwitchBehavior(new Leader(context, this));