You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ra...@apache.org on 2013/03/13 15:35:05 UTC
svn commit: r1455962 - in /hbase/branches/0.95:
hbase-client/src/main/java/org/apache/hadoop/hbase/client/
hbase-server/src/test/java/org/apache/hadoop/hbase/client/
Author: ramkrishna
Date: Wed Mar 13 14:35:05 2013
New Revision: 1455962
URL: http://svn.apache.org/r1455962
Log:
HBASE-8066 - Provide Admin.isTableAvailable() for a given table along with splitkeys (Ram)
Modified:
hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnection.java
hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
Modified: hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1455962&r1=1455961&r2=1455962&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (original)
+++ hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java Wed Mar 13 14:35:05 2013
@@ -976,6 +976,38 @@ public class HBaseAdmin implements Abort
public boolean isTableAvailable(String tableName) throws IOException {
return connection.isTableAvailable(Bytes.toBytes(tableName));
}
+
+ /**
+ * Use this api to check if the table has been created with the specified number of
+ * splitkeys which was used while creating the given table.
+ * Note : If this api is used after a table's region gets splitted, the api may return
+ * false.
+ * @param table
+ * name of table to check
+ * @param split
+ * keys to check if the table has been created with all split keys
+ * @throws IOException
+ * if a remote or network excpetion occurs
+ */
+ public boolean isTableAvailable(String tableName, byte[][] splitKeys) throws IOException {
+ return connection.isTableAvailable(Bytes.toBytes(tableName), splitKeys);
+ }
+
+ /**
+ * Use this api to check if the table has been created with the specified number of
+ * splitkeys which was used while creating the given table.
+ * Note : If this api is used after a table's region gets splitted, the api may return
+ * false.
+ * @param table
+ * name of table to check
+ * @param split
+ * keys to check if the table has been created with all split keys
+ * @throws IOException
+ * if a remote or network excpetion occurs
+ */
+ public boolean isTableAvailable(byte[] tableName, byte[][] splitKeys) throws IOException {
+ return connection.isTableAvailable(tableName, splitKeys);
+ }
/**
* Get the status of alter command - indicates how many regions have received
Modified: hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnection.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnection.java?rev=1455962&r1=1455961&r2=1455962&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnection.java (original)
+++ hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnection.java Wed Mar 13 14:35:05 2013
@@ -101,6 +101,20 @@ public interface HConnection extends Abo
* @throws IOException if a remote or network exception occurs
*/
public boolean isTableAvailable(byte[] tableName) throws IOException;
+
+ /**
+ * Use this api to check if the table has been created with the specified number of
+ * splitkeys which was used while creating the given table.
+ * Note : If this api is used after a table's region gets splitted, the api may return
+ * false.
+ * @param tableName
+ * tableName
+ * @param splitKeys
+ * splitKeys used while creating table
+ * @throws IOException
+ * if a remote or network exception occurs
+ */
+ public boolean isTableAvailable(byte[] tableName, byte[][] splitKeys) throws IOException;
/**
* List all the userspace tables. In other words, scan the META table.
Modified: hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=1455962&r1=1455961&r2=1455962&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (original)
+++ hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java Wed Mar 13 14:35:05 2013
@@ -842,21 +842,65 @@ public class HConnectionManager {
public boolean processRow(Result row) throws IOException {
HRegionInfo info = MetaScanner.getHRegionInfo(row);
if (info != null) {
- if (Bytes.equals(tableName, info.getTableName())) {
+ if (Bytes.compareTo(tableName, info.getTableName()) == 0) {
ServerName server = HRegionInfo.getServerName(row);
if (server == null) {
available.set(false);
return false;
}
regionCount.incrementAndGet();
+ } else if (Bytes.compareTo(tableName, info.getTableName()) < 0) {
+ // Return if we are done with the current table
+ return false;
}
}
return true;
}
};
- MetaScanner.metaScan(conf, visitor);
+ MetaScanner.metaScan(conf, visitor, tableName);
return available.get() && (regionCount.get() > 0);
}
+
+ @Override
+ public boolean isTableAvailable(final byte[] tableName, final byte[][] splitKeys)
+ throws IOException {
+ final AtomicBoolean available = new AtomicBoolean(true);
+ final AtomicInteger regionCount = new AtomicInteger(0);
+ MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
+ @Override
+ public boolean processRow(Result row) throws IOException {
+ HRegionInfo info = MetaScanner.getHRegionInfo(row);
+ if (info != null) {
+ if (Bytes.compareTo(tableName, info.getTableName()) == 0) {
+ ServerName server = HRegionInfo.getServerName(row);
+ if (server == null) {
+ available.set(false);
+ return false;
+ }
+ if (!Bytes.equals(info.getStartKey(), HConstants.EMPTY_BYTE_ARRAY)) {
+ for (byte[] splitKey : splitKeys) {
+ // Just check if the splitkey is available
+ if (Bytes.equals(info.getStartKey(), splitKey)) {
+ regionCount.incrementAndGet();
+ break;
+ }
+ }
+ } else {
+ // Always empty start row should be counted
+ regionCount.incrementAndGet();
+ }
+ } else if (Bytes.compareTo(tableName, info.getTableName()) < 0) {
+ // Return if we are done with the current table
+ return false;
+ }
+ }
+ return true;
+ }
+ };
+ MetaScanner.metaScan(conf, visitor, tableName);
+ // +1 needs to be added so that the empty start row is also taken into account
+ return available.get() && (regionCount.get() == splitKeys.length + 1);
+ }
/*
* @param enabled True if table is enabled
Modified: hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java?rev=1455962&r1=1455961&r2=1455962&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java (original)
+++ hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java Wed Mar 13 14:35:05 2013
@@ -558,6 +558,9 @@ public class TestAdmin {
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
admin.createTable(desc, splitKeys);
+
+ boolean tableAvailable = admin.isTableAvailable(Bytes.toString(tableName), splitKeys);
+ assertTrue("Table should be created with splitKyes + 1 rows in META", tableAvailable);
HTable ht = new HTable(TEST_UTIL.getConfiguration(), tableName);
Map<HRegionInfo, ServerName> regions = ht.getRegionLocations();
@@ -710,6 +713,21 @@ public class TestAdmin {
}
@Test
+ public void testTableAvailableWithRandomSplitKeys() throws Exception {
+ byte[] tableName = Bytes.toBytes("testTableAvailableWithRandomSplitKeys");
+ HTableDescriptor desc = new HTableDescriptor(tableName);
+ desc.addFamily(new HColumnDescriptor("col"));
+ byte[][] splitKeys = new byte[1][];
+ splitKeys = new byte [][] {
+ new byte [] { 1, 1, 1 },
+ new byte [] { 2, 2, 2 }
+ };
+ admin.createTable(desc);
+ boolean tableAvailable = admin.isTableAvailable(Bytes.toString(tableName), splitKeys);
+ assertFalse("Table should be created with 1 row in META", tableAvailable);
+ }
+
+ @Test
public void testCreateTableWithOnlyEmptyStartRow() throws IOException {
byte[] tableName = Bytes.toBytes("testCreateTableWithOnlyEmptyStartRow");
byte[][] splitKeys = new byte[1][];