diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ZNodeClearer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ZNodeClearer.java index 698e3a7..52c4329 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ZNodeClearer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ZNodeClearer.java @@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -90,7 +91,7 @@ public class ZNodeClearer { public static String readMyEphemeralNodeOnDisk() throws IOException { String fileName = getMyEphemeralNodeFileName(); if (fileName == null){ - throw new IOException("No filename"); + throw new FileNotFoundException("No filename; set environment variable HBASE_ZNODE_FILE"); } FileReader znodeFile = new FileReader(fileName); BufferedReader br = new BufferedReader(znodeFile); @@ -141,9 +142,15 @@ public class ZNodeClearer { String znodeFileContent; try { znodeFileContent = ZNodeClearer.readMyEphemeralNodeOnDisk(); + } catch (FileNotFoundException fnfe) { + // If no file, just keep going -- return success. + LOG.warn("Can't find the znode file; presume non-fatal", fnfe); + return true; } catch (IOException e) { LOG.warn("Can't read the content of the znode file", e); return false; + } finally { + zkw.close(); } return MasterAddressTracker.deleteIfEquals(zkw, znodeFileContent); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterCommandLine.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterCommandLine.java new file mode 100644 index 0000000..95dc1c6 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterCommandLine.java @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.master; + +import static org.junit.Assert.*; + +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.junit.Test; + +public class TestHMasterCommandLine { + private static final HBaseTestingUtility TESTING_UTIL = new HBaseTestingUtility(); + @Test + public void testRun() throws Exception { + HMasterCommandLine masterCommandLine = new HMasterCommandLine(HMaster.class); + masterCommandLine.setConf(TESTING_UTIL.getConfiguration()); + assertEquals(0, masterCommandLine.run(new String [] {"clear"})); + } +} \ No newline at end of file