You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by zj...@apache.org on 2020/09/08 03:12:26 UTC
[zeppelin] branch master updated: [ZEPPELIN-5017]. Add retry in
PooledRemoteClient
This is an automated email from the ASF dual-hosted git repository.
zjffdu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new 621e257 [ZEPPELIN-5017]. Add retry in PooledRemoteClient
621e257 is described below
commit 621e2579d4a69b6837619ae3a4a130eb314c6fcd
Author: Jeff Zhang <zj...@apache.org>
AuthorDate: Wed Aug 26 14:34:13 2020 +0800
[ZEPPELIN-5017]. Add retry in PooledRemoteClient
### What is this PR for?
Trivial PR to add retry in PooledRemoteClient in case there's some network issue.
### What type of PR is it?
[Improvement ]
### Todos
* [ ] - Task
### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-5017
### How should this be tested?
* CI pass
### Screenshots (if appropriate)
### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
Author: Jeff Zhang <zj...@apache.org>
Closes #3890 from zjffdu/ZEPPELIN-5017 and squashes the following commits:
b964b884a [Jeff Zhang] add retry
13cbde46b [Jeff Zhang] [ZEPPELIN-5017]. Add retry in PooledRemoteClient
---
.../interpreter/remote/PooledRemoteClient.java | 35 +++++++++++++---------
1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/PooledRemoteClient.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/PooledRemoteClient.java
index a219036..7d5a764 100644
--- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/PooledRemoteClient.java
+++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/PooledRemoteClient.java
@@ -33,6 +33,7 @@ import org.slf4j.LoggerFactory;
public class PooledRemoteClient<T extends TServiceClient> {
private static final Logger LOGGER = LoggerFactory.getLogger(PooledRemoteClient.class);
+ private static final int RETRY_COUNT = 3;
private GenericObjectPool<T> clientPool;
private RemoteClientFactory<T> remoteClientFactory;
@@ -83,23 +84,29 @@ public class PooledRemoteClient<T extends TServiceClient> {
}
public <R> R callRemoteFunction(RemoteFunction<R, T> func) {
- T client = null;
boolean broken = false;
- try {
- client = getClient();
- if (client != null) {
- return func.call(client);
- }
- } catch (TException e) {
- broken = true;
- throw new RuntimeException(e);
- } catch (Exception e1) {
- throw new RuntimeException(e1);
- } finally {
- if (client != null) {
- releaseClient(client, broken);
+ for (int i = 0;i < RETRY_COUNT; ++ i) {
+ T client = null;
+ broken = false;
+ try {
+ client = getClient();
+ if (client != null) {
+ return func.call(client);
+ }
+ } catch (TException e) {
+ broken = true;
+ continue;
+ } catch (Exception e1) {
+ throw new RuntimeException(e1);
+ } finally {
+ if (client != null) {
+ releaseClient(client, broken);
+ }
}
}
+ if (broken) {
+ throw new RuntimeException("Fail to callRemoteFunction, because connection is broken");
+ }
return null;
}