Skip to content

[8.8] [MOD-18502] Move coordinator AGGREGATE FAIL reply serialization off the main thread - #11590

Merged
lerman25 merged 2 commits into
8.8from
omerl-backport-11552-8.8
Sep 28, 2026
Merged

lerman25 merged 2 commits into
8.8from
omerl-backport-11552-8.8

Conversation

@lerman25

@lerman25 lerman25 commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Describe the changes in the pull request

Backport of #11552 (58e0e440b59500a88aa207a3642f4afa3c8032cb) to 8.8.

Coordinator AGGREGATE with ON_TIMEOUT FAIL now serializes replies on workers while retaining the blocked-client deadline through encoding. Preserve complete-chunk error semantics, finalize pending cursors during blocked-client cleanup, and wake cancelled PROFILE workers waiting for shard replies.

Adaptations for 8.8

  • Capture the background-encoding selection as a boolean in CoordRequestCtx; reuse this branch's existing FAIL timeout callbacks and cursor policy snapshot. Do not import the newer timeout-policy API or RETURN_STRICT cursor lifecycle.
  • Use QEXEC_F_BUILDPIPELINE_NO_ROOT for the existing coordinator predicate.
  • Preserve the branch's successful RETURN reply baseline in parity tests because RETURN_STRICT is not publicly supported. Preserve its existing RESP2 count distinction: buffered FAIL reports the full chunk count, while streaming RETURN may report 1. This difference was reproduced with the pre-backport 8.8 binary.
  • Cover WITHCOUNT and cursors separately because 8.8 rejects WITHCOUNT + WITHCURSOR. Use worker completion and cursor counts instead of the newer request-context free counter, and add the debug reply-wait sync point needed by the PROFILE wakeup regression test.

Queued policy-change regression

PROFILE cancellation now checks the background-encoding mode captured at dispatch. A request dispatched under FAIL can otherwise read RETURN when the worker creates its AREQ, then spin after cancellation while waiting for shard profiles. The new regression queues PROFILE under FAIL, changes CONFIG to RETURN, and verifies cancellation releases the worker before the missing shard resumes. It reproduced the worker failing to finish on the previous binary and passes with this fix.

The follow-up debug build and all 978 C/C++ tests passed. The complete three-shard timeout file passed with 45 actual PASS entries and no failures (RLTest reports 58 including skips).

Validation

  • Assertion-enabled debug build passed.
  • 978 C/C++ unit tests passed (15 C, 817 C++, 6 coordinator C, 140 coordinator C++).
  • test_blocked_client_timeout: 36 standalone test cases passed; 44 three-shard cluster test cases passed. The initial clustered run passed 42 cases; the two parity tests were adapted for the release differences above and both passed on targeted rerun. Counts exclude displayed SKIP entries rather than relying on RLTest's headline totals, which include skips.
  • Tests ran against community Redis 8.9.241 without RedisJSON; these regressions use hash indexes.
  • Changed C lines formatted; Python syntax and diff whitespace checks passed.

Accepted limitations inherited from the source PR

  • Error accounting remains best effort: a discarded worker reply may still contribute metrics, including a second timeout count in a narrow interleaving. No exactly-once accounting machinery is added.
  • Standalone/shard disconnect behavior is unchanged: an undelivered initial cursor may remain until MAXIDLE, and an interrupted READ may consume an undelivered chunk. Coordinator disconnect cleanup remains enabled.
  • A worker may continue encoding after client timeout; Redis discards its buffered reply.
  • Disconnect cancellation of a coordinator PROFILE worker waiting for a missing shard remains separate. Existing tracking includes MOD-18986 for PROFILE/cancellation alignment through 8.10 and MOD-18916 for the 8.10 disconnect backport. Free-data cleanup alone cannot wake a worker that has not completed.

Which additional issues this PR fixes

MOD-18502

Main objects this PR modified

  • Coordinator AGGREGATE and cursor dispatch, request context, and PROFILE reply waiting.
  • Shared AREQ reply accounting and cursor finalization.
  • Debug synchronization points and test_blocked_client_timeout.py.

Mark if applicable

  • This PR introduces API changes
  • This PR introduces serialization changes

Release Notes

  • This PR requires release notes
  • This PR does not require release notes

…he main thread (#11552)

* [MOD-18502] Move coordinator AGGREGATE FAIL reply serialization off the main thread

* [MOD-18502] Avoid duplicate timeout accounting for discarded background replies

* [MOD-18502] Discard early worker errors after timeout replies

* test: tolerate background PROFILE timeout warning accounting

* [MOD-18502] Stop collecting shard profiles after FAIL cancellation

* [MOD-18502] Wake coordinator reply waits on FAIL timeout
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-28T12:00:55.143672Z 22cd906 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ee42a4f1eb

ℹ️ 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".

Comment thread src/coord/dist_aggregate.c Outdated

static bool profileShouldStopCollectingReplies(AREQ *req) {
// A cancelled FAIL reply is discarded, so there is no need to collect more shard profiles.
return req->reqConfig.timeoutPolicy == TimeoutPolicy_Fail && AREQ_TimedOut(req);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use the dispatch mode when stopping profile collection

If a coordinator PROFILE request is dispatched while ON_TIMEOUT is FAIL, queued, and the setting changes to RETURN before AREQ_New() runs, encodeReplyInBackground still selects the callback-free FAIL path while reqConfig.timeoutPolicy becomes RETURN. After the blocked-client deadline wakes a worker waiting for a shard profile, this predicate remains false, so printAggProfile() repeatedly calls getNextReply() even though the abort flag makes it return RS_RESULT_TIMEDOUT; that coordinator worker never completes. Test the dispatch snapshot (encodeReplyInBackground) rather than the later configuration snapshot.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 22cd906. The PROFILE stop predicate now uses encodeReplyInBackground, captured at dispatch, instead of the policy read later by AREQ_New. Added a regression that queues PROFILE under FAIL, changes CONFIG to RETURN, and cancels while a shard profile is missing. The previous binary failed to complete the worker; the fixed regression passes. Validation: assertion-enabled debug build, 978 C/C++ unit tests, and 45 clustered timeout test cases passed. This mismatch is specific to the 8.8 adaptation; the original merged implementation restores the captured policy through applyCoordReqConfigTimeoutPolicy.

}
#endif
// The timeout callback already counted errors for discarded background replies.
const bool countError = !(req->encodeReplyInBackground && AREQ_TimedOut(req));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Arbitrate timeout error accounting atomically

When a coordinator FAIL deadline races an expression or pipeline error, the worker can evaluate countError as true and then be descheduled while the timeout callback sets timedOut and increments the timeout metric; on resumption the worker increments an error metric for the same discarded reply. The analogous check in AREQ_ReplyOrStoreError() has the same check-then-act race. Use a shared atomic ownership/once flag for error accounting rather than sampling timedOut before updating the counters.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We accept this limitation, as already agreed for the source PR #11552. Error accounting is best effort: a worker that passes the timeout-state check can still count an error for a subsequently discarded reply, including a second timeout count. We are okay with those metric increments and will not add atomic accounting ownership or additional synchronization in this PR. This is documented in the PR description.

Comment thread src/module.c
Comment on lines +3756 to +3759
if (reqCtx->type == COMMAND_AGGREGATE && reqCtx->encodeReplyInBackground &&
RedisModule_BlockedClientDisconnected(ctx)) {
// A discarded reply must not leave its pending cursor idle.
CoordRequestCtx_SetTimedOut(reqCtx);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Wake profile workers when blocked clients disconnect

For a coordinator FAIL FT.PROFILE request with TIMEOUT 0 (or a long deadline), a client can disconnect while printAggProfile() is waiting for a shard's final profile, leaving the worker blocked in getNextReply(). This free-data callback runs only after threadHandleCommand() returns and unblocks the client, so setting timedOut here is too late to wake that worker; an unresponsive shard plus disconnect can therefore consume a coordinator thread indefinitely, and repeated requests can exhaust the pool. Propagate disconnect cancellation while the handler is still running or avoid draining profiles after the blocked client is gone.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Valid concern; free-data cleanup cannot wake a worker that has not yet completed. We are keeping disconnect cancellation separate from this serialization backport. Existing tracking is MOD-18986 (https://redislabs.atlassian.net/browse/MOD-18986), under MOD-16298, which explicitly requires cancellation to wake blocked PROFILE reply waits and terminate collection. MOD-18916 (https://redislabs.atlassian.net/browse/MOD-18916) covers the broader disconnect-handling backport specifically for 8.10. Both are currently To Do. This limitation also applies to the original #11552 and is now documented in this PR description; no duplicate ticket was created.

@lerman25
lerman25 enabled auto-merge September 28, 2026 12:08
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
3.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@lerman25
lerman25 added this pull request to the merge queue Sep 28, 2026
Merged via the queue into 8.8 with commit bd7816c Sep 28, 2026
27 of 28 checks passed
@lerman25
lerman25 deleted the omerl-backport-11552-8.8 branch September 28, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants