Repository navigation
Fixes for graceful shutdown - #2759
Conversation
Graceful swarm shutdown (SYSTEM STOP SWARM MODE) could still fail the initiator query with NETWORK_ERROR when a drained worker was killed, because the socket sometimes closes via RST instead of FIN (e.g. when the killed process still had unread bytes queued). Only ATTEMPT_TO_READ_AFTER_EOF was tolerated and converted to a ConnectionLost packet for task rescheduling; NETWORK_ERROR was rethrown and failed the whole query. Treat NETWORK_ERROR the same as ATTEMPT_TO_READ_AFTER_EOF (still gated on no data received yet and skip_unavailable_shards) in both the async read path (RemoteQueryExecutorReadContext::Task::run) and the synchronous read path (RemoteQueryExecutor::read), which previously had no such tolerance at all. Related: #1521 Related: #1014 Co-authored-by: Cursor <[email protected]>
Serialize a worker's swarm-mode check and next-task callback with SYSTEM STOP SWARM MODE. A worker previously could observe that the mode was enabled, then receive a task after the command returned and be killed before processing it. Add a failpoint-backed integration test that stops a worker between its pre-admission pause and the task-admission lock, and verifies it sent no task requests. Co-authored-by: Cursor <[email protected]>
Stopping swarm mode was blocked by the retry sleep and metadata resolution because the admission mutex stayed held after the task callback returned. Co-authored-by: Cursor <[email protected]>
A header block has zero rows, so `rows() > 0` is data already received from the replica. The retry-wait test now lives with the object-storage swarm tests. Co-authored-by: Cursor <[email protected]>
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 442b6d972a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| { | ||
| std::lock_guard lock(swarm_mode_mutex); | ||
| swarm_mode_enabled = false; | ||
| CurrentMetrics::set(CurrentMetrics::IsSwarmModeEnabled, 0); |
There was a problem hiding this comment.
Cancel active queries before waiting for swarm admission
During shutdown, an object-storage worker may hold swarm_mode_mutex while callback() waits for the initiator's task response; the callback performs blocking network I/O in TCPHandler.cpp:830-834. This new lock acquisition therefore prevents shutdown() from reaching the later process_list.killAllQueries() call that would cancel and unblock that worker, delaying shutdown until the network receive timeout (300 seconds by default, potentially longer if configured). Reorder shutdown so active queries are canceled before waiting for task-admission callbacks, or avoid taking this blocking admission barrier on the shutdown path.
Useful? React with 👍 / 👎.
| auto swarm_mode_lock = getContext()->lockSwarmMode(); | ||
| if (!getContext()->isSwarmModeEnabled()) | ||
| { | ||
| LOG_DEBUG(getLogger("StorageObjectStorageSource"), "STOP SWARM MODE called, stop getting new tasks"); | ||
| return nullptr; | ||
| } | ||
|
|
||
| auto task = callback(); | ||
| task = callback(); |
There was a problem hiding this comment.
Allow concurrent task admissions while swarm mode is enabled
For concurrent s3Cluster/object-storage cluster queries on one worker, this mutex belongs to the server-wide shared Context, and it is held across the blocking task request/response callback. Consequently, every task admission from every query is now serialized behind a single network round trip, whereas previously only callbacks within one TCP connection were serialized by that connection's callback_mutex. This can severely reduce throughput for concurrent distributed reads; use a shared admission mechanism (for example, shared locking or an active-admission counter) that permits concurrent callbacks while still letting SYSTEM STOP SWARM MODE establish an exclusive barrier.
Useful? React with 👍 / 👎.
…ssion lock The task-response read holds the admission mutex, so shutdown could wait until `receive_timeout`. The read now polls and returns when shutdown asks it to stop. Co-authored-by: Cursor <[email protected]>
An exclusive `swarm_mode_mutex` made one slow initiator block task admission for every other query. Admissions now take a shared lock, while `stopSwarmMode`, `startSwarmMode`, and shutdown still take it exclusively. Co-authored-by: Cursor <[email protected]>
Shutdown threw `ABORTED` while the worker waited for the next task, which failed the initiator query and left that response unread. The callback now returns before sending when shutdown has started, and releases the lock before reading a request that was already sent. Co-authored-by: Cursor <[email protected]>
A sibling thread of the same query can hold `callback_mutex` while reading a task response. Releasing the shared admission lock first lets `stopSwarmMode` return without waiting out `receive_timeout`. Co-authored-by: Cursor <[email protected]>
`createCopy` shares the flag, and shutdown never clears it. A later test in the same process otherwise sees admission as already interrupted. Co-authored-by: Cursor <[email protected]>
A callback waiting on the connection mutex, and the response read, no longer keep `stopSwarmMode` behind `receive_timeout`. The shutdown interrupt and the thread-local unlock are unnecessary. Co-authored-by: Cursor <[email protected]>
The pause is in `takeNextObject` before the next task request. The admission lock is taken later, in the read-task callback. Co-authored-by: Cursor <[email protected]>
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
🤖 [Posted by an LLM agent on behalf of @mkmkme] AI audit note: This review comment was generated by AI (Claude Fable 5.1). Audit update for PR #2759 (graceful shutdown: Confirmed defects: Coverage summary: |
Releasing the lock before the send let `stopSwarmMode` return and still see one more task request from an in-flight callback. The response read stays outside the lock. Co-authored-by: Cursor <[email protected]>
|
No CI failures caused by this PR. AI audit returned no more defects. Bugfix; added tests are sufficient. LGTM |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixes for graceful shutdown
Documentation entry for user-facing changes
Initial implementation (#1014) catch in initiator only
ATTEMPT_TO_READ_AFTER_EOFerror during node shutdown,NETWORK_ERRORis added. Solved #1521.Fixed potential race in turning swarm mode on/off.
CI/CD Options
Exclude tests:
Regression jobs to run: