HBASE-18420 Some methods of Admin don't use ColumnFamilyDescriptor
[hbase.git] / hbase-client / src / main / java / org / apache / hadoop / hbase / client / RawAsyncTable.java
blob4a916d3fca39750de4f2e7468e49ad5c720ec845
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.client;
20 import com.google.protobuf.RpcCallback;
21 import com.google.protobuf.RpcChannel;
22 import com.google.protobuf.RpcController;
24 import java.util.concurrent.CompletableFuture;
25 import java.util.function.Function;
27 import org.apache.hadoop.hbase.HRegionInfo;
28 import org.apache.hadoop.hbase.classification.InterfaceAudience;
30 /**
31 * A low level asynchronous table.
32 * <p>
33 * The implementation is required to be thread safe.
34 * <p>
35 * The returned {@code CompletableFuture} will be finished directly in the rpc framework's callback
36 * thread, so typically you should not do any time consuming work inside these methods, otherwise
37 * you will be likely to block at least one connection to RS(even more if the rpc framework uses
38 * NIO).
39 * <p>
40 * So, only experts that want to build high performance service should use this interface directly,
41 * especially for the {@link #scan(Scan, RawScanResultConsumer)} below.
42 * <p>
43 * TODO: For now the only difference between this interface and {@link AsyncTable} is the scan
44 * method. The {@link RawScanResultConsumer} exposes the implementation details of a scan(heartbeat)
45 * so it is not suitable for a normal user. If it is still the only difference after we implement
46 * most features of AsyncTable, we can think about merge these two interfaces.
48 @InterfaceAudience.Public
49 public interface RawAsyncTable extends AsyncTableBase {
51 /**
52 * The basic scan API uses the observer pattern. All results that match the given scan object will
53 * be passed to the given {@code consumer} by calling {@code RawScanResultConsumer.onNext}.
54 * {@code RawScanResultConsumer.onComplete} means the scan is finished, and
55 * {@code RawScanResultConsumer.onError} means we hit an unrecoverable error and the scan is
56 * terminated. {@code RawScanResultConsumer.onHeartbeat} means the RS is still working but we can
57 * not get a valid result to call {@code RawScanResultConsumer.onNext}. This is usually because
58 * the matched results are too sparse, for example, a filter which almost filters out everything
59 * is specified.
60 * <p>
61 * Notice that, the methods of the given {@code consumer} will be called directly in the rpc
62 * framework's callback thread, so typically you should not do any time consuming work inside
63 * these methods, otherwise you will be likely to block at least one connection to RS(even more if
64 * the rpc framework uses NIO).
65 * @param scan A configured {@link Scan} object.
66 * @param consumer the consumer used to receive results.
68 void scan(Scan scan, RawScanResultConsumer consumer);
70 /**
71 * Delegate to a protobuf rpc call.
72 * <p>
73 * Usually, it is just a simple lambda expression, like:
75 * <pre>
76 * <code>
77 * (stub, controller, rpcCallback) -> {
78 * XXXRequest request = ...; // prepare the request
79 * stub.xxx(controller, request, rpcCallback);
80 * }
81 * </code>
82 * </pre>
84 * And if you can prepare the {@code request} before calling the coprocessorService method, the
85 * lambda expression will be:
87 * <pre>
88 * <code>
89 * (stub, controller, rpcCallback) -> stub.xxx(controller, request, rpcCallback)
90 * </code>
91 * </pre>
93 @InterfaceAudience.Public
94 @FunctionalInterface
95 interface CoprocessorCallable<S, R> {
97 /**
98 * Represent the actual protobuf rpc call.
99 * @param stub the asynchronous stub
100 * @param controller the rpc controller, has already been prepared for you
101 * @param rpcCallback the rpc callback, has already been prepared for you
103 void call(S stub, RpcController controller, RpcCallback<R> rpcCallback);
107 * Execute the given coprocessor call on the region which contains the given {@code row}.
108 * <p>
109 * The {@code stubMaker} is just a delegation to the {@code newStub} call. Usually it is only a
110 * one line lambda expression, like:
112 * <pre>
113 * <code>
114 * channel -> xxxService.newStub(channel)
115 * </code>
116 * </pre>
118 * @param stubMaker a delegation to the actual {@code newStub} call.
119 * @param callable a delegation to the actual protobuf rpc call. See the comment of
120 * {@link CoprocessorCallable} for more details.
121 * @param row The row key used to identify the remote region location
122 * @param <S> the type of the asynchronous stub
123 * @param <R> the type of the return value
124 * @return the return value of the protobuf rpc call, wrapped by a {@link CompletableFuture}.
125 * @see CoprocessorCallable
127 <S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker,
128 CoprocessorCallable<S, R> callable, byte[] row);
131 * The callback when we want to execute a coprocessor call on a range of regions.
132 * <p>
133 * As the locating itself also takes some time, the implementation may want to send rpc calls on
134 * the fly, which means we do not know how many regions we have when we get the return value of
135 * the rpc calls, so we need an {@link #onComplete()} which is used to tell you that we have
136 * passed all the return values to you(through the {@link #onRegionComplete(HRegionInfo, Object)}
137 * or {@link #onRegionError(HRegionInfo, Throwable)} calls), i.e, there will be no
138 * {@link #onRegionComplete(HRegionInfo, Object)} or
139 * {@link #onRegionError(HRegionInfo, Throwable)} calls in the future.
140 * <p>
141 * Here is a pseudo code to describe a typical implementation of a range coprocessor service
142 * method to help you better understand how the {@link CoprocessorCallback} will be called. The
143 * {@code callback} in the pseudo code is our {@link CoprocessorCallback}. And notice that the
144 * {@code whenComplete} is {@code CompletableFuture.whenComplete}.
146 * <pre>
147 * locateThenCall(byte[] row) {
148 * locate(row).whenComplete((location, locateError) -> {
149 * if (locateError != null) {
150 * callback.onError(locateError);
151 * return;
153 * incPendingCall();
154 * region = location.getRegion();
155 * if (region.getEndKey() > endKey) {
156 * locateEnd = true;
157 * } else {
158 * locateThenCall(region.getEndKey());
160 * sendCall().whenComplete((resp, error) -> {
161 * if (error != null) {
162 * callback.onRegionError(region, error);
163 * } else {
164 * callback.onRegionComplete(region, resp);
166 * if (locateEnd && decPendingCallAndGet() == 0) {
167 * callback.onComplete();
169 * });
170 * });
172 * </pre>
174 @InterfaceAudience.Public
175 interface CoprocessorCallback<R> {
178 * @param region the region that the response belongs to
179 * @param resp the response of the coprocessor call
181 void onRegionComplete(HRegionInfo region, R resp);
184 * @param region the region that the error belongs to
185 * @param error the response error of the coprocessor call
187 void onRegionError(HRegionInfo region, Throwable error);
190 * Indicate that all responses of the regions have been notified by calling
191 * {@link #onRegionComplete(HRegionInfo, Object)} or
192 * {@link #onRegionError(HRegionInfo, Throwable)}.
194 void onComplete();
197 * Indicate that we got an error which does not belong to any regions. Usually a locating error.
199 void onError(Throwable error);
203 * Execute the given coprocessor call on the regions which are covered by the range from
204 * {@code startKey} inclusive and {@code endKey} exclusive. See the comment of
205 * {@link #coprocessorService(Function, CoprocessorCallable, byte[], boolean, byte[], boolean, CoprocessorCallback)}
206 * for more details.
207 * @see #coprocessorService(Function, CoprocessorCallable, byte[], boolean, byte[], boolean,
208 * CoprocessorCallback)
210 default <S, R> void coprocessorService(Function<RpcChannel, S> stubMaker,
211 CoprocessorCallable<S, R> callable, byte[] startKey, byte[] endKey,
212 CoprocessorCallback<R> callback) {
213 coprocessorService(stubMaker, callable, startKey, true, endKey, false, callback);
217 * Execute the given coprocessor call on the regions which are covered by the range from
218 * {@code startKey} and {@code endKey}. The inclusive of boundaries are specified by
219 * {@code startKeyInclusive} and {@code endKeyInclusive}. The {@code stubMaker} is just a
220 * delegation to the {@code xxxService.newStub} call. Usually it is only a one line lambda
221 * expression, like:
223 * <pre>
224 * <code>
225 * channel -> xxxService.newStub(channel)
226 * </code>
227 * </pre>
229 * @param stubMaker a delegation to the actual {@code newStub} call.
230 * @param callable a delegation to the actual protobuf rpc call. See the comment of
231 * {@link CoprocessorCallable} for more details.
232 * @param startKey start region selection with region containing this row. If {@code null}, the
233 * selection will start with the first table region.
234 * @param startKeyInclusive whether to include the startKey
235 * @param endKey select regions up to and including the region containing this row. If
236 * {@code null}, selection will continue through the last table region.
237 * @param endKeyInclusive whether to include the endKey
238 * @param callback callback to get the response. See the comment of {@link CoprocessorCallback}
239 * for more details.
240 * @param <S> the type of the asynchronous stub
241 * @param <R> the type of the return value
242 * @see CoprocessorCallable
243 * @see CoprocessorCallback
245 <S, R> void coprocessorService(Function<RpcChannel, S> stubMaker,
246 CoprocessorCallable<S, R> callable, byte[] startKey, boolean startKeyInclusive, byte[] endKey,
247 boolean endKeyInclusive, CoprocessorCallback<R> callback);