Skip to content

Fix a Keeper server never joining the cluster when background snapshot IO is enabled - #114275

Merged
antonio2368 merged 5 commits into
masterfrom
fix-keeper-join-log-sync-async-snapshot-io
Aug 18, 2026
Merged

antonio2368 merged 5 commits into
masterfrom
fix-keeper-join-log-sync-async-snapshot-io

Conversation

@tiandiwonder

@tiandiwonder tiandiwonder commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Related: ClickHouse/NuRaft#123

Problem

With nuraft_use_bg_thread_for_snapshot_io enabled, a Keeper server added to the cluster never joins. The leader's catch-up loop waits indefinitely for a response that cannot arrive, so the configuration change is never committed.

The setting is off by default, which is why this has gone unnoticed.

Root cause

sync_log_to_new_srv builds one of two requests for the joining server — a snapshot request when the peer is below the retained log, or a log-pack sync_log_request otherwise — and then dispatches on the snapshot IO mode:

if (!params->use_bg_thread_for_snapshot_io_) {
    srv_to_join_->send_req(srv_to_join_, req, ex_resp_handler_);
} else {
    snapshot_io_mgr::instance().invoke();
}

Only the snapshot branch hands its work to the IO thread. Nothing ever enqueues a log pack with snapshot_io_mgr — create_sync_snapshot_req is its only producer — so with background snapshot IO on, invoking the thread does not send the log-pack request. It is dropped.

Observed on the unfixed build as the new server absent from the cluster configuration and stuck at log index 1 while the leader was at 12.

Solution

Dispatch on what was actually built rather than on the IO mode. The snapshot branch leaves the request null exactly when it has queued the work with the IO thread; in every other case — including the log-pack branch in both IO modes — there is a request and it must be sent.

Covered by log_sync_with_async_snapshot_io_test in NuRaft's learner_new_joiner_test, verified to fail against the exact pre-patch code while the four existing tests in that binary keep passing.

NuRaft pull request #123 is merged, and the submodule now points at NuRaft's merge commit 2fcee8a rather than the branch, so the Keeper integration tests, nightly_keeper and Jepsen exercise the merged code here. Relative to master's previous pin dd3d098, the only NuRaft change this brings in is that fix.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix a Keeper server never joining the cluster when nuraft_use_bg_thread_for_snapshot_io is enabled: the log batch sent to a joining server was silently dropped, so the membership change never completed.


Workflow [PR]
Sync PR [sync-upstream/pr/114275]

Version info

  • Merged into: 26.8.1.1659 (included in 26.8 and later)

…apshot IO

Bumps contrib/NuRaft to 57a2729 (branch fix-log-sync-dropped-with-async-snapshot-io),
which fixes sync_log_to_new_srv dropping the log-pack sync_log_request whenever
nuraft_use_bg_thread_for_snapshot_io is enabled.

The dispatch was keyed on the snapshot IO mode, but only the snapshot branch
hands its work to the IO thread; nothing enqueues a log pack with
snapshot_io_mgr, so invoking the thread did not send the request. The leader's
catch-up loop then waited for a response that could not arrive and the
configuration change was never committed, so a server added to the cluster
never joined. Synchronous IO is unaffected, which is why this went unnoticed:
the setting is off by default.

Pinned to the pull request branch so that Keeper's integration tests,
nightly_keeper and Jepsen exercise it here; the pointer must be moved to the
merge commit before this pull request is merged.

Related: ClickHouse/NuRaft#123
@clickhouse-gh

clickhouse-gh Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a3db948]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL

AI Review

Summary

This PR no longer carries the Keeper join fix described in the title, body, and changelog metadata. master already contains that functional NuRaft change at 2fcee8a, and the current contrib/NuRaft bump to b053451 only adds NuRaft PR #124, which hardens log_sync_with_async_snapshot_io_test by asserting the two wait_for_sm_exec calls. That test hardening looks correct, but the PR metadata is now stale enough that it would publish an incorrect bug-fix changelog entry.

PR Metadata
  • Changelog category is no longer correct for the actual diff. The current merge only adds upstream test hardening, so Bug Fix would advertise a user-visible Keeper fix that is already in master.
  • Changelog entry is not required if this is reclassified as CI Fix or Improvement or Not for changelog, and the current entry should be dropped because it describes code that is not in the remaining master..PR delta.
  • Exact replacement:
    • Title: Update NuRaft to harden log_sync_with_async_snapshot_io_test
    • Changelog category: CI Fix or Improvement or Not for changelog
    • Changelog entry: remove it if you choose either category above
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    • Retitle and rewrite the PR body so it matches the actual 2fcee8a..b053451 submodule delta.
    • Change the changelog category away from Bug Fix and drop the current bug-fix entry.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default submodule changed At least one submodule changed in this PR. labels Aug 11, 2026
@tiandiwonder
tiandiwonder marked this pull request as ready for review August 11, 2026 05:54
No behaviour change: 4580ef7 only trims the comments added by 57a2729, moving
the call chain and the evidence out of the source and into the pull request
body where they already are.
@tiandiwonder
tiandiwonder marked this pull request as draft August 11, 2026 06:26
@tiandiwonder
tiandiwonder marked this pull request as ready for review August 11, 2026 06:28
Comment thread contrib/NuRaft Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a3db948ad with master 0480d4ec3 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 702.06 MiB 699.03 MiB -3.03 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline.

Job report

@antonio2368

Copy link
Copy Markdown
Member

Why was the NuRaft PR closed?

@tiandiwonder

Copy link
Copy Markdown
Contributor Author

Why was the NuRaft PR closed?

Reopened, I thought we didn't need the NuRaft PR because this PR.

@antonio2368 antonio2368 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please resolve conflict

`master` had moved `contrib/NuRaft` to `dd3d098` while this branch pointed at the
pull request branch `4580ef7`, so the submodule pointer conflicted.

NuRaft pull request #123 has since merged, and NuRaft `master` is now `2fcee8a`,
which contains both `dd3d098` and `4580ef7`. Resolve to `2fcee8a`: the delta over
`master`'s pin is exactly this fix - `handle_join_leave.cxx` plus
`log_sync_with_async_snapshot_io_test` in `learner_new_joiner_test`.

That also satisfies the pull request's own requirement to move the pointer off the
branch and onto the merge commit before merging.

Co-Authored-By: Claude Opus 5 <[email protected]>
Comment thread contrib/NuRaft
@@ -1 +1 @@
Subproject commit dd3d09892fb7185d78363123776a46412b824b94
Subproject commit b053451b233176ef1d2b5c85a780f6ecca1ad8d6

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

master already points NuRaft at 2fcee8a, so this bump to b053451 no longer carries the Keeper join fix described in the PR title/body/changelog. The remaining delta is just NuRaft PR #124, which hardens log_sync_with_async_snapshot_io_test by checking the two wait_for_sm_exec results. Leaving this as Bug Fix would publish a release-note entry for a user-visible Keeper fix that is already in master.

Please retitle/rewrite the PR around the current 2fcee8a..b053451 delta and switch the changelog category to CI Fix or Improvement or Not for changelog, dropping the current bug-fix entry.

@antonio2368
antonio2368 added this pull request to the merge queue Aug 18, 2026
Merged via the queue into master with commit 792d37e Aug 18, 2026
179 of 181 checks passed
@antonio2368
antonio2368 deleted the fix-keeper-join-log-sync-async-snapshot-io branch August 18, 2026 19:51
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 18, 2026
@clickgapai

Copy link
Copy Markdown
Contributor
Reproducer

Shell reproducer — set BIN to a ClickHouse binary path and run with bash; requires the referenced test fixtures from the repo.

#!/bin/bash
BIN="${BIN:-./clickhouse}"  # path to the ClickHouse binary under test
# Keeper `reconfig add` with nuraft_use_bg_thread_for_snapshot_io=1: the leader
# builds a log-pack sync_log_request for the joining server but never sends it,
# so the catch-up never finishes and the membership change never commits.
# The joiner must be behind by more than NuRaft's log_sync_stop_gap (99999),
# otherwise the leader admits it without a log sync at all.
# Oracle: leader reaches "[SYNC LOG] LogSync is done ... put the server into
# cluster" (log pack delivered+acked) vs. stopping at "start syncing logs to it".
[ -x "$BIN" ] || { echo "OBSERVED: no binary at $BIN"; exit 2; }

grep -qa "nuraft_use_bg_thread_for_snapshot_io" "$BIN" || {
    echo "OBSERVED: setting nuraft_use_bg_thread_for_snapshot_io absent (feature absent)"; exit 2; }
python3 -c "import kazoo" 2>/dev/null || { echo "OBSERVED: kazoo missing (harness dependency)"; exit 2; }

WORK=$(mktemp -d /tmp/kprepro.XXXXXX)
PIDS=()
cleanup() { for p in "${PIDS[@]}"; do kill -9 "$p" 2>/dev/null; done; rm -rf "$WORK"; }
trap cleanup EXIT

freeport() { python3 -c "import socket;s=socket.socket();s.bind(('127.0.0.1',0));print(s.getsockname()[1]);s.close()"; }
TCP1=$(freeport); RAFT1=$(freeport); TCP2=$(freeport); RAFT2=$(freeport)
S1="            <server><id>1</id><hostname>127.0.0.1</hostname><port>$RAFT1</port></server>"
S2="            <server><id>2</id><hostname>127.0.0.1</hostname><port>$RAFT2</port></server>"

mkcfg() { # $1=name $2=id $3=tcp $4=servers
mkdir -p "$WORK/$1"
cat > "$WORK/$1.xml" <<EOF
<clickhouse>
    <logger><level>information</level><log>$WORK/$1/keeper.log</log><errorlog>$WORK/$1/keeper.err</errorlog><size>10M</size><count>1</count></logger>
    <path>$WORK/$1/</path>
    <listen_host>127.0.0.1</listen_host>
    <keeper_server>
        <enable_reconfiguration>true</enable_reconfiguration>
        <tcp_port>$3</tcp_port>
        <server_id>$2</server_id>
        <log_storage_path>$WORK/$1/log</log_storage_path>
        <snapshot_storage_path>$WORK/$1/snapshots</snapshot_storage_path>
        <coordination_settings>
            <operation_timeout_ms>10000</operation_timeout_ms>
            <session_timeout_ms>30000</session_timeout_ms>
            <snapshot_distance>1000000000</snapshot_distance>
            <reserved_log_items>1000000000</reserved_log_items>
            <nuraft_use_bg_thread_for_snapshot_io>true</nuraft_use_bg_thread_for_snapshot_io>
        </coordination_settings>
        <raft_configuration>
$4
        </raft_configuration>
    </keeper_server>
</clickhouse>
EOF
}
mkcfg n1 1 "$TCP1" "$S1"
mkcfg n2 2 "$TCP2" "$S1
$S2"

kc() { timeout 30 "$BIN" keeper-client -h 127.0.0.1 -p "$1" -q "$2" 2>&1; }

"$BIN" keeper --config-file="$WORK/n1.xml" >"$WORK/n1.out" 2>&1 & PIDS+=($!)
for _ in $(seq 60); do kc "$TCP1" "ls /" | grep -q keeper && break; sleep 1; done
kc "$TCP1" "ls /" | grep -q keeper || { echo "OBSERVED: leader never started"; sed -n 1,15p "$WORK/n1.out"; exit 2; }

python3 - "$TCP1" 100010 <<'PY' >/dev/null 2>&1 || { echo "OBSERVED: bulk write failed"; exit 2; }
import sys
from kazoo.client import KazooClient
zk = KazooClient(hosts=f"127.0.0.1:{sys.argv[1]}", timeout=30)
zk.start(timeout=30)
n, batch = int(sys.argv[2]), []
for i in range(n):
    batch.append(zk.create_async(f"/x{i}", b"1"))
    if len(batch) >= 2000:
        [a.get(timeout=60) for a in batch]; batch = []
[a.get(timeout=60) for a in batch]
zk.stop()
PY

"$BIN" keeper --config-file="$WORK/n2.xml" >"$WORK/n2.out" 2>&1 & PIDS+=($!)
sleep 6
kc "$TCP1" "reconfig add 'server.2=127.0.0.1:$RAFT2'" >"$WORK/reconfig.out" 2>&1

LEADER_LOG="$WORK/n1/keeper.log"
SYNCED=0
for _ in $(seq 30); do
    grep -q "now put the server into cluster" "$LEADER_LOG" && { SYNCED=1; break; }
    sleep 1
done

grep -q "confirms it will join" "$LEADER_LOG" || {
    echo "OBSERVED: the joining server never confirmed the invitation"; exit 2; }

echo "OBSERVED: leader log after 'reconfig add server.2':"
grep -E "confirms it will join|\[SYNC LOG\]" "$LEADER_LOG" | sed 's/^/  /'
if [ "$SYNCED" = 1 ]; then
    exit 0
fi
echo "OBSERVED: leader stopped at 'start syncing logs to it' - the log pack was never sent"
exit 1

Results:

  • Reproduces on: 26.7, 26.6
  • Does not reproduce on: master
  • Tested versions: master, 26.7, 26.6, 26.5, 26.3, 25.8
  • ✓ Fix is on master — this PR's change fixes the bug on master. The releases listed above still have the bug and need the backport.

Backport the fix to 26.7, 26.6.

CC component owner: @antonio2368 @al13n321

Analysis metadata

comp-keeper · Severity P2 · Finding phase_d_pr114275

  • Could not test: 26.5, 26.3, 25.8
Introducing change: not identified
  • Secondary components: comp-external-dependencies

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

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants