HDFS-2679. Add interface to query current state to HAServiceProtocol. Contributed by Eli Collins.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-1623@1220612 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Todd Lipcon 2011-12-19 05:24:32 +00:00
parent 45e81ae415
commit 329717264f
6 changed files with 34 additions and 11 deletions

View File

@ -63,3 +63,5 @@ HDFS-2602. NN should log newly-allocated blocks without losing BlockInfo (atm)
HDFS-2667. Fix transition from active to standby (todd)
HDFS-2684. Fix up some failing unit tests on HA branch (todd)
HDFS-2679. Add interface to query current state to HAServiceProtocol (eli via todd)

View File

@ -30,6 +30,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.HadoopIllegalArgumentException;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
import org.apache.hadoop.ha.HealthCheckFailedException;
import org.apache.hadoop.ha.ServiceFailedException;
import org.apache.hadoop.fs.CommonConfigurationKeys;
@ -908,7 +909,11 @@ public class NameNode {
}
state.setState(haContext, STANDBY_STATE);
}
synchronized HAServiceState getServiceState() {
return state.getServiceState();
}
/** Check if an operation of given category is allowed */
protected synchronized void checkOperation(final OperationCategory op)
throws StandbyException {

View File

@ -1061,7 +1061,12 @@ class NameNodeRpcServer implements NamenodeProtocols {
public synchronized void transitionToStandby() throws ServiceFailedException {
nn.transitionToStandby();
}
@Override // HAServiceProtocol
public synchronized HAServiceState getServiceState() {
return nn.getServiceState();
}
/**
* Verify version.
*

View File

@ -20,10 +20,10 @@ package org.apache.hadoop.hdfs.server.namenode.ha;
import java.io.IOException;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
import org.apache.hadoop.ha.ServiceFailedException;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.namenode.NameNode.OperationCategory;
import org.apache.hadoop.hdfs.server.namenode.UnsupportedActionException;
/**
* Active state of the namenode. In this state, namenode provides the namenode
@ -33,7 +33,7 @@ import org.apache.hadoop.hdfs.server.namenode.UnsupportedActionException;
@InterfaceAudience.Private
public class ActiveState extends HAState {
public ActiveState() {
super("active");
super(HAServiceState.ACTIVE);
}
@Override

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.hdfs.server.namenode.ha;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
import org.apache.hadoop.ha.ServiceFailedException;
import org.apache.hadoop.hdfs.server.namenode.NameNode.OperationCategory;
import org.apache.hadoop.hdfs.server.namenode.UnsupportedActionException;
@ -28,14 +29,21 @@ import org.apache.hadoop.ipc.StandbyException;
*/
@InterfaceAudience.Private
abstract public class HAState {
protected final String name;
protected final HAServiceState state;
/**
* Constructor
* @param name Name of the state.
*/
public HAState(String name) {
this.name = name;
public HAState(HAServiceState state) {
this.state = state;
}
/**
* @return the generic service state
*/
public HAServiceState getServiceState() {
return state;
}
/**
@ -92,9 +100,11 @@ abstract public class HAState {
*/
public abstract void checkOperation(final HAContext context, final OperationCategory op)
throws StandbyException;
@Override
/**
* @return String representation of the service state.
*/
public String toString() {
return super.toString();
return state.toString();
}
}

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.ha.ServiceFailedException;
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.namenode.NameNode.OperationCategory;
import org.apache.hadoop.ipc.StandbyException;
@ -39,7 +40,7 @@ import org.apache.hadoop.ipc.StandbyException;
@InterfaceAudience.Private
public class StandbyState extends HAState {
public StandbyState() {
super("standby");
super(HAServiceState.STANDBY);
}
@Override