Repository navigation
Expose planned optimizations in API - #7784
Conversation
ea80c7e to
30a8423
Compare
09b6225 to
c7f5732
Compare
4870de6 to
0d0acc7
Compare
c7f5732 to
be92cbf
Compare
0d0acc7 to
fdc8162
Compare
be92cbf to
9ae95d0
Compare
fdc8162 to
f608e87
Compare
📝 WalkthroughWalkthroughAdds a new public PendingOptimizations struct (optimizations, segments, points) in operations types; adds a pending field (PendingOptimizations) to OptimizationsResponse and to TrackerLog; aggregation of per-shard pending counts in the collection optimizations endpoint by merging TrackerLog.pending entries; and populates TrackerLog.pending in the optimization worker when scheduling optimizations (summing scheduled optimizations, segment ids, and points). Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (2)
🧰 Additional context used📓 Path-based instructions (1)**/*.rs📄 CodeRabbit inference engine (.github/review-rules.md)
Files:
🧠 Learnings (3)📚 Learning: 2025-08-15T11:42:00.297ZApplied to files:
📚 Learning: 2025-08-15T11:41:10.629ZApplied to files:
📚 Learning: 2025-09-01T11:42:06.964ZApplied to files:
🧬 Code graph analysis (2)lib/collection/src/update_workers/optimization_worker.rs (2)
lib/collection/src/operations/types.rs (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
🔇 Additional comments (5)
✏️ Tip: You can disable this entire section by setting 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: 0
🧹 Nitpick comments (2)
lib/collection/src/operations/types.rs (1)
324-335: Consider destructuringotherfor compile-time safety when new fields are added.The
selfdestructure is exhaustive (good), butotheris accessed via field notation. If new fields are added toPendingOptimizations, the compiler will flag theselfdestructure but won't flag missing field merges fromother. Based on learnings, this codebase values exhaustive matching for struct evolution safety.♻️ Suggested refactor
impl PendingOptimizations { pub fn merge(&mut self, other: &PendingOptimizations) { let PendingOptimizations { - optimizations, - segments, - points, - } = self; - *optimizations += other.optimizations; - *segments += other.segments; - *points += other.points; + optimizations: other_optimizations, + segments: other_segments, + points: other_points, + } = other; + self.optimizations += other_optimizations; + self.segments += other_segments; + self.points += other_points; } }docs/redoc/master/openapi.json (1)
16483-16511: Clarify that these are approximate counts (and may change between calls).The schema says “Estimation of pending optimizations” (Line 16484). Consider explicitly stating (in the source schema docs) that these values are best-effort/approximate and can fluctuate as optimizers reschedule or segment states change, so clients don’t treat them as strict counters. Based on learnings.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
docs/redoc/master/openapi.jsonlib/collection/src/collection/collection_ops.rslib/collection/src/collection_manager/optimizers/mod.rslib/collection/src/operations/types.rslib/collection/src/update_workers/optimization_worker.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/review-rules.md)
**/*.rs: Prefer explicitSomeType::from(x)over implicitx.into()in Rust
In new code, don't usetransmute_from_u8,transmute_to_u8,transmute_from_u8_to_slice,transmute_from_u8_to_mut_slice,transmute_to_u8_slice- usebytemuckorzerocopycrates instead
Prefer explicit exhaustive matches over catch-all_arm in Rust match expressions, so we don't miss handling new enum variants when they are added later (exceptions: tests and benchmarks, or when sure new variants won't affect logic)
Prefer explicit field ignoring using: _over using..in Rust struct destructuring (exceptions: tests and benchmarks, or when sure new fields won't affect logic)
Files:
lib/collection/src/operations/types.rslib/collection/src/collection/collection_ops.rslib/collection/src/update_workers/optimization_worker.rslib/collection/src/collection_manager/optimizers/mod.rs
🧠 Learnings (6)
📚 Learning: 2025-08-10T18:30:02.986Z
Learnt from: generall
Repo: qdrant/qdrant PR: 7006
File: lib/collection/src/operations/verification/update.rs:158-174
Timestamp: 2025-08-10T18:30:02.986Z
Learning: In Qdrant's strict mode verification code (lib/collection/src/operations/verification/update.rs), exhaustive pattern matching without `..` is intentionally used for structs like PointsBatch and PointsList. This design pattern ensures compilation fails when new fields are added, forcing developers to explicitly consider how new fields should be handled in the indexed_filter_write method. This provides visibility and compile-time safety for struct evolution.
Applied to files:
lib/collection/src/operations/types.rs
📚 Learning: 2025-08-10T18:26:12.443Z
Learnt from: generall
Repo: qdrant/qdrant PR: 7006
File: docs/redoc/master/openapi.json:13645-13652
Timestamp: 2025-08-10T18:26:12.443Z
Learning: In qdrant, docs/redoc/master/openapi.json is auto-generated from the REST schemas. To change field docs, edit lib/api/src/rest/schema.rs (e.g., add doc comments or #[schemars(description = ...)]). Specifically, UpdateVectors.update_filter lacked a description and should state: "If specified, only update vectors for points that match this filter; points not matching the filter are left unchanged."
Applied to files:
docs/redoc/master/openapi.json
📚 Learning: 2025-08-15T11:42:00.297Z
Learnt from: IvanPleshkov
Repo: qdrant/qdrant PR: 7043
File: lib/segment/src/vector_storage/quantized/quantized_mmap_storage.rs:86-90
Timestamp: 2025-08-15T11:42:00.297Z
Learning: In lib/segment/src/vector_storage/quantized/quantized_mmap_storage.rs, overflow protection for encoded_storage_size computation (quantized_vector_size * vectors_count) is implemented in PR #7048, using checked_mul with u64 casting to prevent silent overflow.
Applied to files:
lib/collection/src/update_workers/optimization_worker.rs
📚 Learning: 2025-09-01T11:42:06.964Z
Learnt from: timvisee
Repo: qdrant/qdrant PR: 7157
File: lib/shard/src/segment_holder/mod.rs:808-814
Timestamp: 2025-09-01T11:42:06.964Z
Learning: In Qdrant's segment holder, panicking when no segments exist during flush_all is intentional and preferred over graceful error handling, as having zero segments could permanently corrupt the WAL by acknowledging u64::MAX. The maintainers consider this condition impossible and use the panic as a fail-fast safety mechanism to prevent data corruption.
Applied to files:
lib/collection/src/update_workers/optimization_worker.rs
📚 Learning: 2025-07-11T11:35:21.549Z
Learnt from: generall
Repo: qdrant/qdrant PR: 6854
File: lib/segment/src/index/query_estimator.rs:320-327
Timestamp: 2025-07-11T11:35:21.549Z
Learning: In test code for Qdrant's query estimator (lib/segment/src/index/query_estimator.rs), simplified ID resolution logic using `id.to_string().parse().unwrap()` is acceptable for testing purposes and doesn't need to match production code's `id_tracker.internal_id()` approach. Test code can use mock implementations that serve the testing goals.
Applied to files:
lib/collection/src/collection_manager/optimizers/mod.rs
📚 Learning: 2025-10-13T22:58:03.121Z
Learnt from: generall
Repo: qdrant/qdrant PR: 7400
File: lib/segment/src/id_tracker/simple_id_tracker.rs:234-241
Timestamp: 2025-10-13T22:58:03.121Z
Learning: SimpleIdTracker in lib/segment/src/id_tracker/simple_id_tracker.rs is being deprecated and should not receive fixes related to version tracking or recovery logic, as it has a different version storage structure that is incompatible with newer trackers.
Applied to files:
lib/collection/src/collection_manager/optimizers/mod.rs
🧬 Code graph analysis (2)
lib/collection/src/operations/types.rs (1)
lib/collection/src/collection/collection_ops.rs (1)
optimizations(429-465)
lib/collection/src/update_workers/optimization_worker.rs (2)
lib/collection/src/collection_manager/optimizers/segment_optimizer.rs (1)
scheduled(1005-1007)lib/collection/src/shards/shard.rs (1)
optimizers_log(239-249)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: integration-tests
- GitHub Check: integration-tests-consensus
- GitHub Check: e2e-tests
- GitHub Check: test-consistency
- GitHub Check: test-shard-snapshot-api-s3-minio
- GitHub Check: rust-tests (ubuntu-latest)
- GitHub Check: rust-tests (windows-latest)
- GitHub Check: test-consensus-compose
- GitHub Check: rust-tests (macos-latest)
- GitHub Check: Test Python bindings
- GitHub Check: lint
🔇 Additional comments (7)
lib/collection/src/operations/types.rs (2)
307-309: LGTM!The
pendingfield addition toOptimizationsResponseis well-documented and correctly typed.
311-322: LGTM!The
PendingOptimizationsstruct is well-designed with appropriate derives for an API response type (Serialize,JsonSchema,Default,Clone,Debug). The field documentation clearly explains the semantics of each count.docs/redoc/master/openapi.json (1)
16406-16428: Remove the required marking concern—pendingis always populated.The
pendingfield is non-optional inOptimizationsResponseand has no conditional serialization logic. The server initializes it withPendingOptimizations::default()and always includes it in responses, making the required marking in OpenAPI correct and consistent with the implementation.However, since
openapi.jsonis auto-generated from source structs via schemars, any future schema refinements (e.g., clarifying that values are estimates) should be made inlib/collection/src/operations/types.rsandlib/api/src/rest/schema.rsrather than by editing the JSON directly.lib/collection/src/collection_manager/optimizers/mod.rs (1)
12-12: LGTM!The import and new
pendingfield are correctly added toTrackerLog. The struct already derivesDefault, soPendingOptimizationswill be properly initialized. This cleanly integrates with the broader pending-tracking mechanism.Also applies to: 27-30
lib/collection/src/collection/collection_ops.rs (1)
435-465: LGTM!The pending optimization aggregation is well-structured:
- Lock is acquired and explicitly dropped before extending result vectors
merge()correctly accumulates pending counts across all shards- The response now includes the aggregated
pendingfieldlib/collection/src/update_workers/optimization_worker.rs (2)
15-15: LGTM!The imports for
LockedSegmentandPendingOptimizationsare correctly added to support the new pending tracking logic.Also applies to: 32-32
270-299: LGTM!The pending optimization calculation logic is well-structured:
- Lock ordering is safe:
segments.read()is released before acquiringoptimizers_log.lock()- The
if let Some(LockedSegment::Original(segment))pattern correctly filters to only count original segments, which aligns with how optimizations work (the planner usesiter_original())- The calculated
pendingvalues represent all planned work from the planner, providing useful API insight into optimization backlog
| continue; | ||
| }; | ||
| let IndexingProgressViews { ongoing, completed } = log.lock().progress_views(); | ||
| let log = log.lock(); |
There was a problem hiding this comment.
Nit: I find the scope for log.lock() easier to read than manual drop
| let scheduled; | ||
| let mut pending_segments = 0; | ||
| let mut pending_points = 0; | ||
| { |
There was a problem hiding this comment.
Nit. WDYT about returning scheduled from the scope?
let scheduled = {
...
}
514fb94 to
2799875
Compare
* Expose pending optimizations in API * Address review comments
Depends on #7752.
This PR exposes numerical stats about pending optimizations through HTTP API.
Detailed representation (not in this PR)
Where these numbers come from? A debug representation could help answer this.
I'm not sure that such detailed info could be useful outside of testing/debugging
OptimizationPlanner, so I'd keep it in a separate commit.