Spawn threads with names

This commit is contained in:
Louis Dureuil 2022-11-16 09:50:47 +01:00
parent 51be75a264
commit 93afeedcea
No known key found for this signature in database
3 changed files with 54 additions and 42 deletions

View File

@ -126,7 +126,9 @@ impl IndexMapper {
let index_map = self.index_map.clone();
let index_path = self.base_path.join(uuid.to_string());
let index_name = name.to_string();
thread::spawn(move || {
thread::Builder::new()
.name(String::from("index_deleter"))
.spawn(move || {
// We first wait to be sure that the previously opened index is effectively closed.
// This can take a lot of time, this is why we do that in a seperate thread.
if let Some(closing_event) = closing_event {
@ -143,7 +145,8 @@ impl IndexMapper {
// Finally we remove the entry from the index map.
assert!(matches!(index_map.write().unwrap().remove(&uuid), Some(BeingDeleted)));
});
})
.unwrap();
Ok(())
}

View File

@ -412,7 +412,9 @@ impl IndexScheduler {
/// only once per index scheduler.
fn run(&self) {
let run = self.private_clone();
std::thread::spawn(move || loop {
std::thread::Builder::new()
.name(String::from("scheduler"))
.spawn(move || loop {
run.wake_up.wait();
match run.tick() {
@ -433,7 +435,8 @@ impl IndexScheduler {
run.wake_up.signal();
}
}
});
})
.unwrap();
}
pub fn indexer_config(&self) -> &IndexerConfig {
@ -925,7 +928,10 @@ impl IndexScheduler {
// 2. Process the tasks
let res = {
let cloned_index_scheduler = self.private_clone();
let handle = std::thread::spawn(move || cloned_index_scheduler.process_batch(batch));
let handle = std::thread::Builder::new()
.name(String::from("batch-operation"))
.spawn(move || cloned_index_scheduler.process_batch(batch))
.unwrap();
handle.join().unwrap_or(Err(Error::ProcessBatchPanicked))
};

View File

@ -204,12 +204,15 @@ pub fn setup_meilisearch(opt: &Opt) -> anyhow::Result<(Arc<IndexScheduler>, Auth
if opt.schedule_snapshot {
let snapshot_delay = Duration::from_secs(opt.snapshot_interval_sec);
let index_scheduler = index_scheduler.clone();
thread::spawn(move || loop {
thread::Builder::new()
.name(String::from("register-snapshot-tasks"))
.spawn(move || loop {
thread::sleep(snapshot_delay);
if let Err(e) = index_scheduler.register(KindWithContent::SnapshotCreation) {
error!("Error while registering snapshot: {}", e);
}
});
})
.unwrap();
}
Ok((index_scheduler, auth_controller))