Skip to content

MOD-18289 Reserve file descriptors for the disk open-files cap - #11551

Merged
ofiryanai merged 1 commit into
masterfrom
fd-reservation-disk-config
Sep 29, 2026
Merged

ofiryanai merged 1 commit into
masterfrom
fd-reservation-disk-config

Conversation

@ofiryanai

@ofiryanai ofiryanai commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

search-disk-max-open-files now doubles as the unit of a process-wide file-descriptor reservation: every live disk index costs exactly the cap value in reserved descriptors, requested via the new RedisModule_SetOpenFilesReservation API.

SearchDisk_CanCreateIndex charges that reservation before a new disk index is opened, and is called from IndexSpec_ParseFromArgCursor ahead of SearchDisk_OpenIndex; if the process can't reserve enough descriptors, creation is refused with an ordinary index-creation error rather than an assertion, since running out of reservation headroom is an expected operating condition, not a bug.

Adds SearchDisk_ReleaseCreateFailure, called from spec.c to undo that charge when a create attempt CanCreateIndex admitted subsequently fails to open for an unrelated reason, so the charge doesn't outlive the index it was reserved for.

Adds the RedisModule_SetOpenFilesReservation declaration and its REDISMODULE_GET_API entry, following the same pattern as the module's other Big-module API pointers. The server-side API itself landed in redislabsdev/Redis#1849, and the Rust-visible declaration in RedisLabsModules/redismodule-rs#486 (both merged). The REDISMODULE_GET_API entry is load-bearing rather than cosmetic: the module links one global per API pointer, shared by its C and Rust halves, and only this header's RedisModule_Init populates it — omit the entry and the pointer stays NULL and the Rust disk layer panics on first use.

Lowers the default cap from 1024 to 200: at 1024, 4000 indexes would need ~4.1M reserved descriptors, well past the ~1M per-process ceiling (fs.nr_open); the setting is immutable, so a deployment needing more per-index headroom must set it at module load time rather than raising it later.

Also updates module.conf's documented default to match (200), and rewraps/trims the comments this commit touches.

codecov/patch fails on this PR because the behavioral coverage for this C plumbing (admission, refusal, and release-after-drop) lives in Enterprise PR redislabsdev/RediSearchEnterprise#1040, not because the change itself is untested.

Release Notes

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

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 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-28T10:13:41.273388Z af38471 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

disk->index.updateMaxOpenFiles(sp->diskSpec, maxOpenFiles);

P1 Badge Propagate failures from each live database

IndexDiskAPI.updateMaxOpenFiles now explicitly reports false on failure, but this loop discards that result and unconditionally returns success. If SpeedB rejects a runtime cap update for one index, CONFIG SET updates the stored value while that database retains its old cap; when lowering, the process-wide reservation has already been reduced, so the unchanged database can consume descriptors that are no longer reserved and cause file-open failures elsewhere. Check every result and either roll back the reservation/already-updated databases or make the operation transactional in the disk layer.


while ((entry = dictNext(iter))) {
StrongRef spec_ref = dictGetRef(entry);
IndexSpec *sp = StrongRef_Get(spec_ref);
if (sp && sp->diskSpec) {
disk->index.updateMaxOpenFiles(sp->diskSpec, maxOpenFiles);

P1 Badge Update disk handles pending deferred destruction

This iteration only visits indexes still present in specDict_g, but Indexes_RemoveSpecFromGlobals removes an index from that dictionary before IndexSpec_FreeUnlinkedData eventually calls SearchDisk_CloseIndex, and outstanding strong references can delay that close on the cleanup thread. If the cap is lowered while such a dropped index is still draining, its open database retains the old higher cap even though the process-wide reservation has already been reduced, allowing actual descriptor use to exceed the reservation. Track and update every still-open disk handle, including unlinked specs awaiting destruction, before committing the lower reservation.

ℹ️ 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/spec.c Resolved
Comment thread src/config.c Resolved
@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 11.11111% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.51%. Comparing base (616bb81) to head (af38471).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/search_disk.c 0.00% 7 Missing ⚠️
src/spec.c 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11551      +/-   ##
==========================================
- Coverage   84.26%   83.51%   -0.76%     
==========================================
  Files         640      665      +25     
  Lines       85418    86519    +1101     
  Branches    39255    40347    +1092     
==========================================
+ Hits        71981    72255     +274     
- Misses      13071    13890     +819     
- Partials      366      374       +8     
Flag Coverage Δ
flow 84.59% <11.11%> (-0.09%) ⬇️
unit 58.97% <0.00%> (-0.43%) ⬇️

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.

@ofiryanai
ofiryanai force-pushed the fd-reservation-disk-config branch from 055eb6f to b6169f5 Compare September 27, 2026 14:39

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

ℹ️ 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/config.c Resolved
Comment thread module.conf Resolved
@ofiryanai
ofiryanai force-pushed the fd-reservation-disk-config branch from b6169f5 to 5868d92 Compare September 27, 2026 15:02
@github-actions github-actions Bot added size:S and removed size:M labels Sep 27, 2026
@ofiryanai
ofiryanai force-pushed the fd-reservation-disk-config branch 2 times, most recently from 87f9814 to 153f301 Compare September 28, 2026 07:20
search-disk-max-open-files now doubles as the unit the process-wide
file-descriptor reservation is granted in: every live disk index costs
exactly the cap in reserved descriptors. Raising the cap (at CONFIG SET
time or via the disk backend's cap-reapply path) can therefore be
refused if the process can't reserve enough headroom, in which case
the change is rejected and no database is touched. Lowering always
succeeds. Creating a new disk index can likewise be refused if there
isn't enough headroom for its share of the cap; surface that as an
ordinary index-creation error instead of an assertion, since it's an
expected operating condition rather than a bug.

Also tightens DISK_MAX_OPEN_FILES_MIN to 20 and lowers the default cap
to 200, matching SpeedB's actual table-cache floor (SanitizeOptions
clips below 20 anyway) instead of the previous headroom-for-non-data-
files estimate. Updates the pre-existing default-value assertion in
test_config.py to match.

The reservation is granted through RedisModule_SetOpenFilesReservation,
which redisearch_disk needs from a newer redismodule-rs commit than
RediSearch currently pins; bump the shared redis-module rev so the
combined dependency graph resolves to a single version (two revs in
the same build previously produced extern "C" signature mismatches).
RediSearch's own RedisModule_Init also needs to fetch the new API
pointer from the server's GET_API table itself, since the vendored
crate declaring it doesn't make the server populate it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@ofiryanai
ofiryanai force-pushed the fd-reservation-disk-config branch from 153f301 to af38471 Compare September 28, 2026 10:10
@sonarqubecloud

Copy link
Copy Markdown

@ofiryanai
ofiryanai added this pull request to the merge queue Sep 29, 2026
Merged via the queue into master with commit f8dee70 Sep 29, 2026
61 of 62 checks passed
@ofiryanai
ofiryanai deleted the fd-reservation-disk-config branch September 29, 2026 06:33
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