This is an automated email from the ASF dual-hosted git repository. JackieTien97 pushed a commit to branch ty/fix-ainode-concurrent-it in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 49f112a7d013edef8d661485ebea1c66da04ad0a Author: JackieTien97 <[email protected]> AuthorDate: Mon Nov 23 09:09:16 2026 +0800 Use per-thread JDBC connections in AINode concurrent forecast IT --- .../iotdb/ainode/it/AINodeSharedClusterIT.java | 47 ++++++++++++----- .../apache/iotdb/ainode/utils/AINodeTestUtils.java | 59 +++++++++++++--------- 2 files changed, 70 insertions(+), 36 deletions(-) diff --git a/integration-test/src/test/java/org/apache/iotdb/ainode/it/AINodeSharedClusterIT.java b/integration-test/src/test/java/org/apache/iotdb/ainode/it/AINodeSharedClusterIT.java index cbd0f62f16e..c1367ba2c7d 100644 --- a/integration-test/src/test/java/org/apache/iotdb/ainode/it/AINodeSharedClusterIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/ainode/it/AINodeSharedClusterIT.java @@ -541,19 +541,40 @@ public class AINodeSharedClusterIT { // PR CI keeps a concurrency smoke check; nightly/daily can dial this up if regressions // appear. final int loop = 10; - statement.execute( - String.format("LOAD MODEL %s TO DEVICES '%s'", modelInfo.getModelId(), devices)); - checkModelOnSpecifiedDevice(statement, modelInfo.getModelId(), devices); - long startTime = System.currentTimeMillis(); - concurrentInference(statement, forecastSQL, threadCnt, loop, forecastLength); - long endTime = System.currentTimeMillis(); - LOGGER.info( - String.format( - "Model %s concurrent inference %d reqs (%d threads, %d loops) in GPU takes time: %dms", - modelInfo.getModelId(), threadCnt * loop, threadCnt, loop, endTime - startTime)); - statement.execute( - String.format("UNLOAD MODEL %s FROM DEVICES '%s'", modelInfo.getModelId(), devices)); - checkModelNotOnSpecifiedDevice(statement, modelInfo.getModelId(), devices); + boolean loadSubmitted = false; + Throwable primaryFailure = null; + try { + statement.execute( + String.format("LOAD MODEL %s TO DEVICES '%s'", modelInfo.getModelId(), devices)); + loadSubmitted = true; + checkModelOnSpecifiedDevice(statement, modelInfo.getModelId(), devices); + long startTime = System.currentTimeMillis(); + concurrentInference( + BaseEnv.TABLE_SQL_DIALECT, forecastSQL, threadCnt, loop, forecastLength); + long endTime = System.currentTimeMillis(); + LOGGER.info( + String.format( + "Model %s concurrent inference %d reqs (%d threads, %d loops) in GPU takes time: %dms", + modelInfo.getModelId(), threadCnt * loop, threadCnt, loop, endTime - startTime)); + } catch (Throwable t) { + primaryFailure = t; + throw t; + } finally { + if (loadSubmitted) { + try { + statement.execute( + String.format( + "UNLOAD MODEL %s FROM DEVICES '%s'", modelInfo.getModelId(), devices)); + checkModelNotOnSpecifiedDevice(statement, modelInfo.getModelId(), devices); + } catch (Throwable cleanupError) { + if (primaryFailure != null) { + primaryFailure.addSuppressed(cleanupError); + } else { + throw cleanupError; + } + } + } + } } } diff --git a/integration-test/src/test/java/org/apache/iotdb/ainode/utils/AINodeTestUtils.java b/integration-test/src/test/java/org/apache/iotdb/ainode/utils/AINodeTestUtils.java index 8f5567c7c9c..fb1f54cdcc1 100644 --- a/integration-test/src/test/java/org/apache/iotdb/ainode/utils/AINodeTestUtils.java +++ b/integration-test/src/test/java/org/apache/iotdb/ainode/utils/AINodeTestUtils.java @@ -23,7 +23,6 @@ import org.apache.iotdb.it.env.EnvFactory; import org.apache.iotdb.itbase.env.BaseEnv; import com.google.common.collect.ImmutableSet; -import org.junit.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +38,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -114,15 +113,18 @@ public class AINodeTestUtils { } public static void concurrentInference( - Statement statement, String sql, int threadCnt, int loop, int expectedOutputLength) + String sqlDialect, String sql, int threadCnt, int loop, int expectedOutputLength) throws InterruptedException { - AtomicBoolean allPass = new AtomicBoolean(true); + AtomicReference<Throwable> firstFailure = new AtomicReference<>(); Thread[] threads = new Thread[threadCnt]; for (int i = 0; i < threadCnt; i++) { threads[i] = new Thread( () -> { - try { + // JDBC Statements cannot be shared concurrently because executing a new query + // closes any previously open ResultSet on that Statement. + try (Connection connection = EnvFactory.getEnv().getConnection(sqlDialect); + Statement statement = connection.createStatement()) { for (int j = 0; j < loop; j++) { try (ResultSet resultSet = statement.executeQuery(sql)) { int outputCnt = 0; @@ -130,34 +132,45 @@ public class AINodeTestUtils { outputCnt++; } if (expectedOutputLength != outputCnt) { - allPass.set(false); - fail( - "Output count mismatch for SQL: " - + sql - + ". Expected: " - + expectedOutputLength - + ", but got: " - + outputCnt); + AssertionError error = + new AssertionError( + "Output count mismatch for SQL: " + + sql + + ". Expected: " + + expectedOutputLength + + ", but got: " + + outputCnt); + firstFailure.compareAndSet(null, error); + LOGGER.error("Concurrent inference output mismatch", error); + return; } - } catch (SQLException e) { - allPass.set(false); - fail(e.getMessage()); } } - } catch (Exception e) { - allPass.set(false); - fail(e.getMessage()); + } catch (Throwable t) { + firstFailure.compareAndSet(null, t); + LOGGER.error("Concurrent inference failed for SQL: {}", sql, t); } - }); + }, + "ainode-concurrent-inference-" + i); threads[i].start(); } + long deadlineNanos = System.nanoTime() + TimeUnit.MINUTES.toNanos(10); for (Thread thread : threads) { - thread.join(TimeUnit.MINUTES.toMillis(10)); + long remainingNanos = deadlineNanos - System.nanoTime(); + if (remainingNanos > 0) { + thread.join(Math.max(1L, TimeUnit.NANOSECONDS.toMillis(remainingNanos))); + } if (thread.isAlive()) { - fail("Thread timeout after 10 minutes"); + for (Thread activeThread : threads) { + activeThread.interrupt(); + } + fail("Thread timeout after 10 minutes: " + thread.getName()); } } - Assert.assertTrue(allPass.get()); + Throwable failure = firstFailure.get(); + if (failure != null) { + throw new AssertionError("Concurrent inference failed: " + failure.getMessage(), failure); + } } public static void checkModelOnSpecifiedDevice(Statement statement, String modelId, String device)
