Repository navigation
Delete points by filter with deferred - #8389
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:
📝 WalkthroughWalkthroughChanged 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
🚥 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)
📝 Coding Plan
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 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. |
There was a problem hiding this comment.
🧹 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 == 0would 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
📒 Files selected for processing (1)
lib/shard/src/update.rs
b07759d to
11e680a
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
lib/shard/src/update.rs (2)
411-412: Consider usingexpect()for clearer panic messages.The
unwrap()at line 412 is safe sincesegment_idcomes fromsegments.iter(), but usingexpect()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 wherepoint_versionreturnsNone.At line 440,
segment.point_version(*point_id)returnsOption<SeqNumberType>. While line 436 ensureshas_point()is true, ifpoint_versionreturnsNonefor an existing point (e.g., corrupted state), the comparison at line 447version > *max_versionwould evaluateNone > Some(x)asfalse(sinceNoneis less thanSomein Rust'sOptionordering), which would correctly skip the removal.However, if
*max_versionisNone(all filtered segment versions returnedNone) andversionisSome(x), thenSome(x) > Noneevaluates totrue, which could incorrectly trigger removal fromall_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
📒 Files selected for processing (1)
lib/shard/src/update.rs
9643da4 to
e9c798d
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
lib/shard/src/update.rs (2)
1074-1083: Use explicitPointIdType::from(...)in the new tests.The new helper/assert code uses several implicit
.into()conversions for point IDs. Please switch those toPointIdType::from(...)to match the repository Rust style.As per coding guidelines,
**/*.rs: Prefer explicitSomeType::from(x)over implicitx.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-opdelete_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
📒 Files selected for processing (1)
lib/shard/src/update.rs
a9f21e1 to
b2281da
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
lib/shard/src/update.rs (1)
1065-1074: Prefer explicitPointIdType::from(...)in the new tests.The helper/test code adds several implicit
into()conversions for point IDs. Swapping them toPointIdType::from(...)would keep this new Rust code aligned with repo style.As per coding guidelines,
**/*.rs: Prefer explicitSomeType::from(x)over implicitx.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
📒 Files selected for processing (1)
lib/shard/src/update.rs
* 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]>
* 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]>
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_overwritefrom delete by ids. This PR contain also this change