You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by te...@apache.org on 2012/01/07 01:07:16 UTC
svn commit: r1228505 - in /hbase/branches/0.90: CHANGES.txt
src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
Author: tedyu
Date: Sat Jan 7 00:07:16 2012
New Revision: 1228505
URL: http://svn.apache.org/viewvc?rev=1228505&view=rev
Log:
HBASE-5041 Major compaction on non existing table does not throw error (Shrijeet)
Modified:
hbase/branches/0.90/CHANGES.txt
hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
Modified: hbase/branches/0.90/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/CHANGES.txt?rev=1228505&r1=1228504&r2=1228505&view=diff
==============================================================================
--- hbase/branches/0.90/CHANGES.txt (original)
+++ hbase/branches/0.90/CHANGES.txt Sat Jan 7 00:07:16 2012
@@ -11,6 +11,7 @@ Release 0.90.6 - Unreleased
HBASE-5073 Registered listeners not getting removed leading to memory leak in HBaseAdmin
(Ramkrishna)
HBASE-5009 Failure of creating split dir if it already exists prevents splits from happening further
+ HBASE-5041 Major compaction on non existing table does not throw error (Shrijeet)
IMPROVEMENT
HBASE-5102 Change the default value of the property "hbase.connection.per.config" to false in
Modified: hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1228505&r1=1228504&r2=1228505&view=diff
==============================================================================
--- hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (original)
+++ hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java Sat Jan 7 00:07:16 2012
@@ -45,6 +45,7 @@ import org.apache.hadoop.hbase.NotServin
import org.apache.hadoop.hbase.RegionException;
import org.apache.hadoop.hbase.RemoteExceptionHandler;
import org.apache.hadoop.hbase.TableExistsException;
+import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.UnknownRegionException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.catalog.CatalogTracker;
@@ -918,8 +919,8 @@ public class HBaseAdmin implements Abort
*/
public void flush(final byte [] tableNameOrRegionName)
throws IOException, InterruptedException {
- boolean isRegionName = isRegionName(tableNameOrRegionName);
CatalogTracker ct = getCatalogTracker();
+ boolean isRegionName = isRegionName(tableNameOrRegionName, ct);
try {
if (isRegionName) {
Pair<HRegionInfo, HServerAddress> pair =
@@ -931,9 +932,10 @@ public class HBaseAdmin implements Abort
flush(pair.getSecond(), pair.getFirst());
}
} else {
+ final String tableName = tableNameString(tableNameOrRegionName, ct);
List<Pair<HRegionInfo, HServerAddress>> pairs =
MetaReader.getTableRegionsAndLocations(ct,
- Bytes.toString(tableNameOrRegionName));
+ tableName);
for (Pair<HRegionInfo, HServerAddress> pair: pairs) {
if (pair.getFirst().isOffline()) continue;
if (pair.getSecond() == null) continue;
@@ -1023,7 +1025,7 @@ public class HBaseAdmin implements Abort
throws IOException, InterruptedException {
CatalogTracker ct = getCatalogTracker();
try {
- if (isRegionName(tableNameOrRegionName)) {
+ if (isRegionName(tableNameOrRegionName, ct)) {
Pair<HRegionInfo, HServerAddress> pair =
MetaReader.getRegion(ct, tableNameOrRegionName);
if (pair == null || pair.getSecond() == null) {
@@ -1033,9 +1035,10 @@ public class HBaseAdmin implements Abort
compact(pair.getSecond(), pair.getFirst(), major);
}
} else {
+ final String tableName = tableNameString(tableNameOrRegionName, ct);
List<Pair<HRegionInfo, HServerAddress>> pairs =
MetaReader.getTableRegionsAndLocations(ct,
- Bytes.toString(tableNameOrRegionName));
+ tableName);
for (Pair<HRegionInfo, HServerAddress> pair: pairs) {
if (pair.getFirst().isOffline()) continue;
if (pair.getSecond() == null) continue;
@@ -1173,7 +1176,7 @@ public class HBaseAdmin implements Abort
final byte [] splitPoint) throws IOException, InterruptedException {
CatalogTracker ct = getCatalogTracker();
try {
- if (isRegionName(tableNameOrRegionName)) {
+ if (isRegionName(tableNameOrRegionName, ct)) {
// Its a possible region name.
Pair<HRegionInfo, HServerAddress> pair =
MetaReader.getRegion(ct, tableNameOrRegionName);
@@ -1184,9 +1187,10 @@ public class HBaseAdmin implements Abort
split(pair.getSecond(), pair.getFirst(), splitPoint);
}
} else {
+ final String tableName = tableNameString(tableNameOrRegionName, ct);
List<Pair<HRegionInfo, HServerAddress>> pairs =
MetaReader.getTableRegionsAndLocations(ct,
- Bytes.toString(tableNameOrRegionName));
+ tableName);
for (Pair<HRegionInfo, HServerAddress> pair: pairs) {
// May not be a server for a particular row
if (pair.getSecond() == null) continue;
@@ -1234,17 +1238,38 @@ public class HBaseAdmin implements Abort
/**
* @param tableNameOrRegionName Name of a table or name of a region.
- * @return True if <code>tableNameOrRegionName</code> is *possibly* a region
- * name else false if a verified tablename (we call {@link #tableExists(byte[])};
- * else we throw an exception.
- * @throws IOException
+ * @param ct A {@link #CatalogTracker} instance (caller of this method usually has one).
+ * @return True if <code>tableNameOrRegionName</code> is a verified region
+ * name (we call {@link #MetaReader.getRegion(CatalogTracker catalogTracker,
+ * byte [] regionName)};) else false.
+ * Throw an exception if <code>tableNameOrRegionName</code> is null.
+ * @throws IOException
*/
- private boolean isRegionName(final byte [] tableNameOrRegionName)
+ private boolean isRegionName(final byte[] tableNameOrRegionName,
+ CatalogTracker ct)
throws IOException {
if (tableNameOrRegionName == null) {
throw new IllegalArgumentException("Pass a table name or region name");
}
- return !tableExists(tableNameOrRegionName);
+ return (MetaReader.getRegion(ct, tableNameOrRegionName) != null);
+ }
+
+ /**
+ * Convert the table name byte array into a table name string and check if table
+ * exists or not.
+ * @param tableNameBytes Name of a table.
+ * @param ct A {@link #CatalogTracker} instance (caller of this method usually has one).
+ * @return tableName in string form.
+ * @throws IOException if a remote or network exception occurs.
+ * @throws TableNotFoundException if table does not exist.
+ */
+ private String tableNameString(final byte[] tableNameBytes, CatalogTracker ct)
+ throws IOException {
+ String tableNameString = Bytes.toString(tableNameBytes);
+ if (!MetaReader.tableExists(ct, tableNameString)) {
+ throw new TableNotFoundException(tableNameString);
+ }
+ return tableNameString;
}
/**
Modified: hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java?rev=1228505&r1=1228504&r2=1228505&view=diff
==============================================================================
--- hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java (original)
+++ hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java Sat Jan 7 00:07:16 2012
@@ -95,6 +95,34 @@ public class TestAdmin {
}
@Test
+ public void testSplitFlushCompactUnknownTable() throws InterruptedException {
+ final String unknowntable = "fubar";
+ Exception exception = null;
+ try {
+ this.admin.compact(unknowntable);
+ } catch (IOException e) {
+ exception = e;
+ }
+ assertTrue(exception instanceof TableNotFoundException);
+
+ exception = null;
+ try {
+ this.admin.flush(unknowntable);
+ } catch (IOException e) {
+ exception = e;
+ }
+ assertTrue(exception instanceof TableNotFoundException);
+
+ exception = null;
+ try {
+ this.admin.split(unknowntable);
+ } catch (IOException e) {
+ exception = e;
+ }
+ assertTrue(exception instanceof TableNotFoundException);
+ }
+
+ @Test
public void testDisableAndEnableTable() throws IOException {
final byte [] row = Bytes.toBytes("row");
final byte [] qualifier = Bytes.toBytes("qualifier");