Repository navigation
refactor split of struct_payload_index.rs - #8967
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR replaces a single monolithic StructPayloadIndex implementation with a modular six-file layout: mod.rs (lifecycle and wiring), build.rs (index construction and point removal), filtering.rs (condition-to-cardinality and primary iterators), payload_index_read.rs (PayloadIndexRead trait/read-side logic), payload_index.rs (PayloadIndex trait/mutation-side logic), and tests.rs (integration test verifying config persistence and rebuild behavior). Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
lib/segment/src/index/struct_payload_index/build.rs (2)
18-33: 💤 Low valueAvoid re-borrowing
id_trackerwhen an active borrow already exists.
id_tracker_borrowfrom line 19 is live throughout this block, so the secondself.id_tracker.borrow()on line 31 is redundant. WhileAtomicRefCellpermits concurrent shared borrows, reusing the existing guard makes the lifetime obvious and avoids an extra atomic read.♻️ Proposed cleanup
- let total_point_count = self.id_tracker.borrow().total_point_count(); + let total_point_count = id_tracker_borrow.total_point_count();🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/segment/src/index/struct_payload_index/build.rs` around lines 18 - 33, The code re-borrows id_tracker with self.id_tracker.borrow() when an active borrow id_tracker_borrow is already held; replace the second borrow by using the existing id_tracker_borrow to get total_point_count (call id_tracker_borrow.total_point_count()) and pass that into selector.null_builder(field, total_point_count) so you avoid the redundant atomic borrow and make lifetimes explicit for the id_tracker borrow used with selector.null_builder and builders.push(null_index).
56-66: 💤 Low valueMinor: prefer
values_mut()overiter_mut()with_key.Since the key is unused,
self.field_indexes.values_mut()reads cleaner.♻️ Proposed cleanup
- for (_, field_indexes) in self.field_indexes.iter_mut() { - for index in field_indexes { + for field_indexes in self.field_indexes.values_mut() { + for index in field_indexes { index.remove_point(point_id)?; } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/segment/src/index/struct_payload_index/build.rs` around lines 56 - 66, In clear_index_for_point, replace the map iteration that uses self.field_indexes.iter_mut() with self.field_indexes.values_mut() since the key is unused; update the outer loop to iterate directly over the mutable values (field_indexes) and keep the inner loop calling index.remove_point(point_id)?; this makes the code clearer while preserving the same behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/segment/src/index/struct_payload_index/payload_index.rs`:
- Line 5: Replace the private re-export import of serde_json in the payload
index module: the line importing schemars::_serde_json::Value should instead
import serde_json::Value directly (i.e., use serde_json::Value) so the code uses
the public serde_json crate; update any references to Value in payload_index.rs
as needed to reflect this import change.
In `@lib/segment/src/index/struct_payload_index/tests.rs`:
- Around line 56-92: The closure check_index_types currently returns a bool but
its results are ignored, so replace the two bare calls to
check_index_types(&schema.types) with assertions (e.g.,
assert!(check_index_types(&schema.types))) so the test fails if the index types
don't match; update both places where check_index_types is invoked (the one
before clearing schema.types and the one after re-loading via load_segment) to
assert the returned value, keeping the existing closure and function names
(check_index_types, PayloadConfig::load, load_segment, schema.types) intact.
---
Nitpick comments:
In `@lib/segment/src/index/struct_payload_index/build.rs`:
- Around line 18-33: The code re-borrows id_tracker with
self.id_tracker.borrow() when an active borrow id_tracker_borrow is already
held; replace the second borrow by using the existing id_tracker_borrow to get
total_point_count (call id_tracker_borrow.total_point_count()) and pass that
into selector.null_builder(field, total_point_count) so you avoid the redundant
atomic borrow and make lifetimes explicit for the id_tracker borrow used with
selector.null_builder and builders.push(null_index).
- Around line 56-66: In clear_index_for_point, replace the map iteration that
uses self.field_indexes.iter_mut() with self.field_indexes.values_mut() since
the key is unused; update the outer loop to iterate directly over the mutable
values (field_indexes) and keep the inner loop calling
index.remove_point(point_id)?; this makes the code clearer while preserving the
same behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1029b65f-13ad-4964-b0e8-3de0a135af0e
📒 Files selected for processing (7)
lib/segment/src/index/struct_payload_index.rslib/segment/src/index/struct_payload_index/build.rslib/segment/src/index/struct_payload_index/filtering.rslib/segment/src/index/struct_payload_index/mod.rslib/segment/src/index/struct_payload_index/payload_index.rslib/segment/src/index/struct_payload_index/payload_index_read.rslib/segment/src/index/struct_payload_index/tests.rs
💤 Files with no reviewable changes (1)
- lib/segment/src/index/struct_payload_index.rs
Confirmed dead code — the function had no callers anywhere in the workspace. It was preserved across recent refactors (most recently #8967) but was never referenced. Removing it also drops the now-unused JsonPath and FacetIndexEnum imports in struct_payload_index/mod.rs. This obsoletes the inline variant match introduced in the previous commit: that match existed solely to keep get_facet_index returning the concrete FacetIndexEnum<'_> when as_facet_index moved to the FieldIndexRead trait with an opaque return. With get_facet_index gone, no workaround is needed. The OperationError::MissingMapIndexForFacet variant stays — it is still used by segment::read_view::facet and lib/collection/src/operations/types.rs. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
* refactor: implement FieldIndexRead for FieldIndex
Move the 10 read-only inherent methods on FieldIndex (special_check_condition,
count_indexed_points, filter, estimate_cardinality, for_each_payload_block,
get_telemetry_data, values_count, values_is_empty, as_numeric, as_facet_index)
into impl FieldIndexRead for FieldIndex. Bodies are unchanged.
Write/lifecycle methods (add_point, remove_point, wipe, flusher, files,
immutable_files, ram_usage_bytes, is_on_disk, populate, clear_cache,
get_full_index_type) stay inherent on FieldIndex.
Call sites that hold &FieldIndex now resolve through the trait — added
`use ... FieldIndexRead;` imports where the compiler asked
(read_view/{payload_index_read,filtering}.rs, query_optimization/
condition_converter.rs and match_converter.rs, payload_storage/
query_checker.rs, two integration tests, full_text_index tests module).
StructPayloadIndex::get_facet_index keeps its concrete
OperationResult<FacetIndexEnum<'_>> return: the trait method as_facet_index
returns Option<impl FacetIndex + '_> (RPITIT) which can't be downcast back
to FacetIndexEnum, so the function inlines the variant match. Same shape as
before, just expressed locally.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
* refactor: remove unused StructPayloadIndex::get_facet_index
Confirmed dead code — the function had no callers anywhere in the workspace.
It was preserved across recent refactors (most recently #8967) but was never
referenced. Removing it also drops the now-unused JsonPath and FacetIndexEnum
imports in struct_payload_index/mod.rs.
This obsoletes the inline variant match introduced in the previous commit:
that match existed solely to keep get_facet_index returning the concrete
FacetIndexEnum<'_> when as_facet_index moved to the FieldIndexRead trait
with an opaque return. With get_facet_index gone, no workaround is needed.
The OperationError::MissingMapIndexForFacet variant stays — it is still used
by segment::read_view::facet and lib/collection/src/operations/types.rs.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
* refactor split of struct_payload_index.rs * review fixes
* refactor: implement FieldIndexRead for FieldIndex
Move the 10 read-only inherent methods on FieldIndex (special_check_condition,
count_indexed_points, filter, estimate_cardinality, for_each_payload_block,
get_telemetry_data, values_count, values_is_empty, as_numeric, as_facet_index)
into impl FieldIndexRead for FieldIndex. Bodies are unchanged.
Write/lifecycle methods (add_point, remove_point, wipe, flusher, files,
immutable_files, ram_usage_bytes, is_on_disk, populate, clear_cache,
get_full_index_type) stay inherent on FieldIndex.
Call sites that hold &FieldIndex now resolve through the trait — added
`use ... FieldIndexRead;` imports where the compiler asked
(read_view/{payload_index_read,filtering}.rs, query_optimization/
condition_converter.rs and match_converter.rs, payload_storage/
query_checker.rs, two integration tests, full_text_index tests module).
StructPayloadIndex::get_facet_index keeps its concrete
OperationResult<FacetIndexEnum<'_>> return: the trait method as_facet_index
returns Option<impl FacetIndex + '_> (RPITIT) which can't be downcast back
to FacetIndexEnum, so the function inlines the variant match. Same shape as
before, just expressed locally.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
* refactor: remove unused StructPayloadIndex::get_facet_index
Confirmed dead code — the function had no callers anywhere in the workspace.
It was preserved across recent refactors (most recently #8967) but was never
referenced. Removing it also drops the now-unused JsonPath and FacetIndexEnum
imports in struct_payload_index/mod.rs.
This obsoletes the inline variant match introduced in the previous commit:
that match existed solely to keep get_facet_index returning the concrete
FacetIndexEnum<'_> when as_facet_index moved to the FieldIndexRead trait
with an opaque return. With get_facet_index gone, no workaround is needed.
The OperationError::MissingMapIndexForFacet variant stays — it is still used
by segment::read_view::facet and lib/collection/src/operations/types.rs.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
No description provided.