Skip to content

Delete points by filter with deferred - #8389

Merged
IvanPleshkov merged 13 commits into
devfrom
delete_points_by_filter-with-deferred
Mar 20, 2026
Merged

IvanPleshkov merged 13 commits into
devfrom
delete_points_by_filter-with-deferred

Conversation

@IvanPleshkov

@IvanPleshkov IvanPleshkov commented Mar 13, 2026 •

Copy link
Copy Markdown
Contributor

Deferred by filter with deferred points. Covered scenarios:

Scenario A

Operations:
upsert point: (p=Berlin)
upsert point: (deferred) (p=Amsterdam)
delete by filter on p=Amsterdam

Result: must delete both point versions

Scenario B:

Operations:
upsert point: (p=Berlin)
upsert point: (deferred) (p=Amsterdam)
delete by filter on p=Berlin

Result: must keep both, once the optimizer kicks in we're only left with Amsterdam

Tech debt

After discussion, it was decided to remove bump_max_segment_version_overwrite from delete by ids. This PR contain also this change

coderabbitai[bot]

This comment was marked as resolved.

@qdrant qdrant deleted a comment from coderabbitai Bot Mar 13, 2026
@coderabbitai

coderabbitai Bot commented Mar 13, 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

Changed deletion flows in lib/shard/src/update.rs: removed WAL version bump when explicit-ID delete deletes zero points; rewrote delete_points_by_filter to first collect per-segment matched point IDs (using read_filtered with DeferredBehavior::IncludeAll), record segments reporting deferred points, compute per-point cross-segment max versions when deferred points exist, and remove from per-segment deletion lists any point IDs whose newest copy is a newer deferred version that does not match the filter; remaining deletions are applied per segment. Added test helpers and two tests covering deferred-point deletion corner cases with city payload filters.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested reviewers

  • agourlay
  • timvisee
  • JojiiOfficial
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Delete points by filter with deferred' is specific and directly relates to the main changes in the PR, which implement deletion-by-filter behavior that handles deferred point versions.
Description check ✅ Passed The description explains the specific scenarios (A and B) covered by the PR and mentions the technical debt removal, all of which are directly related to the changeset modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch delete_points_by_filter-with-deferred
📝 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.

Tip

CodeRabbit can scan for known vulnerabilities in your dependencies using OSV Scanner.

OSV Scanner will automatically detect and report security vulnerabilities in your project's dependencies. No additional configuration is required.

@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.

🧹 Nitpick comments (1)
lib/shard/src/update.rs (1)

1176-1176: Consider asserting the returned deletion count.

The returned count is captured but unused. For this scenario, the expected behavior is that no points are deleted (the newest deferred version doesn't match the filter), so asserting deleted == 0 would make the test's expectations more explicit.

💡 Suggested improvement
-        let _deleted = delete_points_by_filter(&holder, 10, &filter, &hw_counter).unwrap();
+        let deleted = delete_points_by_filter(&holder, 10, &filter, &hw_counter).unwrap();
+
+        // No deletions should occur because the deferred version (Amsterdam) is newer
+        // and does not match the filter (Berlin).
+        assert_eq!(deleted, 0, "No copies should be deleted when deferred version doesn't match filter");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/shard/src/update.rs` at line 1176, The test captures the return value of
delete_points_by_filter(&holder, 10, &filter, &hw_counter) but ignores it;
change the binding to a named variable (e.g., let deleted = ...) and add an
assertion that deleted == 0 to make the expectation explicit (the newest
deferred version doesn't match the filter). Keep references to
delete_points_by_filter, holder, filter, hw_counter and ensure the assertion is
included in the same test block.
🤖 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/shard/src/update.rs`:
- Line 1176: The test captures the return value of
delete_points_by_filter(&holder, 10, &filter, &hw_counter) but ignores it;
change the binding to a named variable (e.g., let deleted = ...) and add an
assertion that deleted == 0 to make the expectation explicit (the newest
deferred version doesn't match the filter). Keep references to
delete_points_by_filter, holder, filter, hw_counter and ensure the assertion is
included in the same test block.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 53cca09e-01ee-4c41-b44a-3cc2468168a4

📥 Commits

Reviewing files that changed from the base of the PR and between a244c92 and b07759d.

📒 Files selected for processing (1)
  • lib/shard/src/update.rs

@IvanPleshkov
IvanPleshkov force-pushed the delete_points_by_filter-with-deferred branch from b07759d to 11e680a Compare March 13, 2026 16:19
@IvanPleshkov
IvanPleshkov marked this pull request as draft March 13, 2026 16:22

@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.

🧹 Nitpick comments (2)
lib/shard/src/update.rs (2)

411-412: Consider using expect() for clearer panic messages.

The unwrap() at line 412 is safe since segment_id comes from segments.iter(), but using expect() with a descriptive message would improve debuggability if this invariant is ever violated.

💡 Optional: Use expect() for clearer error messages
         for (segment_id, point_ids) in &points_to_delete {
-            let segment = segments.get(*segment_id).unwrap().get().read();
+            let segment = segments
+                .get(*segment_id)
+                .expect("segment_id must exist since it came from segments.iter()")
+                .get()
+                .read();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/shard/src/update.rs` around lines 411 - 412, Replace the blind unwrap()
on segments.get(*segment_id).unwrap() with expect(...) to provide a clear panic
message; in the loop that iterates "for (segment_id, point_ids) in
&points_to_delete" change the call in update.rs from
segments.get(*segment_id).unwrap() to segments.get(*segment_id).expect("segment
not found for segment_id {segment_id}") (or similar descriptive text) so
failures include the missing segment id and context.

435-450: Verify edge case where point_version returns None.

At line 440, segment.point_version(*point_id) returns Option<SeqNumberType>. While line 436 ensures has_point() is true, if point_version returns None for an existing point (e.g., corrupted state), the comparison at line 447 version > *max_version would evaluate None > Some(x) as false (since None is less than Some in Rust's Option ordering), which would correctly skip the removal.

However, if *max_version is None (all filtered segment versions returned None) and version is Some(x), then Some(x) > None evaluates to true, which could incorrectly trigger removal from all_points_to_delete. This scenario is unlikely but worth a defensive check.

💡 Optional: Add explicit handling for None versions
                 let version = segment.point_version(*point_id);
                 let is_deferred = segment.point_is_deferred(*point_id);

                 // Deferred point is:
                 // - newer than any filtered copy
                 // - deferred
                 // - does not match the filter
-                if version > *max_version && is_deferred {
+                // Only compare when both versions are Some to avoid edge cases
+                if let (Some(v), Some(max_v)) = (version, *max_version) {
+                    if v > max_v && is_deferred {
+                        // Remove this point from deletion across ALL segments.
+                        all_points_to_delete.remove(point_id);
+                    }
+                }
-                    // Remove this point from deletion across ALL segments.
-                    all_points_to_delete.remove(point_id);
-                }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/shard/src/update.rs` around lines 435 - 450, The code currently compares
Option<SeqNumberType> from segment.point_version(*point_id) with max_version
which can be None, risking treating Some(x) > None as true; update the loop that
inspects max_versions so that you explicitly handle Option values: call
segment.point_version and check both version.is_some() and max_version.is_some()
(or match both Some(v) and Some(m)) before performing the comparison and only
remove from all_points_to_delete when both are Some and v > m and
segment.point_is_deferred(*point_id) is true; reference point_version,
point_is_deferred, max_versions, has_point, and all_points_to_delete when making
this change.
🤖 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/shard/src/update.rs`:
- Around line 411-412: Replace the blind unwrap() on
segments.get(*segment_id).unwrap() with expect(...) to provide a clear panic
message; in the loop that iterates "for (segment_id, point_ids) in
&points_to_delete" change the call in update.rs from
segments.get(*segment_id).unwrap() to segments.get(*segment_id).expect("segment
not found for segment_id {segment_id}") (or similar descriptive text) so
failures include the missing segment id and context.
- Around line 435-450: The code currently compares Option<SeqNumberType> from
segment.point_version(*point_id) with max_version which can be None, risking
treating Some(x) > None as true; update the loop that inspects max_versions so
that you explicitly handle Option values: call segment.point_version and check
both version.is_some() and max_version.is_some() (or match both Some(v) and
Some(m)) before performing the comparison and only remove from
all_points_to_delete when both are Some and v > m and
segment.point_is_deferred(*point_id) is true; reference point_version,
point_is_deferred, max_versions, has_point, and all_points_to_delete when making
this change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 85cacb54-9171-4042-ac4f-ccfd1405355c

📥 Commits

Reviewing files that changed from the base of the PR and between b07759d and 11e680a.

📒 Files selected for processing (1)
  • lib/shard/src/update.rs

@IvanPleshkov
IvanPleshkov force-pushed the delete_points_by_filter-with-deferred branch from 9643da4 to e9c798d Compare March 19, 2026 10:12
@IvanPleshkov
IvanPleshkov marked this pull request as ready for review March 19, 2026 10:18
@IvanPleshkov
IvanPleshkov marked this pull request as draft March 19, 2026 10:22

@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/shard/src/update.rs (2)

1074-1083: Use explicit PointIdType::from(...) in the new tests.

The new helper/assert code uses several implicit .into() conversions for point IDs. Please switch those to PointIdType::from(...) to match the repository Rust style.

As per coding guidelines, **/*.rs: Prefer explicit SomeType::from(x) over implicit x.into() in Rust.

Also applies to: 1099-1110, 1154-1160, 1195-1201

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

In `@lib/shard/src/update.rs` around lines 1074 - 1083, Replace implicit .into()
conversions for point IDs with explicit PointIdType::from(...) in the test
helper assertions: update calls like seg.upsert_point(version, point_id.into(),
...) and seg.set_payload(version, point_id.into(), ...) to use
PointIdType::from(point_id) (and similarly for other occurrences referenced
around the seg.upsert_point/seg.set_payload usage and the other mentioned
blocks). Ensure you import or fully qualify PointIdType if necessary and apply
the same change to the other affected call sites (the blocks around lines
mentioned in the review).

1014-1063: Add the companion regression for no-op delete_points.

This module now pins the no-op filter-delete WAL bump, but the PR also changes the explicit-ID path. A focused no-op delete_points(...) regression here would keep that semantic change from drifting.

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

In `@lib/shard/src/update.rs` around lines 1014 - 1063, Add a companion regression
test for the explicit-ID path to ensure no-op delete_points bumps WAL version
like the filter test: create a temp segment holder (use
SegmentHolder::default(), build_segment_1/2, HardwareCounterCell), add segments,
flush_all to get old_version, call delete_points(...) with a list of IDs that do
not exist and verify it returns 0 deletions, then flush_all again and assert
new_version == old_version + 1 and equals the expected DELETE_OP_NUM; reference
test_delete_by_filter_version_bump, delete_points_by_filter, and delete_points
to mirror the existing filter-based assertions so the explicit-ID path keeps the
same no-op WAL bump semantics.
🤖 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/update.rs`:
- Around line 381-395: The current logic builds points_to_delete per segment by
collecting only matches from the segment where the filter hit (using
segment.read_filtered and DeferredBehavior::IncludeAll) and later deletes only
those per-segment vectors; change this so you first compute the global set of
surviving point IDs across all segments (e.g., collect all point IDs returned
from every segment.read_filtered into a single HashSet) and then iterate every
segment to remove any point whose id is in that global set (instead of only
deleting entries present in points_to_delete for that segment); update the code
paths that use points_to_delete (including the deletion loop around the code
currently at lines ~456-477) to reference this global set and ensure
has_deferred semantics remain unchanged.

---

Nitpick comments:
In `@lib/shard/src/update.rs`:
- Around line 1074-1083: Replace implicit .into() conversions for point IDs with
explicit PointIdType::from(...) in the test helper assertions: update calls like
seg.upsert_point(version, point_id.into(), ...) and seg.set_payload(version,
point_id.into(), ...) to use PointIdType::from(point_id) (and similarly for
other occurrences referenced around the seg.upsert_point/seg.set_payload usage
and the other mentioned blocks). Ensure you import or fully qualify PointIdType
if necessary and apply the same change to the other affected call sites (the
blocks around lines mentioned in the review).
- Around line 1014-1063: Add a companion regression test for the explicit-ID
path to ensure no-op delete_points bumps WAL version like the filter test:
create a temp segment holder (use SegmentHolder::default(), build_segment_1/2,
HardwareCounterCell), add segments, flush_all to get old_version, call
delete_points(...) with a list of IDs that do not exist and verify it returns 0
deletions, then flush_all again and assert new_version == old_version + 1 and
equals the expected DELETE_OP_NUM; reference test_delete_by_filter_version_bump,
delete_points_by_filter, and delete_points to mirror the existing filter-based
assertions so the explicit-ID path keeps the same no-op WAL bump semantics.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e2ca02a7-356c-4390-b6f0-e43b4bfe1f7d

📥 Commits

Reviewing files that changed from the base of the PR and between 11e680a and e9c798d.

📒 Files selected for processing (1)
  • lib/shard/src/update.rs

Comment thread lib/shard/src/update.rs Resolved
@IvanPleshkov
IvanPleshkov force-pushed the delete_points_by_filter-with-deferred branch from a9f21e1 to b2281da Compare March 19, 2026 10:49
@IvanPleshkov
IvanPleshkov marked this pull request as ready for review March 19, 2026 10:59

@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/shard/src/update.rs (1)

1065-1074: Prefer explicit PointIdType::from(...) in the new tests.

The helper/test code adds several implicit into() conversions for point IDs. Swapping them to PointIdType::from(...) would keep this new Rust code aligned with repo style.

As per coding guidelines, **/*.rs: Prefer explicit SomeType::from(x) over implicit x.into() in Rust.

Also applies to: 1090-1103, 1145-1152, 1186-1193

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

In `@lib/shard/src/update.rs` around lines 1065 - 1074, Replace implicit into()
conversions for point IDs with explicit PointIdType::from(...) in the test
helper calls: update the seg.upsert_point(...) and seg.set_payload(...)
invocations (and the other occurrences at the indicated ranges) to pass
PointIdType::from(point_id) instead of point_id.into(); ensure you reference the
PointIdType::from conversion for all places using .into() for point IDs (e.g.,
within seg.upsert_point and seg.set_payload) so the code follows the repo style
guide.
🤖 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/update.rs`:
- Around line 441-444: The current points_to_delete construction clones
all_points into every segment causing pop() misses and allowing a single segment
to exceed DELETION_BATCH_SIZE because deleted_in_batch only counts successful
deletes; change the logic around points_to_delete (and the batched loop that
updates deleted_in_batch) to bound each segment by processed IDs rather than
successful deletions: for each (segment_id, _) from segments, create a
per-segment vector/iterator of at most DELETION_BATCH_SIZE IDs taken from
all_points (consuming processed IDs for that segment), and use that bounded
collection when calling the deletion closure so deleted_in_batch advances
correctly; adjust the code paths that reference points_to_delete, all_points,
deleted_in_batch, and the deletion closure to use these per-segment bounded
lists so no single segment can drain more than the configured batch size.

---

Nitpick comments:
In `@lib/shard/src/update.rs`:
- Around line 1065-1074: Replace implicit into() conversions for point IDs with
explicit PointIdType::from(...) in the test helper calls: update the
seg.upsert_point(...) and seg.set_payload(...) invocations (and the other
occurrences at the indicated ranges) to pass PointIdType::from(point_id) instead
of point_id.into(); ensure you reference the PointIdType::from conversion for
all places using .into() for point IDs (e.g., within seg.upsert_point and
seg.set_payload) so the code follows the repo style guide.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 24141969-f69c-4f17-9c68-eaad12630086

📥 Commits

Reviewing files that changed from the base of the PR and between e9c798d and b2281da.

📒 Files selected for processing (1)
  • lib/shard/src/update.rs

Comment thread lib/shard/src/update.rs Resolved
@IvanPleshkov
IvanPleshkov merged commit ed13a5b into dev Mar 20, 2026
15 checks passed
@IvanPleshkov
IvanPleshkov deleted the delete_points_by_filter-with-deferred branch March 20, 2026 14:13
generall pushed a commit that referenced this pull request Mar 26, 2026
* delete_points_by_filter with deferred

* versions check

* tests

* Check for deferred points in first loop

* fix after rebase

* refactor

* fix tests

* fix build after rebase

* refactor

* fix test

* refactor

* fix after rebase

* refactor

---------

Co-authored-by: timvisee <[email protected]>
KShivendu pushed a commit that referenced this pull request Mar 30, 2026
* delete_points_by_filter with deferred

* versions check

* tests

* Check for deferred points in first loop

* fix after rebase

* refactor

* fix tests

* fix build after rebase

* refactor

* fix test

* refactor

* fix after rebase

* refactor

---------

Co-authored-by: timvisee <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants