Skip to content

Propagate OperationResult - #8433

Merged
xzfc merged 1 commit into
devfrom
uio-propagate-result
Mar 25, 2026
Merged

xzfc merged 1 commit into
devfrom
uio-propagate-result

Conversation

@xzfc

@xzfc xzfc commented Mar 17, 2026 •

Copy link
Copy Markdown
Member

Previously, our approach to I/O error handling was this: just read &[u8] slices from mmaped areas. Not a single Result or ? in sight, just the core process living in the moment until being hit by SIGBUS in case if an I/O error occurs.

Tho, the new universal I/O API can return read errors. This PR adds OperationResult propagation in some of the affected places. Particularly, this PR propagates Result from geo_index up to the nearest caller that returns Result. For now, these always return Ok and never Err. In subsequent PRs I plan to return errors from geo_index.

Also, there is an additional commit to replace &GeoHash with GeoHash.

It's a pure refactoring PR, no logic or behavior changes.

I didn't measured the performance impact.

Testimonials

Prompt:

Review commit "Propagate OperationResult".
These changes should propagate/wrap Result. It's pure refactoring: these function always return Result::Ok.

Check these conditions:

  1. only propagation changes are made. No other unrelated changes.
  2. Outside of tests/benchmarks, all errors are propagated. No error is ignored (e.g. using .ok() to convert to None; or .unwrap()).
  3. In tests/benchmarks it's ok to .unwrap()
  4. Important: no new allocations are made. E.g., .collect()/.try_collect() allocates. So, new .collect() can be added only in places where we already calling .collect() (acceptable if that allocation is moved up or down the callstack)
Claude Response

I've reviewed the entire diff (3837 lines across ~40 files). Here's my assessment:

Condition 1: Only propagation changes — PASS (with note)

All changes are mechanical Result wrapping/propagation. One structural change worth noting:

optimizer.rs (optimize_filter): The .and_then() closures were restructured into if let Some(...) && !conditions.is_empty() expressions. This is semantically equivalent but structurally different — necessary because ? can't be used inside closures passed to .and_then(). Acceptable.

Condition 2: All errors propagated outside tests/benchmarks — PASS

All OperationResult errors are propagated via ?. The .ok() calls that appear (e.g., Uuid::from_str(...).ok(), rectangle_hashes(...).ok()) were already present in the original code — they convert non-OperationResult errors to None for "condition doesn't match index" semantics, not newly introduced.

Condition 3: Tests/benchmarks use .unwrap() — PASS

All test and benchmark files consistently add .unwrap() after the newly fallible calls.

Condition 4: No new allocations — one issue

lib/segment/src/index/struct_payload_index.rs in payload_blocks:

// OLD: lazy flat_map, no intermediate collection
Box::new(indexes.iter().flat_map(move |field_index| {
    field_index.payload_blocks(threshold, field_clone.clone())
}))

// NEW: eagerly collects iterators into a Vec, then flattens
let blocks: Vec<_> = indexes
    .iter()
    .map(|field_index| field_index.payload_blocks(threshold, field_clone.clone()))
    .process_results(|iter| iter.collect_vec())?;
Ok(Box::new(blocks.into_iter().flatten()))

This introduces a new collect_vec() that didn't exist before. The old code used lazy flat_map; the new code eagerly collects the iterator objects into a Vec. The allocation is small (number of field indexes per field, typically 1–3), but it is a new allocation.

All other .collect() calls either already existed or replaced an equivalent collect (e.g., Vec<(A,B)> → OperationResult<Vec<(A,B)>> via Result's FromIterator). The process_results usage in segments_searcher.rs, local_shard/scroll.rs, and edge/scroll.rs actually removes intermediate allocations compared to the old two-step collect-then-flatten pattern.


Minor observation: In geo_index/mod.rs tests, values_of_hash calls aren't .unwrap()'d despite the return type changing to OperationResult<usize>. This compiles (comparing Result values via assert_eq!) but is inconsistent with the neighboring points_of_hash calls which do .unwrap().

Appendix: Itertools::process_results

Today I learned about this method. Suppose we have code operating on Iterator<Item=T> and we want to adapt it to use Iterator<Item=Result<T>> and return Result. Instead of slapping extra .collect() and allocating intermediate vector like this:

 foo
     .get_some_iterator()
+    // bad: an extra allocation
+    .collect::<OperationResult<Vec<_>>>()?
+    .into_iterator()
     .map(…)
     .filter(…)
     .blahblah()

we can use Itertools::process_results to avoid allocations:

 foo
     .get_some_iterator()
+    // better
+    .process_results(|iter| {
+        iter
             .map(…)
             .filter(…)
             .blahblah()
+    })?

PR Stack

This PR is stacked:

  1. Use GeoHash instead of &GeoHash #8443
  2. Propagate OperationResult [1/4]: payload_blocks #8444
  3. Propagate OperationResult [2/4]: SegmentEntry #8445
  4. Propagate OperationResult [3/4]: estimate_cardinality #8446
  5. This PR

@xzfc
xzfc force-pushed the uio-propagate-result branch 3 times, most recently from 3ee2607 to f3ce744 Compare March 18, 2026 09:41
@xzfc
xzfc changed the base branch from dev to uio-propagate-result-3 March 18, 2026 09:50
@xzfc
xzfc marked this pull request as ready for review March 18, 2026 09:52
@xzfc
xzfc force-pushed the uio-propagate-result-3 branch from 0404082 to b61f902 Compare March 18, 2026 10:22
@xzfc
xzfc force-pushed the uio-propagate-result branch from f3ce744 to b3c44da Compare March 18, 2026 10:22
@xzfc
xzfc force-pushed the uio-propagate-result-3 branch 2 times, most recently from 11444ac to 337bfdf Compare March 18, 2026 13:17
@xzfc
xzfc force-pushed the uio-propagate-result branch from b3c44da to a560ee6 Compare March 18, 2026 13:17
@xzfc
xzfc force-pushed the uio-propagate-result-3 branch from 337bfdf to 7f74a36 Compare March 18, 2026 13:32
@xzfc
xzfc force-pushed the uio-propagate-result branch from a560ee6 to b73a6db Compare March 18, 2026 13:32
@xzfc
xzfc force-pushed the uio-propagate-result-3 branch from 7f74a36 to a047ac3 Compare March 18, 2026 13:47
@xzfc
xzfc force-pushed the uio-propagate-result branch 2 times, most recently from 916b88c to bc00589 Compare March 18, 2026 15:23
@xzfc
xzfc force-pushed the uio-propagate-result-3 branch 2 times, most recently from e5d91c8 to c9c1cca Compare March 19, 2026 05:48
@xzfc
xzfc force-pushed the uio-propagate-result branch from bc00589 to 90d7f83 Compare March 19, 2026 05:48
Base automatically changed from uio-propagate-result-3 to dev March 23, 2026 11:51
@xzfc
xzfc force-pushed the uio-propagate-result branch from 90d7f83 to 58f0874 Compare March 23, 2026 11:55
@coderabbitai

coderabbitai Bot commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6746e6a0-4c1a-407c-8f42-51122e88e1a3

📥 Commits

Reviewing files that changed from the base of the PR and between 6ddb81d and 58f0874.

📒 Files selected for processing (12)
  • lib/segment/src/index/field_index/bool_index/mod.rs
  • lib/segment/src/index/field_index/bool_index/mutable_bool_index.rs
  • lib/segment/src/index/field_index/bool_index/simple_bool_index.rs
  • lib/segment/src/index/field_index/field_index_base.rs
  • lib/segment/src/index/field_index/full_text_index/mutable_text_index.rs
  • lib/segment/src/index/field_index/full_text_index/text_index.rs
  • lib/segment/src/index/field_index/geo_index/mod.rs
  • lib/segment/src/index/field_index/map_index/mod.rs
  • lib/segment/src/index/field_index/null_index/mutable_null_index.rs
  • lib/segment/src/index/field_index/numeric_index/mod.rs
  • lib/segment/src/index/field_index/numeric_index/tests.rs
  • lib/segment/src/index/struct_payload_index.rs

📝 Walkthrough

Walkthrough

This PR updates the PayloadFieldIndex::filter trait method signature across multiple index implementations to return OperationResult<Option<Box<dyn Iterator<Item = PointOffsetType> + 'a>>> instead of Option<Box<dyn Iterator<Item = PointOffsetType> + 'a>>. The change is applied consistently to boolean, full-text, geospatial, map-based, null, and numeric field indexes. Additionally, the GeoMapIndex::iterator method is updated to return a OperationResult, and StructPayloadIndex is modified to propagate these errors through its query methods. Test code is updated to handle the new Result layer with additional unwrap() calls.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • generall
  • timvisee
  • agourlay
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Propagate OperationResult' directly and clearly summarizes the main objective of the PR, which is to add OperationResult/Result propagation for I/O error handling across multiple index implementations.
Description check ✅ Passed The description is substantially related to the changeset, explaining the motivation (new universal I/O API returning errors), the scope of changes (Result propagation in affected places, particularly geo_index), and explicitly stating this is pure refactoring with no logic changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch uio-propagate-result

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coszio
coszio self-requested a review March 24, 2026 18:58
@xzfc
xzfc merged commit 63c2e7b into dev Mar 25, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants