HBASE-8408; addendum for new HConnection API

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1511885 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
larsh 2013-08-08 17:17:04 +00:00
parent b94a48d104
commit d28f8564ad
4 changed files with 54 additions and 2 deletions

View File

@ -97,6 +97,19 @@ public interface HConnection extends Abortable, Closeable {
*/ */
public HTableInterface getTable(byte[] tableName) throws IOException; public HTableInterface getTable(byte[] tableName) throws IOException;
/**
* Retrieve an HTableInterface implementation for access to a table.
* The returned HTableInterface is not thread safe, a new instance should
* be created for each using thread.
* This is a lightweight operation, pooling or caching of the returned HTableInterface
* is neither required nor desired.
* Note that the HConnection needs to be unmanaged
* (created with {@link HConnectionManager#createConnection(Configuration)}).
* @param tableName
* @return an HTable to use for interactions with this table
*/
public HTableInterface getTable(TableName tableName) throws IOException;
/** /**
* Retrieve an HTableInterface implementation for access to a table. * Retrieve an HTableInterface implementation for access to a table.
* The returned HTableInterface is not thread safe, a new instance should * The returned HTableInterface is not thread safe, a new instance should
@ -125,6 +138,20 @@ public interface HConnection extends Abortable, Closeable {
*/ */
public HTableInterface getTable(byte[] tableName, ExecutorService pool) throws IOException; public HTableInterface getTable(byte[] tableName, ExecutorService pool) throws IOException;
/**
* Retrieve an HTableInterface implementation for access to a table.
* The returned HTableInterface is not thread safe, a new instance should
* be created for each using thread.
* This is a lightweight operation, pooling or caching of the returned HTableInterface
* is neither required nor desired.
* Note that the HConnection needs to be unmanaged
* (created with {@link HConnectionManager#createConnection(Configuration)}).
* @param tableName
* @param pool The thread pool to use for batch operations, null to use a default pool.
* @return an HTable to use for interactions with this table
*/
public HTableInterface getTable(TableName tableName, ExecutorService pool) throws IOException;
/** @return - true if the master server is running */ /** @return - true if the master server is running */
boolean isMasterRunning() boolean isMasterRunning()
throws MasterNotRunningException, ZooKeeperConnectionException; throws MasterNotRunningException, ZooKeeperConnectionException;

View File

@ -653,21 +653,31 @@ public class HConnectionManager {
@Override @Override
public HTableInterface getTable(String tableName) throws IOException { public HTableInterface getTable(String tableName) throws IOException {
return getTable(Bytes.toBytes(tableName)); return getTable(TableName.valueOf(tableName));
} }
@Override @Override
public HTableInterface getTable(byte[] tableName) throws IOException { public HTableInterface getTable(byte[] tableName) throws IOException {
return getTable(TableName.valueOf(tableName));
}
@Override
public HTableInterface getTable(TableName tableName) throws IOException {
return getTable(tableName, getBatchPool()); return getTable(tableName, getBatchPool());
} }
@Override @Override
public HTableInterface getTable(String tableName, ExecutorService pool) throws IOException { public HTableInterface getTable(String tableName, ExecutorService pool) throws IOException {
return getTable(Bytes.toBytes(tableName), pool); return getTable(TableName.valueOf(tableName), pool);
} }
@Override @Override
public HTableInterface getTable(byte[] tableName, ExecutorService pool) throws IOException { public HTableInterface getTable(byte[] tableName, ExecutorService pool) throws IOException {
return getTable(TableName.valueOf(tableName), pool);
}
@Override
public HTableInterface getTable(TableName tableName, ExecutorService pool) throws IOException {
if (managed) { if (managed) {
throw new IOException("The connection has to be unmanaged."); throw new IOException("The connection has to be unmanaged.");
} }

View File

@ -72,6 +72,11 @@ public class HConnectionWrapper implements HConnection {
return hconnection.getTable(tableName); return hconnection.getTable(tableName);
} }
@Override
public HTableInterface getTable(TableName tableName) throws IOException {
return hconnection.getTable(tableName);
}
@Override @Override
public HTableInterface getTable(String tableName, ExecutorService pool) throws IOException { public HTableInterface getTable(String tableName, ExecutorService pool) throws IOException {
return hconnection.getTable(tableName, pool); return hconnection.getTable(tableName, pool);
@ -82,6 +87,11 @@ public class HConnectionWrapper implements HConnection {
return hconnection.getTable(tableName, pool); return hconnection.getTable(tableName, pool);
} }
@Override
public HTableInterface getTable(TableName tableName, ExecutorService pool) throws IOException {
return hconnection.getTable(tableName, pool);
}
@Override @Override
public void abort(String why, Throwable e) { public void abort(String why, Throwable e) {
hconnection.abort(why, e); hconnection.abort(why, e);

View File

@ -148,6 +148,11 @@ public class TestHCM {
assertTrue(otherPool == t.getPool()); assertTrue(otherPool == t.getPool());
t.close(); t.close();
t = (HTable)con2.getTable(TableName.valueOf(tableName));
// try other API too
assertTrue(otherPool == t.getPool());
t.close();
t = (HTable)con1.getTable(tableName); t = (HTable)con1.getTable(tableName);
ExecutorService pool = ((HConnectionImplementation)con1).getCurrentBatchPool(); ExecutorService pool = ((HConnectionImplementation)con1).getCurrentBatchPool();
// make sure an internal pool was created // make sure an internal pool was created