HBASE-9563 Autorestart doesn't work if zkcleaner fails

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1530498 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2013-10-09 05:53:06 +00:00
parent 102dfd9037
commit 419ef531eb
2 changed files with 41 additions and 1 deletions

View File

@ -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);

View File

@ -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"}));
}
}