Skip to content

[tests] Fix cluster tests on main #3267

Closed
Closed

Description

@chernser

Description

There are several tests against local cluster failing. Problem usually in that tests read data too fast before it is on all cluster nodes. But something tells that it is configuration issue. Here is few examples of failed tests:

[ERROR] com.clickhouse.client.HttpTransportTests.testPasswordAuthentication[sha256_password, password, false](5) -- Time elapsed: 0.008 s <<< FAILURE!
java.lang.AssertionError: Failed on setup
	at org.testng.Assert.fail(Assert.java:98)
	at com.clickhouse.client.HttpTransportTests.testPasswordAuthentication(HttpTransportTests.java:1091)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:136)
	at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:658)
	at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:219)
	at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
	at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:923)
	at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:192)
	at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
	at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.testng.TestRunner.privateRun(TestRunner.java:808)
	at org.testng.TestRunner.run(TestRunner.java:603)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:429)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:423)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:383)
	at org.testng.SuiteRunner.run(SuiteRunner.java:326)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1249)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
	at org.testng.TestNG.runSuites(TestNG.java:1092)
	at org.testng.TestNG.run(TestNG.java:1060)
	at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:155)
	at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:169)
	at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:88)
	at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:137)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
	at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
Caused by: com.clickhouse.client.api.ServerException: Code: 493. DB::Exception: user `some_user`: cannot insert because user `some_user` already exists in `replicated`. (ACCESS_ENTITY_ALREADY_EXISTS) (version 26.10.3.7 (official build))  (queryId= 5c6ea623-7121-4f54-9b2b-cd4a8ed6c1d7)
	at com.clickhouse.client.api.internal.HttpAPIClientHelper.readClickHouseError(HttpAPIClientHelper.java:534)
	at com.clickhouse.client.api.internal.HttpAPIClientHelper.readError(HttpAPIClientHelper.java:426)
	at com.clickhouse.client.api.internal.HttpAPIClientHelper.doExecuteRequest(HttpAPIClientHelper.java:833)
	at com.clickhouse.client.api.internal.HttpAPIClientHelper.executeRequest(HttpAPIClientHelper.java:795)
	at com.clickhouse.client.api.internal.HttpAPIClientHelper.executeRequest(HttpAPIClientHelper.java:772)
	at com.clickhouse.client.api.Client.lambda$query$4(Client.java:2035)
	at com.clickhouse.client.api.Client.runAsyncOperation(Client.java:2541)
	at com.clickhouse.client.api.Client.query(Client.java:2081)
	at com.clickhouse.client.api.Client.query(Client.java:1939)
	at com.clickhouse.client.api.Client.execute(Client.java:2479)
	at com.clickhouse.client.HttpTransportTests.testPasswordAuthentication(HttpTransportTests.java:1088)
	... 33 more

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   HttpTransportTests.testPasswordAuthentication:1102 Failed to authenticate
[ERROR]   HttpTransportTests.testPasswordAuthentication:1102 Failed to authenticate
[ERROR]   HttpTransportTests.testPasswordAuthentication:1091 Failed on setup

What to do:

  • review cluster configuration to speedup data transfer between nodes.
  • check if is it enough resources for all cluster nodes - so limiting memory to fit setup on github free runner is needed
  • No timeouts should be used. Fixing with Thead.sleep doesn't solve the problem just defers it to later time. As we have a lot tests it will drag us back fixing them over and over.

Activity

  1. added this to the 0.12.0 milestone on Oct 29, 2026
  2. added theissue type on Oct 29, 2026
  3. chernser commented on Oct 29, 2026

    @chernser
    ContributorAuthor

    @polyglotAI-bot please fix the issue. Read description carefully and create a short plan.

  4. polyglotAI-bot commented on Oct 29, 2026

    @polyglotAI-bot
    Collaborator

    Plan for this issue. I checked the cluster failures on main and reproduced the main one locally with the repo's own cluster configs (3 replicas + Keeper + nginx, CH 26.10.3.7).

    What fails on main (cluster legs)

    1. Users and roles: HttpTransportTests.testPasswordAuthentication, ClientTests.testOperationCustomRoles / testClientCustomRoles (also Flaky test: client-v2 cluster legs — testOperationCustomRoles / testClientCustomRoles / testPasswordAuthentication use a new user or role before it reaches every replica #3237).
    2. Quorum insert right after CREATE TABLE hangs for 1800 s: RowBinaryFormatWriterTest.* (Flaky test: client-v2 cluster legs — insert right after CREATE TABLE hangs 1800 s with UNKNOWN_STATUS_OF_INSERT (quorum never reached) #3246).
    3. jdbc-v2 + CH cluster latest: testAllTableEnginesFromSystemTableEnginesAreMapped (new Elasticsearch engine in 26.10). This is not cluster-specific. It also fails on the single-server leg and is already [jdbc-v2] Add new engine to the list #3265 / [jdbc-v2] Add RETURNING, SHARED keywords and Elasticsearch engine for ClickHouse HEAD #3274. Not in this plan.

    Cause of 1 (verified)

    Each server keeps the users and roles from <replicated> in an in-memory cache. Login, role lookup and DROP ... IF EXISTS read only this cache (ZooKeeperReplicator::findEntity). A Keeper watch thread updates the cache asynchronously. nginx sends each request to any server, so a request just after CREATE USER can go to a server that does not have the user yet.

    The error in the description is the same race. DROP USER IF EXISTS some_user went to a server whose cache did not have the user from the previous run, so it did nothing. Then CREATE USER found the user in Keeper and failed with ACCESS_ENTITY_ALREADY_EXISTS.

    No server setting makes this synchronous. More CPU makes the window smaller, but does not close it.

    Local results (create a user, then 3 logins through nginx):

    CPU per replica No sync With SYSTEM RELOAD USERS ON CLUSTER
    no limit 0/100 failed 0/30 failed
    0.3 2/150 failed 0/100 failed
    0.15 23/120 failed (22 auth failures, 1 ACCESS_ENTITY_ALREADY_EXISTS) 0/120 failed

    CREATE USER ... ON CLUSTER does not help. With replicated storage it fails with ACCESS_ENTITY_ALREADY_EXISTS on the other servers (10/10).

    Plan

    PR 1: a sync point after user/role changes (test code only)

    • Add a helper to BaseIntegrationTest that runs SYSTEM RELOAD USERS ON CLUSTER 'test_cluster' on the cluster and does nothing on a single server.
    • This is not a sleep. On each server, SYSTEM RELOAD USERS syncs with Keeper and reads all users and roles again before it returns (ZooKeeperReplicator::reload). The ON CLUSTER query returns only after all 3 servers did this. It takes about 0.2 s.
    • Call it at the end of the setup in the tests that create, drop, alter or grant users and roles (client-v2 and jdbc-v2). The requests after it still go to any server, so the tests still check the replicated user directory on all 3 servers. No replica pinning and no skipped tests.

    PR 2: cluster resources (containers/clickhouse-cluster and the container starter)

    • Turn off the system logs that the tests do not read (client-v2 and jdbc-v2 tests read only system.query_log): metric_log, asynchronous_metric_log, trace_log, processors_profile_log, background_schedule_pool_log, and similar. Each of the 3 servers flushes and merges these tables all the time.
    • Set a memory limit on each container, so that each server sizes its memory and caches for its share of the runner, not for all 16 GB. I will measure the peak memory in a full local run first and choose the limit from that.
    • Compare CPU time and failure counts in a full local cluster run before and after, with a 4-CPU limit like the GitHub runner.

    Quorum hang (#3246): I found no setting that fixes it. It is a server race: a replica that is still cloning counts as active for the quorum, but the clone fetches the part without the quorum mark, so the quorum never completes. PR 2 makes the window smaller. A real fix must be in the server, so a human should report it to ClickHouse/ClickHouse.

    Questions

    1. Is the SYSTEM RELOAD USERS ON CLUSTER sync point acceptable for PR 1?
    2. Cloud: the helper does nothing there (we probably cannot run SYSTEM RELOAD USERS on Cloud). Is it OK to keep Cloud as it is for now?
    3. Is it OK to handle the quorum hang under Flaky test: client-v2 cluster legs — insert right after CREATE TABLE hangs 1800 s with UNKNOWN_STATUS_OF_INSERT (quorum never reached) #3246, separately from this issue?

    Neither PR changes .github/workflows or production code.

  5. chernser commented on Oct 29, 2026

    @chernser
    ContributorAuthor

    @polyglotAI-bot
    PR 1 should use check instead of delay to verify user is synced across all replicas (do limited number of attempts). Here is SQL example

    SELECT
        hostName() AS host,
        countIf(name = {user:String}) AS matching_users
    FROM clusterAllReplicas('test_cluster', system.users)
    GROUP BY host

    Also this PR should use unique user names if it doesn't matter for tests. In this case we make sure tests are verifying exact user not the one created by another tests.

    All administrative commands should be avoided in tests because:

    • tests should be close to ordinary use. In this case we doing too many operations while in reality there is a small delay between them
    • it is not allowed to run any such impacting command on the Cloud - so test will start failing again.

    P2: completely what I think

    Questions/Answers:

    1. already answered above
    2. already answered above
    3. this waits so yes.

    Please proceed

  6. chernser commented on Nov 2, 2026

    @chernser
    ContributorAuthor

    Closed by #3285

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

Metadata

Metadata

Labels

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions