Repository navigation
Fix a Keeper server never joining the cluster when background snapshot IO is enabled - #114275
Conversation
…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
|
Workflow [PR], commit [a3db948] Summary: ❌
AI ReviewSummaryThis PR no longer carries the Keeper join fix described in the title, body, and changelog metadata. PR Metadata
Final Verdict
|
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.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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 units7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline. |
|
Why was the NuRaft PR closed? |
Reopened, I thought we didn't need the NuRaft PR because this PR. |
`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]>
| @@ -1 +1 @@ | |||
| Subproject commit dd3d09892fb7185d78363123776a46412b824b94 | |||
| Subproject commit b053451b233176ef1d2b5c85a780f6ecca1ad8d6 | |||
There was a problem hiding this comment.
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.
ReproducerShell reproducer — set #!/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 1Results:
Backport the fix to CC component owner: @antonio2368 @al13n321 Analysis metadata
Introducing change: not identified
|
Related: ClickHouse/NuRaft#123
Problem
With
nuraft_use_bg_thread_for_snapshot_ioenabled, 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_srvbuilds one of two requests for the joining server — a snapshot request when the peer is below the retained log, or a log-packsync_log_requestotherwise — and then dispatches on the snapshot IO mode:Only the snapshot branch hands its work to the IO thread. Nothing ever enqueues a log pack with
snapshot_io_mgr—create_sync_snapshot_reqis 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_testin NuRaft'slearner_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
2fcee8arather than the branch, so the Keeper integration tests,nightly_keeperand Jepsen exercise the merged code here. Relative tomaster's previous pindd3d098, the only NuRaft change this brings in is that fix.Changelog category (leave one):
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_iois 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
26.8.1.1659(included in26.8and later)