@InterfaceAudience.Private class AsyncTableImpl extends Object implements AsyncTable<ScanResultConsumer>
RawAsyncTableImpl. The difference is that users need to provide a
thread pool when constructing this class, and the callback methods registered to the returned
CompletableFuture will be executed in this thread pool. So usually it is safe for users
to do anything they want in the callbacks without breaking the rpc framework.AsyncTable.CheckAndMutateBuilder, AsyncTable.CheckAndMutateWithFilterBuilder, AsyncTable.CoprocessorCallback<R>, AsyncTable.CoprocessorServiceBuilder<S,R>| Modifier and Type | Field and Description |
|---|---|
private ExecutorService |
pool |
private AsyncTable<AdvancedScanResultConsumer> |
rawTable |
| Constructor and Description |
|---|
AsyncTableImpl(AsyncConnectionImpl conn,
AsyncTable<AdvancedScanResultConsumer> rawTable,
ExecutorService pool) |
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Result> |
append(Append append)
Appends values to one or more columns within a single row.
|
<T> List<CompletableFuture<T>> |
batch(List<? extends Row> actions)
Method that does a batch call on Deletes, Gets, Puts, Increments, Appends and RowMutations.
|
AsyncTable.CheckAndMutateBuilder |
checkAndMutate(byte[] row,
byte[] family)
Atomically checks if a row/family/qualifier value matches the expected value.
|
AsyncTable.CheckAndMutateWithFilterBuilder |
checkAndMutate(byte[] row,
Filter filter)
Atomically checks if a row matches the specified filter.
|
<S,R> AsyncTable.CoprocessorServiceBuilder<S,R> |
coprocessorService(Function<com.google.protobuf.RpcChannel,S> stubMaker,
ServiceCaller<S,R> callable,
AsyncTable.CoprocessorCallback<R> callback)
Execute a coprocessor call on the regions which are covered by a range.
|
<S,R> CompletableFuture<R> |
coprocessorService(Function<com.google.protobuf.RpcChannel,S> stubMaker,
ServiceCaller<S,R> callable,
byte[] row)
Execute the given coprocessor call on the region which contains the given
row. |
CompletableFuture<Void> |
delete(Delete delete)
Deletes the specified cells/row.
|
List<CompletableFuture<Void>> |
delete(List<Delete> deletes)
Deletes the specified cells/rows in bulk.
|
CompletableFuture<Result> |
get(Get get)
Extracts certain cells from a given row.
|
List<CompletableFuture<Result>> |
get(List<Get> gets)
Extracts certain cells from the given rows, in batch.
|
org.apache.hadoop.conf.Configuration |
getConfiguration()
Returns the
Configuration object used by this instance. |
CompletableFuture<TableDescriptor> |
getDescriptor()
Gets the
TableDescriptor for this table. |
TableName |
getName()
Gets the fully qualified table name instance of this table.
|
long |
getOperationTimeout(TimeUnit unit)
Get timeout of each operation in Table instance.
|
long |
getReadRpcTimeout(TimeUnit unit)
Get timeout of each rpc read request in this Table instance.
|
AsyncTableRegionLocator |
getRegionLocator()
Gets the
AsyncTableRegionLocator for this table. |
long |
getRpcTimeout(TimeUnit unit)
Get timeout of each rpc request in this Table instance.
|
ResultScanner |
getScanner(Scan scan)
Returns a scanner on the current table as specified by the
Scan object. |
long |
getScanTimeout(TimeUnit unit)
Get the timeout of a single operation in a scan.
|
long |
getWriteRpcTimeout(TimeUnit unit)
Get timeout of each rpc write request in this Table instance.
|
CompletableFuture<Result> |
increment(Increment increment)
Increments one or more columns within a single row.
|
CompletableFuture<Void> |
mutateRow(RowMutations mutation)
Performs multiple mutations atomically on a single row.
|
List<CompletableFuture<Void>> |
put(List<Put> puts)
Puts some data in the table, in batch.
|
CompletableFuture<Void> |
put(Put put)
Puts some data to the table.
|
void |
scan(Scan scan,
ScanResultConsumer consumer)
The scan API uses the observer pattern.
|
private void |
scan0(Scan scan,
ScanResultConsumer consumer) |
CompletableFuture<List<Result>> |
scanAll(Scan scan)
Return all the results that match the given scan object.
|
private <T> CompletableFuture<T> |
wrap(CompletableFuture<T> future) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbatchAll, deleteAll, exists, exists, existsAll, getAll, getScanner, getScanner, incrementColumnValue, incrementColumnValue, putAllprivate final AsyncTable<AdvancedScanResultConsumer> rawTable
private final ExecutorService pool
AsyncTableImpl(AsyncConnectionImpl conn, AsyncTable<AdvancedScanResultConsumer> rawTable, ExecutorService pool)
public TableName getName()
AsyncTablegetName in interface AsyncTable<ScanResultConsumer>public org.apache.hadoop.conf.Configuration getConfiguration()
AsyncTableConfiguration object used by this instance.
The reference returned is not a copy, so any change made to it will affect this instance.
getConfiguration in interface AsyncTable<ScanResultConsumer>public CompletableFuture<TableDescriptor> getDescriptor()
AsyncTableTableDescriptor for this table.getDescriptor in interface AsyncTable<ScanResultConsumer>public AsyncTableRegionLocator getRegionLocator()
AsyncTableAsyncTableRegionLocator for this table.getRegionLocator in interface AsyncTable<ScanResultConsumer>public long getRpcTimeout(TimeUnit unit)
AsyncTablegetRpcTimeout in interface AsyncTable<ScanResultConsumer>unit - the unit of time the timeout to be represented inAsyncTable.getReadRpcTimeout(TimeUnit),
AsyncTable.getWriteRpcTimeout(TimeUnit)public long getReadRpcTimeout(TimeUnit unit)
AsyncTablegetReadRpcTimeout in interface AsyncTable<ScanResultConsumer>unit - the unit of time the timeout to be represented inpublic long getWriteRpcTimeout(TimeUnit unit)
AsyncTablegetWriteRpcTimeout in interface AsyncTable<ScanResultConsumer>unit - the unit of time the timeout to be represented inpublic long getOperationTimeout(TimeUnit unit)
AsyncTablegetOperationTimeout in interface AsyncTable<ScanResultConsumer>unit - the unit of time the timeout to be represented inpublic long getScanTimeout(TimeUnit unit)
AsyncTablegetScanTimeout in interface AsyncTable<ScanResultConsumer>unit - the unit of time the timeout to be represented inprivate <T> CompletableFuture<T> wrap(CompletableFuture<T> future)
public CompletableFuture<Result> get(Get get)
AsyncTableget in interface AsyncTable<ScanResultConsumer>get - The object that specifies what data to fetch and from which row.Result instance returned won't contain any
KeyValue, as indicated by Result.isEmpty(). The
return value will be wrapped by a CompletableFuture.public CompletableFuture<Void> put(Put put)
AsyncTableput in interface AsyncTable<ScanResultConsumer>put - The data to put.CompletableFuture that always returns null when complete normally.public CompletableFuture<Void> delete(Delete delete)
AsyncTabledelete in interface AsyncTable<ScanResultConsumer>delete - The object that specifies what to delete.CompletableFuture that always returns null when complete normally.public CompletableFuture<Result> append(Append append)
AsyncTableThis operation does not appear atomic to readers. Appends are done under a single row lock, so write operations to a row are synchronized, but readers do not take row locks so get and scan operations can see this operation partially completed.
append in interface AsyncTable<ScanResultConsumer>append - object that specifies the columns and amounts to be used for the increment
operationsCompletableFuture.public CompletableFuture<Result> increment(Increment increment)
AsyncTableThis operation does not appear atomic to readers. Increments are done under a single row lock, so write operations to a row are synchronized, but readers do not take row locks so get and scan operations can see this operation partially completed.
increment in interface AsyncTable<ScanResultConsumer>increment - object that specifies the columns and amounts to be used for the increment
operationsCompletableFuture.public AsyncTable.CheckAndMutateBuilder checkAndMutate(byte[] row, byte[] family)
AsyncTable
Use the returned AsyncTable.CheckAndMutateBuilder to construct your request and then execute it.
This is a fluent style API, the code is like:
table.checkAndMutate(row, family).qualifier(qualifier).ifNotExists().thenPut(put)
.thenAccept(succ -> {
if (succ) {
System.out.println("Check and put succeeded");
} else {
System.out.println("Check and put failed");
}
});
checkAndMutate in interface AsyncTable<ScanResultConsumer>public AsyncTable.CheckAndMutateWithFilterBuilder checkAndMutate(byte[] row, Filter filter)
AsyncTable
Use the returned AsyncTable.CheckAndMutateWithFilterBuilder to construct your request and then
execute it. This is a fluent style API, the code is like:
table.checkAndMutate(row, filter).thenPut(put)
.thenAccept(succ -> {
if (succ) {
System.out.println("Check and put succeeded");
} else {
System.out.println("Check and put failed");
}
});
checkAndMutate in interface AsyncTable<ScanResultConsumer>public CompletableFuture<Void> mutateRow(RowMutations mutation)
AsyncTablemutateRow in interface AsyncTable<ScanResultConsumer>mutation - object that specifies the set of mutations to perform atomicallyCompletableFuture that always returns null when complete normally.public CompletableFuture<List<Result>> scanAll(Scan scan)
AsyncTable
Notice that usually you should use this method with a Scan object that has limit set.
For example, if you want to get the closest row after a given row, you could do this:
table.scanAll(new Scan().withStartRow(row, false).setLimit(1)).thenAccept(results -> {
if (results.isEmpty()) {
System.out.println("No row after " + Bytes.toStringBinary(row));
} else {
System.out.println("The closest row after " + Bytes.toStringBinary(row) + " is "
+ Bytes.toStringBinary(results.stream().findFirst().get().getRow()));
}
});
If your result set is very large, you should use other scan method to get a scanner or use callback to process the results. They will do chunking to prevent OOM. The scanAll method will fetch all the results and store them in a List and then return the list to you.
The scan metrics will be collected background if you enable it but you have no way to get it.
Usually you can get scan metrics from ResultScanner, or through
ScanResultConsumer.onScanMetricsCreated but this method only returns a list of results.
So if you really care about scan metrics then you'd better use other scan methods which return
a ResultScanner or let you pass in a ScanResultConsumer. There is no
performance difference between these scan methods so do not worry.
scanAll in interface AsyncTable<ScanResultConsumer>scan - A configured Scan object. So if you use this method to fetch a really large
result set, it is likely to cause OOM.CompletableFuture.public ResultScanner getScanner(Scan scan)
AsyncTableScan object.getScanner in interface AsyncTable<ScanResultConsumer>scan - A configured Scan object.private void scan0(Scan scan, ScanResultConsumer consumer)
public void scan(Scan scan, ScanResultConsumer consumer)
AsyncTablescan in interface AsyncTable<ScanResultConsumer>scan - A configured Scan object.consumer - the consumer used to receive results.ScanResultConsumer,
AdvancedScanResultConsumerpublic List<CompletableFuture<Result>> get(List<Get> gets)
AsyncTable
Notice that you may not get all the results with this function, which means some of the
returned CompletableFutures may succeed while some of the other returned
CompletableFutures may fail.
get in interface AsyncTable<ScanResultConsumer>gets - The objects that specify what data to fetch and from which rows.CompletableFutures that represent the result for each get.public List<CompletableFuture<Void>> put(List<Put> puts)
AsyncTableput in interface AsyncTable<ScanResultConsumer>puts - The list of mutations to apply.CompletableFutures that represent the result for each put.public List<CompletableFuture<Void>> delete(List<Delete> deletes)
AsyncTabledelete in interface AsyncTable<ScanResultConsumer>deletes - list of things to delete.CompletableFutures that represent the result for each delete.public <T> List<CompletableFuture<T>> batch(List<? extends Row> actions)
AsyncTableAsyncTable.batch(java.util.List<? extends org.apache.hadoop.hbase.client.Row>) call, you will not necessarily be guaranteed that the Get returns what the
Put had put.batch in interface AsyncTable<ScanResultConsumer>actions - list of Get, Put, Delete, Increment, Append, and RowMutations objectsCompletableFutures that represent the result for each action.public <S,R> CompletableFuture<R> coprocessorService(Function<com.google.protobuf.RpcChannel,S> stubMaker, ServiceCaller<S,R> callable, byte[] row)
AsyncTablerow.
The stubMaker is just a delegation to the newStub call. Usually it is only a
one line lambda expression, like:
channel -> xxxService.newStub(channel)
coprocessorService in interface AsyncTable<ScanResultConsumer>S - the type of the asynchronous stubR - the type of the return valuestubMaker - a delegation to the actual newStub call.callable - a delegation to the actual protobuf rpc call. See the comment of
ServiceCaller for more details.row - The row key used to identify the remote region locationCompletableFuture.ServiceCallerpublic <S,R> AsyncTable.CoprocessorServiceBuilder<S,R> coprocessorService(Function<com.google.protobuf.RpcChannel,S> stubMaker, ServiceCaller<S,R> callable, AsyncTable.CoprocessorCallback<R> callback)
AsyncTable
Use the returned AsyncTable.CoprocessorServiceBuilder construct your request and then execute it.
The stubMaker is just a delegation to the xxxService.newStub call. Usually it
is only a one line lambda expression, like:
channel -> xxxService.newStub(channel)
coprocessorService in interface AsyncTable<ScanResultConsumer>stubMaker - a delegation to the actual newStub call.callable - a delegation to the actual protobuf rpc call. See the comment of
ServiceCaller for more details.callback - callback to get the response. See the comment of AsyncTable.CoprocessorCallback
for more details.Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.