HBASE-9177 Cluster UUID is not properly parsable after rewriting to PB.

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1514161 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2013-08-15 05:34:41 +00:00
parent 7170a40dec
commit c8db00c87a
3 changed files with 47 additions and 3 deletions

View File

@ -43,7 +43,7 @@ public class ClusterId {
this(UUID.randomUUID().toString());
}
ClusterId(final String uuid) {
public ClusterId(final String uuid) {
this.id = uuid;
}

View File

@ -711,7 +711,19 @@ public abstract class FSUtils {
throw new IOException("content=" + Bytes.toString(content), e);
}
// If not pb'd, make it so.
if (!ProtobufUtil.isPBMagicPrefix(content)) rewriteAsPb(fs, rootdir, idPath, clusterId);
if (!ProtobufUtil.isPBMagicPrefix(content)) {
String cid = new String();
in = fs.open(idPath);
try {
cid = in.readUTF();
clusterId = new ClusterId(cid);
} catch (EOFException eof) {
LOG.warn("Cluster ID file " + idPath.toString() + " was empty");
} finally {
in.close();
}
rewriteAsPb(fs, rootdir, idPath, clusterId);
}
return clusterId;
} else {
LOG.warn("Cluster ID file does not exist at " + idPath.toString());
@ -1324,7 +1336,7 @@ public abstract class FSUtils {
/**
* Checks if the given path is the one with 'recovered.edits' dir.
* @param path
* @return
* @return True if we recovered edits
*/
public static boolean isRecoveredEdits(Path path) {
return path.toString().contains(HConstants.RECOVERED_EDITS_DIR);

View File

@ -21,11 +21,19 @@ package org.apache.hadoop.hbase.regionserver;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.UUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.MediumTests;
import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.util.FSUtils;
import org.apache.hadoop.hbase.util.JVMClusterUtil;
import org.apache.hadoop.hbase.zookeeper.ZKClusterId;
import org.junit.After;
@ -84,5 +92,29 @@ public class TestClusterId {
assertNotNull(clusterId);
assertEquals(clusterId, rst.getRegionServer().getClusterId());
}
@Test
public void testRewritingClusterIdToPB() throws Exception {
TEST_UTIL.startMiniZKCluster();
TEST_UTIL.startMiniDFSCluster(1);
TEST_UTIL.createRootDir();
TEST_UTIL.getConfiguration().setBoolean("hbase.replication", true);
Path rootDir = FSUtils.getRootDir(TEST_UTIL.getConfiguration());
FileSystem fs = rootDir.getFileSystem(TEST_UTIL.getConfiguration());
Path filePath = new Path(rootDir, HConstants.CLUSTER_ID_FILE_NAME);
FSDataOutputStream s = null;
try {
s = fs.create(filePath);
s.writeUTF(UUID.randomUUID().toString());
} finally {
if (s != null) {
s.close();
}
}
TEST_UTIL.startMiniHBaseCluster(1, 1);
HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
assertEquals(1, master.getServerManager().getOnlineServersList().size());
}
}