diff --git a/crates/index-scheduler/src/scheduler/process_upgrade/mod.rs b/crates/index-scheduler/src/scheduler/process_upgrade/mod.rs index 319b7b594..78ea0ba1b 100644 --- a/crates/index-scheduler/src/scheduler/process_upgrade/mod.rs +++ b/crates/index-scheduler/src/scheduler/process_upgrade/mod.rs @@ -21,18 +21,22 @@ impl IndexScheduler { indexes.len() as u32, )); let index = self.index(uid)?; - let mut wtxn = index.write_txn()?; - let regen_stats = milli::update::upgrade::upgrade(&mut wtxn, &index, progress.clone()) - .map_err(|e| Error::from_milli(e, Some(uid.to_string())))?; - if regen_stats { - let stats = crate::index_mapper::IndexStats::new(&index, &wtxn) + let mut index_wtxn = index.write_txn()?; + let regen_stats = + milli::update::upgrade::upgrade(&mut index_wtxn, &index, progress.clone()) .map_err(|e| Error::from_milli(e, Some(uid.to_string())))?; + if regen_stats { + let stats = crate::index_mapper::IndexStats::new(&index, &index_wtxn) + .map_err(|e| Error::from_milli(e, Some(uid.to_string())))?; + index_wtxn.commit()?; + // Release wtxn as soon as possible because it stops us from registering tasks let mut index_schd_wtxn = self.env.write_txn()?; self.index_mapper.store_stats_of(&mut index_schd_wtxn, uid, &stats)?; index_schd_wtxn.commit()?; + } else { + index_wtxn.commit()?; } - wtxn.commit()?; } Ok(()) diff --git a/crates/index-scheduler/src/test_utils.rs b/crates/index-scheduler/src/test_utils.rs index a6d29e2ea..024d56622 100644 --- a/crates/index-scheduler/src/test_utils.rs +++ b/crates/index-scheduler/src/test_utils.rs @@ -406,7 +406,8 @@ impl IndexSchedulerHandle { .recv_timeout(std::time::Duration::from_secs(1)) { Ok((_, true)) => continue, Ok((b, false)) => panic!("The scheduler was supposed to be down but successfully moved to the next breakpoint: {b:?}"), - Err(RecvTimeoutError::Timeout | RecvTimeoutError::Disconnected) => break, + Err(RecvTimeoutError::Timeout) => panic!(), + Err(RecvTimeoutError::Disconnected) => break, } } }