Skip to content

Use per-thread JDBC connections in AINode concurrent forecast IT - #19360

Open
JackieTien97 wants to merge 2 commits into
masterfrom
ty/fix-ainode-concurrent-it
Open

JackieTien97 wants to merge 2 commits into
masterfrom
ty/fix-ainode-concurrent-it

Conversation

@JackieTien97

Copy link
Copy Markdown
Contributor

Description

Problem & Trigger Scenario

AINodeSharedClusterIT.concurrentForecastTest failed in the Cluster IT - 1C1D1A GPU job (e.g., PR #19355 run 45011571306) after sundial loaded successfully onto GPU devices 0,1.

  • Trigger: AINodeSharedClusterIT.concurrentGPUForecastTest passed a single JDBC Statement to AINodeTestUtils.concurrentInference, which spawned 10 worker threads each running 10 FORECAST(...) queries concurrently on that shared Statement.
  • Observed failure: After [Bug] Fix JDBC edge cases and resource cleanup #19257 aligned IoTDBStatement with the JDBC specification (closing the current ResultSet before executing the next query on the same Statement), a thread executing its next query closed the ResultSet still being iterated by another thread, causing multiple worker threads to fail with:
    java.sql.SQLException: ResultSet has been closed
        at org.apache.iotdb.jdbc.IoTDBJDBCResultSet.checkOpen(IoTDBJDBCResultSet.java:1044)
        at org.apache.iotdb.jdbc.IoTDBJDBCResultSet.next(IoTDBJDBCResultSet.java:1080)
    
    and failing AINodeSharedClusterIT.concurrentForecastTest:527->concurrentGPUForecastTest:548.

Fix

Keep JDBC driver behavior unchanged and fix the test concurrency setup:

  • Update AINodeTestUtils.concurrentInference to take the target sqlDialect (BaseEnv.TABLE_SQL_DIALECT) instead of a shared Statement, so each of the 10 worker threads opens and closes its own JDBC Connection and Statement via try-with-resources.
  • Preserve the exact workload and assertions: 10 threads × 10 requests per model (sundial, timer_xl), verifying 512 forecast rows per request.
  • Capture the first worker Throwable in an AtomicReference and rethrow it from the test thread with full cause/message instead of dropping worker AssertionError details, and enforce a shared 10-minute join deadline.
  • Wrap LOAD MODEL / concurrentInference in AINodeSharedClusterIT.concurrentGPUForecastTest with try/finally so loaded models are unloaded even if a failure occurs, without masking the primary failure.

Validation

  • Local checks passed on dd450f7ede:
    • python3 .github/scripts/check-it-selection.py (all 847 test classes verified)
    • mvn spotless:apply -pl integration-test -P with-integration-tests
    • mvn test-compile -pl integration-test -am -P with-integration-tests -DskipTests (Checkstyle: 0 violations, Spotless: clean, test compilation succeeded)
  • GPU verification (AINodeSharedClusterIT) is not available locally and will be validated by the Cluster IT - 1C1D1A workflow on this PR.

This PR has:

  • been self-reviewed.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.

Key changed/added files in this PR
  • integration-test/src/test/java/org/apache/iotdb/ainode/utils/AINodeTestUtils.java
  • integration-test/src/test/java/org/apache/iotdb/ainode/it/AINodeSharedClusterIT.java

@JackieTien97 JackieTien97 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Giving each worker its own JDBC connection and statement addresses the shared ResultSet failure. The inline findings cover worker shutdown, the test’s effective concurrency, cleanup of a queued model load, and failure reporting. I recommend addressing them before merging.

Comment on lines +160 to +166
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();
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Wait for the inference workers before unloading the model. An interrupt of the test thread escapes join() without signalling the workers. On the deadline path, the test interrupts them and immediately calls fail(). Either path lets the caller run UNLOAD MODEL while workers are still using the model. With the PR’s scheduling code and a simulated JDBC backend, all 10 workers survived an interrupted join and issued 90 more queries after the caller received InterruptedException. Please stop new iterations on cancellation, bound in-flight JDBC calls, and wait for the workers to exit before starting model cleanup.

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);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Exercise all ten concurrent forecast requests. In AIEnv, this overload creates a ClusterTestConnection even when AIClusterIT sets ReadAndVerifyWithMultiNode=false. It routes the underlying executeQuery calls through the five threads in RequestThreadPool. With 10 workers and 100 queries against a simulated JDBC backend, the peak was 5 concurrent calls. The single-node connection path reached 10 with the same workload. Please use the overload that honors the profile, such as getConnection(Constant.Version.V_1_0, sqlDialect), so failures that require six or more simultaneous requests are covered.

Comment on lines +565 to +568
statement.execute(
String.format(
"UNLOAD MODEL %s FROM DEVICES '%s'", modelInfo.getModelId(), devices));
checkModelNotOnSpecifiedDevice(statement, modelInfo.getModelId(), devices);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Account for a queued model load during cleanup. LOAD MODEL returns once the load is queued. If the readiness check throws before either device has registered a model pool, AINode acknowledges UNLOAD MODEL without queuing an unload. The following SHOW can see zero instances and pass. In a queue-level simulation, resuming the loader after that check left sundial visible on both devices with zero unload tasks executed. Please wait for the submitted load to complete or fail on this path, then unload any instances and verify removal before the next test reuses the cluster.

for (Thread activeThread : threads) {
activeThread.interrupt();
}
fail("Thread timeout after 10 minutes: " + thread.getName());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Preserve the first worker failure on timeout. If one worker records a SQLException or row-count mismatch and another worker times out, this fail() skips the firstFailure check below. The JUnit failure then shows only the timeout and thread name. Please attach the recorded failure as the cause or a suppressed exception on the timeout assertion so the report preserves the original stack trace.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant