Skip to content

Fix flaky genuine ZooKeeper startup in test_keeper_zookeeper_converter - #110631

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-keeper-zookeeper-converter-start-flaky
Jul 16, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-keeper-zookeeper-converter-start-flaky

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

Fixes a flaky failure of test_keeper_zookeeper_converter seen on master CI (Integration tests (amd_tsan, 3/6) and other flavors).

copy_zookeeper_data restarts genuine ZooKeeper after converting its data. zkServer.sh start keeps the freshly launched JVM for only one second before checking that the process is still alive, and prints an opaque FAILED TO START (exit code 1) without saying why when that racy check loses:

Command [... /opt/zookeeper/bin/zkServer.sh start] return non-zero code 1:
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg

In the observed failure the same data directory had started fine a few seconds earlier and a re-run started it successfully ~3 seconds after the last failed attempt, so the JVM is transiently killed or slow to come up under load rather than the data being broken — but the existing 5×/16s retry window was just too short to ride it out.

Instead of trusting the script's exit code, start_zookeeper now:

  • waits until ZooKeeper actually accepts connections on its client port;
  • cleans up any half-started JVM between attempts (a lingering one keeps the client port busy and makes every retry fail);
  • dumps the ZooKeeper daemon logs when it never becomes ready, so residual failures are diagnosable from CI artifacts instead of leaving only FAILED TO START.

It still fails loudly if ZooKeeper truly cannot start, so real problems are not masked.

No existing open tracking issue was found for this flaky test.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=e590300d41503a2abbaef54d88306e56cba6dd71&name_0=MasterCI&name_1=Integration%20tests%20%28amd_tsan%2C%203%2F6%29

Changelog category (leave one):

  • CI Fix or Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Not for changelog (CI-only test change).

Documentation entry for user-facing changes

  • Documentation is not required for this change

Version info

  • Merged into: 26.7.1.1036 (included in 26.7 and later)

`test_keeper_zookeeper_converter` occasionally fails on a busy CI host with:

    Command [... /opt/zookeeper/bin/zkServer.sh start] return non-zero code 1:
    ZooKeeper JMX enabled by default
    Using config: /opt/zookeeper/bin/../conf/zoo.cfg

`copy_zookeeper_data` restarts genuine ZooKeeper after converting its data,
and `zkServer.sh start` keeps the freshly launched JVM for only one second
before it checks that the process is still alive. When that racy check loses,
the script prints an opaque "FAILED TO START" (exit code 1) without saying
why. In the observed failure the same data directory had started fine a few
seconds earlier and a re-run started it successfully ~3 seconds after the last
failed attempt, so the JVM is transiently killed or slow to come up under load
rather than the data being broken - but the existing 5x/16s retry window was
just too short to ride it out.

Instead of trusting the script's exit code, `start_zookeeper` now waits until
ZooKeeper actually accepts connections on its client port, cleans up any
half-started JVM between attempts (a lingering one keeps the client port busy
and makes every retry fail), and dumps the ZooKeeper daemon logs when it never
becomes ready so residual failures are diagnosable from CI artifacts instead
of leaving only "FAILED TO START". It still fails loudly if ZooKeeper truly
cannot start, so real problems are not masked.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=e590300d41503a2abbaef54d88306e56cba6dd71&name_0=MasterCI&name_1=Integration%20tests%20%28amd_tsan%2C%203%2F6%29

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [32f35e6]

Summary: ✅


AI Review

Summary

This PR hardens test_keeper_zookeeper_converter against the zkServer.sh start false-negative path by waiting for a real Kazoo request, preserving the last start output, and dumping ZooKeeper daemon logs on terminal failure. The two earlier review concerns are addressed in the current head, and I do not see any unresolved correctness or CI-safety regressions in the updated retry logic.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 16, 2026
The AI review on the PR flagged two issues with `start_zookeeper`:
a bare TCP connect to port `2181` can succeed before the standalone
server can actually serve requests, and the 20s per-attempt deadline
was too short for a healthy but slow snapshot load — it would get
killed and retried on every attempt. `nothrow=True` also dropped
`zkServer.sh start`'s `stderr`, so a failure before the daemon log
existed collapsed to an opaque message.

`_wait_zk_client_ready` now probes readiness the same way the rest of
the harness does (a real Kazoo request via `cluster.get_kazoo_client`,
as in `get_genuine_zk`/`ClickHouseCluster.wait_zookeeper_to_start`),
with a 60s per-attempt deadline instead of 20s. The last
`zkServer.sh start` output is captured with `2>&1` and included in the
exception raised on terminal failure.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

The Integration tests (amd_tsan, 3/6) failure (test_replicated_database/test.py::test_replicated_table_structure_alter) is unrelated to this change — it's a known master-wide regression tracked in #110036, since 2026-07-10.

@groeneai, a fix already appears to be in progress at #110145 — please let me know if that's still the right one, or link an alternative fix if it's superseded.

@groeneai

Copy link
Copy Markdown
Collaborator

Yes, #110145 is the right fix and is current (open, not superseded). It closes #110036 at the server-side root cause: on Replicated database recovery a kept matching-UUID table never re-reads zookeeper_path/metadata when its ALTER_METADATA was already GC'd from /log, so the recovered replica serves the pre-ALTER structure. #110145 repairs that (syncTableStructureFromZooKeeperIfNeeded prepends a dummy ALTER_METADATA during recovery, same mechanism cloneMetadataIfNeeded already uses for cloned replicas).

Our #110030 (test-only, assert_eq_with_retry) is not a competing fix; we deferred it to #110145 in the issue thread. No alternative to link.

Note the test is still failing on master (last 12d: 07-15 x7, 07-14 x19, 07-13 x16) because #110145 has not merged yet.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Very nice.

@alexey-milovidov alexey-milovidov self-assigned this Jul 16, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 16, 2026
Merged via the queue into master with commit 67e0771 Jul 16, 2026
178 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-keeper-zookeeper-converter-start-flaky branch July 16, 2026 15:00
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 16, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…eper-converter-start-flaky

Fix flaky genuine ZooKeeper startup in test_keeper_zookeeper_converter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants