HADOOP-8208. Disallow self failover. Contributed by Eli Collins

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1306935 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Eli Collins 2012-03-29 15:48:58 +00:00
parent f11a5dc5f6
commit 978404d1a8
3 changed files with 38 additions and 2 deletions

View File

@ -445,6 +445,8 @@ Release 0.23.2 - UNRELEASED
HADOOP-8088. User-group mapping cache incorrectly does negative caching on HADOOP-8088. User-group mapping cache incorrectly does negative caching on
transient failures (Khiwal Lee via bobby) transient failures (Khiwal Lee via bobby)
HADOOP-8208. Disallow self failover. (eli)
Release 0.23.1 - 2012-02-17 Release 0.23.1 - 2012-02-17
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -54,16 +54,23 @@ public class FailoverController {
* allow it to become active, eg because it triggers a log roll * allow it to become active, eg because it triggers a log roll
* so the standby can learn about new blocks and leave safemode. * so the standby can learn about new blocks and leave safemode.
* *
* @param from currently active service
* @param target service to make active * @param target service to make active
* @param forceActive ignore toSvc if it reports that it is not ready * @param forceActive ignore toSvc if it reports that it is not ready
* @throws FailoverFailedException if we should avoid failover * @throws FailoverFailedException if we should avoid failover
*/ */
private static void preFailoverChecks(HAServiceTarget target, private static void preFailoverChecks(HAServiceTarget from,
HAServiceTarget target,
boolean forceActive) boolean forceActive)
throws FailoverFailedException { throws FailoverFailedException {
HAServiceStatus toSvcStatus; HAServiceStatus toSvcStatus;
HAServiceProtocol toSvc; HAServiceProtocol toSvc;
if (from.getAddress().equals(target.getAddress())) {
throw new FailoverFailedException(
"Can't failover a service to itself");
}
try { try {
toSvc = target.getProxy(); toSvc = target.getProxy();
toSvcStatus = toSvc.getServiceStatus(); toSvcStatus = toSvc.getServiceStatus();
@ -146,7 +153,7 @@ public class FailoverController {
throws FailoverFailedException { throws FailoverFailedException {
Preconditions.checkArgument(fromSvc.getFencer() != null, Preconditions.checkArgument(fromSvc.getFencer() != null,
"failover requires a fencer"); "failover requires a fencer");
preFailoverChecks(toSvc, forceActive); preFailoverChecks(fromSvc, toSvc, forceActive);
// Try to make fromSvc standby // Try to make fromSvc standby
boolean tryFence = true; boolean tryFence = true;

View File

@ -377,4 +377,31 @@ public class TestFailoverController {
assertEquals(HAServiceState.STANDBY, svc1.state); assertEquals(HAServiceState.STANDBY, svc1.state);
assertEquals(HAServiceState.STANDBY, svc2.state); assertEquals(HAServiceState.STANDBY, svc2.state);
} }
@Test
public void testSelfFailoverFails() throws Exception {
DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr);
DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr);
svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName());
AlwaysSucceedFencer.fenceCalled = 0;
try {
FailoverController.failover(svc1, svc1, false, false);
fail("Can't failover to yourself");
} catch (FailoverFailedException ffe) {
// Expected
}
assertEquals(0, TestNodeFencer.AlwaysSucceedFencer.fenceCalled);
assertEquals(HAServiceState.ACTIVE, svc1.state);
try {
FailoverController.failover(svc2, svc2, false, false);
fail("Can't failover to yourself");
} catch (FailoverFailedException ffe) {
// Expected
}
assertEquals(0, TestNodeFencer.AlwaysSucceedFencer.fenceCalled);
assertEquals(HAServiceState.STANDBY, svc2.state);
}
} }