HDFS-3412. Fix findbugs warnings in auto-HA branch. Contributed by Todd Lipcon.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-3042@1338817 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4cd70e87be
commit
52ecdb751e
|
@ -290,5 +290,9 @@
|
||||||
<!-- protobuf generated code -->
|
<!-- protobuf generated code -->
|
||||||
<Class name="~org\.apache\.hadoop\.ha\.proto\.HAServiceProtocolProtos.*"/>
|
<Class name="~org\.apache\.hadoop\.ha\.proto\.HAServiceProtocolProtos.*"/>
|
||||||
</Match>
|
</Match>
|
||||||
|
<Match>
|
||||||
|
<!-- protobuf generated code -->
|
||||||
|
<Class name="~org\.apache\.hadoop\.ha\.proto\.ZKFCProtocolProtos.*"/>
|
||||||
|
</Match>
|
||||||
|
|
||||||
</FindBugsFilter>
|
</FindBugsFilter>
|
||||||
|
|
|
@ -44,7 +44,6 @@ import org.apache.hadoop.security.SecurityUtil;
|
||||||
import org.apache.hadoop.security.UserGroupInformation;
|
import org.apache.hadoop.security.UserGroupInformation;
|
||||||
import org.apache.hadoop.security.authorize.PolicyProvider;
|
import org.apache.hadoop.security.authorize.PolicyProvider;
|
||||||
import org.apache.hadoop.util.StringUtils;
|
import org.apache.hadoop.util.StringUtils;
|
||||||
import org.apache.hadoop.util.Tool;
|
|
||||||
import org.apache.zookeeper.KeeperException;
|
import org.apache.zookeeper.KeeperException;
|
||||||
import org.apache.zookeeper.ZooDefs.Ids;
|
import org.apache.zookeeper.ZooDefs.Ids;
|
||||||
import org.apache.hadoop.util.ToolRunner;
|
import org.apache.hadoop.util.ToolRunner;
|
||||||
|
@ -56,7 +55,7 @@ import com.google.common.base.Throwables;
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
|
|
||||||
@InterfaceAudience.LimitedPrivate("HDFS")
|
@InterfaceAudience.LimitedPrivate("HDFS")
|
||||||
public abstract class ZKFailoverController implements Tool {
|
public abstract class ZKFailoverController {
|
||||||
|
|
||||||
static final Log LOG = LogFactory.getLog(ZKFailoverController.class);
|
static final Log LOG = LogFactory.getLog(ZKFailoverController.class);
|
||||||
|
|
||||||
|
@ -93,15 +92,14 @@ public abstract class ZKFailoverController implements Tool {
|
||||||
/** Cannot connect to ZooKeeper */
|
/** Cannot connect to ZooKeeper */
|
||||||
static final int ERR_CODE_NO_ZK = 6;
|
static final int ERR_CODE_NO_ZK = 6;
|
||||||
|
|
||||||
private Configuration conf;
|
protected Configuration conf;
|
||||||
private String zkQuorum;
|
private String zkQuorum;
|
||||||
|
protected final HAServiceTarget localTarget;
|
||||||
|
|
||||||
private HealthMonitor healthMonitor;
|
private HealthMonitor healthMonitor;
|
||||||
private ActiveStandbyElector elector;
|
private ActiveStandbyElector elector;
|
||||||
protected ZKFCRpcServer rpcServer;
|
protected ZKFCRpcServer rpcServer;
|
||||||
|
|
||||||
private HAServiceTarget localTarget;
|
|
||||||
|
|
||||||
private State lastHealthState = State.INITIALIZING;
|
private State lastHealthState = State.INITIALIZING;
|
||||||
|
|
||||||
/** Set if a fatal error occurs */
|
/** Set if a fatal error occurs */
|
||||||
|
@ -123,15 +121,13 @@ public abstract class ZKFailoverController implements Tool {
|
||||||
private ActiveAttemptRecord lastActiveAttemptRecord;
|
private ActiveAttemptRecord lastActiveAttemptRecord;
|
||||||
private Object activeAttemptRecordLock = new Object();
|
private Object activeAttemptRecordLock = new Object();
|
||||||
|
|
||||||
@Override
|
protected ZKFailoverController(Configuration conf, HAServiceTarget localTarget) {
|
||||||
public void setConf(Configuration conf) {
|
this.localTarget = localTarget;
|
||||||
this.conf = conf;
|
this.conf = conf;
|
||||||
localTarget = getLocalTarget();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected abstract byte[] targetToData(HAServiceTarget target);
|
protected abstract byte[] targetToData(HAServiceTarget target);
|
||||||
protected abstract HAServiceTarget getLocalTarget();
|
|
||||||
protected abstract HAServiceTarget dataToTarget(byte[] data);
|
protected abstract HAServiceTarget dataToTarget(byte[] data);
|
||||||
protected abstract void loginAsFCUser() throws IOException;
|
protected abstract void loginAsFCUser() throws IOException;
|
||||||
protected abstract void checkRpcAdminAccess()
|
protected abstract void checkRpcAdminAccess()
|
||||||
|
@ -147,12 +143,10 @@ public abstract class ZKFailoverController implements Tool {
|
||||||
*/
|
*/
|
||||||
protected abstract String getScopeInsideParentNode();
|
protected abstract String getScopeInsideParentNode();
|
||||||
|
|
||||||
@Override
|
public HAServiceTarget getLocalTarget() {
|
||||||
public Configuration getConf() {
|
return localTarget;
|
||||||
return conf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int run(final String[] args) throws Exception {
|
public int run(final String[] args) throws Exception {
|
||||||
if (!localTarget.isAutoFailoverEnabled()) {
|
if (!localTarget.isAutoFailoverEnabled()) {
|
||||||
LOG.fatal("Automatic failover is not enabled for " + localTarget + "." +
|
LOG.fatal("Automatic failover is not enabled for " + localTarget + "." +
|
||||||
|
@ -792,10 +786,16 @@ public abstract class ZKFailoverController implements Tool {
|
||||||
* by the HealthMonitor.
|
* by the HealthMonitor.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
State getLastHealthState() {
|
synchronized State getLastHealthState() {
|
||||||
return lastHealthState;
|
return lastHealthState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized void setLastHealthState(HealthMonitor.State newState) {
|
||||||
|
LOG.info("Local service " + localTarget +
|
||||||
|
" entered state: " + newState);
|
||||||
|
lastHealthState = newState;
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
ActiveStandbyElector getElectorForTests() {
|
ActiveStandbyElector getElectorForTests() {
|
||||||
return elector;
|
return elector;
|
||||||
|
@ -836,7 +836,9 @@ public abstract class ZKFailoverController implements Tool {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Elector callbacks for " + localTarget;
|
synchronized (ZKFailoverController.this) {
|
||||||
|
return "Elector callbacks for " + localTarget;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -846,9 +848,7 @@ public abstract class ZKFailoverController implements Tool {
|
||||||
class HealthCallbacks implements HealthMonitor.Callback {
|
class HealthCallbacks implements HealthMonitor.Callback {
|
||||||
@Override
|
@Override
|
||||||
public void enteredState(HealthMonitor.State newState) {
|
public void enteredState(HealthMonitor.State newState) {
|
||||||
LOG.info("Local service " + localTarget +
|
setLastHealthState(newState);
|
||||||
" entered state: " + newState);
|
|
||||||
lastHealthState = newState;
|
|
||||||
recheckElectability();
|
recheckElectability();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,8 +253,7 @@ public class MiniZKFCCluster {
|
||||||
|
|
||||||
public DummyZKFCThread(TestContext ctx, DummyHAService svc) {
|
public DummyZKFCThread(TestContext ctx, DummyHAService svc) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
this.zkfc = new DummyZKFC(svc);
|
this.zkfc = new DummyZKFC(conf, svc);
|
||||||
zkfc.setConf(conf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -276,7 +275,8 @@ public class MiniZKFCCluster {
|
||||||
SCOPED_PARENT_ZNODE + "/" + ActiveStandbyElector.LOCK_FILENAME;
|
SCOPED_PARENT_ZNODE + "/" + ActiveStandbyElector.LOCK_FILENAME;
|
||||||
private final DummyHAService localTarget;
|
private final DummyHAService localTarget;
|
||||||
|
|
||||||
public DummyZKFC(DummyHAService localTarget) {
|
public DummyZKFC(Configuration conf, DummyHAService localTarget) {
|
||||||
|
super(conf, localTarget);
|
||||||
this.localTarget = localTarget;
|
this.localTarget = localTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,11 +291,6 @@ public class MiniZKFCCluster {
|
||||||
return DummyHAService.getInstance(index);
|
return DummyHAService.getInstance(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected HAServiceTarget getLocalTarget() {
|
|
||||||
return localTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void loginAsFCUser() throws IOException {
|
protected void loginAsFCUser() throws IOException {
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,13 +112,12 @@ public class TestZKFailoverController extends ClientBaseWithFixes {
|
||||||
public void testFormatOneClusterLeavesOtherClustersAlone() throws Exception {
|
public void testFormatOneClusterLeavesOtherClustersAlone() throws Exception {
|
||||||
DummyHAService svc = cluster.getService(1);
|
DummyHAService svc = cluster.getService(1);
|
||||||
|
|
||||||
DummyZKFC zkfcInOtherCluster = new DummyZKFC(cluster.getService(1)) {
|
DummyZKFC zkfcInOtherCluster = new DummyZKFC(conf, cluster.getService(1)) {
|
||||||
@Override
|
@Override
|
||||||
protected String getScopeInsideParentNode() {
|
protected String getScopeInsideParentNode() {
|
||||||
return "other-scope";
|
return "other-scope";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
zkfcInOtherCluster.setConf(conf);
|
|
||||||
|
|
||||||
// Run without formatting the base dir,
|
// Run without formatting the base dir,
|
||||||
// should barf
|
// should barf
|
||||||
|
@ -580,8 +579,7 @@ public class TestZKFailoverController extends ClientBaseWithFixes {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int runFC(DummyHAService target, String ... args) throws Exception {
|
private int runFC(DummyHAService target, String ... args) throws Exception {
|
||||||
DummyZKFC zkfc = new DummyZKFC(target);
|
DummyZKFC zkfc = new DummyZKFC(conf, target);
|
||||||
zkfc.setConf(conf);
|
|
||||||
return zkfc.run(args);
|
return zkfc.run(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,3 +13,5 @@ HDFS-3223. add zkfc to hadoop-daemon.sh script (todd)
|
||||||
HDFS-3261. TestHASafeMode fails on HDFS-3042 branch (todd)
|
HDFS-3261. TestHASafeMode fails on HDFS-3042 branch (todd)
|
||||||
|
|
||||||
HDFS-3159. Document NN auto-failover setup and configuration (todd)
|
HDFS-3159. Document NN auto-failover setup and configuration (todd)
|
||||||
|
|
||||||
|
HDFS-3412. Fix findbugs warnings in auto-HA branch (todd)
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.apache.hadoop.hdfs.DFSConfigKeys;
|
||||||
import org.apache.hadoop.hdfs.DFSUtil;
|
import org.apache.hadoop.hdfs.DFSUtil;
|
||||||
import org.apache.hadoop.hdfs.HAUtil;
|
import org.apache.hadoop.hdfs.HAUtil;
|
||||||
import org.apache.hadoop.hdfs.HDFSPolicyProvider;
|
import org.apache.hadoop.hdfs.HDFSPolicyProvider;
|
||||||
|
import org.apache.hadoop.hdfs.HdfsConfiguration;
|
||||||
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
||||||
import org.apache.hadoop.hdfs.server.namenode.ha.proto.HAZKInfoProtos.ActiveNodeInfo;
|
import org.apache.hadoop.hdfs.server.namenode.ha.proto.HAZKInfoProtos.ActiveNodeInfo;
|
||||||
import org.apache.hadoop.ipc.Server;
|
import org.apache.hadoop.ipc.Server;
|
||||||
|
@ -42,10 +43,9 @@ import org.apache.hadoop.security.SecurityUtil;
|
||||||
import org.apache.hadoop.security.UserGroupInformation;
|
import org.apache.hadoop.security.UserGroupInformation;
|
||||||
import org.apache.hadoop.security.authorize.AccessControlList;
|
import org.apache.hadoop.security.authorize.AccessControlList;
|
||||||
import org.apache.hadoop.security.authorize.PolicyProvider;
|
import org.apache.hadoop.security.authorize.PolicyProvider;
|
||||||
|
import org.apache.hadoop.util.GenericOptionsParser;
|
||||||
import org.apache.hadoop.util.StringUtils;
|
import org.apache.hadoop.util.StringUtils;
|
||||||
import org.apache.hadoop.util.ToolRunner;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
|
@ -53,9 +53,9 @@ public class DFSZKFailoverController extends ZKFailoverController {
|
||||||
|
|
||||||
private static final Log LOG =
|
private static final Log LOG =
|
||||||
LogFactory.getLog(DFSZKFailoverController.class);
|
LogFactory.getLog(DFSZKFailoverController.class);
|
||||||
private NNHAServiceTarget localTarget;
|
|
||||||
private Configuration localNNConf;
|
|
||||||
private AccessControlList adminAcl;
|
private AccessControlList adminAcl;
|
||||||
|
/* the same as superclass's localTarget, but with the more specfic NN type */
|
||||||
|
private final NNHAServiceTarget localNNTarget;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected HAServiceTarget dataToTarget(byte[] data) {
|
protected HAServiceTarget dataToTarget(byte[] data) {
|
||||||
|
@ -67,7 +67,7 @@ public class DFSZKFailoverController extends ZKFailoverController {
|
||||||
StringUtils.byteToHexString(data));
|
StringUtils.byteToHexString(data));
|
||||||
}
|
}
|
||||||
NNHAServiceTarget ret = new NNHAServiceTarget(
|
NNHAServiceTarget ret = new NNHAServiceTarget(
|
||||||
getConf(), proto.getNameserviceId(), proto.getNamenodeId());
|
conf, proto.getNameserviceId(), proto.getNamenodeId());
|
||||||
InetSocketAddress addressFromProtobuf = new InetSocketAddress(
|
InetSocketAddress addressFromProtobuf = new InetSocketAddress(
|
||||||
proto.getHostname(), proto.getPort());
|
proto.getHostname(), proto.getPort());
|
||||||
|
|
||||||
|
@ -89,15 +89,15 @@ public class DFSZKFailoverController extends ZKFailoverController {
|
||||||
.setHostname(addr.getHostName())
|
.setHostname(addr.getHostName())
|
||||||
.setPort(addr.getPort())
|
.setPort(addr.getPort())
|
||||||
.setZkfcPort(target.getZKFCAddress().getPort())
|
.setZkfcPort(target.getZKFCAddress().getPort())
|
||||||
.setNameserviceId(localTarget.getNameServiceId())
|
.setNameserviceId(localNNTarget.getNameServiceId())
|
||||||
.setNamenodeId(localTarget.getNameNodeId())
|
.setNamenodeId(localNNTarget.getNameNodeId())
|
||||||
.build()
|
.build()
|
||||||
.toByteArray();
|
.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected InetSocketAddress getRpcAddressToBindTo() {
|
protected InetSocketAddress getRpcAddressToBindTo() {
|
||||||
int zkfcPort = getZkfcPort(localNNConf);
|
int zkfcPort = getZkfcPort(conf);
|
||||||
return new InetSocketAddress(localTarget.getAddress().getAddress(),
|
return new InetSocketAddress(localTarget.getAddress().getAddress(),
|
||||||
zkfcPort);
|
zkfcPort);
|
||||||
}
|
}
|
||||||
|
@ -113,9 +113,8 @@ public class DFSZKFailoverController extends ZKFailoverController {
|
||||||
DFSConfigKeys.DFS_HA_ZKFC_PORT_DEFAULT);
|
DFSConfigKeys.DFS_HA_ZKFC_PORT_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static DFSZKFailoverController create(Configuration conf) {
|
||||||
public void setConf(Configuration conf) {
|
Configuration localNNConf = DFSHAAdmin.addSecurityConfiguration(conf);
|
||||||
localNNConf = DFSHAAdmin.addSecurityConfiguration(conf);
|
|
||||||
String nsId = DFSUtil.getNamenodeNameServiceId(conf);
|
String nsId = DFSUtil.getNamenodeNameServiceId(conf);
|
||||||
|
|
||||||
if (!HAUtil.isHAEnabled(localNNConf, nsId)) {
|
if (!HAUtil.isHAEnabled(localNNConf, nsId)) {
|
||||||
|
@ -126,47 +125,50 @@ public class DFSZKFailoverController extends ZKFailoverController {
|
||||||
NameNode.initializeGenericKeys(localNNConf, nsId, nnId);
|
NameNode.initializeGenericKeys(localNNConf, nsId, nnId);
|
||||||
DFSUtil.setGenericConf(localNNConf, nsId, nnId, ZKFC_CONF_KEYS);
|
DFSUtil.setGenericConf(localNNConf, nsId, nnId, ZKFC_CONF_KEYS);
|
||||||
|
|
||||||
localTarget = new NNHAServiceTarget(localNNConf, nsId, nnId);
|
NNHAServiceTarget localTarget = new NNHAServiceTarget(
|
||||||
|
localNNConf, nsId, nnId);
|
||||||
|
return new DFSZKFailoverController(localNNConf, localTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DFSZKFailoverController(Configuration conf,
|
||||||
|
NNHAServiceTarget localTarget) {
|
||||||
|
super(conf, localTarget);
|
||||||
|
this.localNNTarget = localTarget;
|
||||||
// Setup ACLs
|
// Setup ACLs
|
||||||
adminAcl = new AccessControlList(
|
adminAcl = new AccessControlList(
|
||||||
conf.get(DFSConfigKeys.DFS_ADMIN, " "));
|
conf.get(DFSConfigKeys.DFS_ADMIN, " "));
|
||||||
|
|
||||||
super.setConf(localNNConf);
|
|
||||||
LOG.info("Failover controller configured for NameNode " +
|
LOG.info("Failover controller configured for NameNode " +
|
||||||
nsId + "." + nnId);
|
localTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initRPC() throws IOException {
|
protected void initRPC() throws IOException {
|
||||||
super.initRPC();
|
super.initRPC();
|
||||||
localTarget.setZkfcPort(rpcServer.getAddress().getPort());
|
localNNTarget.setZkfcPort(rpcServer.getAddress().getPort());
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HAServiceTarget getLocalTarget() {
|
|
||||||
Preconditions.checkState(localTarget != null,
|
|
||||||
"setConf() should have already been called");
|
|
||||||
return localTarget;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loginAsFCUser() throws IOException {
|
public void loginAsFCUser() throws IOException {
|
||||||
InetSocketAddress socAddr = NameNode.getAddress(localNNConf);
|
InetSocketAddress socAddr = NameNode.getAddress(conf);
|
||||||
SecurityUtil.login(getConf(), DFS_NAMENODE_KEYTAB_FILE_KEY,
|
SecurityUtil.login(conf, DFS_NAMENODE_KEYTAB_FILE_KEY,
|
||||||
DFS_NAMENODE_USER_NAME_KEY, socAddr.getHostName());
|
DFS_NAMENODE_USER_NAME_KEY, socAddr.getHostName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getScopeInsideParentNode() {
|
protected String getScopeInsideParentNode() {
|
||||||
return localTarget.getNameServiceId();
|
return localNNTarget.getNameServiceId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[])
|
public static void main(String args[])
|
||||||
throws Exception {
|
throws Exception {
|
||||||
System.exit(ToolRunner.run(
|
|
||||||
new DFSZKFailoverController(), args));
|
GenericOptionsParser parser = new GenericOptionsParser(
|
||||||
|
new HdfsConfiguration(), args);
|
||||||
|
DFSZKFailoverController zkfc = DFSZKFailoverController.create(
|
||||||
|
parser.getConfiguration());
|
||||||
|
|
||||||
|
System.exit(zkfc.run(parser.getRemainingArgs()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -193,8 +193,8 @@ public class TestDFSZKFailoverController extends ClientBaseWithFixes {
|
||||||
|
|
||||||
public ZKFCThread(TestContext ctx, int idx) {
|
public ZKFCThread(TestContext ctx, int idx) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
this.zkfc = new DFSZKFailoverController();
|
this.zkfc = DFSZKFailoverController.create(
|
||||||
zkfc.setConf(cluster.getConfiguration(idx));
|
cluster.getConfiguration(idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue