Class AsyncTableImpl
- All Implemented Interfaces:
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.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.hadoop.hbase.client.AsyncTable
AsyncTable.CheckAndMutateBuilder, AsyncTable.CheckAndMutateWithFilterBuilder, AsyncTable.CoprocessorCallback<R>, AsyncTable.CoprocessorServiceBuilder<S,
R> -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAppends values to one or more columns within a single row.<T> List<CompletableFuture<T>>
Method that does a batch call on Deletes, Gets, Puts, Increments, Appends and RowMutations.checkAndMutate
(byte[] row, byte[] family) Atomically checks if a row/family/qualifier value matches the expected value.checkAndMutate
(byte[] row, Filter filter) Atomically checks if a row matches the specified filter.checkAndMutate
(List<CheckAndMutate> checkAndMutates) Batch version of checkAndMutate.checkAndMutate
(CheckAndMutate checkAndMutate) checkAndMutate that atomically checks if a row matches the specified condition.<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 givenrow
.<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.Deletes the specified cells/rows in bulk.Deletes the specified cells/row.Extracts certain cells from the given rows, in batch.Extracts certain cells from a given row.org.apache.hadoop.conf.Configuration
Returns theConfiguration
object used by this instance.Gets theTableDescriptor
for this table.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.Gets theAsyncTableRegionLocator
for this table.Get the map of request attributeslong
getRpcTimeout
(TimeUnit unit) Get timeout of each rpc request in this Table instance.getScanner
(Scan scan) Returns a scanner on the current table as specified by theScan
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.Increments one or more columns within a single row.mutateRow
(RowMutations mutation) Performs multiple mutations atomically on a single row.Puts some data in the table, in batch.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) Return all the results that match the given scan object.private <T> CompletableFuture<T>
wrap
(CompletableFuture<T> future) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.hadoop.hbase.client.AsyncTable
batchAll, checkAndMutateAll, deleteAll, exists, exists, existsAll, getAll, getScanner, getScanner, incrementColumnValue, incrementColumnValue, putAll
-
Field Details
-
rawTable
-
pool
-
-
Constructor Details
-
AsyncTableImpl
AsyncTableImpl(RawAsyncTableImpl rawTable, ExecutorService pool)
-
-
Method Details
-
getName
Description copied from interface:AsyncTable
Gets the fully qualified table name instance of this table.- Specified by:
getName
in interfaceAsyncTable<ScanResultConsumer>
-
getConfiguration
Description copied from interface:AsyncTable
Returns theConfiguration
object used by this instance.The reference returned is not a copy, so any change made to it will affect this instance.
- Specified by:
getConfiguration
in interfaceAsyncTable<ScanResultConsumer>
-
getDescriptor
Description copied from interface:AsyncTable
Gets theTableDescriptor
for this table.- Specified by:
getDescriptor
in interfaceAsyncTable<ScanResultConsumer>
-
getRegionLocator
Description copied from interface:AsyncTable
Gets theAsyncTableRegionLocator
for this table.- Specified by:
getRegionLocator
in interfaceAsyncTable<ScanResultConsumer>
-
getRpcTimeout
Description copied from interface:AsyncTable
Get timeout of each rpc request in this Table instance. It will be overridden by a more specific rpc timeout config such as readRpcTimeout or writeRpcTimeout.- Specified by:
getRpcTimeout
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
unit
- the unit of time the timeout to be represented in- Returns:
- rpc timeout in the specified time unit
- See Also:
-
getReadRpcTimeout
Description copied from interface:AsyncTable
Get timeout of each rpc read request in this Table instance.- Specified by:
getReadRpcTimeout
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
unit
- the unit of time the timeout to be represented in- Returns:
- read rpc timeout in the specified time unit
-
getWriteRpcTimeout
Description copied from interface:AsyncTable
Get timeout of each rpc write request in this Table instance.- Specified by:
getWriteRpcTimeout
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
unit
- the unit of time the timeout to be represented in- Returns:
- write rpc timeout in the specified time unit
-
getOperationTimeout
Description copied from interface:AsyncTable
Get timeout of each operation in Table instance.- Specified by:
getOperationTimeout
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
unit
- the unit of time the timeout to be represented in- Returns:
- operation rpc timeout in the specified time unit
-
getScanTimeout
Description copied from interface:AsyncTable
Get the timeout of a single operation in a scan. It works like operation timeout for other operations.- Specified by:
getScanTimeout
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
unit
- the unit of time the timeout to be represented in- Returns:
- scan rpc timeout in the specified time unit
-
getRequestAttributes
Description copied from interface:AsyncTable
Get the map of request attributes- Specified by:
getRequestAttributes
in interfaceAsyncTable<ScanResultConsumer>
- Returns:
- a map of request attributes supplied by the client
-
wrap
-
get
Description copied from interface:AsyncTable
Extracts certain cells from a given row.- Specified by:
get
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
get
- The object that specifies what data to fetch and from which row.- Returns:
- The data coming from the specified row, if it exists. If the row specified doesn't
exist, the
Result
instance returned won't contain anyKeyValue
, as indicated byResult.isEmpty()
. The return value will be wrapped by aCompletableFuture
.
-
put
Description copied from interface:AsyncTable
Puts some data to the table.- Specified by:
put
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
put
- The data to put.- Returns:
- A
CompletableFuture
that always returns null when complete normally.
-
delete
Description copied from interface:AsyncTable
Deletes the specified cells/row.- Specified by:
delete
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
delete
- The object that specifies what to delete.- Returns:
- A
CompletableFuture
that always returns null when complete normally.
-
append
Description copied from interface:AsyncTable
Appends values to one or more columns within a single row.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.
- Specified by:
append
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
append
- object that specifies the columns and amounts to be used for the increment operations- Returns:
- values of columns after the append operation (maybe null). The return value will be
wrapped by a
CompletableFuture
.
-
increment
Description copied from interface:AsyncTable
Increments one or more columns within a single row.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.
- Specified by:
increment
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
increment
- object that specifies the columns and amounts to be used for the increment operations- Returns:
- values of columns after the increment. The return value will be wrapped by a
CompletableFuture
.
-
checkAndMutate
Description copied from interface:AsyncTable
Atomically checks if a row/family/qualifier value matches the expected value. If it does, it adds the Put/Delete/RowMutations.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"); } });
- Specified by:
checkAndMutate
in interfaceAsyncTable<ScanResultConsumer>
-
checkAndMutate
Description copied from interface:AsyncTable
Atomically checks if a row matches the specified filter. If it does, it adds the Put/Delete/RowMutations.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"); } });
- Specified by:
checkAndMutate
in interfaceAsyncTable<ScanResultConsumer>
-
checkAndMutate
Description copied from interface:AsyncTable
checkAndMutate that atomically checks if a row matches the specified condition. If it does, it performs the specified action.- Specified by:
checkAndMutate
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
checkAndMutate
- The CheckAndMutate object.- Returns:
- A
CompletableFuture
s that represent the result for the CheckAndMutate.
-
checkAndMutate
public List<CompletableFuture<CheckAndMutateResult>> checkAndMutate(List<CheckAndMutate> checkAndMutates) Description copied from interface:AsyncTable
Batch version of checkAndMutate. The specified CheckAndMutates are batched only in the sense that they are sent to a RS in one RPC, but each CheckAndMutate operation is still executed atomically (and thus, each may fail independently of others).- Specified by:
checkAndMutate
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
checkAndMutates
- The list of CheckAndMutate.- Returns:
- A list of
CompletableFuture
s that represent the result for each CheckAndMutate.
-
mutateRow
Description copied from interface:AsyncTable
- Specified by:
mutateRow
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
mutation
- object that specifies the set of mutations to perform atomically- Returns:
- A
CompletableFuture
that returns results of Increment/Append operations
-
scanAll
Description copied from interface:AsyncTable
Return all the results that match the given scan object.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 throughScanResultConsumer.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 aResultScanner
or let you pass in aScanResultConsumer
. There is no performance difference between these scan methods so do not worry.- Specified by:
scanAll
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
scan
- A configuredScan
object. So if you use this method to fetch a really large result set, it is likely to cause OOM.- Returns:
- The results of this small scan operation. The return value will be wrapped by a
CompletableFuture
.
-
getScanner
Description copied from interface:AsyncTable
Returns a scanner on the current table as specified by theScan
object.- Specified by:
getScanner
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
scan
- A configuredScan
object.- Returns:
- A scanner.
-
scan0
-
scan
Description copied from interface:AsyncTable
The scan API uses the observer pattern.- Specified by:
scan
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
scan
- A configuredScan
object.consumer
- the consumer used to receive results.- See Also:
-
get
Description copied from interface:AsyncTable
Extracts certain cells from the given rows, in batch.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 returnedCompletableFuture
s may fail.- Specified by:
get
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
gets
- The objects that specify what data to fetch and from which rows.- Returns:
- A list of
CompletableFuture
s that represent the result for each get.
-
put
Description copied from interface:AsyncTable
Puts some data in the table, in batch.- Specified by:
put
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
puts
- The list of mutations to apply.- Returns:
- A list of
CompletableFuture
s that represent the result for each put.
-
delete
Description copied from interface:AsyncTable
Deletes the specified cells/rows in bulk.- Specified by:
delete
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
deletes
- list of things to delete.- Returns:
- A list of
CompletableFuture
s that represent the result for each delete.
-
batch
Description copied from interface:AsyncTable
Method that does a batch call on Deletes, Gets, Puts, Increments, Appends and RowMutations. The ordering of execution of the actions is not defined. Meaning if you do a Put and a Get in the sameAsyncTable.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.- Specified by:
batch
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
actions
- list of Get, Put, Delete, Increment, Append, and RowMutations objects- Returns:
- A list of
CompletableFuture
s that represent the result for each action.
-
coprocessorService
public <S,R> CompletableFuture<R> coprocessorService(Function<com.google.protobuf.RpcChannel, S> stubMaker, ServiceCaller<S, R> callable, byte[] row) Description copied from interface:AsyncTable
Execute the given coprocessor call on the region which contains the givenrow
.The
stubMaker
is just a delegation to thenewStub
call. Usually it is only a one line lambda expression, like:channel -> xxxService.newStub(channel)
- Specified by:
coprocessorService
in interfaceAsyncTable<ScanResultConsumer>
- Type Parameters:
S
- the type of the asynchronous stubR
- the type of the return value- Parameters:
stubMaker
- a delegation to the actualnewStub
call.callable
- a delegation to the actual protobuf rpc call. See the comment ofServiceCaller
for more details.row
- The row key used to identify the remote region location- Returns:
- the return value of the protobuf rpc call, wrapped by a
CompletableFuture
. - See Also:
-
coprocessorService
public <S,R> AsyncTable.CoprocessorServiceBuilder<S,R> coprocessorService(Function<com.google.protobuf.RpcChannel, S> stubMaker, ServiceCaller<S, R> callable, AsyncTable.CoprocessorCallback<R> callback) Description copied from interface:AsyncTable
Execute a coprocessor call on the regions which are covered by a range.Use the returned
AsyncTable.CoprocessorServiceBuilder
construct your request and then execute it.The
stubMaker
is just a delegation to thexxxService.newStub
call. Usually it is only a one line lambda expression, like:channel -> xxxService.newStub(channel)
- Specified by:
coprocessorService
in interfaceAsyncTable<ScanResultConsumer>
- Parameters:
stubMaker
- a delegation to the actualnewStub
call.callable
- a delegation to the actual protobuf rpc call. See the comment ofServiceCaller
for more details.callback
- callback to get the response. See the comment ofAsyncTable.CoprocessorCallback
for more details.
-