@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.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.
|
<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. |
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.
|
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, wait
batchAll, deleteAll, exists, exists, existsAll, getAll, getScanner, getScanner, incrementColumnValue, incrementColumnValue, putAll
private final AsyncTable<AdvancedScanResultConsumer> rawTable
private final ExecutorService pool
AsyncTableImpl(AsyncConnectionImpl conn, AsyncTable<AdvancedScanResultConsumer> rawTable, ExecutorService pool)
public TableName getName()
AsyncTable
getName
in interface AsyncTable<ScanResultConsumer>
public org.apache.hadoop.conf.Configuration getConfiguration()
AsyncTable
Configuration
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 long getRpcTimeout(TimeUnit unit)
AsyncTable
getRpcTimeout
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)
AsyncTable
getReadRpcTimeout
in interface AsyncTable<ScanResultConsumer>
unit
- the unit of time the timeout to be represented inpublic long getWriteRpcTimeout(TimeUnit unit)
AsyncTable
getWriteRpcTimeout
in interface AsyncTable<ScanResultConsumer>
unit
- the unit of time the timeout to be represented inpublic long getOperationTimeout(TimeUnit unit)
AsyncTable
getOperationTimeout
in interface AsyncTable<ScanResultConsumer>
unit
- the unit of time the timeout to be represented inpublic long getScanTimeout(TimeUnit unit)
AsyncTable
getScanTimeout
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)
AsyncTable
get
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)
AsyncTable
put
in interface AsyncTable<ScanResultConsumer>
put
- The data to put.CompletableFuture
that always returns null when complete normally.public CompletableFuture<Void> delete(Delete delete)
AsyncTable
delete
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)
AsyncTable
This 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)
AsyncTable
This 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 CompletableFuture<Void> mutateRow(RowMutations mutation)
AsyncTable
mutateRow
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)
AsyncTable
Scan
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)
AsyncTable
scan
in interface AsyncTable<ScanResultConsumer>
scan
- A configured Scan
object.consumer
- the consumer used to receive results.ScanResultConsumer
,
AdvancedScanResultConsumer
public 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 CompletableFuture
s may succeed while some of the other returned
CompletableFuture
s may fail.
get
in interface AsyncTable<ScanResultConsumer>
gets
- The objects that specify what data to fetch and from which rows.CompletableFuture
s that represent the result for each get.public List<CompletableFuture<Void>> put(List<Put> puts)
AsyncTable
put
in interface AsyncTable<ScanResultConsumer>
puts
- The list of mutations to apply.CompletableFuture
s that represent the result for each put.public List<CompletableFuture<Void>> delete(List<Delete> deletes)
AsyncTable
delete
in interface AsyncTable<ScanResultConsumer>
deletes
- list of things to delete.CompletableFuture
s that represent the result for each delete.public <T> List<CompletableFuture<T>> batch(List<? extends Row> actions)
AsyncTable
AsyncTable.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 objectsCompletableFuture
s 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)
AsyncTable
row
.
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
.ServiceCaller
public <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–2019 The Apache Software Foundation. All rights reserved.