HBASE-26688 Threads shared EMPTY_RESULT may lead to unexpected client job down. ...
[hbase.git] / hbase-client / src / main / java / org / apache / hadoop / hbase / client / AsyncAdminRequestRetryingCaller.java
blob7a381db39c828c4749ec9fbacf6b449f13a98208
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 static org.apache.hadoop.hbase.util.FutureUtils.addListener;
22 import java.io.IOException;
23 import java.util.concurrent.CompletableFuture;
24 import org.apache.hadoop.hbase.ServerName;
25 import org.apache.hadoop.hbase.ipc.HBaseRpcController;
26 import org.apache.yetus.audience.InterfaceAudience;
28 import org.apache.hbase.thirdparty.io.netty.util.Timer;
30 import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService;
32 /**
33 * @since 2.0.0
35 @InterfaceAudience.Private
36 public class AsyncAdminRequestRetryingCaller<T> extends AsyncRpcRetryingCaller<T> {
38 @FunctionalInterface
39 public interface Callable<T> {
40 CompletableFuture<T> call(HBaseRpcController controller, AdminService.Interface stub);
43 private final Callable<T> callable;
44 private ServerName serverName;
46 public AsyncAdminRequestRetryingCaller(Timer retryTimer, AsyncConnectionImpl conn, int priority,
47 long pauseNs, long pauseForCQTBENs, int maxAttempts, long operationTimeoutNs,
48 long rpcTimeoutNs, int startLogErrorsCnt, ServerName serverName, Callable<T> callable) {
49 super(retryTimer, conn, priority, pauseNs, pauseForCQTBENs, maxAttempts, operationTimeoutNs,
50 rpcTimeoutNs, startLogErrorsCnt);
51 this.serverName = serverName;
52 this.callable = callable;
55 @Override
56 protected void doCall() {
57 AdminService.Interface adminStub;
58 try {
59 adminStub = this.conn.getAdminStub(serverName);
60 } catch (IOException e) {
61 onError(e, () -> "Get async admin stub to " + serverName + " failed", err -> {
62 });
63 return;
65 resetCallTimeout();
66 addListener(callable.call(controller, adminStub), (result, error) -> {
67 if (error != null) {
68 onError(error, () -> "Call to admin stub failed", err -> {
69 });
70 return;
72 future.complete(result);
73 });