[jdbc-v1] Fix flaky testAsyncInsert: pin the async insert buffer instead of racing the flush - #3054
[jdbc-v1] Fix flaky testAsyncInsert: pin the async insert buffer instead of racing the flush#3054polyglotAI-bot wants to merge 2 commits into
Conversation
…ync insert flush The second half of the test asserted that a row inserted with wait_for_async_insert=0 is not queryable yet, which only held while the server had not flushed its async insert buffer. Since 24.2 the adaptive busy timeout is on by default and starts at 50 ms, which is shorter than the client latency before the next SELECT on a loaded runner, so the assertion failed intermittently. Pin the buffer open for the check (adaptive timeout off where supported, busy timeout 30 s) and add the other half of the contract: after SYSTEM FLUSH ASYNC INSERT QUEUE the row must be there. Fixes: #3053
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0d1826d. Configure here.
Client V2 CoverageCoverage Report
Class Coverage
|
JDBC V2 CoverageCoverage Report
Class Coverage
|
JDBC V1 CoverageCoverage Report
Class Coverage
|
Client V1 CoverageCoverage Report
Class Coverage
|
The command was added in ClickHouse 23.7, but testAsyncInsert only skips servers older than 21.12. On 21.12-23.6 the post-assert flush failed with a syntax error. Gate the flush and the follow-up assertion the same way the adaptive busy timeout setting is gated; older servers keep the "row not queryable yet" check only.
TriageCategory: Summary What this impacts
Concerns
Required reviewer action
|
|




Description
Fixes #3053.
The second half of
ClickHouseStatementTest.testAsyncInsertinserts one row withasync_insert=1,wait_for_async_insert=0and asserts the row is not yet queryable. Thatassertion only holds while the server has not flushed its async insert buffer, and the test does
not control that timeout. Since ClickHouse
24.2the adaptive busy timeout is enabled by defaultand starts at its minimum (
async_insert_busy_timeout_min_ms=50), so the row becomes visible about50 ms after the INSERT. The gap before the driver's next
SELECT(statement splitting, two moreHTTP round trips, JIT warm-up) is not bounded by anything, so on a loaded runner it exceeds that
window and the row is already there. The test then failed with
"Server was probably busy at that time, so the row was inserted before your query", on PRs that do
not touch async insert (#3014, #3016, #3026).
The fix makes the window deterministic: the check now disables the adaptive busy timeout (where the
server supports it) and sets the busy timeout to 30 s, so the buffer stays open for the whole
assertion. The test then also verifies the other half of the contract - after
SYSTEM FLUSH ASYNC INSERT QUEUEthe row is present with the expected values - so both states arecovered deterministically instead of one being a race.
Changes
clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseStatementTest.javawait_for_async_insert=0block now sendsasync_insert_busy_timeout_ms=30000and, onservers that have it,
async_insert_use_adaptive_busy_timeout=024.2; they areskipped for an older or unknown version, where the non-adaptive
async_insert_busy_timeout_msalone is enough)
readable with the expected values
//TODO: I'm not sure this is a valid test...comment is removed - the assertion is now a real invariantTest-only change: no production code is touched, so there is no user-facing behavior change and no
CHANGELOG entry. The first half of the test (
wait_for_async_insert=1) and the Cloud skip areunchanged.
Test
mvn -B -pl clickhouse-jdbc -DskipUTs=true -Dit.test=ClickHouseStatementTest#testAsyncInsert -Dfailsafe.failIfNoSpecifiedTests=false verify, against ClickHouse26.7.3.19:current settings the row was already visible in 18 of 20 runs - that is the flake. With the
settings this PR adds and a deliberate 500 ms delay before the
SELECT(10x the old window), itwas visible in 0 of 15 runs, and
SYSTEM FLUSH ASYNC INSERT QUEUEmade it visible every time.testAsyncInsertpass, 3 of them with 12 busy-loop processes on 4 vCPU -the load profile that reproduces the failure on
main.ClickHouseStatementTestclass passes (37/37).Pre-PR validation gate
AGENTS.md/docs/changes_checklist.mdNote for reviewers
SYSTEM FLUSH ASYNC INSERT QUEUEis server-global. That is safe for the CI layout, whereclickhouse-jdbcandjdbc-v2run sequentially in one Maven invocation, but it is worth knowing ifthese modules are ever run in parallel against one shared server.