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: dailidong <dailidong66@gmail.com> Co-authored-by: qiaozhanwei <qiaozhanwei@outlook.com>dev-131
parent
a23a3e2d12
commit
d87d2d80dd
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
#zookeeper.retry.maxtime=10
|
||||
#zookeeper.max.wait.time=10000
|
||||
Loading…
Reference in New Issue