+++ /dev/null
-/*
- * 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.base.messages;
-
-/**
- * Message sent by the IsolatedLeaderCheck scheduler in the Leader to itself
- * in order to check if its isolated.
- */
-public class IsolatedLeaderCheck {
-}
import org.opendaylight.controller.cluster.raft.RaftActorLeadershipTransferCohort;
import org.opendaylight.controller.cluster.raft.RaftState;
import org.opendaylight.controller.cluster.raft.base.messages.ElectionTimeout;
-import org.opendaylight.controller.cluster.raft.base.messages.IsolatedLeaderCheck;
import org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply;
/**
* set commitIndex = N (§5.3, §5.4).
*/
public class Leader extends AbstractLeader {
- private static final IsolatedLeaderCheck ISOLATED_LEADER_CHECK = new IsolatedLeaderCheck();
+ /**
+ * Internal message sent to periodically check if this leader has become isolated and should transition
+ * to {@link IsolatedLeader}.
+ */
+ @VisibleForTesting
+ static final Object ISOLATED_LEADER_CHECK = new Object();
+
private final Stopwatch isolatedLeaderCheck;
private @Nullable LeadershipTransferContext leadershipTransferContext;
@Override public RaftActorBehavior handleMessage(ActorRef sender, Object originalMessage) {
Preconditions.checkNotNull(sender, "sender should not be null");
- if (originalMessage instanceof IsolatedLeaderCheck) {
+ if (ISOLATED_LEADER_CHECK.equals(originalMessage)) {
if (isLeaderIsolated()) {
LOG.warn("{}: At least {} followers need to be active, Switching {} from Leader to IsolatedLeader",
context.getId(), getMinIsolatedLeaderPeerCount(), leaderId);
import org.opendaylight.controller.cluster.raft.base.messages.ApplyState;
import org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshot;
import org.opendaylight.controller.cluster.raft.base.messages.ElectionTimeout;
-import org.opendaylight.controller.cluster.raft.base.messages.IsolatedLeaderCheck;
import org.opendaylight.controller.cluster.raft.base.messages.Replicate;
import org.opendaylight.controller.cluster.raft.base.messages.SendHeartBeat;
import org.opendaylight.controller.cluster.raft.base.messages.SendInstallSnapshot;
MockRaftActorContext leaderActorContext = createActorContext();
leader = new Leader(leaderActorContext);
- RaftActorBehavior behavior = leader.handleMessage(leaderActor, new IsolatedLeaderCheck());
+ RaftActorBehavior behavior = leader.handleMessage(leaderActor, Leader.ISOLATED_LEADER_CHECK);
Assert.assertTrue(behavior instanceof Leader);
}
leader.markFollowerActive("follower-1");
leader.markFollowerActive("follower-2");
- RaftActorBehavior behavior = leader.handleMessage(leaderActor, new IsolatedLeaderCheck());
+ RaftActorBehavior behavior = leader.handleMessage(leaderActor, Leader.ISOLATED_LEADER_CHECK);
Assert.assertTrue("Behavior not instance of Leader when all followers are active",
behavior instanceof Leader);
leader.markFollowerInActive("follower-1");
leader.markFollowerActive("follower-2");
- behavior = leader.handleMessage(leaderActor, new IsolatedLeaderCheck());
+ behavior = leader.handleMessage(leaderActor, Leader.ISOLATED_LEADER_CHECK);
Assert.assertTrue("Behavior not instance of Leader when majority of followers are active",
behavior instanceof Leader);
assertEquals(termMsg2.getActor(), followerActor2);
leader.markFollowerInActive("follower-2");
- return leader.handleMessage(leaderActor, new IsolatedLeaderCheck());
+ return leader.handleMessage(leaderActor, Leader.ISOLATED_LEADER_CHECK);
}
@Test