Skip to content

Commit

Permalink
[fix] Fix doris backend connection via http does not take effect (apa…
Browse files Browse the repository at this point in the history
  • Loading branch information
DongLiang-0 authored Aug 15, 2024
1 parent 189fec3 commit e548b4e
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private List<BackendV2.BackendRowV2> initBackends(String beNodes) {
nodes.forEach(
node -> {
if (tryHttpConnection(node)) {
LOG.info("{} backend http connection success.", node);
node = node.trim();
String[] ipAndPort = node.split(":");
BackendRowV2 backendRowV2 = new BackendRowV2();
Expand Down Expand Up @@ -100,11 +101,22 @@ public static boolean tryHttpConnection(String host) {
LOG.debug("try to connect host {}", host);
host = "http://" + host;
URL url = new URL(host);
HttpURLConnection co = (HttpURLConnection) url.openConnection();
co.setConnectTimeout(60000);
co.connect();
co.disconnect();
return true;
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(60000);
connection.setReadTimeout(60000);
int responseCode = connection.getResponseCode();
String responseMessage = connection.getResponseMessage();
connection.disconnect();
if (200 == responseCode) {
return true;
}
LOG.warn(
"Failed to connect host {}, responseCode={}, msg={}",
host,
responseCode,
responseMessage);
return false;
} catch (Exception ex) {
LOG.warn("Failed to connect to host:{}", host, ex);
return false;
Expand Down

0 comments on commit e548b4e

Please sign in to comment.