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.opendaylight.controller.cluster.raft.RaftActorContext;
12 import org.opendaylight.controller.cluster.raft.RaftState;
13 import org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply;
16 * Leader which is termed as isolated.
18 * If the reply from the majority of the followers is not received then the leader changes its behavior
19 * to IsolatedLeader. An isolated leader may have followers and they would continue to receive replicated messages.
21 * A schedule is run, at an interval of (10 * Heartbeat-time-interval), in the Leader
22 * to check if its isolated or not.
24 * In the Isolated Leader , on every AppendEntriesReply, we aggressively check if the leader is isolated.
25 * If no, then the state is switched back to Leader.
28 public class IsolatedLeader extends AbstractLeader {
29 public IsolatedLeader(RaftActorContext context) {
33 // we received an Append Entries reply, we should switch the Behavior to Leader
35 protected RaftActorBehavior handleAppendEntriesReply(ActorRef sender,
36 AppendEntriesReply appendEntriesReply) {
37 RaftActorBehavior ret = super.handleAppendEntriesReply(sender, appendEntriesReply);
39 // it can happen that this isolated leader interacts with a new leader in the cluster and
40 // changes its state to Follower, hence we only need to switch to Leader if the state is still Isolated
41 if (ret.state() == RaftState.IsolatedLeader && !isLeaderIsolated()) {
42 LOG.info("IsolatedLeader {} switching from IsolatedLeader to Leader", leaderId);
43 return internalSwitchBehavior(RaftState.Leader);
49 public RaftState state() {
50 return RaftState.IsolatedLeader;