diff --git a/CHANGES.txt b/CHANGES.txt index 5a91135d098..779431e0e22 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -51,6 +51,8 @@ Trunk (unreleased changes) HADOOP-2139 (phase 2) Make region server more event driven HADOOP-2289 Useless efforts of looking for the non-existant table in select command. + HADOOP-2262 HADOOP-2261 fail fast on non-existing table, change abort to + function after commit even if commit was successful Release 0.15.1 Branch 0.15 diff --git a/src/java/org/apache/hadoop/hbase/HConnectionManager.java b/src/java/org/apache/hadoop/hbase/HConnectionManager.java index 0300ff7dba6..3ce47895ce6 100644 --- a/src/java/org/apache/hadoop/hbase/HConnectionManager.java +++ b/src/java/org/apache/hadoop/hbase/HConnectionManager.java @@ -738,7 +738,10 @@ public class HConnectionManager implements HConstants { regionInfo, new HServerAddress(serverAddress))); } } catch (IOException e) { - if (tries == numRetries - 1) { // no retries left + if (e instanceof TableNotFoundException) { + throw e; // don't retry + } + if (tries == numRetries - 1) { // no retries left if (e instanceof RemoteException) { e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); } diff --git a/src/java/org/apache/hadoop/hbase/HTable.java b/src/java/org/apache/hadoop/hbase/HTable.java index f254424a85a..cec09a03f18 100644 --- a/src/java/org/apache/hadoop/hbase/HTable.java +++ b/src/java/org/apache/hadoop/hbase/HTable.java @@ -57,12 +57,17 @@ public class HTable implements HConstants { protected Random rand; protected volatile SortedMap tableServers; protected AtomicReference batch; + + protected volatile boolean tableDoesNotExist; // For row mutation operations protected volatile boolean closed; protected void checkClosed() { + if (tableDoesNotExist) { + throw new IllegalStateException("table does not exist: " + tableName); + } if (closed) { throw new IllegalStateException("table is closed"); } @@ -77,13 +82,15 @@ public class HTable implements HConstants { */ public HTable(HBaseConfiguration conf, Text tableName) throws IOException { closed = true; + tableDoesNotExist = true; this.connection = HConnectionManager.getConnection(conf); this.tableName = tableName; this.pause = conf.getLong("hbase.client.pause", 10 * 1000); this.numRetries = conf.getInt("hbase.client.retries.number", 5); this.rand = new Random(); - tableServers = connection.getTableServers(tableName); this.batch = new AtomicReference(); + tableServers = connection.getTableServers(tableName); + tableDoesNotExist = false; closed = false; } @@ -685,8 +692,7 @@ public class HTable implements HConstants { */ public synchronized void abort(long lockid) { checkClosed(); - updateInProgress(true); - if (batch.get().getLockid() != lockid) { + if (batch.get() != null && batch.get().getLockid() != lockid) { throw new IllegalArgumentException("invalid lock id " + lockid); } batch.set(null); diff --git a/src/test/org/apache/hadoop/hbase/TestHTable.java b/src/test/org/apache/hadoop/hbase/TestHTable.java index 348c17b622b..694d5017a19 100644 --- a/src/test/org/apache/hadoop/hbase/TestHTable.java +++ b/src/test/org/apache/hadoop/hbase/TestHTable.java @@ -31,7 +31,8 @@ import org.apache.hadoop.io.Text; public class TestHTable extends HBaseClusterTestCase implements HConstants { private static final HColumnDescriptor column = new HColumnDescriptor(COLUMN_FAMILY.toString()); - + + private static final Text nosuchTable = new Text("nosuchTable"); private static final Text tableAname = new Text("tableA"); private static final Text tableBname = new Text("tableB"); @@ -42,6 +43,19 @@ public class TestHTable extends HBaseClusterTestCase implements HConstants { * @throws IOException */ public void testHTable() throws IOException { + byte[] value = "value".getBytes(UTF8_ENCODING); + + try { + new HTable(conf, nosuchTable); + + } catch (TableNotFoundException e) { + // expected + + } catch (IOException e) { + e.printStackTrace(); + fail(); + } + HTableDescriptor tableAdesc = new HTableDescriptor(tableAname.toString()); tableAdesc.addFamily(column); @@ -56,8 +70,6 @@ public class TestHTable extends HBaseClusterTestCase implements HConstants { // put some data into table A - byte[] value = "value".getBytes(UTF8_ENCODING); - HTable a = new HTable(conf, tableAname); long lockid = a.startUpdate(row); a.put(lockid, COLUMN_FAMILY, value); @@ -82,6 +94,7 @@ public class TestHTable extends HBaseClusterTestCase implements HConstants { b.put(lockid, e.getKey(), e.getValue()); } b.commit(lockid); + b.abort(lockid); } } finally { s.close();