HADOOP-2262 HADOOP-2261 fail fast on non-existing table, change abort to function after commit even if commit was successful
git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk/src/contrib/hbase@598555 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3786f399a6
commit
70004192f1
|
@ -51,6 +51,8 @@ Trunk (unreleased changes)
|
||||||
HADOOP-2139 (phase 2) Make region server more event driven
|
HADOOP-2139 (phase 2) Make region server more event driven
|
||||||
HADOOP-2289 Useless efforts of looking for the non-existant table in select
|
HADOOP-2289 Useless efforts of looking for the non-existant table in select
|
||||||
command.
|
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
|
Release 0.15.1
|
||||||
Branch 0.15
|
Branch 0.15
|
||||||
|
|
|
@ -738,6 +738,9 @@ public class HConnectionManager implements HConstants {
|
||||||
regionInfo, new HServerAddress(serverAddress)));
|
regionInfo, new HServerAddress(serverAddress)));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
if (e instanceof TableNotFoundException) {
|
||||||
|
throw e; // don't retry
|
||||||
|
}
|
||||||
if (tries == numRetries - 1) { // no retries left
|
if (tries == numRetries - 1) { // no retries left
|
||||||
if (e instanceof RemoteException) {
|
if (e instanceof RemoteException) {
|
||||||
e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e);
|
e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e);
|
||||||
|
|
|
@ -58,11 +58,16 @@ public class HTable implements HConstants {
|
||||||
protected volatile SortedMap<Text, HRegionLocation> tableServers;
|
protected volatile SortedMap<Text, HRegionLocation> tableServers;
|
||||||
protected AtomicReference<BatchUpdate> batch;
|
protected AtomicReference<BatchUpdate> batch;
|
||||||
|
|
||||||
|
protected volatile boolean tableDoesNotExist;
|
||||||
|
|
||||||
// For row mutation operations
|
// For row mutation operations
|
||||||
|
|
||||||
protected volatile boolean closed;
|
protected volatile boolean closed;
|
||||||
|
|
||||||
protected void checkClosed() {
|
protected void checkClosed() {
|
||||||
|
if (tableDoesNotExist) {
|
||||||
|
throw new IllegalStateException("table does not exist: " + tableName);
|
||||||
|
}
|
||||||
if (closed) {
|
if (closed) {
|
||||||
throw new IllegalStateException("table is closed");
|
throw new IllegalStateException("table is closed");
|
||||||
}
|
}
|
||||||
|
@ -77,13 +82,15 @@ public class HTable implements HConstants {
|
||||||
*/
|
*/
|
||||||
public HTable(HBaseConfiguration conf, Text tableName) throws IOException {
|
public HTable(HBaseConfiguration conf, Text tableName) throws IOException {
|
||||||
closed = true;
|
closed = true;
|
||||||
|
tableDoesNotExist = true;
|
||||||
this.connection = HConnectionManager.getConnection(conf);
|
this.connection = HConnectionManager.getConnection(conf);
|
||||||
this.tableName = tableName;
|
this.tableName = tableName;
|
||||||
this.pause = conf.getLong("hbase.client.pause", 10 * 1000);
|
this.pause = conf.getLong("hbase.client.pause", 10 * 1000);
|
||||||
this.numRetries = conf.getInt("hbase.client.retries.number", 5);
|
this.numRetries = conf.getInt("hbase.client.retries.number", 5);
|
||||||
this.rand = new Random();
|
this.rand = new Random();
|
||||||
tableServers = connection.getTableServers(tableName);
|
|
||||||
this.batch = new AtomicReference<BatchUpdate>();
|
this.batch = new AtomicReference<BatchUpdate>();
|
||||||
|
tableServers = connection.getTableServers(tableName);
|
||||||
|
tableDoesNotExist = false;
|
||||||
closed = false;
|
closed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -685,8 +692,7 @@ public class HTable implements HConstants {
|
||||||
*/
|
*/
|
||||||
public synchronized void abort(long lockid) {
|
public synchronized void abort(long lockid) {
|
||||||
checkClosed();
|
checkClosed();
|
||||||
updateInProgress(true);
|
if (batch.get() != null && batch.get().getLockid() != lockid) {
|
||||||
if (batch.get().getLockid() != lockid) {
|
|
||||||
throw new IllegalArgumentException("invalid lock id " + lockid);
|
throw new IllegalArgumentException("invalid lock id " + lockid);
|
||||||
}
|
}
|
||||||
batch.set(null);
|
batch.set(null);
|
||||||
|
|
|
@ -32,6 +32,7 @@ public class TestHTable extends HBaseClusterTestCase implements HConstants {
|
||||||
private static final HColumnDescriptor column =
|
private static final HColumnDescriptor column =
|
||||||
new HColumnDescriptor(COLUMN_FAMILY.toString());
|
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 tableAname = new Text("tableA");
|
||||||
private static final Text tableBname = new Text("tableB");
|
private static final Text tableBname = new Text("tableB");
|
||||||
|
|
||||||
|
@ -42,6 +43,19 @@ public class TestHTable extends HBaseClusterTestCase implements HConstants {
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void testHTable() 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());
|
HTableDescriptor tableAdesc = new HTableDescriptor(tableAname.toString());
|
||||||
tableAdesc.addFamily(column);
|
tableAdesc.addFamily(column);
|
||||||
|
|
||||||
|
@ -56,8 +70,6 @@ public class TestHTable extends HBaseClusterTestCase implements HConstants {
|
||||||
|
|
||||||
// put some data into table A
|
// put some data into table A
|
||||||
|
|
||||||
byte[] value = "value".getBytes(UTF8_ENCODING);
|
|
||||||
|
|
||||||
HTable a = new HTable(conf, tableAname);
|
HTable a = new HTable(conf, tableAname);
|
||||||
long lockid = a.startUpdate(row);
|
long lockid = a.startUpdate(row);
|
||||||
a.put(lockid, COLUMN_FAMILY, value);
|
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.put(lockid, e.getKey(), e.getValue());
|
||||||
}
|
}
|
||||||
b.commit(lockid);
|
b.commit(lockid);
|
||||||
|
b.abort(lockid);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
s.close();
|
s.close();
|
||||||
|
|
Loading…
Reference in New Issue