Skip to content

[MOD-17410] Introduce QueryRequest base state for aggregate and hybrid requests - #10877

Merged
GuyAv46 merged 32 commits into
masterfrom
omerl-queryrequest-as-base-struct
Aug 13, 2026
Merged

GuyAv46 merged 32 commits into
masterfrom
omerl-queryrequest-as-base-struct

Conversation

@lerman25

@lerman25 lerman25 commented Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

Describe the changes in the pull request

  1. Current: Aggregate and hybrid requests duplicate blocked-client, cursor, reply, pipeline, registry, timeout, and asynchronous coordination state across request-specific structures.
  2. Change: Introduce a first-member QueryRequest base for AREQ and HybridRequest, and passively mirror the relevant legacy state into typed cursor, reply, registry, timeout, and async substructures.
  3. Outcome: Establish a shared request abstraction that can incrementally replace BlockedRequestCtx without changing current consumers or synchronization behavior in this PR.

The mirrored legacy assignments are intentionally retained and marked with searchable TODO($$$) comments. The temporary async state is expected to be consolidated after MOD-17486.

Which additional issues this PR fixes

  1. MOD-17410

Main objects this PR modified

  1. QueryRequest, QueryRequestTimeout, and QueryRequestAsyncState
  2. AREQ and HybridRequest
  3. Cursor/reply/registry and coordinator abort-wake mirror paths

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

Internal refactoring only; existing request state remains authoritative and consumed by current code paths.

Validation

  • Focused C syntax checks for the new request source and hybrid cursor mapping source
  • git diff --check
  • Full build was attempted earlier but was blocked during Rust FFI header generation by an environment database error.

@lerman25 lerman25 changed the title Introduce QueryRequest base state for aggregate and hybrid requests [MOD-17410] Introduce QueryRequest base state for aggregate and hybrid requests Aug 11, 2026
@lerman25
lerman25 force-pushed the omerl-queryrequest-as-base-struct branch from d470efd to c906490 Compare August 11, 2026 21:59
@lerman25
lerman25 force-pushed the omerl-queryrequest-as-base-struct branch from a873e0b to a5a323c Compare August 11, 2026 22:27
@github-actions github-actions Bot added size:XL and removed size:L labels Aug 12, 2026
@lerman25
lerman25 force-pushed the omerl-queryrequest-as-base-struct branch from 93d3700 to e46eedb Compare August 12, 2026 07:48
@lerman25
lerman25 marked this pull request as ready for review August 12, 2026 11:43

@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: c30134daaf

ℹ️ 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/query_request.c Outdated
Comment on lines +98 to +99
QueryError_ClearError(&request->reply.err);
ChunkReplyState_Init(&request->reply);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Destroy reply contents before resetting state

When a blocked FAIL/RETURN_STRICT timeout wins after the worker stores rows but before the reply callback consumes them, BlockedRequestCtx_EndCycle calls this function to clean the unconsumed reply. Clearing only the error and then zeroing the structure makes reply.results and its SearchResult objects unreachable without invoking ChunkReplyState_Destroy; QueryRequest_Destroy also omits that former safety net. Repeated timed-out large queries can therefore cause sustained module-memory growth, so destroy the chunk state before reinitializing it.

AGENTS.md reference: AGENTS.md:L133-L133

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 local commit 363b68c62. QueryRequest_ResetReply() now calls ChunkReplyState_Destroy() before reinitializing the state, and QueryRequest_Destroy() uses the same reset path as an idempotent safety net. This preserves the existing cursor-cleanup ordering in QueryRequest_EndCycle() while releasing any unconsumed stored results and errors. Verified with the build plus 7 focused coordinator/standalone timeout and cursor-lifecycle tests.

@codecov

codecov Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.92929% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.22%. Comparing base (5d87f55) to head (bc60b18).
⚠️ Report is 30 commits behind head on master.

Files with missing lines Patch % Lines
src/query_request.c 87.12% 13 Missing ⚠️
src/hybrid/hybrid_exec.c 76.74% 10 Missing ⚠️
src/aggregate/aggregate_exec.c 96.55% 3 Missing ⚠️
src/aggregate/reply_empty.c 71.42% 2 Missing ⚠️
src/search_disk.c 0.00% 2 Missing ⚠️
src/aggregate/aggregate_request.c 98.11% 1 Missing ⚠️
src/coord/dist_aggregate.c 96.77% 1 Missing ⚠️
src/hybrid/hybrid_request.c 95.00% 1 Missing ⚠️
...disearch_rs/c_entrypoint/query_eval_ffi/src/lib.rs 0.00% 1 Missing ⚠️
src/result_processor.c 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10877      +/-   ##
==========================================
- Coverage   83.00%   82.22%   -0.79%     
==========================================
  Files         607      632      +25     
  Lines       80798    82115    +1317     
  Branches    35690    37363    +1673     
==========================================
+ Hits        67068    67520     +452     
- Misses      13391    14248     +857     
- Partials      339      347       +8     
Flag Coverage Δ
flow 84.34% <93.11%> (+0.34%) ⬆️
unit 55.74% <21.81%> (-0.18%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@GuyAv46 GuyAv46 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Awesome!!

Comment thread src/aggregate/aggregate_exec.c Resolved
Comment thread src/query_request.c
if (!request) {
return;
}
int previous = atomic_fetch_sub_explicit(&request->refcount, 1, memory_order_acq_rel);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not memory_order_release?

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.

Another thread may write request state before releasing its reference. If the refcount is what transfers ownership of that state to the final thread, the final decrement needs acquire semantics before destruction.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ok. This is transitional anyway, right?

Comment thread src/query_request.c Resolved
Comment thread src/redisearch_rs/ffi/build.rs Resolved
Comment thread src/aggregate/aggregate.h Resolved
GuyAv46
GuyAv46 previously approved these changes Aug 12, 2026
@GuyAv46
GuyAv46 enabled auto-merge August 12, 2026 15:53

@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: 95767f3ed9

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

int coord_aggregate_query_reply_empty(RedisModuleCtx *ctx, RedisModuleString **argv, int argc, QueryErrorCode errCode) {

AREQ *req = AREQ_New();
AREQ *req = AREQ_New(argv, argc);

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 Release retained arguments on profile parse failure

When a coordinator using ON_OOM RETURN handles a malformed FT.PROFILE ... AGGREGATE request without QUERY, AREQ_New(argv, argc) retains every command argument, but the following parseProfileArgs(...) == -1 branch returns without decrementing the request reference. Repeated requests containing large arguments therefore permanently retain those strings; release the request and clear its error state before returning.

AGENTS.md reference: AGENTS.md:L134-L134

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 bc60b180c. The profile parse-error path now decrements the request, releasing its retained arguments, and replies through QueryError_ReplyAndClear(). The module build passes.

GuyAv46
GuyAv46 previously approved these changes Aug 12, 2026

@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: bc60b180cf

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

}

AREQ_Debug *debug_req = rm_realloc(AREQ_New(), sizeof(*debug_req));
AREQ_Debug *debug_req = rm_realloc(AREQ_New(argv, argc), sizeof(*debug_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 Initialize request state after resizing the debug object

AREQ_New initializes the mutexes and condition variable embedded in QueryRequestAsyncState before this rm_realloc enlarges the containing allocation. If realloc moves it, the initialized pthread objects are copied to new addresses, which is undefined behavior; a debug aggregate/coordinator request using RETURN_STRICT can consequently hang or crash during timeout synchronization or destruction. Allocate the final AREQ_Debug object before initializing its QueryRequest state.

AGENTS.md reference: AGENTS.md:L284-L287

Useful? React with 👍 / 👎.

@sonarqubecloud

Copy link
Copy Markdown

@GuyAv46
GuyAv46 added this pull request to the merge queue Aug 13, 2026
Merged via the queue into master with commit 40bb6fa Aug 13, 2026
102 of 105 checks passed
@GuyAv46
GuyAv46 deleted the omerl-queryrequest-as-base-struct branch August 13, 2026 08:09
dor-forer added a commit that referenced this pull request Aug 18, 2026
Resolves the conflict in src/coord/dist_aggregate.c and ports this branch onto
the QueryRequest base-state refactor from #10877:

- DistCursorReadTimeoutReturnStrictCallback: keep this branch's corrected
  comment (the pre-pipeline bail is reachable now that coordinator cursors
  carry a real spec ref) over master's stale "currently unreachable" wording,
  and take master's field rename, req->brc->reply.err -> req->base.reply.err.

- Cursor::is_coord no longer exists; coordinator-ness is derived from the
  cursor id via CURSOR_IS_COORD. Ported the two uses this branch added:
  the counter selection in Cursor_FreeInternal and the RSCursorProfileCommand
  assert. Cursors_Reserve still selects on CursorList::is_coord, which master
  kept.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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