Skip to content

Explicit point_mappings guard in IdTracker - #8261

Merged
monoid merged 7 commits into
devfrom
point_mappings_ref
Mar 19, 2026
Merged

monoid merged 7 commits into
devfrom
point_mappings_ref

Conversation

@monoid

@monoid monoid commented Mar 2, 2026 •

Copy link
Copy Markdown
Contributor

The IdTracker methods do not return iterators anymore. Instead, you should take explicitely the PointMappingsRefEnum guard and use its methods. It prepares for moving the point_mappings under a lock to allow parallel searches and deletions.

All Submissions:

  • Contributions should target the dev branch. Did you create your branch from dev?
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you formatted your code locally using cargo +nightly fmt --all command prior to submission?
  3. Have you checked your code using cargo clippy --workspace --all-features command?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@monoid monoid self-assigned this Mar 2, 2026
@monoid monoid changed the title Explicit owning of point_mappnigs guard in the API Explicit owning of point_mappnigs in the API Mar 2, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/shard/src/proxy_segment/segment_entry.rs (1)

236-240: ⚠️ Potential issue | 🔴 Critical

Fix comment text and address that dedup cannot process proxy segments.

The method is get_points, not iter_points. More importantly, find_duplicated_points() at line 918 calls self.get_points() to retrieve all segments, then calls .iter_points() on each segment (line 928 in segment_holder/mod.rs)—which will invoke get_points() on proxy segments and panic during deduplication. Either:

  • Exclude proxy segments from dedup iteration using iter_original() pattern (as used elsewhere for optimizers), or
  • Implement get_points() for proxy segments to delegate to the wrapped segment with appropriate point filtering.
🤖 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 236 - 240, The
get_points() stub on ProxySegment currently panics and causes
find_duplicated_points() (which calls self.get_points() then .iter_points() on
each segment) to fail for proxy segments; either skip proxy segments during
dedup by using the iter_original() pattern where segments are iterated over
their original/non-proxy implementations, or implement
ProxySegment::get_points() to delegate to the wrapped segment’s
get_points()/iter_points() while applying the correct point filtering/visibility
logic so it returns a valid PointExternalIterator instead of unimplemented!;
update references in find_duplicated_points() / segment iteration so proxy
segments are excluded or return a real iterator (refer to get_points,
iter_points, iter_original, and find_duplicated_points to locate affected code).
🧹 Nitpick comments (2)
lib/collection/src/collection_manager/optimizers/vacuum_optimizer.rs (1)

370-373: Use get_points() consistently and fix the typo in the comment.

This block still uses iter_points().iter() while neighboring updates use get_points().iter().

♻️ Suggested cleanup
-            // Deget_points points
+            // Delete points
             let segment_points_to_delete = segment
-                .iter_points()
+                .get_points()
                 .iter()
                 .enumerate()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/collection/src/collection_manager/optimizers/vacuum_optimizer.rs` around
lines 370 - 373, The comment "Deget_points points" is a typo and the code uses
segment.iter_points().iter() inconsistently; change the comment to "Deleted
points" (or "Delete points") and replace segment.iter_points().iter() with
segment.get_points().iter() so it matches neighboring code and uses the correct
accessor (reference the variable segment_points_to_delete and method names
iter_points and get_points in vacuum_optimizer.rs).
lib/segment/src/segment/entry.rs (1)

257-261: Rename owinging_guard to owning_guard for clarity in unsafe-adjacent code.

This makes the block easier to audit.

🧹 Suggested rename
-        let owinging_guard =
+        let owning_guard =
             unsafe { OwningGuard::new(id_tracker_guard, IdTrackerEnum::point_mappings) };
         PointExternalIterator {
-            mappings: owinging_guard,
+            mappings: owning_guard,
         }
🤖 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 257 - 261, The variable name
owinging_guard is a typo and should be renamed to owning_guard where it's
created (unsafe { OwningGuard::new(id_tracker_guard,
IdTrackerEnum::point_mappings) }) and where it's used to construct
PointExternalIterator { mappings: ... }; update the identifier consistently to
owning_guard to improve clarity around the unsafe block and the OwningGuard
usage.
🤖 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/common/common/src/guards.rs`:
- Around line 26-28: The safety docs currently reference `inner_guard_fn` but
the actual parameter is named `inner_value_fn`; update the unsafe contract text
in guards.rs so all occurrences of `inner_guard_fn` are renamed to
`inner_value_fn` (and similarly verify any related mentions like `outer_guard`
remain correct) to ensure the doc matches the function signature and the unsafe
API contract precisely.

In `@lib/segment/src/id_tracker/id_tracker_base.rs`:
- Around line 256-259: Update the documentation on PointExternalIterator to
reference the current API: replace the stale mention of
NonAppendableSegmentEntry::iter_points() with
NonAppendableSegmentEntry::get_points(); edit the doc comment above
PointExternalIterator where it describes usage to mention get_points() as the
method that returns the external ID iterator and ensure wording reflects the new
method name (PointExternalIterator, NonAppendableSegmentEntry::get_points()) so
docs align with the current API.

In `@lib/segment/src/segment/tests.rs`:
- Line 277: The test still calls segment.iter_points() but the API now exposes
get_points(); update the loop to iterate over segment.get_points().iter() (or
directly segment.get_points().iter() in the for loop) wherever iter_points() is
referenced (e.g., the loop using iter_points() at the test harness), ensuring
you replace calls to iter_points() with get_points() and keep .iter() to iterate
over the returned collection.
- Around line 268-271: The assert_eq! invocation is broken by an extraneous
token "get_points"; remove the stray "get_points" so the assertion reads
assert_eq!(segment.available_point_count(),
restored_segment.available_point_count()); (locate the broken macro call around
assert_eq!, get_points, segment.available_point_count, and
restored_segment.available_point_count and fix the macro invocation to have only
the two arguments and optional message).

In `@lib/shard/src/optimize.rs`:
- Around line 381-383: Fix the typo and improve readability in the comment that
currently reads "Avoid unnecessary point removing in the cget_pointstion:" (the
comment block above the post-optimization removal logic in optimize.rs); replace
"cget_pointstion" with "critical section" and consider changing "point removing"
to "point removal" so the comment reads something like "Avoid unnecessary point
removal in the critical section: - save already removed points while avoiding
long read locks - exclude already removed points from post-optimization
removing".

---

Outside diff comments:
In `@lib/shard/src/proxy_segment/segment_entry.rs`:
- Around line 236-240: The get_points() stub on ProxySegment currently panics
and causes find_duplicated_points() (which calls self.get_points() then
.iter_points() on each segment) to fail for proxy segments; either skip proxy
segments during dedup by using the iter_original() pattern where segments are
iterated over their original/non-proxy implementations, or implement
ProxySegment::get_points() to delegate to the wrapped segment’s
get_points()/iter_points() while applying the correct point filtering/visibility
logic so it returns a valid PointExternalIterator instead of unimplemented!;
update references in find_duplicated_points() / segment iteration so proxy
segments are excluded or return a real iterator (refer to get_points,
iter_points, iter_original, and find_duplicated_points to locate affected code).

---

Nitpick comments:
In `@lib/collection/src/collection_manager/optimizers/vacuum_optimizer.rs`:
- Around line 370-373: The comment "Deget_points points" is a typo and the code
uses segment.iter_points().iter() inconsistently; change the comment to "Deleted
points" (or "Delete points") and replace segment.iter_points().iter() with
segment.get_points().iter() so it matches neighboring code and uses the correct
accessor (reference the variable segment_points_to_delete and method names
iter_points and get_points in vacuum_optimizer.rs).

In `@lib/segment/src/segment/entry.rs`:
- Around line 257-261: The variable name owinging_guard is a typo and should be
renamed to owning_guard where it's created (unsafe {
OwningGuard::new(id_tracker_guard, IdTrackerEnum::point_mappings) }) and where
it's used to construct PointExternalIterator { mappings: ... }; update the
identifier consistently to owning_guard to improve clarity around the unsafe
block and the OwningGuard usage.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15be52f and 1d761dc.

📒 Files selected for processing (31)
  • lib/collection/src/collection_manager/optimizers/vacuum_optimizer.rs
  • lib/collection/src/collection_manager/tests/mod.rs
  • lib/common/common/src/guards.rs
  • lib/common/common/src/lib.rs
  • lib/segment/src/entry/entry_point.rs
  • lib/segment/src/id_tracker/id_tracker_base.rs
  • lib/segment/src/id_tracker/immutable_id_tracker.rs
  • lib/segment/src/id_tracker/in_memory_id_tracker.rs
  • lib/segment/src/id_tracker/mod.rs
  • lib/segment/src/id_tracker/mutable_id_tracker.rs
  • lib/segment/src/id_tracker/simple_id_tracker.rs
  • lib/segment/src/index/hnsw_index/hnsw.rs
  • lib/segment/src/index/plain_payload_index.rs
  • lib/segment/src/index/query_optimization/condition_converter.rs
  • lib/segment/src/index/sparse_index/sparse_vector_index.rs
  • lib/segment/src/index/struct_payload_index.rs
  • lib/segment/src/segment/entry.rs
  • lib/segment/src/segment/sampling.rs
  • lib/segment/src/segment/scroll.rs
  • lib/segment/src/segment/segment_ops.rs
  • lib/segment/src/segment/tests.rs
  • lib/segment/src/segment_constructor/segment_constructor_base.rs
  • lib/segment/src/vector_storage/dense/memmap_dense_vector_storage.rs
  • lib/segment/src/vector_storage/tests/test_appendable_dense_vector_storage.rs
  • lib/segment/tests/integration/payload_index_test.rs
  • lib/segment/tests/integration/segment_builder_test.rs
  • lib/segment/tests/integration/segment_on_disk_snapshot.rs
  • lib/segment/tests/integration/segment_tests.rs
  • lib/shard/src/optimize.rs
  • lib/shard/src/proxy_segment/segment_entry.rs
  • lib/shard/src/segment_holder/mod.rs

Comment thread lib/common/common/src/guards.rs Resolved
Comment thread lib/segment/src/segment/tests.rs Resolved
Comment thread lib/segment/src/segment/tests.rs Resolved
Comment thread lib/shard/src/optimize.rs Resolved
@timvisee timvisee changed the title Explicit owning of point_mappnigs in the API Explicit owning of point_mappings in the API Mar 2, 2026
@monoid
monoid force-pushed the point_mappings_ref branch from 1d761dc to 5e39fd5 Compare March 2, 2026 15:29
coderabbitai[bot]

This comment was marked as resolved.

@monoid
monoid force-pushed the point_mappings_ref branch 2 times, most recently from 5dabf89 to ffd38f1 Compare March 2, 2026 15:40

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
lib/segment/src/segment/entry.rs (1)

252-261: Minor naming typo in guard variable.

Consider renaming owinging_guard to owning_guard for readability and consistency with OwningGuard.

🤖 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 252 - 261, Rename the
misspelled local variable `owinging_guard` to `owning_guard` in fn get_points so
the OwningGuard returned by unsafe { OwningGuard::new(id_tracker_guard,
IdTrackerEnum::point_mappings) } is assigned to `owning_guard` and then used in
PointMappingsGuard { mappings: owning_guard }, keeping id_tracker_guard and
IdTrackerEnum::point_mappings references unchanged.
🤖 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 236-240: ProxySegment::get_points() currently panics via
unimplemented!() and is reachable from production through
deduplicate_points_tasks() → find_duplicated_points() which iterates all
segments in SegmentHolder and calls get_points(); fix by either (A) preventing
ProxySegment instances from being iterated there (use
SegmentHolder::iter_original() or add a predicate to skip proxies inside
find_duplicated_points()/deduplicate_points_tasks()), or (B) provide a safe
non-panicking implementation in ProxySegment::get_points() that returns an empty
or appropriately-formed PointMappingsGuard fallback; locate the symbols
ProxySegment::get_points, SegmentHolder, find_duplicated_points,
deduplicate_points_tasks, and iter_original to apply the chosen change.

---

Nitpick comments:
In `@lib/segment/src/segment/entry.rs`:
- Around line 252-261: Rename the misspelled local variable `owinging_guard` to
`owning_guard` in fn get_points so the OwningGuard returned by unsafe {
OwningGuard::new(id_tracker_guard, IdTrackerEnum::point_mappings) } is assigned
to `owning_guard` and then used in PointMappingsGuard { mappings: owning_guard
}, keeping id_tracker_guard and IdTrackerEnum::point_mappings references
unchanged.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e39fd5 and ffd38f1.

📒 Files selected for processing (12)
  • lib/collection/src/collection_manager/optimizers/vacuum_optimizer.rs
  • lib/collection/src/collection_manager/tests/mod.rs
  • lib/segment/src/entry/entry_point.rs
  • lib/segment/src/id_tracker/id_tracker_base.rs
  • lib/segment/src/segment/entry.rs
  • lib/segment/src/segment/tests.rs
  • lib/segment/tests/integration/segment_builder_test.rs
  • lib/segment/tests/integration/segment_on_disk_snapshot.rs
  • lib/segment/tests/integration/segment_tests.rs
  • lib/shard/src/optimize.rs
  • lib/shard/src/proxy_segment/segment_entry.rs
  • lib/shard/src/segment_holder/mod.rs
🚧 Files skipped from review as they are similar to previous changes (4)
  • lib/shard/src/optimize.rs
  • lib/segment/tests/integration/segment_tests.rs
  • lib/segment/tests/integration/segment_on_disk_snapshot.rs
  • lib/shard/src/segment_holder/mod.rs

Comment thread lib/common/common/src/guards.rs Outdated
Comment on lines +4 to +13
/// Owning guard holder.
pub struct OwningGuard<'ctx, Outer, Inner>
where
Outer: 'ctx,
{
// Fields are dropped in the order of their definition. It is important to drop the `inner_value` first.
inner_value: Inner,
_outer_guard: Outer,
phantom: PhantomData<&'ctx ()>,
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this struct can be replaced by self_cell. We already have a few usages of it.

Comment on lines +200 to +205
pub fn iter_external(self) -> Box<dyn Iterator<Item = PointIdType> + 'a> {
match self {
PointMappingsRefEnum::Plain(m) => m.iter_external(),
PointMappingsRefEnum::Compressed(m) => m.iter_external(),
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance: use enum dispatch instead of Box<dyn Iterator>.

either::Either implements iterator boilerplate for two-variant enums. So, it'll look like this:

pub fn iter_external(self) -> impl Iterator<Item = PointIdType> {
    match self {
        PointMappingsRefEnum::Plain(m) => Either::Left(m.iter_external()),
        PointMappingsRefEnum::Compressed(m) => Either::Right(m.iter_external()),
    }
}

If we decide to add more variants, it can be chained, e.g.:
Either<Either<A, B>, C>

@monoid monoid Mar 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to implement it. There are cases where there's 3 variants returned from PointMappings, but then it goes down to IdTrackerEnum which has 4 cases, so there's deeply nested Either. I wonder if it is still faster than dyn dispatch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say enum dispatch would still be preferred because it compiles with better optimizations, even for like inlining next() calls. If we keep using impl Iterator as return type, the nesting should not be a problem for ergonomics.

There's also auto_enums crate which makes the +2 variants case more ergonomic to write

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it can be simplified if implementations refer to point_mappings directly. While there are several implementations of IdTracker, they all use only two point mappings implementations. But I suggest doing it in another PR.

@generall

generall commented Mar 2, 2026

Copy link
Copy Markdown
Member

Please add explicit description and motivation of what is changed in this PR and why

@qdrant qdrant deleted a comment from coderabbitai Bot Mar 3, 2026
/// Enum holding a reference to point mappings from an ID tracker.
///
/// Provides iteration methods over external/internal IDs without requiring
/// the `IdTracker` trait to return boxed iterators.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we don't return a boxed iterator from the trait, now we do still return it from pub fn iter_external(self) (and others) below

@monoid
monoid force-pushed the point_mappings_ref branch from ba6c529 to 8b9ca4e Compare March 18, 2026 09:25
@coderabbitai

coderabbitai Bot commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR consolidates IdTracker iteration by removing multiple iterator-returning trait methods and adding a single point_mappings() accessor that returns PointMappingsRefEnum (Plain | Compressed). PointMappingsRefEnum exposes iterator methods that delegate to the underlying mapping. Implementations (InMemory, Immutable, Mutable, Simple, and IdTrackerEnum) and all call sites across segment, index, payload, vector storage, sampling, scroll, and segment construction code were updated to use point_mappings(). A PointMappingsGuard (self_cell) was added to safely couple lifetimes for guarded iteration. A Cargo.toml dependency syntax tweak was also applied.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • JojiiOfficial
  • timvisee
  • ffuugoo
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The PR description clearly explains the purpose of the changes: refactoring IdTracker to return a PointMappingsRefEnum guard instead of direct iterator methods, preparing for future lock-based concurrent access.
Title check ✅ Passed The title clearly summarizes the main change: refactoring IdTracker to explicitly return a point_mappings guard object instead of exposing iterator methods directly.

✏️ 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 point_mappings_ref
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
lib/segment/src/segment/order_by.rs (1)

45-50: Avoid re-entering IdTracker while the mappings view is live.

Given the stated goal of moving point_mappings under a lock, this iterator still keeps the mappings view alive while resolving each hit through id_tracker.external_id(). If that lookup ends up taking the same lock, this path will need another pass. Consider either exposing the reverse lookup on the mappings view itself, or materializing the internal IDs before calling back into id_tracker.

Also applies to: 67-70

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/segment/order_by.rs` around lines 45 - 50, The iterator
returned by payload_index.iter_filtered_points holds point_mappings while you
later call back into id_tracker.external_id(), risking re-entering IdTracker;
fix by materializing the internal IDs (e.g., collect the iterator into a Vec of
internal IDs) before any external_id lookups or by adding a reverse-lookup
method on the point_mappings view so you can resolve external IDs without
calling id_tracker again; update the code paths around point_mappings,
payload_index.iter_filtered_points, and id_tracker.external_id to use the chosen
approach to avoid holding the mappings view while re-entering IdTracker.
lib/segment/src/index/struct_payload_index.rs (1)

620-625: Avoid a split id_tracker / point_mappings contract here.

iter_filtered_points() now accepts two values that must come from the same tracker, but the signature does not enforce that. Since this method only still uses id_tracker for total_point_count(), consider collapsing that dependency before this API spreads further.

Also applies to: 642-642

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/index/struct_payload_index.rs` around lines 620 - 625,
iter_filtered_points currently takes both id_tracker: IdTrackerEnum and
point_mappings: PointMappingsRefEnum but only uses id_tracker for
total_point_count(), creating a fragile split contract; change the API to accept
a single tracker/mappings object instead (e.g., replace the two params with a
single enum/trait that exposes both point_mappings accessors and
total_point_count(), or remove id_tracker and call total_point_count() through
the existing point_mappings variant if it can provide it), update
iter_filtered_points signature and all callers to pass the unified
tracker/mappings value, and remove any direct references to IdTrackerEnum in
this function so the contract requiring paired values is enforced by the type
system.
🤖 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/segment_tests.rs`:
- Around line 68-69: The test currently builds both point_ids1 and point_ids2
from the same call to segment.get_points(), so the assert_eq! only verifies
deterministic iteration rather than comparing two independent API paths; change
the second collection to use a different API or data source (for example call a
different accessor such as segment.get_point_ids() or iterate points via another
method / map lookup provided by the Segment type) so that point_ids2 is produced
by a distinct code path from get_points(), then assert_eq!(point_ids1,
point_ids2) to validate API consistency (update both occurrences around the
other assertion at lines 126-127 similarly).

---

Nitpick comments:
In `@lib/segment/src/index/struct_payload_index.rs`:
- Around line 620-625: iter_filtered_points currently takes both id_tracker:
IdTrackerEnum and point_mappings: PointMappingsRefEnum but only uses id_tracker
for total_point_count(), creating a fragile split contract; change the API to
accept a single tracker/mappings object instead (e.g., replace the two params
with a single enum/trait that exposes both point_mappings accessors and
total_point_count(), or remove id_tracker and call total_point_count() through
the existing point_mappings variant if it can provide it), update
iter_filtered_points signature and all callers to pass the unified
tracker/mappings value, and remove any direct references to IdTrackerEnum in
this function so the contract requiring paired values is enforced by the type
system.

In `@lib/segment/src/segment/order_by.rs`:
- Around line 45-50: The iterator returned by payload_index.iter_filtered_points
holds point_mappings while you later call back into id_tracker.external_id(),
risking re-entering IdTracker; fix by materializing the internal IDs (e.g.,
collect the iterator into a Vec of internal IDs) before any external_id lookups
or by adding a reverse-lookup method on the point_mappings view so you can
resolve external IDs without calling id_tracker again; update the code paths
around point_mappings, payload_index.iter_filtered_points, and
id_tracker.external_id to use the chosen approach to avoid holding the mappings
view while re-entering IdTracker.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3c58038c-eb3d-4231-af00-796687c372e5

📥 Commits

Reviewing files that changed from the base of the PR and between 8c54545 and 8b9ca4e.

📒 Files selected for processing (33)
  • lib/collection/src/collection_manager/optimizers/vacuum_optimizer.rs
  • lib/collection/src/collection_manager/tests/mod.rs
  • lib/collection/src/tests/deferred_points_dedup.rs
  • lib/segment/Cargo.toml
  • lib/segment/src/entry/entry_point.rs
  • lib/segment/src/id_tracker/id_tracker_base.rs
  • lib/segment/src/id_tracker/immutable_id_tracker.rs
  • lib/segment/src/id_tracker/in_memory_id_tracker.rs
  • lib/segment/src/id_tracker/mod.rs
  • lib/segment/src/id_tracker/mutable_id_tracker.rs
  • lib/segment/src/id_tracker/simple_id_tracker.rs
  • lib/segment/src/index/hnsw_index/hnsw.rs
  • lib/segment/src/index/plain_payload_index.rs
  • lib/segment/src/index/query_optimization/condition_converter.rs
  • lib/segment/src/index/sparse_index/sparse_vector_index.rs
  • lib/segment/src/index/struct_payload_index.rs
  • lib/segment/src/segment/entry.rs
  • lib/segment/src/segment/facet.rs
  • lib/segment/src/segment/order_by.rs
  • lib/segment/src/segment/sampling.rs
  • lib/segment/src/segment/scroll.rs
  • lib/segment/src/segment/segment_ops.rs
  • lib/segment/src/segment/tests.rs
  • lib/segment/src/segment_constructor/segment_constructor_base.rs
  • lib/segment/src/vector_storage/dense/memmap_dense_vector_storage.rs
  • lib/segment/src/vector_storage/tests/test_appendable_dense_vector_storage.rs
  • lib/segment/tests/integration/payload_index_test.rs
  • lib/segment/tests/integration/segment_builder_test.rs
  • lib/segment/tests/integration/segment_on_disk_snapshot.rs
  • lib/segment/tests/integration/segment_tests.rs
  • lib/shard/src/optimize.rs
  • lib/shard/src/proxy_segment/segment_entry.rs
  • lib/shard/src/segment_holder/mod.rs

@coszio coszio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already had dynamic dispatch for all these cases, current changes are only improving code, so I'll approve. Please consider the renaming nits, though.

Comment on lines +200 to +205
pub fn iter_external(self) -> Box<dyn Iterator<Item = PointIdType> + 'a> {
match self {
PointMappingsRefEnum::Plain(m) => m.iter_external(),
PointMappingsRefEnum::Compressed(m) => m.iter_external(),
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say enum dispatch would still be preferred because it compiles with better optimizations, even for like inlining next() calls. If we keep using impl Iterator as return type, the nesting should not be a problem for ergonomics.

There's also auto_enums crate which makes the +2 variants case more ergonomic to write

Comment thread lib/segment/src/segment/entry.rs Resolved
Ivan Boldyrev added 5 commits March 19, 2026 17:01
Instead of IdTracker to have iter_* methods, it returns point mappings object
that can be extended to contain a lock guard.
Fix potentially incorrect `unsafe` (it is still `unsafe`, but
correct one).
to `get_points` because it doesn't return an iterator anymore.
@monoid
monoid force-pushed the point_mappings_ref branch from 6a18437 to 0196133 Compare March 19, 2026 16:06

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
lib/segment/tests/integration/segment_tests.rs (1)

68-69: ⚠️ Potential issue | 🟡 Minor

Use an independent source for point_ids2 (current assertion is tautological).

At Line 68 and Line 126, both sides of assert_eq! come from the same call path, so the test only checks determinism, not API consistency.

🔧 Suggested test adjustment
-    let point_ids2: Vec<_> = segment.get_points().iter().collect();
+    let point_ids2 = segment.read_range(None, None);
...
-    let point_ids2: Vec<_> = segment.get_points().iter().collect();
+    let point_ids2 = segment.read_range(None, None);

Also applies to: 126-127

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/tests/integration/segment_tests.rs` around lines 68 - 69, The
test currently assigns both point_ids1 and point_ids2 from the same call path
(segment.get_points()), making the assert_eq! tautological; change point_ids2 to
come from an independent source — for example, collect expected IDs from the
original data fixture or from a second segment instance (or a different API such
as segment.get_point_ids()/segment.iter_points() if available) and then compare
that independent list to point_ids1; update uses of point_ids2 at both the
earlier (point_ids1/point_ids2) and later (lines around the second assertion)
locations so the assertions validate API consistency rather than determinism.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@lib/segment/tests/integration/segment_tests.rs`:
- Around line 68-69: The test currently assigns both point_ids1 and point_ids2
from the same call path (segment.get_points()), making the assert_eq!
tautological; change point_ids2 to come from an independent source — for
example, collect expected IDs from the original data fixture or from a second
segment instance (or a different API such as
segment.get_point_ids()/segment.iter_points() if available) and then compare
that independent list to point_ids1; update uses of point_ids2 at both the
earlier (point_ids1/point_ids2) and later (lines around the second assertion)
locations so the assertions validate API consistency rather than determinism.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 269b792c-26b6-4ae3-939d-6f4168552dd7

📥 Commits

Reviewing files that changed from the base of the PR and between 6a18437 and 0196133.

📒 Files selected for processing (33)
  • lib/collection/src/collection_manager/optimizers/vacuum_optimizer.rs
  • lib/collection/src/collection_manager/tests/mod.rs
  • lib/collection/src/tests/deferred_points_dedup.rs
  • lib/segment/Cargo.toml
  • lib/segment/src/entry/entry_point.rs
  • lib/segment/src/id_tracker/id_tracker_base.rs
  • lib/segment/src/id_tracker/immutable_id_tracker.rs
  • lib/segment/src/id_tracker/in_memory_id_tracker.rs
  • lib/segment/src/id_tracker/mod.rs
  • lib/segment/src/id_tracker/mutable_id_tracker.rs
  • lib/segment/src/id_tracker/simple_id_tracker.rs
  • lib/segment/src/index/hnsw_index/hnsw.rs
  • lib/segment/src/index/plain_payload_index.rs
  • lib/segment/src/index/query_optimization/condition_converter.rs
  • lib/segment/src/index/sparse_index/sparse_vector_index.rs
  • lib/segment/src/index/struct_payload_index.rs
  • lib/segment/src/segment/entry.rs
  • lib/segment/src/segment/facet.rs
  • lib/segment/src/segment/order_by.rs
  • lib/segment/src/segment/sampling.rs
  • lib/segment/src/segment/scroll.rs
  • lib/segment/src/segment/segment_ops.rs
  • lib/segment/src/segment/tests.rs
  • lib/segment/src/segment_constructor/segment_constructor_base.rs
  • lib/segment/src/vector_storage/dense/memmap_dense_vector_storage.rs
  • lib/segment/src/vector_storage/tests/test_appendable_dense_vector_storage.rs
  • lib/segment/tests/integration/payload_index_test.rs
  • lib/segment/tests/integration/segment_builder_test.rs
  • lib/segment/tests/integration/segment_on_disk_snapshot.rs
  • lib/segment/tests/integration/segment_tests.rs
  • lib/shard/src/optimize.rs
  • lib/shard/src/proxy_segment/segment_entry.rs
  • lib/shard/src/segment_holder/mod.rs
✅ Files skipped from review due to trivial changes (7)
  • lib/collection/src/collection_manager/tests/mod.rs
  • lib/segment/Cargo.toml
  • lib/segment/tests/integration/segment_on_disk_snapshot.rs
  • lib/segment/src/vector_storage/tests/test_appendable_dense_vector_storage.rs
  • lib/shard/src/segment_holder/mod.rs
  • lib/segment/src/segment/scroll.rs
  • lib/collection/src/tests/deferred_points_dedup.rs
🚧 Files skipped from review as they are similar to previous changes (15)
  • lib/segment/src/index/query_optimization/condition_converter.rs
  • lib/segment/src/vector_storage/dense/memmap_dense_vector_storage.rs
  • lib/segment/src/segment/order_by.rs
  • lib/collection/src/collection_manager/optimizers/vacuum_optimizer.rs
  • lib/segment/src/segment/sampling.rs
  • lib/segment/tests/integration/payload_index_test.rs
  • lib/segment/src/id_tracker/mod.rs
  • lib/shard/src/proxy_segment/segment_entry.rs
  • lib/segment/src/entry/entry_point.rs
  • lib/segment/tests/integration/segment_builder_test.rs
  • lib/segment/src/index/plain_payload_index.rs
  • lib/segment/src/index/struct_payload_index.rs
  • lib/segment/src/id_tracker/mutable_id_tracker.rs
  • lib/segment/src/id_tracker/immutable_id_tracker.rs
  • lib/segment/src/segment/entry.rs

Ivan Boldyrev added 2 commits March 19, 2026 17:47
Use nested `self_cell` to provide an iterator.
It replaces "crate" inside a macro even if it is "pub(crate)".
@monoid
monoid force-pushed the point_mappings_ref branch from 41120f3 to ceb9bea Compare March 19, 2026 17:07
@monoid monoid changed the title Explicit owning of point_mappings in the API Explicit owning of point_mappings Mar 19, 2026

@coszio coszio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's nicer, thanks!

@monoid monoid changed the title Explicit owning of point_mappings Explicit owning of point_mappings refs Mar 19, 2026
@monoid monoid changed the title Explicit owning of point_mappings refs Explicit owning of point_mappings guard Mar 19, 2026
@monoid monoid changed the title Explicit owning of point_mappings guard Explicit point_mappings guard Mar 19, 2026
@monoid monoid changed the title Explicit point_mappings guard Explicit point_mappings guard in IdTracker Mar 19, 2026
@monoid
monoid merged commit 9146dc4 into dev Mar 19, 2026
15 checks passed
@monoid
monoid deleted the point_mappings_ref branch March 19, 2026 20:07
@coderabbitai coderabbitai Bot mentioned this pull request Mar 23, 2026
9 tasks done
generall pushed a commit that referenced this pull request Mar 26, 2026
Instead of `IdTracker` to have `iter_*` methods, it now has a `point_mappings()` method, returning a guard to `PointMapping` value.  It prepares for moving the point_mappings under a lock to allow parallel searches and deletions.

Also, an incorrect unsafe in `Segment::iter_points` is replaced by a safe version with `self_cell`.
@coderabbitai coderabbitai Bot mentioned this pull request Mar 27, 2026
9 tasks done
KShivendu pushed a commit that referenced this pull request Mar 30, 2026
Instead of `IdTracker` to have `iter_*` methods, it now has a `point_mappings()` method, returning a guard to `PointMapping` value.  It prepares for moving the point_mappings under a lock to allow parallel searches and deletions.

Also, an incorrect unsafe in `Segment::iter_points` is replaced by a safe version with `self_cell`.
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.

5 participants