mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-10-31 16:06:31 +00:00 
			
		
		
		
	Upgrade supports cancelling
This commit is contained in:
		| @@ -1,5 +1,5 @@ | ||||
| use meilisearch_types::milli; | ||||
| use meilisearch_types::milli::progress::{Progress, VariableNameStep}; | ||||
| use meilisearch_types::milli::{self}; | ||||
|  | ||||
| use crate::{Error, IndexScheduler, Result}; | ||||
|  | ||||
| @@ -16,6 +16,11 @@ impl IndexScheduler { | ||||
|         let indexes = self.index_names()?; | ||||
|  | ||||
|         for (i, uid) in indexes.iter().enumerate() { | ||||
|             let must_stop_processing = self.scheduler.must_stop_processing.clone(); | ||||
|  | ||||
|             if must_stop_processing.get() { | ||||
|                 return Err(Error::AbortedTask); | ||||
|             } | ||||
|             progress.update_progress(VariableNameStep::<UpgradeIndex>::new( | ||||
|                 format!("Upgrading index `{uid}`"), | ||||
|                 i as u32, | ||||
| @@ -27,6 +32,7 @@ impl IndexScheduler { | ||||
|                 &mut index_wtxn, | ||||
|                 &index, | ||||
|                 db_version, | ||||
|                 || must_stop_processing.get(), | ||||
|                 progress.clone(), | ||||
|             ) | ||||
|             .map_err(|e| Error::from_milli(e, Some(uid.to_string())))?; | ||||
|   | ||||
| @@ -23,12 +23,16 @@ trait UpgradeIndex { | ||||
| } | ||||
|  | ||||
| /// Return true if the cached stats of the index must be regenerated | ||||
| pub fn upgrade( | ||||
| pub fn upgrade<MSP>( | ||||
|     wtxn: &mut RwTxn, | ||||
|     index: &Index, | ||||
|     db_version: (u32, u32, u32), | ||||
|     must_stop_processing: MSP, | ||||
|     progress: Progress, | ||||
| ) -> Result<bool> { | ||||
| ) -> Result<bool> | ||||
| where | ||||
|     MSP: Fn() -> bool + Sync, | ||||
| { | ||||
|     let from = index.get_version(wtxn)?.unwrap_or(db_version); | ||||
|     let upgrade_functions: &[&dyn UpgradeIndex] = &[ | ||||
|         &V1_12_To_V1_12_3 {}, | ||||
| @@ -56,6 +60,9 @@ pub fn upgrade( | ||||
|     let mut current_version = from; | ||||
|     let mut regenerate_stats = false; | ||||
|     for (i, upgrade) in upgrade_path.iter().enumerate() { | ||||
|         if (must_stop_processing)() { | ||||
|             return Err(crate::Error::InternalError(InternalError::AbortedIndexation)); | ||||
|         } | ||||
|         let target = upgrade.target_version(); | ||||
|         progress.update_progress(VariableNameStep::<UpgradeVersion>::new( | ||||
|             format!( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user