mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-11-04 01:46:28 +00:00 
			
		
		
		
	move the version check to the task queue
This commit is contained in:
		@@ -10,7 +10,7 @@ use rhai::EvalAltResult;
 | 
			
		||||
use serde_json::Value;
 | 
			
		||||
use thiserror::Error;
 | 
			
		||||
 | 
			
		||||
use crate::constants::{RESERVED_GEO_FIELD_NAME, VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH};
 | 
			
		||||
use crate::constants::RESERVED_GEO_FIELD_NAME;
 | 
			
		||||
use crate::documents::{self, DocumentsBatchCursorError};
 | 
			
		||||
use crate::thread_pool_no_abort::PanicCatched;
 | 
			
		||||
use crate::{CriterionError, DocumentId, FieldId, Object, SortError};
 | 
			
		||||
@@ -74,6 +74,8 @@ pub enum InternalError {
 | 
			
		||||
    AbortedIndexation,
 | 
			
		||||
    #[error("The matching words list contains at least one invalid member")]
 | 
			
		||||
    InvalidMatchingWords,
 | 
			
		||||
    #[error("Cannot upgrade to the following version: v{0}.{1}.{2}.")]
 | 
			
		||||
    CannotUpgradeToVersion(u32, u32, u32),
 | 
			
		||||
    #[error(transparent)]
 | 
			
		||||
    ArroyError(#[from] arroy::Error),
 | 
			
		||||
    #[error(transparent)]
 | 
			
		||||
@@ -288,12 +290,6 @@ and can not be more than 511 bytes.", .document_id.to_string()
 | 
			
		||||
    DocumentEditionCompilationError(rhai::ParseError),
 | 
			
		||||
    #[error("{0}")]
 | 
			
		||||
    DocumentEmbeddingError(String),
 | 
			
		||||
    #[error("Upgrade could not be processed because v{0}.{1}.{2} of the database is too old. Please re-open the v{0}.{1}.{2} and use a dump to upgrade your version. The oldest version meilisearch can upgrade from is v1.12.0.")]
 | 
			
		||||
    TooOldForUpgrade(u32, u32, u32),
 | 
			
		||||
    #[error("Upgrade could not be processed because the database version (v{0}.{1}.{2}) is newer than the targeted version (v{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH})")]
 | 
			
		||||
    CannotDowngrade(u32, u32, u32),
 | 
			
		||||
    #[error("Cannot upgrade to unknown version v{0}.{1}.{2}.")]
 | 
			
		||||
    CannotUpgradeToUnknownVersion(u32, u32, u32),
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl From<crate::vector::Error> for Error {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,47 +1,17 @@
 | 
			
		||||
use crate::constants::{VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH};
 | 
			
		||||
use crate::progress::{Progress, VariableNameStep};
 | 
			
		||||
use crate::{Index, Result, UserError};
 | 
			
		||||
use crate::{Index, InternalError, Result};
 | 
			
		||||
 | 
			
		||||
pub fn upgrade(index: &Index, base_version: (u32, u32, u32), progress: Progress) -> Result<()> {
 | 
			
		||||
pub fn upgrade(index: &Index, progress: Progress) -> Result<()> {
 | 
			
		||||
    let wtxn = index.env.write_txn()?;
 | 
			
		||||
    let from = index.get_version(&wtxn)?;
 | 
			
		||||
    let upgrade_functions =
 | 
			
		||||
        [(v1_12_to_v1_13 as fn(&Index, Progress) -> Result<()>, "Upgrading from v1.12 to v1.13")];
 | 
			
		||||
 | 
			
		||||
    let current_major: u32 = VERSION_MAJOR.parse().unwrap();
 | 
			
		||||
    let current_minor: u32 = VERSION_MINOR.parse().unwrap();
 | 
			
		||||
    let current_patch: u32 = VERSION_PATCH.parse().unwrap();
 | 
			
		||||
 | 
			
		||||
    let start = match from {
 | 
			
		||||
        // If there was no version it means we're coming from the base version specified by the index-scheduler
 | 
			
		||||
        None if base_version.0 == 1 && base_version.1 == 12 => 0,
 | 
			
		||||
        Some((1, 12, _)) => 0,
 | 
			
		||||
 | 
			
		||||
        // --- Error handling
 | 
			
		||||
        None => {
 | 
			
		||||
            return Err(UserError::TooOldForUpgrade(
 | 
			
		||||
                base_version.0,
 | 
			
		||||
                base_version.1,
 | 
			
		||||
                base_version.2,
 | 
			
		||||
            )
 | 
			
		||||
            .into());
 | 
			
		||||
        }
 | 
			
		||||
        Some((major, minor, patch)) if major == 0 || (major == 1 && minor < 12) => {
 | 
			
		||||
            return Err(UserError::TooOldForUpgrade(major, minor, patch).into());
 | 
			
		||||
        }
 | 
			
		||||
        Some((major, minor, patch)) if major > current_major => {
 | 
			
		||||
            return Err(UserError::CannotDowngrade(major, minor, patch).into());
 | 
			
		||||
        }
 | 
			
		||||
        Some((major, minor, patch)) if major == current_major && minor > current_minor => {
 | 
			
		||||
            return Err(UserError::CannotDowngrade(major, minor, patch).into());
 | 
			
		||||
        }
 | 
			
		||||
        Some((major, minor, patch))
 | 
			
		||||
            if major == current_major && minor == current_minor && patch > current_patch =>
 | 
			
		||||
        {
 | 
			
		||||
            return Err(UserError::CannotDowngrade(major, minor, patch).into());
 | 
			
		||||
        }
 | 
			
		||||
        None | Some((1, 12, _)) => 0,
 | 
			
		||||
        Some((major, minor, patch)) => {
 | 
			
		||||
            return Err(UserError::CannotUpgradeToUnknownVersion(major, minor, patch).into())
 | 
			
		||||
            return Err(InternalError::CannotUpgradeToVersion(major, minor, patch).into())
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user