未验证 提交 d87d2d80 编写于 作者: T tswstarplanet 提交者: GitHub

add maxWaitTime config when build zookeeper client (#3133)

* add maxWaitTime config when build zookeeper client

* throw exception when connect zk timeout

* use dedicated exception instead of a generic one
Co-authored-by: Ndailidong <dailidong66@gmail.com>
Co-authored-by: Nqiaozhanwei <qiaozhanwei@outlook.com>
上级 a23a3e2d
......@@ -52,6 +52,9 @@ public class ZookeeperConfig {
@Value("${zookeeper.dolphinscheduler.root:/dolphinscheduler}")
private String dsRoot;
@Value("${zookeeper.max.wait.time:10000}")
private int maxWaitTime;
public String getServerList() {
return serverList;
}
......@@ -115,4 +118,12 @@ public class ZookeeperConfig {
public void setDsRoot(String dsRoot) {
this.dsRoot = dsRoot;
}
public int getMaxWaitTime() {
return maxWaitTime;
}
public void setMaxWaitTime(int maxWaitTime) {
this.maxWaitTime = maxWaitTime;
}
}
\ No newline at end of file
......@@ -37,6 +37,7 @@ import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.apache.dolphinscheduler.common.utils.Preconditions.checkNotNull;
......@@ -109,7 +110,9 @@ public class ZookeeperOperator implements InitializingBean {
zkClient = builder.build();
zkClient.start();
try {
zkClient.blockUntilConnected();
if (!zkClient.blockUntilConnected(zookeeperConfig.getMaxWaitTime(), TimeUnit.MILLISECONDS)) {
throw new IllegalStateException("Connect zookeeper expire max wait time");
}
} catch (final Exception ex) {
throw new RuntimeException(ex);
}
......
......@@ -26,4 +26,5 @@ zookeeper.quorum=localhost:2181
#zookeeper.connection.timeout=30000
#zookeeper.retry.base.sleep=100
#zookeeper.retry.max.sleep=30000
#zookeeper.retry.maxtime=10
\ No newline at end of file
#zookeeper.retry.maxtime=10
#zookeeper.max.wait.time=10000
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册