From 8495a5a6ae32536dcbfdefdbbe15b313864eafb9 Mon Sep 17 00:00:00 2001 From: Alex Newman Date: Tue, 13 Dec 2011 11:32:46 -0800 Subject: [PATCH 2/3] Moved to a uuid tablename --- .../java/org/apache/hadoop/hbase/HRegionInfo.java | 12 ++- .../apache/hadoop/hbase/catalog/MetaReader.java | 3 +- .../apache/hadoop/hbase/client/MetaSearchRow.java | 36 ++++--- .../java/org/apache/hadoop/hbase/util/Merge.java | 4 +- .../org/apache/hadoop/hbase/client/TestAdmin.java | 18 ++-- .../hbase/coprocessor/SampleRegionWALObserver.java | 2 +- .../hadoop/hbase/coprocessor/TestClassLoading.java | 108 +++++++++++--------- .../hadoop/hbase/coprocessor/TestWALObserver.java | 14 +-- .../hadoop/hbase/regionserver/TestHRegionInfo.java | 6 +- .../hadoop/hbase/rest/TestStatusResource.java | 17 +++- src/test/ruby/hbase/admin_test.rb | 4 +- 11 files changed, 130 insertions(+), 94 deletions(-) diff --git src/main/java/org/apache/hadoop/hbase/HRegionInfo.java src/main/java/org/apache/hadoop/hbase/HRegionInfo.java index 3710b5a..52d3e7f 100644 --- src/main/java/org/apache/hadoop/hbase/HRegionInfo.java +++ src/main/java/org/apache/hadoop/hbase/HRegionInfo.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; import java.util.Arrays; +import java.util.UUID; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -343,12 +344,13 @@ implements WritableComparable { boolean newFormat){ byte [] oneByte = new byte[1]; - int allocation = tableName == null ? 2 : tableName.length + 2; + byte[] uuidTableName = UUID.nameUUIDFromBytes(tableName).toString().getBytes(); + int allocation = uuidTableName == null ? 2 : uuidTableName.length + 2; allocation += endKey == null ? 1 : endKey.length + 1; allocation += id == null ? 0 : id.length; ByteBuffer byteArrayDataOutput = MappedByteBuffer.allocate(allocation); - byteArrayDataOutput.put(tableName); + byteArrayDataOutput.put(uuidTableName); if ( endKey == null || endKey.length <= 0 ) { oneByte[0] = END_OF_TABLE_NAME_FOR_EMPTY_ENDKEY; @@ -386,7 +388,7 @@ implements WritableComparable { // // Encoded name should be built into the region name. // - // Use the region name thus far (namely, ,,) + // Use the region name thus far (namely, ,,) // to compute a MD5 hash to be used as the encoded name, and append // it to the byte buffer. // @@ -412,7 +414,7 @@ implements WritableComparable { * @param regionName * @return Table name. */ - public static byte [] getTableName(byte[] regionName) { + public static byte [] getTableNameUUID(byte[] regionName) { int offset = -1; for (int i = 0; i < regionName.length; i++) { if (regionName[i] == DELIMITER) { @@ -445,7 +447,7 @@ implements WritableComparable { /** * Separate elements of a regionName. * @param regionName - * @return Array of byte[] containing tableName, endKey and id + * @return Array of byte[] containing tableNameUUID, endKey and id * @throws IOException */ public static byte [][] parseRegionName(final byte [] regionName) diff --git src/main/java/org/apache/hadoop/hbase/catalog/MetaReader.java src/main/java/org/apache/hadoop/hbase/catalog/MetaReader.java index 705a743..4a8471a 100644 --- src/main/java/org/apache/hadoop/hbase/catalog/MetaReader.java +++ src/main/java/org/apache/hadoop/hbase/catalog/MetaReader.java @@ -51,7 +51,8 @@ public class MetaReader { static final byte [] META_REGION_PREFIX; static { // Copy the prefix from FIRST_META_REGIONINFO into META_REGION_PREFIX. - // FIRST_META_REGIONINFO == '.META.,,1'. META_REGION_PREFIX == '.META.,' + // FIRST_META_REGIONINFO == '.UUIDoF(META)\002.,,1'. + // META_REGION_PREFIX == 'UUIDoF(.META.),' int len = HRegionInfo.FIRST_META_REGIONINFO.getRegionName().length - 2; META_REGION_PREFIX = new byte [len]; System.arraycopy(HRegionInfo.FIRST_META_REGIONINFO.getRegionName(), 0, diff --git src/main/java/org/apache/hadoop/hbase/client/MetaSearchRow.java src/main/java/org/apache/hadoop/hbase/client/MetaSearchRow.java index e096d0c..17983a2 100644 --- src/main/java/org/apache/hadoop/hbase/client/MetaSearchRow.java +++ src/main/java/org/apache/hadoop/hbase/client/MetaSearchRow.java @@ -24,15 +24,18 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; +import java.util.UUID; + public class MetaSearchRow { static final Log LOG = LogFactory.getLog(MetaSearchRow.class); - public static byte[] getStopRow(final byte[] tableName){ - byte [] b = new byte [tableName.length + 3 + HConstants.NINES.getBytes().length ]; + public static byte[] getStopRow(final byte[] tableName) { + final byte[] uuidTableName = UUID.nameUUIDFromBytes(tableName).toString().getBytes(); + byte[] b = new byte[uuidTableName.length + 3 + HConstants.NINES.getBytes().length]; + int offset = uuidTableName.length; + System.arraycopy(uuidTableName, 0, b, 0, offset); - int offset = tableName.length; - System.arraycopy(tableName, 0, b, 0, offset); b[offset++] = (byte) (HRegionInfo.END_OF_TABLE_NAME_FOR_EMPTY_ENDKEY + 1); b[offset++] = HRegionInfo.DELIMITER; b[offset++] = HRegionInfo.DELIMITER; @@ -42,21 +45,24 @@ public class MetaSearchRow { public static byte[] getStartRow(final byte[] tableName, final byte[] searchRow) { // Get first region in META + final byte[] uuidTableName = UUID.nameUUIDFromBytes(tableName).toString().getBytes(); + + if (searchRow == null || searchRow.length == 0) { + byte[] startRow = new byte[uuidTableName.length + 3 + HConstants.ZEROES.getBytes().length]; + System.arraycopy(uuidTableName, 0, startRow, 0, uuidTableName.length); + startRow[uuidTableName.length] = HRegionInfo.END_OF_TABLE_NAME - 1; + startRow[uuidTableName.length + 1] = HRegionInfo.DELIMITER; + startRow[uuidTableName.length + 2] = HRegionInfo.DELIMITER; + System.arraycopy(HConstants.ZEROES.getBytes(), 0, startRow, uuidTableName.length + 3, HConstants.ZEROES.getBytes().length); - if (searchRow == null || searchRow.length == 0){ - byte[] startRow = new byte[tableName.length + 3 + HConstants.ZEROES.getBytes().length]; - System.arraycopy(tableName, 0, startRow, 0, tableName.length); - startRow[tableName.length] = HRegionInfo.END_OF_TABLE_NAME - 1 ; - startRow[tableName.length+1] = HRegionInfo.DELIMITER; - startRow[tableName.length+2] = HRegionInfo.DELIMITER; - System.arraycopy(HConstants.ZEROES.getBytes(), 0, startRow, tableName.length + 3, HConstants.ZEROES.getBytes().length); return startRow; } + //Create tablename will handle uuiding our tablename return HRegionInfo.createRegionName(tableName, - null, - searchRow, - HConstants.NINES.getBytes(), - false); + null, + searchRow, + HConstants.NINES.getBytes(), + false); } } diff --git src/main/java/org/apache/hadoop/hbase/util/Merge.java src/main/java/org/apache/hadoop/hbase/util/Merge.java index 67d0fda..00eb21e 100644 --- src/main/java/org/apache/hadoop/hbase/util/Merge.java +++ src/main/java/org/apache/hadoop/hbase/util/Merge.java @@ -45,6 +45,7 @@ import org.apache.hadoop.util.ToolRunner; import java.io.IOException; import java.util.List; +import java.util.UUID; /** * Utility that can merge any two regions in the same table: adjacent, @@ -364,7 +365,8 @@ public class Merge extends Configured implements Tool { } private boolean notInTable(final byte [] tn, final byte [] rn) { - if (WritableComparator.compareBytes(tn, 0, tn.length, rn, 0, tn.length) != 0) { + byte[] uuidTableName = UUID.nameUUIDFromBytes(tn).toString().getBytes(); + if (WritableComparator.compareBytes(uuidTableName, 0, uuidTableName.length, rn, 0, uuidTableName.length) != 0) { LOG.error("Region " + Bytes.toStringBinary(rn) + " does not belong to table " + Bytes.toString(tn)); return true; diff --git src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java index 81e109e..c3b9350 100644 --- src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java +++ src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java @@ -1165,12 +1165,13 @@ public class TestAdmin { public void testCloseRegionIfInvalidRegionNameIsPassed() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion1"); createTableWithDefaultConf(TABLENAME); + String encodedTableName = UUID.nameUUIDFromBytes(TABLENAME).toString(); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); List onlineRegions = rs.getOnlineRegions(); for (HRegionInfo regionInfo : onlineRegions) { if (!regionInfo.isMetaTable()) { - if (regionInfo.getRegionNameAsString().contains("TestHBACloseRegion1")) { + if (regionInfo.getRegionNameAsString().contains(encodedTableName)) { info = regionInfo; admin.closeRegionWithEncodedRegionName("sample", rs.getServerName() .getServerName()); @@ -1186,13 +1187,14 @@ public class TestAdmin { public void testCloseRegionThatFetchesTheHRIFromMeta() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion2"); createTableWithDefaultConf(TABLENAME); + String encodedTableName = UUID.nameUUIDFromBytes(TABLENAME).toString(); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); List onlineRegions = rs.getOnlineRegions(); for (HRegionInfo regionInfo : onlineRegions) { if (!regionInfo.isMetaTable()) { - if (regionInfo.getRegionNameAsString().contains("TestHBACloseRegion2")) { + if (regionInfo.getRegionNameAsString().contains(encodedTableName)) { info = regionInfo; admin.closeRegion(regionInfo.getRegionName(), rs .getServerName().getServerName()); @@ -1215,8 +1217,7 @@ public class TestAdmin { public void testCloseRegionWhenServerNameIsNull() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion3"); createTableWithDefaultConf(TABLENAME); - HBaseAdmin admin = createTable(TABLENAME); - + String encodedTableName = UUID.nameUUIDFromBytes(TABLENAME).toString(); HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); try { @@ -1224,7 +1225,7 @@ public class TestAdmin { for (HRegionInfo regionInfo : onlineRegions) { if (!regionInfo.isMetaTable()) { if (regionInfo.getRegionNameAsString() - .contains("TestHBACloseRegion3")) { + .contains(encodedTableName)) { admin.closeRegionWithEncodedRegionName(regionInfo.getEncodedName(), null); } @@ -1240,7 +1241,7 @@ public class TestAdmin { public void testCloseRegionWhenServerNameIsEmpty() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegionWhenServerNameIsEmpty"); createTableWithDefaultConf(TABLENAME); - + String encodedTableName = UUID.nameUUIDFromBytes(TABLENAME).toString(); HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); try { @@ -1248,7 +1249,7 @@ public class TestAdmin { for (HRegionInfo regionInfo : onlineRegions) { if (!regionInfo.isMetaTable()) { if (regionInfo.getRegionNameAsString() - .contains("TestHBACloseRegionWhenServerNameIsEmpty")) { + .contains(encodedTableName)) { admin.closeRegionWithEncodedRegionName(regionInfo.getEncodedName(), " "); } @@ -1263,6 +1264,7 @@ public class TestAdmin { public void testCloseRegionWhenEncodedRegionNameIsNotGiven() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion4"); createTableWithDefaultConf(TABLENAME); + String encodedTableName = UUID.nameUUIDFromBytes(TABLENAME).toString(); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); @@ -1270,7 +1272,7 @@ public class TestAdmin { List onlineRegions = rs.getOnlineRegions(); for (HRegionInfo regionInfo : onlineRegions) { if (!regionInfo.isMetaTable()) { - if (regionInfo.getRegionNameAsString().contains("TestHBACloseRegion4")) { + if (regionInfo.getRegionNameAsString().contains(encodedTableName)) { info = regionInfo; admin.closeRegionWithEncodedRegionName(regionInfo .getRegionNameAsString(), rs.getServerName().getServerName()); diff --git src/test/java/org/apache/hadoop/hbase/coprocessor/SampleRegionWALObserver.java src/test/java/org/apache/hadoop/hbase/coprocessor/SampleRegionWALObserver.java index ff9c502..20f8915 100644 --- src/test/java/org/apache/hadoop/hbase/coprocessor/SampleRegionWALObserver.java +++ src/test/java/org/apache/hadoop/hbase/coprocessor/SampleRegionWALObserver.java @@ -87,7 +87,7 @@ implements WALObserver { HRegionInfo info, HLogKey logKey, WALEdit logEdit) throws IOException { boolean bypass = false; // check table name matches or not. - if (!Arrays.equals(HRegionInfo.getTableName(info.getRegionName()), this.tableName)) { + if (!Arrays.equals(info.getTableName(), this.tableName)) { return bypass; } preWALWriteCalled = true; diff --git src/test/java/org/apache/hadoop/hbase/coprocessor/TestClassLoading.java src/test/java/org/apache/hadoop/hbase/coprocessor/TestClassLoading.java index 368a0e5..4bc66c0 100644 --- src/test/java/org/apache/hadoop/hbase/coprocessor/TestClassLoading.java +++ src/test/java/org/apache/hadoop/hbase/coprocessor/TestClassLoading.java @@ -55,12 +55,24 @@ public class TestClassLoading { private static MiniDFSCluster cluster; static final int BUFFER_SIZE = 4096; - static final String tableName = "TestClassLoading"; - static final String cpName1 = "TestCP1"; - static final String cpName2 = "TestCP2"; - static final String cpName3 = "TestCP3"; - static final String cpName4 = "TestCP4"; - static final String cpName5 = "TestCP5"; + static final String TABLE_NAME = "TestClassLoading"; + static final String UUID_TABLE_NAME = UUID.nameUUIDFromBytes(TABLE_NAME.getBytes()).toString(); + + static final String CP_NAME_1 = "TestCP1"; + static final String UUID_CP_NAME_1 = UUID.nameUUIDFromBytes(CP_NAME_1.getBytes()).toString(); + + static final String CP_NAME_2 = "TestCP2"; + static final String UUID_CP_NAME_2 = UUID.nameUUIDFromBytes(CP_NAME_2.getBytes()).toString(); + + static final String CP_NAME_3 = "TestCP3"; + static final String UUID_CP_NAME_3 = UUID.nameUUIDFromBytes(CP_NAME_3.getBytes()).toString(); + + static final String CP_NAME_4 = "TestCP4"; + static final String UUID_CP_NAME_4 = UUID.nameUUIDFromBytes(CP_NAME_4.getBytes()).toString(); + + static final String CP_NAME_5 = "TestCP5"; + static final String UUID_CP_NAME_5 = UUID.nameUUIDFromBytes(CP_NAME_5.getBytes()).toString(); + private static Class regionCoprocessor1 = ColumnAggregationEndpoint.class; private static Class regionCoprocessor2 = GenericEndpoint.class; @@ -200,8 +212,8 @@ public class TestClassLoading { public void testClassLoadingFromHDFS() throws Exception { FileSystem fs = cluster.getFileSystem(); - File jarFile1 = buildCoprocessorJar(cpName1); - File jarFile2 = buildCoprocessorJar(cpName2); + File jarFile1 = buildCoprocessorJar(CP_NAME_1); + File jarFile2 = buildCoprocessorJar(CP_NAME_2); // copy the jars into dfs fs.copyFromLocalFile(new Path(jarFile1.getPath()), @@ -221,18 +233,18 @@ public class TestClassLoading { LOG.info("Copied jar file to HDFS: " + jarFileOnHDFS2); // create a table that references the coprocessors - HTableDescriptor htd = new HTableDescriptor(tableName); + HTableDescriptor htd = new HTableDescriptor(TABLE_NAME); htd.addFamily(new HColumnDescriptor("test")); // without configuration values - htd.setValue("COPROCESSOR$1", jarFileOnHDFS1.toString() + "|" + cpName1 + + htd.setValue("COPROCESSOR$1", jarFileOnHDFS1.toString() + "|" + CP_NAME_1 + "|" + Coprocessor.PRIORITY_USER); // with configuration values - htd.setValue("COPROCESSOR$2", jarFileOnHDFS2.toString() + "|" + cpName2 + + htd.setValue("COPROCESSOR$2", jarFileOnHDFS2.toString() + "|" + CP_NAME_2 + "|" + Coprocessor.PRIORITY_USER + "|k1=v1,k2=v2,k3=v3"); HBaseAdmin admin = new HBaseAdmin(this.conf); - if (admin.tableExists(tableName)) { - admin.disableTable(tableName); - admin.deleteTable(tableName); + if (admin.tableExists(TABLE_NAME)) { + admin.disableTable(TABLE_NAME); + admin.deleteTable(TABLE_NAME); } admin.createTable(htd); @@ -242,13 +254,13 @@ public class TestClassLoading { MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster(); for (HRegion region: hbase.getRegionServer(0).getOnlineRegionsLocalContext()) { - if (region.getRegionNameAsString().startsWith(tableName)) { + if (region.getRegionNameAsString().startsWith(UUID_TABLE_NAME)) { CoprocessorEnvironment env; - env = region.getCoprocessorHost().findCoprocessorEnvironment(cpName1); + env = region.getCoprocessorHost().findCoprocessorEnvironment(CP_NAME_1); if (env != null) { found1 = true; } - env = region.getCoprocessorHost().findCoprocessorEnvironment(cpName2); + env = region.getCoprocessorHost().findCoprocessorEnvironment(CP_NAME_2); if (env != null) { found2 = true; Configuration conf = env.getConfiguration(); @@ -258,8 +270,8 @@ public class TestClassLoading { } } } - assertTrue("Class " + cpName1 + " was missing on a region", found1); - assertTrue("Class " + cpName2 + " was missing on a region", found2); + assertTrue("Class " + CP_NAME_1 + " was missing on a region", found1); + assertTrue("Class " + CP_NAME_2 + " was missing on a region", found2); assertTrue("Configuration key 'k1' was missing on a region", found2_k1); assertTrue("Configuration key 'k2' was missing on a region", found2_k2); assertTrue("Configuration key 'k3' was missing on a region", found2_k3); @@ -268,12 +280,12 @@ public class TestClassLoading { @Test // HBASE-3516: Test CP Class loading from local file system public void testClassLoadingFromLocalFS() throws Exception { - File jarFile = buildCoprocessorJar(cpName3); + File jarFile = buildCoprocessorJar(CP_NAME_3); // create a table that references the jar - HTableDescriptor htd = new HTableDescriptor(cpName3); + HTableDescriptor htd = new HTableDescriptor(CP_NAME_3); htd.addFamily(new HColumnDescriptor("test")); - htd.setValue("COPROCESSOR$1", jarFile.toString() + "|" + cpName3 + "|" + + htd.setValue("COPROCESSOR$1", jarFile.toString() + "|" + CP_NAME_3 + "|" + Coprocessor.PRIORITY_USER); HBaseAdmin admin = new HBaseAdmin(this.conf); admin.createTable(htd); @@ -283,11 +295,11 @@ public class TestClassLoading { MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster(); for (HRegion region: hbase.getRegionServer(0).getOnlineRegionsLocalContext()) { - if (region.getRegionNameAsString().startsWith(cpName3)) { - found = (region.getCoprocessorHost().findCoprocessor(cpName3) != null); + if (region.getRegionNameAsString().startsWith(UUID_CP_NAME_3)) { + found = (region.getCoprocessorHost().findCoprocessor(CP_NAME_3) != null); } } - assertTrue("Class " + cpName3 + " was missing on a region", found); + assertTrue("Class " + CP_NAME_3 + " was missing on a region", found); } @Test @@ -296,24 +308,24 @@ public class TestClassLoading { public void testHBase3810() throws Exception { // allowed value pattern: [path] | class name | [priority] | [key values] - File jarFile1 = buildCoprocessorJar(cpName1); - File jarFile2 = buildCoprocessorJar(cpName2); - File jarFile4 = buildCoprocessorJar(cpName4); - File jarFile5 = buildCoprocessorJar(cpName5); + File jarFile1 = buildCoprocessorJar(CP_NAME_1); + File jarFile2 = buildCoprocessorJar(CP_NAME_2); + File jarFile4 = buildCoprocessorJar(CP_NAME_4); + File jarFile5 = buildCoprocessorJar(CP_NAME_5); String cpKey1 = "COPROCESSOR$1"; String cpKey2 = " Coprocessor$2 "; String cpKey3 = " coprocessor$03 "; - String cpValue1 = jarFile1.toString() + "|" + cpName1 + "|" + + String cpValue1 = jarFile1.toString() + "|" + CP_NAME_1 + "|" + Coprocessor.PRIORITY_USER; - String cpValue2 = jarFile2.toString() + " | " + cpName2 + " | "; + String cpValue2 = jarFile2.toString() + " | " + CP_NAME_2 + " | "; // load from default class loader String cpValue3 = " | org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver | | k=v "; // create a table that references the jar - HTableDescriptor htd = new HTableDescriptor(tableName); + HTableDescriptor htd = new HTableDescriptor(TABLE_NAME); htd.addFamily(new HColumnDescriptor("test")); // add 3 coprocessors by setting htd attributes directly. @@ -322,19 +334,19 @@ public class TestClassLoading { htd.setValue(cpKey3, cpValue3); // add 2 coprocessor by using new htd.addCoprocessor() api - htd.addCoprocessor(cpName4, new Path(jarFile4.getPath()), + htd.addCoprocessor(CP_NAME_4, new Path(jarFile4.getPath()), Coprocessor.PRIORITY_USER, null); Map kvs = new HashMap(); kvs.put("k1", "v1"); kvs.put("k2", "v2"); kvs.put("k3", "v3"); - htd.addCoprocessor(cpName5, new Path(jarFile5.getPath()), + htd.addCoprocessor(CP_NAME_5, new Path(jarFile5.getPath()), Coprocessor.PRIORITY_USER, kvs); HBaseAdmin admin = new HBaseAdmin(this.conf); - if (admin.tableExists(tableName)) { - admin.disableTable(tableName); - admin.deleteTable(tableName); + if (admin.tableExists(TABLE_NAME)) { + admin.disableTable(TABLE_NAME); + admin.deleteTable(TABLE_NAME); } admin.createTable(htd); @@ -347,19 +359,19 @@ public class TestClassLoading { MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster(); for (HRegion region: hbase.getRegionServer(0).getOnlineRegionsLocalContext()) { - if (region.getRegionNameAsString().startsWith(tableName)) { + if (region.getRegionNameAsString().startsWith(UUID_TABLE_NAME)) { found_1 = found_1 || - (region.getCoprocessorHost().findCoprocessor(cpName1) != null); + (region.getCoprocessorHost().findCoprocessor(CP_NAME_1) != null); found_2 = found_2 || - (region.getCoprocessorHost().findCoprocessor(cpName2) != null); + (region.getCoprocessorHost().findCoprocessor(CP_NAME_2) != null); found_3 = found_3 || (region.getCoprocessorHost().findCoprocessor("SimpleRegionObserver") != null); found_4 = found_4 || - (region.getCoprocessorHost().findCoprocessor(cpName4) != null); + (region.getCoprocessorHost().findCoprocessor(CP_NAME_4) != null); CoprocessorEnvironment env = - region.getCoprocessorHost().findCoprocessorEnvironment(cpName5); + region.getCoprocessorHost().findCoprocessorEnvironment(CP_NAME_5); if (env != null) { found_5 = true; Configuration conf = env.getConfiguration(); @@ -370,11 +382,11 @@ public class TestClassLoading { } } - assertTrue("Class " + cpName1 + " was missing on a region", found_1); - assertTrue("Class " + cpName2 + " was missing on a region", found_2); + assertTrue("Class " + CP_NAME_1 + " was missing on a region", found_1); + assertTrue("Class " + CP_NAME_2 + " was missing on a region", found_2); assertTrue("Class SimpleRegionObserver was missing on a region", found_3); - assertTrue("Class " + cpName4 + " was missing on a region", found_4); - assertTrue("Class " + cpName5 + " was missing on a region", found_5); + assertTrue("Class " + CP_NAME_4 + " was missing on a region", found_4); + assertTrue("Class " + CP_NAME_5 + " was missing on a region", found_5); assertTrue("Configuration key 'k1' was missing on a region", found5_k1); assertTrue("Configuration key 'k2' was missing on a region", found5_k2); @@ -477,7 +489,7 @@ public class TestClassLoading { for(Map.Entry region: server.getValue().getRegionsLoad().entrySet()) { if (region.getValue().getNameAsString().equals(tableName)) { - // this server server hosts a region of tableName: add this server.. + // this server server hosts a region of TABLE_NAME: add this server.. serverLoadHashMap.put(server.getKey(),server.getValue()); // .. and skip the rest of the regions that it hosts. break; @@ -494,7 +506,7 @@ public class TestClassLoading { boolean success = false; for(int i = 0; i < 5; i++) { if (tableName == null) { - //if no tableName specified, use all servers. + //if no TABLE_NAMEME specified, use all servers. servers = TEST_UTIL.getMiniHBaseCluster().getMaster().getServerManager(). getOnlineServers(); diff --git src/test/java/org/apache/hadoop/hbase/coprocessor/TestWALObserver.java src/test/java/org/apache/hadoop/hbase/coprocessor/TestWALObserver.java index 36dd289..55a280d 100644 --- src/test/java/org/apache/hadoop/hbase/coprocessor/TestWALObserver.java +++ src/test/java/org/apache/hadoop/hbase/coprocessor/TestWALObserver.java @@ -136,8 +136,6 @@ public class TestWALObserver { HRegionInfo hri = createBasic3FamilyHRegionInfo(Bytes.toString(TEST_TABLE)); final HTableDescriptor htd = createBasic3FamilyHTD(Bytes.toString(TEST_TABLE)); - HRegion region2 = HRegion.createHRegion(hri, - hbaseRootDir, this.conf, htd); Path basedir = new Path(this.hbaseRootDir, Bytes.toString(TEST_TABLE)); deleteDir(basedir); @@ -174,11 +172,9 @@ public class TestWALObserver { for (KeyValue kv : kvs) { if (Arrays.equals(kv.getFamily(), TEST_FAMILY[0])) { foundFamily0 = true; - } - if (Arrays.equals(kv.getFamily(), TEST_FAMILY[2])) { + } else if (Arrays.equals(kv.getFamily(), TEST_FAMILY[2])) { foundFamily2 = true; - } - if (Arrays.equals(kv.getFamily(), TEST_FAMILY[1])) { + } else if (Arrays.equals(kv.getFamily(), TEST_FAMILY[1])) { if (!Arrays.equals(kv.getValue(), TEST_VALUE[1])) { modifiedFamily1 = true; } @@ -199,11 +195,9 @@ public class TestWALObserver { for (KeyValue kv : kvs) { if (Arrays.equals(kv.getFamily(), TEST_FAMILY[0])) { foundFamily0 = true; - } - if (Arrays.equals(kv.getFamily(), TEST_FAMILY[2])) { + } else if (Arrays.equals(kv.getFamily(), TEST_FAMILY[2])) { foundFamily2 = true; - } - if (Arrays.equals(kv.getFamily(), TEST_FAMILY[1])) { + } else if (Arrays.equals(kv.getFamily(), TEST_FAMILY[1])) { if (!Arrays.equals(kv.getValue(), TEST_VALUE[1])) { modifiedFamily1 = true; } diff --git src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java index f507fa0..350897a 100644 --- src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java +++ src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java @@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; +import java.util.UUID; import org.apache.hadoop.hbase.*; import org.apache.hadoop.hbase.util.Bytes; @@ -39,6 +40,7 @@ public class TestHRegionInfo { @Test public void testCreateHRegionInfoName() throws Exception { String tableName = "tablename"; + String encodedTable = UUID.nameUUIDFromBytes(tableName.getBytes()).toString(); final byte [] tn = Bytes.toBytes(tableName); String endKey = "endkey"; final byte [] ek = Bytes.toBytes(endKey); @@ -47,7 +49,7 @@ public class TestHRegionInfo { // old format region name byte [] name = HRegionInfo.createRegionName(tn, null, ek, id.getBytes(), false); String nameStr = Bytes.toString(name); - assertEquals(tableName + (char)HRegionInfo.END_OF_TABLE_NAME + (char)HRegionInfo.DELIMITER + assertEquals(encodedTable + (char)HRegionInfo.END_OF_TABLE_NAME + (char)HRegionInfo.DELIMITER + endKey + (char)HRegionInfo.DELIMITER + id, nameStr); @@ -56,7 +58,7 @@ public class TestHRegionInfo { assertEquals(HRegionInfo.MD5_HEX_LENGTH, md5HashInHex.length()); name = HRegionInfo.createRegionName(tn, null, ek, id.getBytes(), true); nameStr = Bytes.toString(name); - assertEquals(tableName + (char)HRegionInfo.END_OF_TABLE_NAME + + assertEquals(encodedTable + (char)HRegionInfo.END_OF_TABLE_NAME + (char)HRegionInfo.DELIMITER + endKey + (char)HRegionInfo.DELIMITER + id + (char)HRegionInfo.ENC_SEPARATOR + md5HashInHex + (char)HRegionInfo.ENC_SEPARATOR, diff --git src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java index cffdcb6..108c9a1 100644 --- src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java +++ src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java @@ -27,6 +27,8 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.MediumTests; import org.apache.hadoop.hbase.rest.client.Client; import org.apache.hadoop.hbase.rest.client.Cluster; @@ -42,8 +44,19 @@ import org.junit.experimental.categories.Category; @Category(MediumTests.class) public class TestStatusResource { - private static final byte[] ROOT_REGION_NAME = Bytes.toBytes("-ROOT-,,0"); - private static final byte[] META_REGION_NAME = Bytes.toBytes(".META.,,1"); + + private static final byte[] ROOT_REGION_NAME = HRegionInfo.createRegionName(HConstants.ROOT_TABLE_NAME, + HConstants.EMPTY_BYTE_ARRAY, + HConstants.EMPTY_BYTE_ARRAY, + "0".getBytes(), + false); + + private static final byte[] META_REGION_NAME = HRegionInfo.createRegionName(HConstants.META_TABLE_NAME, + HConstants.EMPTY_BYTE_ARRAY, + HConstants.EMPTY_BYTE_ARRAY, + "1".getBytes(), + false); + private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private static final HBaseRESTTestingUtility REST_TEST_UTIL = diff --git src/test/ruby/hbase/admin_test.rb src/test/ruby/hbase/admin_test.rb index 0c2672b..8b97a0f 100644 --- src/test/ruby/hbase/admin_test.rb +++ src/test/ruby/hbase/admin_test.rb @@ -64,6 +64,8 @@ module Hbase # Create table test table name @create_test_name = 'hbase_create_table_test_table' + @uuid_create_test_name = '724e3234-bc78-3e72-b859-3b113f2ec3ee\x02,,' + end define_test "list should return a list of tables" do @@ -166,7 +168,7 @@ module Hbase admin.drop(@create_test_name) end admin.create(@create_test_name, 'foo') - admin.close_region(@create_test_name + ',,0', nil) + admin.close_region(@uuid_create_test_name, nil) end #------------------------------------------------------------------------------- -- 1.7.4.4