From e548b4e5053084202f737b00a5d3a372f8928356 Mon Sep 17 00:00:00 2001 From: wudongliang <46414265+DongLiang-0@users.noreply.github.com> Date: Thu, 15 Aug 2024 15:26:48 +0800 Subject: [PATCH] [fix] Fix doris backend connection via http does not take effect (#461) --- .../apache/doris/flink/sink/BackendUtil.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/flink-doris-connector/src/main/java/org/apache/doris/flink/sink/BackendUtil.java b/flink-doris-connector/src/main/java/org/apache/doris/flink/sink/BackendUtil.java index e043788b2..987ec9a1b 100644 --- a/flink-doris-connector/src/main/java/org/apache/doris/flink/sink/BackendUtil.java +++ b/flink-doris-connector/src/main/java/org/apache/doris/flink/sink/BackendUtil.java @@ -56,6 +56,7 @@ private List 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(); @@ -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;