-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ENH] Handle one-off compaction message in compaction manager #3379
Merged
Sicheng-Pan
merged 3 commits into
main
from
12-31-_enh_handle_one-off_compaction_message_in_compaction_manager
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,36 +146,36 @@ impl CompactionManager { | |
}; | ||
} | ||
|
||
// TODO: make the return type more informative | ||
#[instrument(name = "CompactionManager::compact_batch")] | ||
pub(crate) async fn compact_batch( | ||
&mut self, | ||
compacted: &mut Vec<CollectionUuid>, | ||
) -> (u32, u32) { | ||
pub(crate) async fn compact_batch(&mut self) -> Vec<CollectionUuid> { | ||
self.scheduler.schedule().await; | ||
let mut jobs = FuturesUnordered::new(); | ||
for job in self.scheduler.get_jobs() { | ||
let instrumented_span = span!(parent: None, tracing::Level::INFO, "Compacting job", collection_id = ?job.collection_id); | ||
instrumented_span.follows_from(Span::current()); | ||
jobs.push(self.compact(job).instrument(instrumented_span)); | ||
} | ||
tracing::info!("Compacting {} jobs", jobs.len()); | ||
let mut num_completed_jobs = 0; | ||
let mut num_failed_jobs = 0; | ||
while let Some(job) = jobs.next().await { | ||
match job { | ||
Ok(result) => { | ||
tracing::info!("Compaction completed: {:?}", result); | ||
compacted.push(result.compaction_job.collection_id); | ||
num_completed_jobs += 1; | ||
} | ||
Err(e) => { | ||
tracing::info!("Compaction failed {}", e); | ||
num_failed_jobs += 1; | ||
let job_futures = self | ||
.scheduler | ||
.get_jobs() | ||
.map(|job| { | ||
let instrumented_span = span!(parent: None, tracing::Level::INFO, "Compacting job", collection_id = ?job.collection_id); | ||
instrumented_span.follows_from(Span::current()); | ||
self.compact(job).instrument(instrumented_span) | ||
}) | ||
.collect::<FuturesUnordered<_>>(); | ||
|
||
tracing::info!("Running {} compaction jobs", job_futures.len()); | ||
|
||
job_futures | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice cleanup |
||
.filter_map(|result| async move { | ||
match result { | ||
Ok(response) => { | ||
tracing::info!("Compaction completed: {response:?}"); | ||
Some(response.compaction_job.collection_id) | ||
} | ||
Err(err) => { | ||
tracing::error!("Compaction failed {err}"); | ||
None | ||
} | ||
} | ||
} | ||
} | ||
(num_completed_jobs, num_failed_jobs) | ||
}) | ||
.collect() | ||
.await | ||
} | ||
|
||
pub(crate) fn set_dispatcher(&mut self, dispatcher: ComponentHandle<Dispatcher>) { | ||
|
@@ -311,10 +311,8 @@ impl Handler<ScheduledCompactionMessage> for CompactionManager { | |
_message: ScheduledCompactionMessage, | ||
ctx: &ComponentContext<CompactionManager>, | ||
) { | ||
tracing::info!("CompactionManager: Performing compaction"); | ||
let mut ids = Vec::new(); | ||
self.compact_batch(&mut ids).await; | ||
|
||
tracing::info!("CompactionManager: Performing scheduled compaction"); | ||
let ids = self.compact_batch().await; | ||
self.hnsw_index_provider.purge_by_id(&ids).await; | ||
|
||
// Compaction is done, schedule the next compaction | ||
|
@@ -332,11 +330,15 @@ impl Handler<OneOffCompactionMessage> for CompactionManager { | |
type Result = (); | ||
async fn handle( | ||
&mut self, | ||
_message: OneOffCompactionMessage, | ||
message: OneOffCompactionMessage, | ||
_ctx: &ComponentContext<CompactionManager>, | ||
) { | ||
tracing::info!("CompactionManager: Performing compaction"); | ||
todo!("To be implemented in next PR in the stack"); | ||
self.scheduler | ||
.add_oneoff_collections(message.collection_ids); | ||
tracing::info!( | ||
"One-off collections queued: {:?}", | ||
self.scheduler.get_oneoff_collections() | ||
); | ||
} | ||
} | ||
|
||
|
@@ -585,10 +587,7 @@ mod tests { | |
let dispatcher_handle = system.start_component(dispatcher); | ||
manager.set_dispatcher(dispatcher_handle); | ||
manager.set_system(system); | ||
let mut compacted = vec![]; | ||
let (num_completed, number_failed) = manager.compact_batch(&mut compacted).await; | ||
assert_eq!(num_completed, 2); | ||
assert_eq!(number_failed, 0); | ||
let compacted = manager.compact_batch().await; | ||
assert!( | ||
(compacted == vec![collection_uuid_1, collection_uuid_2]) | ||
|| (compacted == vec![collection_uuid_2, collection_uuid_1]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we change the interface of this away from num success/failed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old interface seemed strange for me. We are able to tell the number of successful compactions using the length of the returned
Vec
. The number of successful/failed compactions are only examined in one test case, and not used anywhere else. I updated the interface so that it looks cleaner to me.