You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "diggle1 (via GitHub)" <gi...@apache.org> on 2026/05/13 02:59:58 UTC
[PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and s… [doris-kafka-connector]
diggle1 opened a new pull request, #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99
Previously DorisStreamLoad / AsyncDorisStreamLoad / DorisCommitter
called BackendUtils.getAvailableBackend() before every stream load,
which round-robined all BEs and ran tryHttpConnection() on each one
with a hard-coded 60s connect timeout. On a hot write path this added
unnecessary HTTP probes per request, and a single unreachable BE could
block writes for up to 60s per node.
Changes:
- BackendUtils: add a TTL cache for the picked backend with double-checked
locking; expose invalidateCache() so callers can drop the cache after a
failure. Shorten the default probe timeout from 60s to 5s and apply it to
both connect and read timeouts; ensure the HttpURLConnection is always
disconnected.
- DorisStreamLoad / AsyncDorisStreamLoad: invalidate the cached backend on
load failure so the next attempt re-probes and may pick another BE.
- DorisCommitter: invalidate the cache before re-selecting a BE on commit
failure to avoid sticking to the failing node.
- DorisOptions / DorisSinkConnectorConfig: add two new config options,
backend.cache.ttl.ms (default 60000, 0 disables the cache) and
backend.probe.timeout.ms (default 5000), both backward compatible.
- Add BackendUtilsTest covering cache hit, TTL expiry, invalidateCache,
ttl=0 disabling the cache, multi-BE selection and the short probe
timeout.
--
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-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and shorten probe timeout [doris-kafka-connector]
Posted by "diggle1 (via GitHub)" <gi...@apache.org>.
diggle1 commented on code in PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#discussion_r3663956637
##########
src/main/java/org/apache/doris/kafka/connector/utils/BackendUtils.java:
##########
@@ -43,18 +52,47 @@ public static BackendUtils getInstance(DorisOptions dorisOptions, Logger logger)
return new BackendUtils(RestService.getBackendsV2(dorisOptions, logger));
}
+ /**
+ * Pick a usable backend via round-robin so load is balanced across BEs. A BE that was recently
+ * probed alive skips the HTTP probe within {@link #PROBE_CACHE_TTL_MS}.
+ */
public String getAvailableBackend() {
long tmp = pos + backends.size();
while (pos < tmp) {
BackendV2.BackendRowV2 backend = backends.get((int) (pos++ % backends.size()));
String res = backend.toBackendString();
+ if (isRecentlyAlive(res)) {
+ return res;
+ }
if (tryHttpConnection(res)) {
+ aliveProbeAtNanos.put(res, System.nanoTime());
return res;
}
+ aliveProbeAtNanos.remove(res);
}
+ invalidateCache();
throw new DorisException("no available backend.");
}
+ /**
+ * Clear cached probe results. Callers should invoke this after a stream load / commit failure
+ * so the next {@link #getAvailableBackend()} re-probes instead of trusting a stale result.
+ */
+ public void invalidateCache() {
+ if (!aliveProbeAtNanos.isEmpty()) {
+ LOG.info("Invalidate doris backend probe cache, size={}", aliveProbeAtNanos.size());
+ }
+ aliveProbeAtNanos.clear();
+ }
+
+ private boolean isRecentlyAlive(String backend) {
+ Long probedAt = aliveProbeAtNanos.get(backend);
+ if (probedAt == null) {
+ return false;
+ }
+ return (System.nanoTime() - probedAt) / 1_000_000L < PROBE_CACHE_TTL_MS;
+ }
+
public static boolean tryHttpConnection(String backend) {
try {
backend = "http://" + backend;
Review Comment:
Shortening the probe timeout is out of scope for this PR — tryHttpConnection() is intentionally unchanged from master (still 60s). Happy to follow up in a separate PR if we want a shorter / configurable timeout.
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and s… [doris-kafka-connector]
Posted by "diggle1 (via GitHub)" <gi...@apache.org>.
diggle1 commented on code in PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#discussion_r3232084986
##########
src/main/java/org/apache/doris/kafka/connector/utils/BackendUtils.java:
##########
@@ -56,17 +111,25 @@ public String getAvailableBackend() {
}
public static boolean tryHttpConnection(String backend) {
+ HttpURLConnection co = null;
try {
- backend = "http://" + backend;
- URL url = new URL(backend);
- HttpURLConnection co = (HttpURLConnection) url.openConnection();
- co.setConnectTimeout(60000);
+ URL url = new URL("http://" + backend);
+ co = (HttpURLConnection) url.openConnection();
+ co.setConnectTimeout(PROBE_TIMEOUT_MS);
Review Comment:
Agree, will keep the existing timeout settings.
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and s… [doris-kafka-connector]
Posted by "diggle1 (via GitHub)" <gi...@apache.org>.
diggle1 commented on PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#issuecomment-4437205724
> @diggle1 Thanks for your contribution~ The code implementation is somewhat complex, and the two configurations of `connector` you added pose a high learning curve for users. I think it would be better to use internal constants for the cache expiration time of `be` without adding additional configurations.
@rnb-tron
Thanks for the review!
Makes sense — I'll simplify the change by:
Removing the two new configs (backend.cache.ttl.ms and backend.probe.timeout.ms) and using internal constants in BackendUtils instead (planned defaults: cache TTL = 60s, probe connect timeout = 5s, down from the previous hard-coded 60s).
Inlining the cache logic so BackendUtils stays small — keep getAvailableBackend() / invalidateCache() as the only public surface change, and revert DorisOptions / DorisSinkConnectorConfig to their original state.
Keeping the invalidateCache() calls on stream-load / commit failure so a bad BE is dropped from the cache immediately.
Please let me know if the default TTL / probe timeout values look reasonable to you, or if you'd prefer different numbers. I'll push an updated commit shortly.
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and s… [doris-kafka-connector]
Posted by "diggle1 (via GitHub)" <gi...@apache.org>.
diggle1 commented on code in PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#discussion_r3232079524
##########
src/main/java/org/apache/doris/kafka/connector/utils/BackendUtils.java:
##########
@@ -43,7 +54,51 @@ public static BackendUtils getInstance(DorisOptions dorisOptions, Logger logger)
return new BackendUtils(RestService.getBackendsV2(dorisOptions, logger));
}
+ /**
+ * Pick a usable backend. The previously chosen backend is reused while it is still within the
+ * cache TTL, so the hot write path does not pay for an HTTP probe on every call. When the cache
+ * is empty/expired we fall back to the round-robin probe behaviour.
+ */
public String getAvailableBackend() {
+ String cached = cachedBackend;
+ if (cached != null && !isCacheExpired()) {
+ return cached;
+ }
+
+ synchronized (lock) {
Review Comment:
You're right. Since this only runs in a single thread, the lock is unnecessary. I'll remove it.
##########
src/main/java/org/apache/doris/kafka/connector/utils/BackendUtils.java:
##########
@@ -43,7 +54,51 @@ public static BackendUtils getInstance(DorisOptions dorisOptions, Logger logger)
return new BackendUtils(RestService.getBackendsV2(dorisOptions, logger));
}
+ /**
+ * Pick a usable backend. The previously chosen backend is reused while it is still within the
+ * cache TTL, so the hot write path does not pay for an HTTP probe on every call. When the cache
+ * is empty/expired we fall back to the round-robin probe behaviour.
+ */
public String getAvailableBackend() {
+ String cached = cachedBackend;
+ if (cached != null && !isCacheExpired()) {
+ return cached;
+ }
+
+ synchronized (lock) {
+ cached = cachedBackend;
+ if (cached != null && !isCacheExpired()) {
+ return cached;
+ }
+
+ String picked = pickBackendLocked();
+ cachedBackend = picked;
+ cachedAtNanos = System.nanoTime();
+ return picked;
+ }
+ }
+
+ /**
+ * Invalidate the cached backend. Callers should invoke this after a stream load / commit
+ * failure so that the next {@link #getAvailableBackend()} probes a fresh node instead of
+ * returning the failing one again.
+ */
+ public void invalidateCache() {
+ synchronized (lock) {
Review Comment:
You're right. Since this only runs in a single thread, the lock is unnecessary. I'll remove it.
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and s… [doris-kafka-connector]
Posted by "rnb-tron (via GitHub)" <gi...@apache.org>.
rnb-tron commented on code in PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#discussion_r3232479737
##########
src/test/java/org/apache/doris/kafka/connector/utils/BackendUtilsTest.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.doris.kafka.connector.utils;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.util.Arrays;
+import java.util.Collections;
+import org.apache.doris.kafka.connector.exception.DorisException;
+import org.apache.doris.kafka.connector.model.BackendV2;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class BackendUtilsTest {
+
+ private ServerSocket alive;
+ private int alivePort;
+
+ /**
+ * Port 1 on loopback is normally not bound and triggers an immediate "connection refused", so
+ * the probe fails fast without waiting for the timeout.
+ */
+ private static final BackendV2.BackendRowV2 DEAD_BACKEND =
+ BackendV2.BackendRowV2.of("127.0.0.1", 1, true);
+
+ @Before
+ public void setUp() throws IOException {
+ alive = new ServerSocket();
+ alive.bind(new InetSocketAddress("127.0.0.1", 0));
+ alivePort = alive.getLocalPort();
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ if (alive != null) {
+ alive.close();
+ }
+ }
+
+ private BackendV2.BackendRowV2 aliveBackend() {
+ return BackendV2.BackendRowV2.of("127.0.0.1", alivePort, true);
+ }
+
+ @Test
+ public void testGetAvailableBackend_returnsAliveOne() {
Review Comment:
Please user camelCase format, and the same for other method.
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and s… [doris-kafka-connector]
Posted by "diggle1 (via GitHub)" <gi...@apache.org>.
diggle1 commented on code in PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#discussion_r3232043726
##########
src/main/java/org/apache/doris/kafka/connector/utils/BackendUtils.java:
##########
@@ -31,8 +31,19 @@
public class BackendUtils {
private static final Logger LOG = LoggerFactory.getLogger(BackendUtils.class);
+
+ /** TTL of the cached available backend (ms). */
+ private static final long CACHE_TTL_MS = 60_000L;
Review Comment:
Updated to 30s. Thanks for the suggestion.
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and s… [doris-kafka-connector]
Posted by "rnb-tron (via GitHub)" <gi...@apache.org>.
rnb-tron commented on code in PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#discussion_r3231955881
##########
src/main/java/org/apache/doris/kafka/connector/utils/BackendUtils.java:
##########
@@ -56,17 +111,25 @@ public String getAvailableBackend() {
}
public static boolean tryHttpConnection(String backend) {
+ HttpURLConnection co = null;
try {
- backend = "http://" + backend;
- URL url = new URL(backend);
- HttpURLConnection co = (HttpURLConnection) url.openConnection();
- co.setConnectTimeout(60000);
+ URL url = new URL("http://" + backend);
+ co = (HttpURLConnection) url.openConnection();
+ co.setConnectTimeout(PROBE_TIMEOUT_MS);
+ co.setReadTimeout(PROBE_TIMEOUT_MS);
co.connect();
- co.disconnect();
return true;
} catch (Exception ex) {
LOG.warn("Failed to connect to backend:{}", backend, ex);
return false;
+ } finally {
Review Comment:
It's obvious that the original code impl is simpler, right?
##########
src/main/java/org/apache/doris/kafka/connector/utils/BackendUtils.java:
##########
@@ -43,7 +54,51 @@ public static BackendUtils getInstance(DorisOptions dorisOptions, Logger logger)
return new BackendUtils(RestService.getBackendsV2(dorisOptions, logger));
}
+ /**
+ * Pick a usable backend. The previously chosen backend is reused while it is still within the
+ * cache TTL, so the hot write path does not pay for an HTTP probe on every call. When the cache
+ * is empty/expired we fall back to the round-robin probe behaviour.
+ */
public String getAvailableBackend() {
+ String cached = cachedBackend;
+ if (cached != null && !isCacheExpired()) {
+ return cached;
+ }
+
+ synchronized (lock) {
+ cached = cachedBackend;
+ if (cached != null && !isCacheExpired()) {
+ return cached;
+ }
+
+ String picked = pickBackendLocked();
+ cachedBackend = picked;
+ cachedAtNanos = System.nanoTime();
+ return picked;
+ }
+ }
+
+ /**
+ * Invalidate the cached backend. Callers should invoke this after a stream load / commit
+ * failure so that the next {@link #getAvailableBackend()} probes a fresh node instead of
+ * returning the failing one again.
+ */
+ public void invalidateCache() {
+ synchronized (lock) {
Review Comment:
There is not need to add a lock, as this will only be executed in one thread.
##########
src/main/java/org/apache/doris/kafka/connector/utils/BackendUtils.java:
##########
@@ -56,17 +111,25 @@ public String getAvailableBackend() {
}
public static boolean tryHttpConnection(String backend) {
+ HttpURLConnection co = null;
try {
- backend = "http://" + backend;
- URL url = new URL(backend);
- HttpURLConnection co = (HttpURLConnection) url.openConnection();
- co.setConnectTimeout(60000);
+ URL url = new URL("http://" + backend);
+ co = (HttpURLConnection) url.openConnection();
+ co.setConnectTimeout(PROBE_TIMEOUT_MS);
Review Comment:
It's better to retain the existing timeout settings.
##########
src/main/java/org/apache/doris/kafka/connector/utils/BackendUtils.java:
##########
@@ -43,7 +54,51 @@ public static BackendUtils getInstance(DorisOptions dorisOptions, Logger logger)
return new BackendUtils(RestService.getBackendsV2(dorisOptions, logger));
}
+ /**
+ * Pick a usable backend. The previously chosen backend is reused while it is still within the
+ * cache TTL, so the hot write path does not pay for an HTTP probe on every call. When the cache
+ * is empty/expired we fall back to the round-robin probe behaviour.
+ */
public String getAvailableBackend() {
+ String cached = cachedBackend;
+ if (cached != null && !isCacheExpired()) {
+ return cached;
+ }
+
+ synchronized (lock) {
Review Comment:
There is not need to add a lock, as this will only be executed in one thread.
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and shorten probe timeout [doris-kafka-connector]
Posted by "rnb-tron (via GitHub)" <gi...@apache.org>.
rnb-tron commented on PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#issuecomment-5067582872
> @DongLiang-0 ptal
@JNSimba PTAL~
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and shorten probe timeout [doris-kafka-connector]
Posted by "JNSimba (via GitHub)" <gi...@apache.org>.
JNSimba commented on PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#issuecomment-5088899044
Thank you for your contribution. It seems this change alters the semantics of the current polling mechanism? In certain scenarios, users require resource consumption to be roughly balanced across all BEs.
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and shorten probe timeout [doris-kafka-connector]
Posted by "diggle1 (via GitHub)" <gi...@apache.org>.
diggle1 commented on PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#issuecomment-5058745140
@rnb-tron ptal
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and s… [doris-kafka-connector]
Posted by "diggle1 (via GitHub)" <gi...@apache.org>.
diggle1 commented on code in PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#discussion_r3232864219
##########
src/test/java/org/apache/doris/kafka/connector/utils/BackendUtilsTest.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.doris.kafka.connector.utils;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.util.Arrays;
+import java.util.Collections;
+import org.apache.doris.kafka.connector.exception.DorisException;
+import org.apache.doris.kafka.connector.model.BackendV2;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class BackendUtilsTest {
+
+ private ServerSocket alive;
+ private int alivePort;
+
+ /**
+ * Port 1 on loopback is normally not bound and triggers an immediate "connection refused", so
+ * the probe fails fast without waiting for the timeout.
+ */
+ private static final BackendV2.BackendRowV2 DEAD_BACKEND =
+ BackendV2.BackendRowV2.of("127.0.0.1", 1, true);
+
+ @Before
+ public void setUp() throws IOException {
+ alive = new ServerSocket();
+ alive.bind(new InetSocketAddress("127.0.0.1", 0));
+ alivePort = alive.getLocalPort();
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ if (alive != null) {
+ alive.close();
+ }
+ }
+
+ private BackendV2.BackendRowV2 aliveBackend() {
+ return BackendV2.BackendRowV2.of("127.0.0.1", alivePort, true);
+ }
+
+ @Test
+ public void testGetAvailableBackend_returnsAliveOne() {
Review Comment:
ok, i will change it!
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and s… [doris-kafka-connector]
Posted by "diggle1 (via GitHub)" <gi...@apache.org>.
diggle1 commented on code in PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#discussion_r3232864219
##########
src/test/java/org/apache/doris/kafka/connector/utils/BackendUtilsTest.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.doris.kafka.connector.utils;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.util.Arrays;
+import java.util.Collections;
+import org.apache.doris.kafka.connector.exception.DorisException;
+import org.apache.doris.kafka.connector.model.BackendV2;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class BackendUtilsTest {
+
+ private ServerSocket alive;
+ private int alivePort;
+
+ /**
+ * Port 1 on loopback is normally not bound and triggers an immediate "connection refused", so
+ * the probe fails fast without waiting for the timeout.
+ */
+ private static final BackendV2.BackendRowV2 DEAD_BACKEND =
+ BackendV2.BackendRowV2.of("127.0.0.1", 1, true);
+
+ @Before
+ public void setUp() throws IOException {
+ alive = new ServerSocket();
+ alive.bind(new InetSocketAddress("127.0.0.1", 0));
+ alivePort = alive.getLocalPort();
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ if (alive != null) {
+ alive.close();
+ }
+ }
+
+ private BackendV2.BackendRowV2 aliveBackend() {
+ return BackendV2.BackendRowV2.of("127.0.0.1", alivePort, true);
+ }
+
+ @Test
+ public void testGetAvailableBackend_returnsAliveOne() {
Review Comment:
Done, renamed all test methods to camelCase.
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and s… [doris-kafka-connector]
Posted by "rnb-tron (via GitHub)" <gi...@apache.org>.
rnb-tron commented on PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#issuecomment-4437125107
Thanks for your contribution~ The code implementation is somewhat complex, and the two configurations of `connector` you added pose a high learning curve for users. I think it would be better to use internal constants for the cache expiration time of `be` without adding additional configurations.
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and s… [doris-kafka-connector]
Posted by "diggle1 (via GitHub)" <gi...@apache.org>.
diggle1 commented on code in PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#discussion_r3232088675
##########
src/main/java/org/apache/doris/kafka/connector/utils/BackendUtils.java:
##########
@@ -56,17 +111,25 @@ public String getAvailableBackend() {
}
public static boolean tryHttpConnection(String backend) {
+ HttpURLConnection co = null;
try {
- backend = "http://" + backend;
- URL url = new URL(backend);
- HttpURLConnection co = (HttpURLConnection) url.openConnection();
- co.setConnectTimeout(60000);
+ URL url = new URL("http://" + backend);
+ co = (HttpURLConnection) url.openConnection();
+ co.setConnectTimeout(PROBE_TIMEOUT_MS);
+ co.setReadTimeout(PROBE_TIMEOUT_MS);
co.connect();
- co.disconnect();
return true;
} catch (Exception ex) {
LOG.warn("Failed to connect to backend:{}", backend, ex);
return false;
+ } finally {
Review Comment:
I'll keep the original simpler implementation.
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and shorten probe timeout [doris-kafka-connector]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#discussion_r3663616953
##########
src/main/java/org/apache/doris/kafka/connector/utils/BackendUtils.java:
##########
@@ -31,8 +34,14 @@
public class BackendUtils {
private static final Logger LOG = LoggerFactory.getLogger(BackendUtils.class);
+
+ /** TTL of a successful HTTP probe result for a BE (ms). */
+ private static final long PROBE_CACHE_TTL_MS = 5_000L;
+
Review Comment:
PR description/title mention a ~30s backend/probe cache window, but the implementation uses 5s. Please reconcile this (either adjust the TTL here or update the PR description/expectations), otherwise behavior won’t match what reviewers/users read.
##########
src/main/java/org/apache/doris/kafka/connector/utils/BackendUtils.java:
##########
@@ -43,18 +52,47 @@ public static BackendUtils getInstance(DorisOptions dorisOptions, Logger logger)
return new BackendUtils(RestService.getBackendsV2(dorisOptions, logger));
}
+ /**
+ * Pick a usable backend via round-robin so load is balanced across BEs. A BE that was recently
+ * probed alive skips the HTTP probe within {@link #PROBE_CACHE_TTL_MS}.
+ */
public String getAvailableBackend() {
long tmp = pos + backends.size();
while (pos < tmp) {
BackendV2.BackendRowV2 backend = backends.get((int) (pos++ % backends.size()));
String res = backend.toBackendString();
+ if (isRecentlyAlive(res)) {
+ return res;
+ }
if (tryHttpConnection(res)) {
+ aliveProbeAtNanos.put(res, System.nanoTime());
return res;
}
+ aliveProbeAtNanos.remove(res);
}
+ invalidateCache();
throw new DorisException("no available backend.");
}
+ /**
+ * Clear cached probe results. Callers should invoke this after a stream load / commit failure
+ * so the next {@link #getAvailableBackend()} re-probes instead of trusting a stale result.
+ */
+ public void invalidateCache() {
+ if (!aliveProbeAtNanos.isEmpty()) {
+ LOG.info("Invalidate doris backend probe cache, size={}", aliveProbeAtNanos.size());
+ }
+ aliveProbeAtNanos.clear();
+ }
+
+ private boolean isRecentlyAlive(String backend) {
+ Long probedAt = aliveProbeAtNanos.get(backend);
+ if (probedAt == null) {
+ return false;
+ }
+ return (System.nanoTime() - probedAt) / 1_000_000L < PROBE_CACHE_TTL_MS;
+ }
+
public static boolean tryHttpConnection(String backend) {
try {
backend = "http://" + backend;
Review Comment:
The PR aims to “shorten probe timeout”, but the HTTP probe connect timeout is still 60s. A long connect timeout can stall stream-load/commit failover paths when a BE IP is unroutable (no immediate RST). Consider reducing this to a few seconds (and/or making it configurable/constant).
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and s… [doris-kafka-connector]
Posted by "rnb-tron (via GitHub)" <gi...@apache.org>.
rnb-tron commented on code in PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#discussion_r3231977944
##########
src/main/java/org/apache/doris/kafka/connector/utils/BackendUtils.java:
##########
@@ -31,8 +31,19 @@
public class BackendUtils {
private static final Logger LOG = LoggerFactory.getLogger(BackendUtils.class);
+
+ /** TTL of the cached available backend (ms). */
+ private static final long CACHE_TTL_MS = 60_000L;
Review Comment:
In addition,i think it can be reduce to 30s or 10s.
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and shorten probe timeout [doris-kafka-connector]
Posted by "diggle1 (via GitHub)" <gi...@apache.org>.
diggle1 commented on code in PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#discussion_r3663949660
##########
src/main/java/org/apache/doris/kafka/connector/utils/BackendUtils.java:
##########
@@ -31,8 +34,14 @@
public class BackendUtils {
private static final Logger LOG = LoggerFactory.getLogger(BackendUtils.class);
+
+ /** TTL of a successful HTTP probe result for a BE (ms). */
+ private static final long PROBE_CACHE_TTL_MS = 5_000L;
+
Review Comment:
The PR description is outdated — the final code uses a 5s per-BE probe cache with round-robin (not the earlier 30s sticky cache). I'll update the description to match.
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe and shorten probe timeout [doris-kafka-connector]
Posted by "diggle1 (via GitHub)" <gi...@apache.org>.
diggle1 commented on PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99#issuecomment-5099401410
Thanks for the review — you're right.
I realize the previous sticky TTL cache changed the per-call round-robin selection, and in some cases it could skew load onto a single BE within the cache window. That was not what I intended.
I've updated the patch as follows:
1. I keep round-robin selection with `pos++` on every `getAvailableBackend()` call, so load remains balanced across BEs.
2. I only cache per-BE HTTP probe success for a short TTL (5s). If a BE was recently confirmed alive, I skip `tryHttpConnection()` for that BE on the next selection.
3. On stream-load / commit failure, or when no BE is available, I clear the probe cache via `invalidateCache()`, so the next attempt re-probes instead of trusting a stale result.
Please take another look when you have time.
--
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: dev-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org
Re: [PR] [improve] Cache available BE in BackendUtils to avoid per-load HTTP probe [doris-kafka-connector]
Posted by "JNSimba (via GitHub)" <gi...@apache.org>.
JNSimba merged PR #99:
URL: https://github.com/apache/doris-kafka-connector/pull/99
--
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-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org