JNSimba commented on code in PR #187: URL: https://github.com/apache/doris-flink-connector/pull/187#discussion_r1308248781
########## flink-doris-connector/src/main/java/org/apache/doris/flink/sink/BackendUtil.java: ########## @@ -19,30 +19,55 @@ import org.apache.doris.flink.exception.DorisRuntimeException; import org.apache.doris.flink.rest.models.BackendV2; +import org.apache.doris.flink.rest.models.BackendV2.BackendRowV2; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.net.HttpURLConnection; import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class BackendUtil { private static final Logger LOG = LoggerFactory.getLogger(BackendUtil.class); - private final List<BackendV2.BackendRowV2> backends; + private List<BackendV2.BackendRowV2> backends; private long pos; public BackendUtil(List<BackendV2.BackendRowV2> backends) { this.backends = backends; this.pos = 0; } + public BackendUtil(String beNodes) { + this.backends = initBackends(beNodes); + this.pos = 0; + } + + public List<BackendV2.BackendRowV2> initBackends(String beNodes) { + List<BackendV2.BackendRowV2> backends = new ArrayList<>(); + List<String> nodes = Arrays.asList(beNodes.split(",")); + nodes.forEach(node -> { + if (tryHttpConnection(node)) { + node = node.trim(); + String[] ipAndPort = node.split(":"); + BackendRowV2 backendRowV2 = new BackendRowV2(); + backendRowV2.setIp(ipAndPort[0]); + backendRowV2.setHttpPort(Integer.parseInt(ipAndPort[1])); + backendRowV2.setAlive(true); + backends.add(backendRowV2); + } + }); + return backends; + } + public String getAvailableBackend() { long tmp = pos + backends.size(); while (pos < tmp) { - BackendV2.BackendRowV2 backend = backends.get((int) (pos % backends.size())); + BackendV2.BackendRowV2 backend = backends.get((int) (pos++ % backends.size())); Review Comment: There might be a problem here, because tryHttpConnection function alse has pos++ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org