Class HBaseConnection
- java.lang.Object
-
- com.amazonaws.athena.connectors.hbase.connection.HBaseConnection
-
public class HBaseConnection extends Object
This class wraps Hbase's Connection construct and provides both a simplified facade for common operations but also automatic retry and reconnect logic to make client reuse simpler. Some specific cases that this construct handles are: replacement of an HBase region server, replacement of HBase master server, other transient errors while communicating with HBase.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedHBaseConnection(org.apache.hadoop.conf.Configuration config, int maxRetries)Used by HBaseConnectionFactory to construct new connections.protectedHBaseConnection(org.apache.hadoop.hbase.client.Connection connection, int maxRetries)Used to facilitate testing by allowing for injection of the underlying HBase connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidclose()Used to close this connection by closing the underlying HBase Connection.protected org.apache.hadoop.hbase.client.Connectionconnect(org.apache.hadoop.conf.Configuration config)Creates a new HBase connection using the provided config.protected intgetRetries()List<org.apache.hadoop.hbase.HRegionInfo>getTableRegions(org.apache.hadoop.hbase.TableName tableName)Retreieves the regions for the requested TableName.booleanisHealthy()Used to determine if this connection can be reused or if it is unhealthy.org.apache.hadoop.hbase.NamespaceDescriptor[]listNamespaceDescriptors()Lists the available namespaces in the HBase instance.org.apache.hadoop.hbase.TableName[]listTableNamesByNamespace(String schemaName)Lists the table names present in the given schema (aka namespace)<T> TscanTable(org.apache.hadoop.hbase.TableName tableName, org.apache.hadoop.hbase.client.Scan scan, ResultProcessor<T> resultProcessor)Used to perform a scan of the given table, scan, and resultProcessor.booleantableExists(org.apache.hadoop.hbase.TableName tableName)Retrieves whether the table exists
-
-
-
Constructor Detail
-
HBaseConnection
protected HBaseConnection(org.apache.hadoop.conf.Configuration config, int maxRetries)Used by HBaseConnectionFactory to construct new connections.- Parameters:
config- The HBase config to use for this connection.maxRetries- The max retries this connection will allow before marking itself unhealthy.
-
HBaseConnection
protected HBaseConnection(org.apache.hadoop.hbase.client.Connection connection, int maxRetries)Used to facilitate testing by allowing for injection of the underlying HBase connection.- Parameters:
connection- The actual Hbase connection to use.maxRetries- The max retries this connection will allow before marking itself unhealthy.
-
-
Method Detail
-
isHealthy
public boolean isHealthy()
Used to determine if this connection can be reused or if it is unhealthy.- Returns:
- True if the connection can be safely reused, false otherwise.
-
listNamespaceDescriptors
public org.apache.hadoop.hbase.NamespaceDescriptor[] listNamespaceDescriptors() throws IOExceptionLists the available namespaces in the HBase instance.- Returns:
- Array of NamespaceDescriptor representing the available namespaces in the HBase instance.
- Throws:
IOException
-
listTableNamesByNamespace
public org.apache.hadoop.hbase.TableName[] listTableNamesByNamespace(String schemaName)
Lists the table names present in the given schema (aka namespace)- Parameters:
schemaName- The schema name (aka hbase namespace) to list table names from.- Returns:
- An array of hbase TableName objects for the given schema name.
-
getTableRegions
public List<org.apache.hadoop.hbase.HRegionInfo> getTableRegions(org.apache.hadoop.hbase.TableName tableName)
Retreieves the regions for the requested TableName.- Parameters:
tableName- The fully qualified HBase TableName for which we should obtain region info.- Returns:
- List of HRegionInfo representing the regions hosting the requested table.
-
scanTable
public <T> T scanTable(org.apache.hadoop.hbase.TableName tableName, org.apache.hadoop.hbase.client.Scan scan, ResultProcessor<T> resultProcessor)Used to perform a scan of the given table, scan, and resultProcessor.- Type Parameters:
T- The return type of the ResultProcessor and this this method.- Parameters:
tableName- The HBase table to scan.scan- The HBase scan (filters, etc...) to run.resultProcessor- The ResultProcessor that will be used to process the results of the scan.- Returns:
- The result produced by the resultProcessor when it has completed processing all results of the scan.
-
tableExists
public boolean tableExists(org.apache.hadoop.hbase.TableName tableName)
Retrieves whether the table exists- Parameters:
tableName- The fully qualified HBase TableName for which to check existence.- Returns:
- Whether the table exists or not.
-
close
protected void close()
Used to close this connection by closing the underlying HBase Connection.
-
getRetries
protected int getRetries()
-
connect
protected org.apache.hadoop.hbase.client.Connection connect(org.apache.hadoop.conf.Configuration config)
Creates a new HBase connection using the provided config.- Parameters:
config- The config to use for the new HBase connection.- Returns:
- The new connection.
-
-