Repository navigation
Further split segment traits - #8434
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe PR refactors the segment entry trait hierarchy: Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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: 1
🧹 Nitpick comments (4)
lib/segment/src/entry/entry_point.rs (1)
30-34: Reword theSearchSegmentEntrycontract.The new doc says this trait contains operations that do not require mutable access, but the trait still exposes mutable APIs later in the file, like
delete_field_index*andapply_field_index. Renaming the doc to describe the shared segment surface, or narrowing the trait further, would make the split easier to follow.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/entry/entry_point.rs` around lines 30 - 34, The trait doc for SearchSegmentEntry is misleading: it claims to only contain operations that do not require mutable access while the trait actually exposes mutable APIs such as delete_field_index, delete_field_index_if_exist, apply_field_index and similar methods; update the documentation string for SearchSegmentEntry (which extends SnapshotEntry) to accurately describe it as the shared segment surface that includes both immutable query operations and some mutation-related index-management APIs, or alternatively narrow the trait by moving the mutating methods (delete_field_index*, apply_field_index) into a separate trait (e.g., MutableSegmentIndexEntry) and leave SearchSegmentEntry for read-only/query operations only so the contract matches the exposed methods.lib/shard/src/locked_segment.rs (1)
60-65: Consider renamingget_non_appendableto reflect the new return type.The method now returns
&RwLock<dyn SearchSegmentEntry>but retains the nameget_non_appendable. This could be confusing sinceSearchSegmentEntryis meant to be the common search interface for both appendable and non-appendable segments. Consider renaming toget_search_segmentor similar to better reflect the semantics.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/shard/src/locked_segment.rs` around lines 60 - 65, Rename the method get_non_appendable on enum LockedSegment to a name that reflects it now returns the common search interface, e.g., get_search_segment (or get_search_entry); update the method signature and its match arms (LockedSegment::Original and LockedSegment::Proxy) accordingly and then update all call sites to use the new name to avoid confusion with appendability—search for uses of get_non_appendable and replace them with the new method name (preserve the return type &RwLock<dyn SearchSegmentEntry>).lib/shard/src/optimize.rs (1)
27-29: Unify deletion calls to the mutable API in optimization flow.
build_new_segmentnow usesdelete_point_mut, butfinish_optimizationstill callsdelete_pointon the sameSegmenttype. Aligning both paths todelete_point_mutkeeps mutation semantics explicit and lets you drop the legacyNonAppendableSegmentEntryimport here.♻️ Suggested diff
-use segment::entry::entry_point::NonAppendableSegmentEntry as _; use segment::entry::{SearchSegmentEntry, SegmentEntry}; @@ - optimized_segment - .delete_point(versions.operation_version, point_id, hw_counter) - .unwrap(); + optimized_segment + .delete_point_mut(versions.operation_version, point_id, hw_counter) + .unwrap();Also applies to: 334-335
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/shard/src/optimize.rs` around lines 27 - 29, finish_optimization still calls delete_point on Segment while build_new_segment uses delete_point_mut, and the NonAppendableSegmentEntry import is now unused; update finish_optimization to call delete_point_mut (same signature/semantics as build_new_segment) and remove the unused NonAppendableSegmentEntry import to keep mutation API consistent and drop the legacy symbol.lib/segment/src/segment/entry.rs (1)
931-976: Consider extracting shared deletion logic to reduce duplication.
delete_point(lines 932-952) anddelete_point_mut(lines 956-976) have identical implementations. This duplication increases maintenance burden and risk of divergence.Consider having one method delegate to the other or extracting the shared logic:
♻️ Option 1: Delegate from one to the other
impl NonAppendableSegmentEntry for Segment { fn delete_point( &mut self, op_num: SeqNumberType, point_id: PointIdType, hw_counter: &HardwareCounterCell, ) -> OperationResult<bool> { - let internal_id = self.id_tracker.borrow().internal_id(point_id); - match internal_id { - // Point does already not exist anymore - None => Ok(false), - Some(internal_id) => { - self.handle_point_version_and_failure(op_num, Some(internal_id), |segment| { - segment.delete_point_internal(internal_id, hw_counter)?; - - segment.version_tracker.set_payload(Some(op_num)); - - Ok((true, Some(internal_id))) - }) - } - } + self.delete_point_mut(op_num, point_id, hw_counter) } }♻️ Option 2: Extract helper method
impl Segment { fn delete_point_impl( &mut self, op_num: SeqNumberType, point_id: PointIdType, hw_counter: &HardwareCounterCell, ) -> OperationResult<bool> { let internal_id = self.id_tracker.borrow().internal_id(point_id); match internal_id { None => Ok(false), Some(internal_id) => { self.handle_point_version_and_failure(op_num, Some(internal_id), |segment| { segment.delete_point_internal(internal_id, hw_counter)?; segment.version_tracker.set_payload(Some(op_num)); Ok((true, Some(internal_id))) }) } } } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/segment/entry.rs` around lines 931 - 976, The two methods delete_point (impl NonAppendableSegmentEntry for Segment) and delete_point_mut (impl SegmentEntry for Segment) contain identical logic; extract the shared logic into a single helper on Segment (e.g., fn delete_point_impl(&mut self, op_num: SeqNumberType, point_id: PointIdType, hw_counter: &HardwareCounterCell) -> OperationResult<bool>) that performs id_tracker.borrow().internal_id(...), calls handle_point_version_and_failure(..., |segment| { segment.delete_point_internal(...); segment.version_tracker.set_payload(Some(op_num)); Ok((true, Some(internal_id))) }), and returns the result, then have both delete_point and delete_point_mut delegate to that helper (or have one delegate to the other) to remove duplication.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/shard/src/proxy_segment/segment_entry.rs`:
- Around line 780-835: delete_point currently records a tombstone regardless of
the wrapped point's current local version, allowing stale or repeated deletes;
fix by first fetching the wrapped point's current local version (use
raw_segment.read().point_version(point_id) for LockedSegment::Original and
proxy.read().point_version(point_id) for LockedSegment::Proxy) and if the point
does not exist return Ok(false), and if op_num <= current_local_version do not
insert into deleted_points (treat as stale/idempotent and return Ok(false));
only when op_num > current_local_version insert the ProxyDeletedPoint,
set_deleted_offset as before, and return true iff the insert was new. Ensure
existing debug_assert path is replaced with this guarded version check so
repeated equal op_num is idempotent.
---
Nitpick comments:
In `@lib/segment/src/entry/entry_point.rs`:
- Around line 30-34: The trait doc for SearchSegmentEntry is misleading: it
claims to only contain operations that do not require mutable access while the
trait actually exposes mutable APIs such as delete_field_index,
delete_field_index_if_exist, apply_field_index and similar methods; update the
documentation string for SearchSegmentEntry (which extends SnapshotEntry) to
accurately describe it as the shared segment surface that includes both
immutable query operations and some mutation-related index-management APIs, or
alternatively narrow the trait by moving the mutating methods
(delete_field_index*, apply_field_index) into a separate trait (e.g.,
MutableSegmentIndexEntry) and leave SearchSegmentEntry for read-only/query
operations only so the contract matches the exposed methods.
In `@lib/segment/src/segment/entry.rs`:
- Around line 931-976: The two methods delete_point (impl
NonAppendableSegmentEntry for Segment) and delete_point_mut (impl SegmentEntry
for Segment) contain identical logic; extract the shared logic into a single
helper on Segment (e.g., fn delete_point_impl(&mut self, op_num: SeqNumberType,
point_id: PointIdType, hw_counter: &HardwareCounterCell) ->
OperationResult<bool>) that performs id_tracker.borrow().internal_id(...), calls
handle_point_version_and_failure(..., |segment| {
segment.delete_point_internal(...);
segment.version_tracker.set_payload(Some(op_num)); Ok((true, Some(internal_id)))
}), and returns the result, then have both delete_point and delete_point_mut
delegate to that helper (or have one delegate to the other) to remove
duplication.
In `@lib/shard/src/locked_segment.rs`:
- Around line 60-65: Rename the method get_non_appendable on enum LockedSegment
to a name that reflects it now returns the common search interface, e.g.,
get_search_segment (or get_search_entry); update the method signature and its
match arms (LockedSegment::Original and LockedSegment::Proxy) accordingly and
then update all call sites to use the new name to avoid confusion with
appendability—search for uses of get_non_appendable and replace them with the
new method name (preserve the return type &RwLock<dyn SearchSegmentEntry>).
In `@lib/shard/src/optimize.rs`:
- Around line 27-29: finish_optimization still calls delete_point on Segment
while build_new_segment uses delete_point_mut, and the NonAppendableSegmentEntry
import is now unused; update finish_optimization to call delete_point_mut (same
signature/semantics as build_new_segment) and remove the unused
NonAppendableSegmentEntry import to keep mutation API consistent and drop the
legacy symbol.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 36780b68-a3d7-4b0b-8c7f-c5eff3938d29
📒 Files selected for processing (50)
lib/collection/src/collection_manager/collection_updater.rslib/collection/src/collection_manager/optimizers/config_mismatch_optimizer.rslib/collection/src/collection_manager/optimizers/indexing_optimizer.rslib/collection/src/collection_manager/optimizers/vacuum_optimizer.rslib/collection/src/collection_manager/tests/mod.rslib/collection/src/shards/local_shard/mod.rslib/collection/src/shards/local_shard/snapshot.rslib/edge/src/lib.rslib/segment/benches/hnsw_incremental_build.rslib/segment/benches/segment_info.rslib/segment/src/entry/entry_point.rslib/segment/src/entry/mod.rslib/segment/src/index/struct_payload_index.rslib/segment/src/segment/entry.rslib/segment/src/segment/facet.rslib/segment/src/segment/scroll.rslib/segment/src/segment/search.rslib/segment/src/segment/segment_ops.rslib/segment/src/segment/snapshot.rslib/segment/src/segment/tests.rslib/segment/src/segment_constructor/segment_builder.rslib/segment/src/segment_constructor/segment_constructor_base.rslib/segment/src/segment_constructor/simple_segment_constructor.rslib/segment/tests/integration/batch_search_test.rslib/segment/tests/integration/disbalanced_vectors_test.rslib/segment/tests/integration/hnsw_quantized_search_test.rslib/segment/tests/integration/multivector_hnsw_test.rslib/segment/tests/integration/payload_index_test.rslib/segment/tests/integration/segment_builder_test.rslib/segment/tests/integration/segment_on_disk_snapshot.rslib/segment/tests/integration/segment_tests.rslib/segment/tests/integration/sparse_vector_index_search_tests.rslib/shard/src/fixtures.rslib/shard/src/locked_segment.rslib/shard/src/optimize.rslib/shard/src/optimizers/config_mismatch_optimizer.rslib/shard/src/optimizers/indexing_optimizer.rslib/shard/src/optimizers/merge_optimizer.rslib/shard/src/optimizers/segment_optimizer.rslib/shard/src/optimizers/vacuum_optimizer.rslib/shard/src/proxy_segment/mod.rslib/shard/src/proxy_segment/segment_entry.rslib/shard/src/proxy_segment/tests.rslib/shard/src/segment_holder/flush.rslib/shard/src/segment_holder/mod.rslib/shard/src/segment_holder/read_points.rslib/shard/src/segment_holder/snapshot.rslib/shard/src/segment_holder/tests.rslib/shard/src/update.rssrc/segment_inspector.rs
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (4)
lib/shard/src/proxy_segment/tests.rs (1)
72-74: Make the new point-ID conversions explicit.These
delete_point_mutupdates reintroduce implicit.into()conversions for point IDs. Please spell out the target type explicitly in the new calls to keep the Rust style consistent with the repo convention.As per coding guidelines,
**/*.rs: Prefer explicitSomeType::from(x)over implicitx.into()in Rust.Also applies to: 251-253, 290-292, 381-383, 428-430, 436-438, 492-494, 500-502, 521-523
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/shard/src/proxy_segment/tests.rs` around lines 72 - 74, Replace implicit .into() conversions for point IDs with an explicit SomePointIdType::from(...) call: locate uses like proxy_segment.delete_point_mut(102, 1.into(), &hw_counter) (and the other similar invocations noted) and change the second argument from x.into() to the concrete point-ID constructor, e.g., PointId::from(1) (use the actual point-ID type in this crate). Ensure all occurrences (including the other listed call sites) follow this explicit SomeType::from(x) pattern.lib/segment/src/segment/tests.rs (1)
68-70: Make the new point-ID conversions explicit.The new
delete_point_mutcall sites rely on.into()again for point IDs. Please make the target type explicit in these additions to stay aligned with the repo’s Rust convention.As per coding guidelines,
**/*.rs: Prefer explicitSomeType::from(x)over implicitx.into()in Rust.Also applies to: 418-420, 426-428, 496-498, 504-506
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/segment/tests.rs` around lines 68 - 70, Replace implicit `.into()` conversions for point IDs with an explicit type conversion using PointId::from(...) at each delete_point_mut call site (e.g., in the delete_point_mut(...) invocations in tests.rs). Locate the calls to delete_point_mut (the ones using `1.into()` etc.) and change the point-id argument to `PointId::from(<value>)` (and similarly for other occurrences listed: 418-420, 426-428, 496-498, 504-506) so the point-id conversion is explicit and follows the repo convention.lib/segment/tests/integration/payload_index_test.rs (1)
223-234: Make the new point-ID conversions explicit.The updated delete loops switched to
delete_point_mut(...), but the new point-ID arguments still use implicit.into()conversions. Please make those conversions explicit as part of the rename.As per coding guidelines,
**/*.rs: Prefer explicitSomeType::from(x)over implicitx.into()in Rust.Also applies to: 474-482
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/tests/integration/payload_index_test.rs` around lines 223 - 234, The delete loops call delete_point_mut(opnum, idx_to_remove.into(), &hw_counter) with implicit .into(); change these to explicit conversions using the concrete parameter type of delete_point_mut (e.g., PointId::from(idx_to_remove) or the actual second-parameter type used by delete_point_mut) so the conversion is explicit; update every occurrence in this block and the similar loop at the other location (around lines 474-482) to use <TargetType>::from(idx_to_remove) where <TargetType> is the function's second-parameter type.lib/segment/src/segment/entry.rs (1)
935-957: Consider extracting shared deletion logic.
delete_pointanddelete_point_muthave identical implementations. While the trait separation is intentional for enabling future differentiation, the current duplication could be reduced by extracting a shared private helper method.♻️ Optional: Extract shared helper
+impl Segment { + fn delete_point_impl( + &mut self, + op_num: SeqNumberType, + point_id: PointIdType, + hw_counter: &HardwareCounterCell, + ) -> OperationResult<bool> { + let internal_id = self.id_tracker.borrow().internal_id(point_id); + match internal_id { + None => Ok(false), + Some(internal_id) => { + self.handle_point_version_and_failure(op_num, Some(internal_id), |segment| { + segment.delete_point_internal(internal_id, hw_counter)?; + segment.version_tracker.set_payload(Some(op_num)); + Ok((true, Some(internal_id))) + }) + } + } + } +} + impl NonAppendableSegmentEntry for Segment { fn delete_point( &mut self, op_num: SeqNumberType, point_id: PointIdType, hw_counter: &HardwareCounterCell, ) -> OperationResult<bool> { - let internal_id = self.id_tracker.borrow().internal_id(point_id); - match internal_id { - // Point does already not exist anymore - None => Ok(false), - Some(internal_id) => { - self.handle_point_version_and_failure(op_num, Some(internal_id), |segment| { - segment.delete_point_internal(internal_id, hw_counter)?; - - segment.version_tracker.set_payload(Some(op_num)); - - Ok((true, Some(internal_id))) - }) - } - } + self.delete_point_impl(op_num, point_id, hw_counter) } }Then similarly delegate
delete_point_muttodelete_point_impl. This keeps the trait split while reducing duplication.Also applies to: 959-980
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/segment/entry.rs` around lines 935 - 957, The two methods delete_point and delete_point_mut duplicate the same logic; extract a private helper (e.g., delete_point_impl) that accepts (op_num: SeqNumberType, point_id: PointIdType, hw_counter: &HardwareCounterCell) and contains the shared body calling self.id_tracker.borrow().internal_id(...), self.handle_point_version_and_failure(...), delete_point_internal(...) and version_tracker.set_payload(...); then refactor both trait implementations to delegate to this helper (maintaining both method signatures) so behavior is unchanged while removing duplication around delete_point, delete_point_mut, handle_point_version_and_failure, delete_point_internal and version_tracker.set_payload.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/segment/tests/integration/disbalanced_vectors_test.rs`:
- Line 74: Replace the implicit .into() conversion used as the second argument
to delete_point_mut with an explicit PointIdType conversion: change the call to
pass segment::types::PointIdType::from(NUM_VECTORS_1 + i) (or
PointIdType::from(...) after importing the type) so the second parameter is
explicitly a PointIdType for the delete_point_mut invocation.
In `@lib/shard/src/proxy_segment/segment_entry.rs`:
- Around line 662-664: The deferred_points_count() currently returns the wrapped
segment's raw count and can include points hidden by the proxy; change it to
compute the count consistent with the proxy by using the proxy-aware visibility
helpers (e.g., call deferred_point_ids().len() or iterate
wrapped_segment.get().read().deferred_point_ids() and filter with
point_is_deferred()) so deleted proxy tombstones are excluded; update the
implementation in deferred_points_count() to return the filtered count instead
of forwarding wrapped_segment.get().read().deferred_points_count().
---
Nitpick comments:
In `@lib/segment/src/segment/entry.rs`:
- Around line 935-957: The two methods delete_point and delete_point_mut
duplicate the same logic; extract a private helper (e.g., delete_point_impl)
that accepts (op_num: SeqNumberType, point_id: PointIdType, hw_counter:
&HardwareCounterCell) and contains the shared body calling
self.id_tracker.borrow().internal_id(...),
self.handle_point_version_and_failure(...), delete_point_internal(...) and
version_tracker.set_payload(...); then refactor both trait implementations to
delegate to this helper (maintaining both method signatures) so behavior is
unchanged while removing duplication around delete_point, delete_point_mut,
handle_point_version_and_failure, delete_point_internal and
version_tracker.set_payload.
In `@lib/segment/src/segment/tests.rs`:
- Around line 68-70: Replace implicit `.into()` conversions for point IDs with
an explicit type conversion using PointId::from(...) at each delete_point_mut
call site (e.g., in the delete_point_mut(...) invocations in tests.rs). Locate
the calls to delete_point_mut (the ones using `1.into()` etc.) and change the
point-id argument to `PointId::from(<value>)` (and similarly for other
occurrences listed: 418-420, 426-428, 496-498, 504-506) so the point-id
conversion is explicit and follows the repo convention.
In `@lib/segment/tests/integration/payload_index_test.rs`:
- Around line 223-234: The delete loops call delete_point_mut(opnum,
idx_to_remove.into(), &hw_counter) with implicit .into(); change these to
explicit conversions using the concrete parameter type of delete_point_mut
(e.g., PointId::from(idx_to_remove) or the actual second-parameter type used by
delete_point_mut) so the conversion is explicit; update every occurrence in this
block and the similar loop at the other location (around lines 474-482) to use
<TargetType>::from(idx_to_remove) where <TargetType> is the function's
second-parameter type.
In `@lib/shard/src/proxy_segment/tests.rs`:
- Around line 72-74: Replace implicit .into() conversions for point IDs with an
explicit SomePointIdType::from(...) call: locate uses like
proxy_segment.delete_point_mut(102, 1.into(), &hw_counter) (and the other
similar invocations noted) and change the second argument from x.into() to the
concrete point-ID constructor, e.g., PointId::from(1) (use the actual point-ID
type in this crate). Ensure all occurrences (including the other listed call
sites) follow this explicit SomeType::from(x) pattern.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2a2287ba-7a6e-458f-ace0-febbbd4739d9
📒 Files selected for processing (47)
lib/collection/src/collection_manager/collection_updater.rslib/collection/src/collection_manager/optimizers/config_mismatch_optimizer.rslib/collection/src/collection_manager/optimizers/indexing_optimizer.rslib/collection/src/collection_manager/optimizers/vacuum_optimizer.rslib/collection/src/collection_manager/tests/mod.rslib/collection/src/shards/local_shard/mod.rslib/collection/src/shards/local_shard/snapshot.rslib/edge/src/lib.rslib/segment/benches/hnsw_incremental_build.rslib/segment/benches/segment_info.rslib/segment/src/entry/entry_point.rslib/segment/src/entry/mod.rslib/segment/src/index/struct_payload_index.rslib/segment/src/segment/entry.rslib/segment/src/segment/facet.rslib/segment/src/segment/scroll.rslib/segment/src/segment/search.rslib/segment/src/segment/segment_ops.rslib/segment/src/segment/snapshot.rslib/segment/src/segment/tests.rslib/segment/src/segment_constructor/segment_builder.rslib/segment/src/segment_constructor/segment_constructor_base.rslib/segment/src/segment_constructor/simple_segment_constructor.rslib/segment/tests/integration/batch_search_test.rslib/segment/tests/integration/disbalanced_vectors_test.rslib/segment/tests/integration/hnsw_quantized_search_test.rslib/segment/tests/integration/multivector_hnsw_test.rslib/segment/tests/integration/payload_index_test.rslib/segment/tests/integration/segment_builder_test.rslib/segment/tests/integration/segment_on_disk_snapshot.rslib/segment/tests/integration/segment_tests.rslib/segment/tests/integration/sparse_vector_index_search_tests.rslib/shard/src/fixtures.rslib/shard/src/locked_segment.rslib/shard/src/optimize.rslib/shard/src/optimizers/config_mismatch_optimizer.rslib/shard/src/optimizers/indexing_optimizer.rslib/shard/src/optimizers/merge_optimizer.rslib/shard/src/optimizers/segment_optimizer.rslib/shard/src/optimizers/vacuum_optimizer.rslib/shard/src/proxy_segment/segment_entry.rslib/shard/src/proxy_segment/tests.rslib/shard/src/segment_holder/flush.rslib/shard/src/segment_holder/mod.rslib/shard/src/segment_holder/read_points.rslib/shard/src/segment_holder/snapshot.rssrc/segment_inspector.rs
✅ Files skipped from review due to trivial changes (1)
- lib/shard/src/optimizers/segment_optimizer.rs
🚧 Files skipped from review as they are similar to previous changes (25)
- lib/collection/src/shards/local_shard/mod.rs
- lib/segment/tests/integration/batch_search_test.rs
- lib/segment/tests/integration/multivector_hnsw_test.rs
- lib/segment/src/segment/snapshot.rs
- lib/shard/src/fixtures.rs
- lib/collection/src/collection_manager/collection_updater.rs
- lib/collection/src/collection_manager/tests/mod.rs
- lib/segment/src/segment_constructor/segment_builder.rs
- lib/segment/src/segment/segment_ops.rs
- lib/segment/src/index/struct_payload_index.rs
- lib/segment/src/segment/search.rs
- lib/segment/benches/hnsw_incremental_build.rs
- lib/segment/src/segment_constructor/segment_constructor_base.rs
- lib/collection/src/shards/local_shard/snapshot.rs
- lib/segment/tests/integration/sparse_vector_index_search_tests.rs
- lib/segment/tests/integration/segment_tests.rs
- lib/shard/src/segment_holder/read_points.rs
- lib/shard/src/optimize.rs
- lib/edge/src/lib.rs
- src/segment_inspector.rs
- lib/segment/src/segment/scroll.rs
- lib/collection/src/collection_manager/optimizers/vacuum_optimizer.rs
- lib/segment/tests/integration/segment_builder_test.rs
- lib/shard/src/segment_holder/snapshot.rs
- lib/segment/src/entry/mod.rs
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
lib/shard/src/proxy_segment/segment_entry.rs (1)
591-593:⚠️ Potential issue | 🟡 Minor
deferred_points_count()is not proxy-aware and can overcount deferred points.Line 591 forwards the wrapped segment count directly, while this proxy already filters tombstoned points in
deferred_point_ids()(Line 585-588). That makes the count inconsistent with the proxy-visible deferred set.🔧 Suggested fix
fn deferred_points_count(&self) -> usize { - self.wrapped_segment.get().read().deferred_points_count() + self.deferred_point_ids().len() }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/shard/src/proxy_segment/segment_entry.rs` around lines 591 - 593, The proxy's deferred_points_count() currently returns the wrapped segment's count and can overcount because the proxy filters out tombstoned points in deferred_point_ids(); change deferred_points_count() to compute its value from the proxy-visible set (e.g., return self.deferred_point_ids().len()) so it reflects the same tombstone-filtered deferred points as deferred_point_ids() rather than forwarding wrapped_segment.get().read().deferred_points_count().
🧹 Nitpick comments (1)
lib/segment/src/segment/entry.rs (1)
958-979: Reduce duplication betweenSegmentEntryandNonAppendableSegmentEntryindex/delete paths.
delete_point_mutand the_mutfield-index methods mirror logic already implemented in theNonAppendableSegmentEntryblock. Keeping both copies in sync will be easy to miss in future changes.♻️ Suggested direction
impl SegmentEntry for Segment { fn delete_point_mut( &mut self, op_num: SeqNumberType, point_id: PointIdType, hw_counter: &HardwareCounterCell, ) -> OperationResult<bool> { - // duplicated body + NonAppendableSegmentEntry::delete_point(self, op_num, point_id, hw_counter) } fn delete_field_index_mut( &mut self, op_num: u64, key: PayloadKeyTypeRef, ) -> OperationResult<bool> { - // duplicated body + NonAppendableSegmentEntry::delete_field_index(self, op_num, key) } // same delegation pattern for other shared index methods }Also applies to: 1159-1243
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/segment/entry.rs` around lines 958 - 979, The delete and _mut field-index logic in SegmentEntry::delete_point_mut duplicates code already present in NonAppendableSegmentEntry; refactor by extracting the shared behavior into a single helper used by both implementations: create a private method (e.g., handle_delete_or_field_mut) on Segment that encapsulates the sequence of resolving internal_id via id_tracker.internal_id(point_id), calling handle_point_version_and_failure with the closure that calls delete_point_internal (or the field-index variant) and then version_tracker.set_payload(Some(op_num)), and returning the same OperationResult; update Segment::delete_point_mut and the _mut field-index methods to call that helper, and ensure the helper accepts parameters to differentiate delete vs field-index actions (e.g., an enum or closure) so both code paths use the single implementation used by NonAppendableSegmentEntry.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/segment/tests/integration/payload_index_test.rs`:
- Line 418: Replace the implicit conversion Keyword.into() with an explicit call
to PayloadFieldSchema::from(Keyword) where the field index is created (see the
create_field_index_mut call using nested_str_key and hw_counter); update any
other occurrences in this test to use PayloadFieldSchema::from(Keyword) instead
of .into() to match the repository style for Rust files.
---
Duplicate comments:
In `@lib/shard/src/proxy_segment/segment_entry.rs`:
- Around line 591-593: The proxy's deferred_points_count() currently returns the
wrapped segment's count and can overcount because the proxy filters out
tombstoned points in deferred_point_ids(); change deferred_points_count() to
compute its value from the proxy-visible set (e.g., return
self.deferred_point_ids().len()) so it reflects the same tombstone-filtered
deferred points as deferred_point_ids() rather than forwarding
wrapped_segment.get().read().deferred_points_count().
---
Nitpick comments:
In `@lib/segment/src/segment/entry.rs`:
- Around line 958-979: The delete and _mut field-index logic in
SegmentEntry::delete_point_mut duplicates code already present in
NonAppendableSegmentEntry; refactor by extracting the shared behavior into a
single helper used by both implementations: create a private method (e.g.,
handle_delete_or_field_mut) on Segment that encapsulates the sequence of
resolving internal_id via id_tracker.internal_id(point_id), calling
handle_point_version_and_failure with the closure that calls
delete_point_internal (or the field-index variant) and then
version_tracker.set_payload(Some(op_num)), and returning the same
OperationResult; update Segment::delete_point_mut and the _mut field-index
methods to call that helper, and ensure the helper accepts parameters to
differentiate delete vs field-index actions (e.g., an enum or closure) so both
code paths use the single implementation used by NonAppendableSegmentEntry.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 786ce772-6c34-4163-8085-ccaed1c71584
📒 Files selected for processing (20)
lib/collection/src/collection_manager/collection_updater.rslib/collection/src/collection_manager/optimizers/vacuum_optimizer.rslib/segment/benches/segment_info.rslib/segment/src/entry/entry_point.rslib/segment/src/index/struct_payload_index.rslib/segment/src/segment/entry.rslib/segment/src/segment/segment_ops.rslib/segment/src/segment/tests.rslib/segment/tests/integration/batch_search_test.rslib/segment/tests/integration/hnsw_quantized_search_test.rslib/segment/tests/integration/multivector_hnsw_test.rslib/segment/tests/integration/payload_index_test.rslib/segment/tests/integration/segment_builder_test.rslib/segment/tests/integration/segment_on_disk_snapshot.rslib/shard/src/optimize.rslib/shard/src/proxy_segment/mod.rslib/shard/src/proxy_segment/segment_entry.rslib/shard/src/proxy_segment/tests.rslib/shard/src/segment_holder/mod.rslib/shard/src/update.rs
🚧 Files skipped from review as they are similar to previous changes (4)
- lib/shard/src/optimize.rs
- lib/segment/benches/segment_info.rs
- lib/segment/tests/integration/segment_builder_test.rs
- lib/segment/src/index/struct_payload_index.rs
generall
left a comment
There was a problem hiding this comment.
newly introduced *_mut functions duplicate a lot of code. They are not strictly necessary for this PR, please remove
407f7be to
01fe8f1
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (4)
lib/shard/src/locked_segment.rs (1)
7-7: Add aget_storage()accessor alongsideget_read().
flush.rsnow has to recover storage-only capabilities through the broaderget()path. Adding a storage-scoped accessor here would keep that invariant local toLockedSegmentand make the new split easier to follow.♻️ Possible follow-up
-use segment::entry::{ReadSegmentEntry, SegmentEntry, StorageSegmentEntry as _}; +use segment::entry::{ReadSegmentEntry, SegmentEntry, StorageSegmentEntry}; @@ pub fn get_read(&self) -> &RwLock<dyn ReadSegmentEntry> { match self { LockedSegment::Original(segment) => segment.as_ref(), LockedSegment::Proxy(proxy) => proxy.as_ref(), } } + + pub fn get_storage(&self) -> &RwLock<dyn StorageSegmentEntry> { + match self { + LockedSegment::Original(segment) => segment.as_ref(), + LockedSegment::Proxy(proxy) => proxy.as_ref(), + } + }Also applies to: 60-65
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/shard/src/locked_segment.rs` at line 7, Add a storage-scoped accessor on LockedSegment parallel to the existing get_read(): implement a pub fn get_storage(&self) -> StorageSegmentEntry (or the concrete storage-entry type used) that mirrors get_read() but returns the StorageSegmentEntry view from the underlying SegmentEntry so callers like flush.rs can call get_storage() instead of routing through get(); update imports to ensure StorageSegmentEntry is in scope alongside ReadSegmentEntry and use the new method in flush.rs where storage-only capabilities are required.lib/shard/src/segment_holder/tests.rs (1)
1243-1248: Prefer explicitPointIdType::from(...)in the updated delete calls.These two new call sites still use implicit
.into(). Making the conversion explicit keeps the target type obvious and matches the repo’s Rust style.As per coding guidelines "Prefer explicit SomeType::from(x) over implicit x.into() in Rust".
Also applies to: 1274-1278
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/shard/src/segment_holder/tests.rs` around lines 1243 - 1248, Replace the implicit .into() conversions with explicit PointIdType::from(...) at the two delete call sites to match repo style: in the calls to inner_proxies[0].1.get().write().delete_point_mut(10, 1.into(), &hw_counter) and the similar call around lines 1274–1278, change the second argument to PointIdType::from(1) (or the appropriate literal/variable) so the type conversion is explicit for delete_point_mut.lib/segment/src/segment/entry.rs (1)
852-956: Consider extracting shared implementation to reduce duplication.The implementations of
delete_point/delete_point_mut,delete_field_index/delete_field_index_mut,delete_field_index_if_incompatible/delete_field_index_if_incompatible_mut,build_field_index(duplicated), andapply_field_index/apply_field_index_mutare identical betweenNonAppendableSegmentEntryandSegmentEntry.If the intent is for these to diverge in the future (as suggested in past review discussions), this is acceptable. However, if they will remain identical, consider extracting the shared logic into private helper methods to reduce maintenance burden.
Also applies to: 958-1243
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/segment/entry.rs` around lines 852 - 956, Multiple methods (delete_point/delete_point_mut, delete_field_index/delete_field_index_mut, delete_field_index_if_incompatible/delete_field_index_if_incompatible_mut, build_field_index, apply_field_index/apply_field_index_mut) in NonAppendableSegmentEntry and SegmentEntry are identical; extract the shared logic into private helper methods on Segment (e.g., segment_delete_point_helper, segment_drop_index_helper, segment_drop_index_if_incompatible_helper, segment_build_field_index_helper, segment_apply_field_index_helper) and have both trait impls call those helpers to remove duplication; update references inside helpers to use the same symbols used now (id_tracker.internal_id, handle_point_version_and_failure, handle_segment_version_and_failure, payload_index.borrow_mut()/borrow(), version_tracker.set_payload..., BuildIndexResult/BuildFieldIndexResult and HardwareCounterCell) so behavior remains unchanged.lib/segment/src/segment/tests.rs (1)
193-194: Redundant import.
StorageSegmentEntry as _is already imported at module level (line 29). This inner import can be removed.🧹 Suggested removal
fn test_snapshot(#[case] format: SnapshotFormat) { - use crate::entry::StorageSegmentEntry as _; - init_logger();🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/segment/tests.rs` around lines 193 - 194, Remove the redundant inner import of StorageSegmentEntry as _ from the test module: the symbol StorageSegmentEntry is already imported at module level, so delete the line `use crate::entry::StorageSegmentEntry as _` in the tests.rs block referenced (it is unnecessary and should be removed to avoid duplication).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@lib/segment/src/segment/entry.rs`:
- Around line 852-956: Multiple methods (delete_point/delete_point_mut,
delete_field_index/delete_field_index_mut,
delete_field_index_if_incompatible/delete_field_index_if_incompatible_mut,
build_field_index, apply_field_index/apply_field_index_mut) in
NonAppendableSegmentEntry and SegmentEntry are identical; extract the shared
logic into private helper methods on Segment (e.g., segment_delete_point_helper,
segment_drop_index_helper, segment_drop_index_if_incompatible_helper,
segment_build_field_index_helper, segment_apply_field_index_helper) and have
both trait impls call those helpers to remove duplication; update references
inside helpers to use the same symbols used now (id_tracker.internal_id,
handle_point_version_and_failure, handle_segment_version_and_failure,
payload_index.borrow_mut()/borrow(), version_tracker.set_payload...,
BuildIndexResult/BuildFieldIndexResult and HardwareCounterCell) so behavior
remains unchanged.
In `@lib/segment/src/segment/tests.rs`:
- Around line 193-194: Remove the redundant inner import of StorageSegmentEntry
as _ from the test module: the symbol StorageSegmentEntry is already imported at
module level, so delete the line `use crate::entry::StorageSegmentEntry as _` in
the tests.rs block referenced (it is unnecessary and should be removed to avoid
duplication).
In `@lib/shard/src/locked_segment.rs`:
- Line 7: Add a storage-scoped accessor on LockedSegment parallel to the
existing get_read(): implement a pub fn get_storage(&self) ->
StorageSegmentEntry (or the concrete storage-entry type used) that mirrors
get_read() but returns the StorageSegmentEntry view from the underlying
SegmentEntry so callers like flush.rs can call get_storage() instead of routing
through get(); update imports to ensure StorageSegmentEntry is in scope
alongside ReadSegmentEntry and use the new method in flush.rs where storage-only
capabilities are required.
In `@lib/shard/src/segment_holder/tests.rs`:
- Around line 1243-1248: Replace the implicit .into() conversions with explicit
PointIdType::from(...) at the two delete call sites to match repo style: in the
calls to inner_proxies[0].1.get().write().delete_point_mut(10, 1.into(),
&hw_counter) and the similar call around lines 1274–1278, change the second
argument to PointIdType::from(1) (or the appropriate literal/variable) so the
type conversion is explicit for delete_point_mut.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 91164ca5-bdbf-4317-b7a2-49ea2a5053ae
📒 Files selected for processing (50)
lib/collection/src/collection_manager/collection_updater.rslib/collection/src/collection_manager/optimizers/config_mismatch_optimizer.rslib/collection/src/collection_manager/optimizers/indexing_optimizer.rslib/collection/src/collection_manager/optimizers/vacuum_optimizer.rslib/collection/src/collection_manager/tests/mod.rslib/collection/src/shards/local_shard/mod.rslib/collection/src/shards/local_shard/snapshot.rslib/edge/src/lib.rslib/segment/benches/hnsw_incremental_build.rslib/segment/benches/segment_info.rslib/segment/src/entry/entry_point.rslib/segment/src/entry/mod.rslib/segment/src/index/struct_payload_index.rslib/segment/src/segment/entry.rslib/segment/src/segment/facet.rslib/segment/src/segment/scroll.rslib/segment/src/segment/search.rslib/segment/src/segment/segment_ops.rslib/segment/src/segment/snapshot.rslib/segment/src/segment/tests.rslib/segment/src/segment_constructor/segment_builder.rslib/segment/src/segment_constructor/segment_constructor_base.rslib/segment/src/segment_constructor/simple_segment_constructor.rslib/segment/tests/integration/batch_search_test.rslib/segment/tests/integration/disbalanced_vectors_test.rslib/segment/tests/integration/hnsw_quantized_search_test.rslib/segment/tests/integration/multivector_hnsw_test.rslib/segment/tests/integration/payload_index_test.rslib/segment/tests/integration/segment_builder_test.rslib/segment/tests/integration/segment_on_disk_snapshot.rslib/segment/tests/integration/segment_tests.rslib/segment/tests/integration/sparse_vector_index_search_tests.rslib/shard/src/fixtures.rslib/shard/src/locked_segment.rslib/shard/src/optimize.rslib/shard/src/optimizers/config_mismatch_optimizer.rslib/shard/src/optimizers/indexing_optimizer.rslib/shard/src/optimizers/merge_optimizer.rslib/shard/src/optimizers/segment_optimizer.rslib/shard/src/optimizers/vacuum_optimizer.rslib/shard/src/proxy_segment/mod.rslib/shard/src/proxy_segment/segment_entry.rslib/shard/src/proxy_segment/tests.rslib/shard/src/segment_holder/flush.rslib/shard/src/segment_holder/mod.rslib/shard/src/segment_holder/read_points.rslib/shard/src/segment_holder/snapshot.rslib/shard/src/segment_holder/tests.rslib/shard/src/update.rssrc/segment_inspector.rs
✅ Files skipped from review due to trivial changes (19)
- lib/collection/src/collection_manager/optimizers/config_mismatch_optimizer.rs
- lib/segment/src/segment/scroll.rs
- lib/collection/src/collection_manager/optimizers/indexing_optimizer.rs
- lib/segment/src/segment_constructor/simple_segment_constructor.rs
- lib/edge/src/lib.rs
- lib/segment/src/segment/snapshot.rs
- lib/shard/src/optimizers/merge_optimizer.rs
- lib/shard/src/segment_holder/snapshot.rs
- lib/segment/benches/hnsw_incremental_build.rs
- lib/segment/src/segment/facet.rs
- lib/collection/src/shards/local_shard/mod.rs
- src/segment_inspector.rs
- lib/segment/src/segment_constructor/segment_constructor_base.rs
- lib/shard/src/optimize.rs
- lib/shard/src/fixtures.rs
- lib/segment/tests/integration/sparse_vector_index_search_tests.rs
- lib/segment/src/index/struct_payload_index.rs
- lib/shard/src/optimizers/segment_optimizer.rs
- lib/shard/src/optimizers/config_mismatch_optimizer.rs
🚧 Files skipped from review as they are similar to previous changes (20)
- lib/segment/src/segment/search.rs
- lib/collection/src/collection_manager/tests/mod.rs
- lib/segment/src/entry/mod.rs
- lib/segment/tests/integration/multivector_hnsw_test.rs
- lib/shard/src/optimizers/indexing_optimizer.rs
- lib/collection/src/collection_manager/collection_updater.rs
- lib/segment/src/segment_constructor/segment_builder.rs
- lib/segment/tests/integration/batch_search_test.rs
- lib/segment/benches/segment_info.rs
- lib/segment/tests/integration/segment_tests.rs
- lib/collection/src/collection_manager/optimizers/vacuum_optimizer.rs
- lib/segment/tests/integration/segment_builder_test.rs
- lib/shard/src/update.rs
- lib/segment/tests/integration/disbalanced_vectors_test.rs
- lib/segment/tests/integration/payload_index_test.rs
- lib/shard/src/proxy_segment/tests.rs
- lib/shard/src/segment_holder/read_points.rs
- lib/segment/src/segment/segment_ops.rs
- lib/segment/tests/integration/hnsw_quantized_search_test.rs
- lib/shard/src/proxy_segment/segment_entry.rs
1f5a49d to
4f50779
Compare
|
@monoid there are conflicts again =( |
4f50779 to
4c7f127
Compare
It contains methods dealing with storage and syncronization
to `SegmentEntry`
4c7f127 to
b82ef93
Compare
Rebased. |
* Refactor: `SearchSegmentEntry` for search ops * Move `has_deferrend_points_method` to `SearchSegmentEntry` * Reorg imports * Renamings per review * fixup! Renamings per review * `StorageSegmentEntry` trait It contains methods dealing with storage and syncronization * Move index methods from `ReadSegmentEntry` to `SegmentEntry` * Add `_concurrent` suffix to some methods * move field index methods into NonAppendableSegmentEntry --------- Co-authored-by: generall <[email protected]>
* Refactor: `SearchSegmentEntry` for search ops * Move `has_deferrend_points_method` to `SearchSegmentEntry` * Reorg imports * Renamings per review * fixup! Renamings per review * `StorageSegmentEntry` trait It contains methods dealing with storage and syncronization * Move index methods from `ReadSegmentEntry` to `SegmentEntry` * Add `_concurrent` suffix to some methods * move field index methods into NonAppendableSegmentEntry --------- Co-authored-by: generall <[email protected]>
Make Y-shaped segment trait hierarchy: introduce a
SearchSegmentEntrywith common functionality, andNonAppendableSegmentEntryfor non-appendable segments, andSegmentEntryfor appendable ones.It would allow to to have
NonAppendableSegmentEntryandSegmentEntrymethods have different mutability, and have different segment type to have different implementation.All Submissions:
devbranch. Did you create your branch fromdev?New Feature Submissions:
cargo +nightly fmt --allcommand prior to submission?cargo clippy --workspace --all-featurescommand?Changes to Core Features: