Repository navigation
Added configurable min term len for phonetic matching. - #431
Merged
Merged
Conversation
mnunberg
approved these changes
Aug 15, 2018
mnunberg
left a comment
Contributor
There was a problem hiding this comment.
@itamarhaber Here's an example of a configuration variable that has underscores. I like it, I think it's easier to read, but I'm unsure if this matches our existing convention.
Collaborator
|
@mnunberg it doesn't match the convention :) Please add the new directive to docs/Configuration.md as well. |
kei-nan
added a commit
that referenced
this pull request
May 28, 2026
`SearchDiskWriteBatchHandle` is now owned by `RSAddDocumentCtx` for its full lifetime and released by `AddDocumentCtx_Free` via a new `SearchDisk_FreeWriteBatch`. Commit and abort still finalize the staged writes but leave the handle valid (and empty) instead of consuming it. The previous "pointer is invalid after this call, you must NULL it" contract required every caller to clear `aCtx->disk.batch` after commit or abort, and only the `RS_ASSERT(!aCtx->disk.batch)` in `AddDocumentCtx_Free` caught the case of an indexing path that bailed out between staging and commit. With this change the cleanup is unconditional in `AddDocumentCtx_Free` and that class of leak is structurally impossible. `SearchDisk_FreeWriteBatch` is null-safe so memory-mode contexts (where no batch was ever created) can call it without a guard. Addresses review feedback on PR #431 (RediSearchEnterprise). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
pull Bot
pushed a commit
to Stars1233/RediSearch
that referenced
this pull request
May 31, 2026
…#9756) * initial commit * switch to using post commit callbacks to account for possible batch failure * document write-batch poison contract on FFI staging entry points Codifies that indexTerm / indexTags / putDocument poison the batch on failure so callers that discard the return value still see commit fail. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * post-commit hooks: fallible signature, short-circuit, status propagation Addresses three bot reviews on the previous batch-hook commit: - On-commit callbacks now return `bool`. When a hook returns false the drain skips every subsequent hook's `on_commit` (their `user_data_free` still runs), so downstream in-memory bookkeeping no longer mutates state for a document the failing hook just rolled back. - `SearchDisk_CommitWriteBatch` propagates the hook outcome: a disk commit that succeeded but whose hook failed returns false, so `Indexer_Process` takes the existing commit-failure branch and stamps `aCtx->status` + `ACTX_F_ERRORED`. - `onCommit_AssignIds` is now the only hook that can fail (DocIdMeta_Set). On that path it deletes the orphan disk doc, applies the REPLACE-side stat decrement (the committed old-doc delete must be reflected somewhere), sets the add-document status, and returns false. The other hooks return `true` unconditionally — they only do infallible in-memory bookkeeping. - `AssignIdsHookData` carries `aCtx` for the status stamp; it is borrowed and valid for the lifetime of the batch (the indexing flow commits or aborts before `AddDocumentCtx_Free` runs). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * panic on DocIdMeta_Set failure instead of plumbing fallibility everywhere The previous commit threaded `bool` returns through every on-commit hook, the drain, and `SearchDisk_CommitWriteBatch` so that a single failure site — `DocIdMeta_Set` returning non-OK — could short-circuit the rest of the post-commit work. That failure means `RedisModule_HashSet` failed (OOM / fundamentally-broken Redis): the module cannot continue in any sensible way, and best-effort cleanup (`SearchDisk_DeleteDocumentById`, stat rollback) can itself fail and leave permanent in-memory / on-disk divergence. Switch to `RS_LOG_ASSERT_ALWAYS` so this case crashes loudly and the server restarts from a well-defined state. The fallibility plumbing goes away: - On-commit callbacks return `void` again. - `searchDisk_writeBatchDrain` no longer short-circuits. - `SearchDisk_CommitWriteBatch` reports only the disk-commit result. - `AssignIdsHookData` no longer carries `aCtx`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * address review feedback: status, renames, more deferrals, fewer aborts - docId==0 failure path in doAssignIds now stamps `aCtx->status` with a reason string and uses `RS_LOG_ASSERT_FMT` so the failure surfaces to the reply path instead of silently returning OK (Codex P1, JoanFM). - Hook-data structs renamed `*HookData` -> `*WriteCommitData` per suggestion: `AssignIdsWriteCommitData`, `WriteCurEntriesWriteCommitData`, `TagIndexWriteCommitData` (JoanFM). - `FieldsGlobalStats_UpdateFieldDocsIndexed` for tag fields now fires from `onCommit_TagIndex`; `IndexerBulkAdd` skips the eager bump for disk-mode tags so the counter never advances for a doc that did not reach disk (Codex P2). - `writeExistingDocs` and `writeMissingFieldDocs` split into pure-data helpers (`*_apply`) and disk-aware wrappers that defer the in-memory side-index writes to on-commit hooks. Aborted / failed-to-commit batches no longer leak phantom doc IDs into `spec->existingDocs` or `spec->missingFieldDict` (Codex P2). - Consolidated abort sites: `doAssignIds` no longer aborts eagerly on `docId==0`; `Indexer_Process` only commits and leaves errored batches to be aborted by `AddDocumentCtx_Free`'s existing safety net. One abort path instead of three (JoanFM). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * non-batched indexers: assert for numeric/geo/geometry, defer vector Codex P1 flagged that `indexBulkFields` writes numeric/geo/geometry/ vector indexes eagerly. If the disk batch commit later fails, those in-memory indexes are left referencing a doc that did not reach disk — a regression the pre-batch sync flow did not have. Numeric, geo, and geometry are not implemented on the disk side yet, so the cleanest signal here is `RS_LOG_ASSERT_ALWAYS(!aCtx->diskBatch)`: if a disk-mode spec ever routes through these indexers it surfaces a configuration that we don't fully support, instead of silently leaving phantom entries on commit failure. Vector is implemented on disk (via `vecsim_disk`), so the eager `VecSimIndex_AddVector` calls are now deferred to an on-commit hook on `aCtx->diskBatch`. The vector payload is copied into the hook data so the deferred call doesn't depend on `fdata->vector`'s lifetime. On abort or commit failure the hook never runs, so the VecSim index never sees the doc. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * vectorIndexer: borrow fdata->vector instead of copying The previous commit copied the vector blob into the hook payload, which is unnecessary — `fdata->vector` borrows from the document field (`aCtx->doc->fields[ii]`), and the document outlives the commit (the hook fires from `SearchDisk_CommitWriteBatch` inside `Indexer_Process`, well before `AddDocumentCtx_Free`). `VecSimIndex_AddVector` is synchronous and copies internally; the eager non-batched code path already relies on the same guarantee. Avoids per-vector `rm_malloc` + `memcpy` (vectors are typically a few KB and there can be many per doc). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * drop post-commit hooks: eager mutations + mark-deleted on commit fail Reverts the C-side on-commit hook infrastructure and goes back to applying in-memory mutations eagerly alongside batch staging. On a commit failure `Indexer_Process` calls `SearchDisk_DeleteDocumentById(aCtx->doc->docId)`, which adds the id to `deleted_ids`; query iterators against the term, tag, suffix, existing-docs, missing-field and vector indexes filter the doc out via that bitmap and doc-table lookups for the missing id drop the result. GC reclaims the orphaned trie entries on its own schedule. Removed: - `SearchDiskWriteBatchOnCommit` / `SearchDiskWriteBatchUserDataFree` typedefs and the `SearchDisk_WriteBatch_OnCommit` C wrapper. - `OnCommitNode` list, drain plumbing, and the `hooks_head` / `hooks_tail` fields on the C-side batch wrapper (now just `{ handle }`). - `AssignIdsWriteCommitData`, `WriteCurEntriesWriteCommitData`, `WriteExistingDocs/MissingFieldDocsWriteCommitData`, `TagIndexWriteCommitData`, `VectorIndexWriteCommitData` and their paired `*_apply` / `onCommit_*` / `free*` helpers. - Numeric / geometry `RS_LOG_ASSERT_ALWAYS(!aCtx->diskBatch, ...)` — they ride the same `deleted_ids` mechanism now. Restored: - Eager `DocIdMeta_Set` + scoring stats + GC notify in `doAssignIds`. - Eager `IndexSpec_AddTerm` + `addSuffixTrie` + `FieldsGlobalStats_UpdateFieldDocsIndexed` in `writeCurEntries`. - Eager bodies for `writeExistingDocs` / `writeMissingFieldDocs`. - Eager tag-trie / suffix / `numRecords` updates in `TagIndex_Index`. - Eager `VecSimIndex_AddVector` in `vectorIndexer`. - Unconditional `FieldsGlobalStats_UpdateFieldDocsIndexed(fs->types, 1)` in `IndexerBulkAdd`. Net diff: -482 / +110. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * mark-deleted on errored finalization; drop now-redundant poisoning The mark-deleted-on-commit-fail design from the previous commit had a gap: when `ACTX_F_ERRORED` was set upstream of the batch finalization (e.g. a tag staging UTF-8 failure surfaced via `tagIndexer` → `IndexerBulkAdd` → `indexBulkFields`), `Indexer_Process` skipped the commit and left the batch for `AddDocumentCtx_Free` to abort — but the eager in-memory mutations from `doAssignIds`, `writeExistingDocs`, `writeMissingFieldDocs`, and `writeCurEntries` had already referenced `aCtx->doc->docId`. With nothing adding the id to `deleted_ids`, those orphan references would never be filtered out of query results. Fix: `Indexer_Process` now calls `SearchDisk_DeleteDocumentById` on both the upstream-errored path and the commit-failure path (skipping when `docId == 0`, which means we never got past staging). The batch is aborted explicitly on the errored path. With that handled, the batch-poisoning machinery becomes redundant — every C-side caller of the staging FFI fns already checks the return value and propagates failure via `ACTX_F_ERRORED`, so the `mark_failed` / `is_failed` flag on the Rust `IndexSpecWriteBatch` was no longer load-bearing. Dropped from both sides and refreshed the header docs accordingly. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * try and separate staging from commit phase * address some code review comments * add asserts * address code review comments * reduce code duplication * refactor text to align to tag * try and split flow into index + commit + apply phases * address code review comments * more changes * indexer: tighten disk-mode batch lifecycle, drop unreachable hooks Address review feedback on the per-document disk write batch flow: - Remove writeExistingDocs / writeMissingFieldDocs from indexDocumentDisk Phase 3. Wildcard (`index_all`) and INDEXMISSING are memory-only features with no disk side-effects, so the calls were dead code (and the writeMissingFieldDocs no-op still did a dictCreate + schema walk). - Upgrade `doAssignIds` failure to RS_LOG_ASSERT_FMT_ALWAYS so a NULL batch or staging failure crashes in release builds too — best-effort cleanup of a partial batch risks permanent on-disk / in-memory divergence, and a hard fail lets the server restart from a well-defined state. With that guarantee `commitDocument`'s NULL guard and the dead status-recovery setup are gone. - Hoist the disk-batch early-return out of `vectorIndexer` and into `IndexerBulkAdd`'s VECTOR case. The indexer no longer knows about disk mode; the dispatcher owns "defer to Phase 3 on disk". - Replace `AddDocumentCtx_Free`'s safety-net abort with RS_ASSERT — the branch was unreachable through any current path (commitDocument is the single owner of the batch lifecycle once doAssignIds opens one), and the assertion documents the invariant so a future bailout path is forced to pair its own abort. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * document: drop redundant RedisSearchCtx* from FIELD_BULK_APPLIER Addresses raz-mon's review feedback on the apply-hook signature: the spec is already directly available on `aCtx->spec`, and Redis API access can go through `aCtx->sctx->redisCtx`, so the separate `RedisSearchCtx *ctx` parameter on `FIELD_BULK_APPLIER` was redundant. Drop the parameter from the macro, the five appliers (tagApplier, vectorApplier, numericApplier, geoApplier, geometryApplier), the `IndexerBulkApply` dispatcher, `bulkApplyFields`, and the two call sites in `bulkIndexFields` / `indexDocumentDisk`. `tagApplier` switches from `ctx->spec` to `aCtx->spec`; the four no-op appliers shed the unused `(void)ctx;` line. `FIELD_BULK_INDEXER` and its callees still take `ctx` — the bulk indexers read from it more heavily and untangling them is out of scope here. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * indexer: clean up old VecSim / geometry entries on disk REPLACE Disk-mode REPLACE was leaving stale VecSim and GeometryIndex entries from the previous doc-id. Memory-mode `makeDocumentId` already handled this inline; the disk path never had an equivalent step, so REPLACE on a doc with vectors or geometry quietly leaked phantom entries that queries could still hit. Extract a `removeOldDocAuxIndexes(spec, oldDocId)` helper and call it from both flows: - Memory mode: from `makeDocumentId`, same point as before (replaces the inline VecSim/Geometry loop). - Disk mode: stash `oldDocId` on `aCtx` in `doAssignIds` and call the helper from `applyDocTable` after the disk batch commits — keeps the in-memory cleanup paired with the durable replace. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * indexer: extract stats-delta helpers, unify memory + disk update paths Pulls the REPLACE-decrement block and the new-doc increment out of `makeDocumentId` / `doAssignIds` / `applyDocTable` into two helpers: - `removeOldDocStats(spec, oldDocLen)` — drops the old doc's contribution from `numDocuments` / `totalDocsLen` with the existing assertions. - `addNewDocStats(spec, newDocLen)` — folds the new doc in. Memory mode `makeDocumentId` no longer touches stats for the new doc; `doAssignIds` calls `addNewDocStats` once the DMD is allocated. Disk-mode `applyDocTable` now reads the same as memory mode: optional REPLACE cleanup (stats + aux indexes) followed by `addNewDocStats`. No behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * indexer: fix disk-mode vector index creation; rephrase 'Phase' comments Two follow-ups to review feedback: - Cursor bot caught a real regression from the earlier change that moved the disk-mode vector gate up into `IndexerBulkAdd`. The original `vectorIndexer` did both `openVectorIndex(..., CREATE_INDEX)` and the insert, so skipping the indexer entirely in disk mode meant the VecSim index was never lazily created — `applyVectorInserts` then opened it with `DONT_CREATE_INDEX` and silently no-op'd. Switch `applyVectorInserts` to `CREATE_INDEX` with the live `redisCtx` so the disk-mode insert mirrors the memory-mode behavior. - JoanFM flagged the "Phase 1 / Phase 2 / Phase 3" wording in the comments as session-local jargon that doesn't appear anywhere else in the codebase. Replace with descriptions of what each step actually does (stage / commit fence / apply) without numbering. No behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * indexer: address PR 9756 review feedback - Group disk-mode RSAddDocumentCtx fields (batch / oldDocId / oldDocLen) under an anonymous nested `disk` struct so the disk-only contract is visible at the type level. Per JoanFM. - applyDocTable: split the REPLACE gate. The key-meta `oldDocId` can survive a prior deindex path that removed the disk row, so cleaning up stale VecSim / geometry entries is keyed on `oldDocId != 0`, but the stats decrement and GC OnUpdate signal are keyed on `oldDocLen != 0` (the actual "on-disk row was overwritten" signal). Prevents numDocuments drift for stale-meta-with-no-disk-row. Codex P2. - applyVectorInserts: a NULL from `openVectorIndex(..., CREATE_INDEX)` after the disk commit landed means we have a doc on disk with no matching vector entry, which the next RDB save would persist. Match the post-commit policy from `applyDocTable` and `RS_LOG_ASSERT_ALWAYS` instead of silently skipping. Codex P2. - tag_index: rename `tag_index_write_postings` to `TagIndex_WritePostings` to match the rest of the TagIndex_* helper family. Per JoanFM. - Trim verbose comments on `geometryIndexer` / `numericIndexer` asserts (the assert message itself states the contract), on the `tagIndexer` disk/memory branching (covered by `TagIndex_Index` docs), and on the search_disk.h file-level lifecycle block (covered by per-function docs). Per JoanFM. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * rqe_iterators_test_utils: add missing `staged` field to ForwardIndexEntry literal `ForwardIndexEntry` gained a disk-mode-only `staged: bool` field earlier in this branch; the rqe_iterators_test_utils struct literal was missed and broke the Rust build. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * indexer: rename removeOldDocAuxIndexes to removeReplacedDocVectorAndGeometry Per raz-mon's review feedback: `aux` was vague — the function specifically drops the replaced doc's VecSim and Geometry entries, the two index types whose REPLACE cleanup isn't covered by `SearchDisk_PutDocument` (disk) or `DocTable_PopR` (memory). Expanded the doc comment to spell this out so the grouping isn't load-bearing on jargon. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * ffi: allow clippy::type_complexity for generated bindings The auto-generated bindings.rs for the FFI crate now contains a `putDocument` function pointer whose 10+ parameter signature trips clippy's `type_complexity` lint and breaks `make lint`. Suppress it alongside the other generated-code allows. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * free batch handle separately from commit/abort `SearchDiskWriteBatchHandle` is now owned by `RSAddDocumentCtx` for its full lifetime and released by `AddDocumentCtx_Free` via a new `SearchDisk_FreeWriteBatch`. Commit and abort still finalize the staged writes but leave the handle valid (and empty) instead of consuming it. The previous "pointer is invalid after this call, you must NULL it" contract required every caller to clear `aCtx->disk.batch` after commit or abort, and only the `RS_ASSERT(!aCtx->disk.batch)` in `AddDocumentCtx_Free` caught the case of an indexing path that bailed out between staging and commit. With this change the cleanup is unconditional in `AddDocumentCtx_Free` and that class of leak is structurally impossible. `SearchDisk_FreeWriteBatch` is null-safe so memory-mode contexts (where no batch was ever created) can call it without a guard. Addresses review feedback on PR RediSearch#431 (RediSearchEnterprise). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.