diff --git a/crates/index-scheduler/src/insta_snapshot.rs b/crates/index-scheduler/src/insta_snapshot.rs index ee271b5df..89e615132 100644 --- a/crates/index-scheduler/src/insta_snapshot.rs +++ b/crates/index-scheduler/src/insta_snapshot.rs @@ -41,11 +41,8 @@ pub fn snapshot_index_scheduler(scheduler: &IndexScheduler) -> String { let mut snap = String::new(); let indx_sched_version = version.get_version(&rtxn).unwrap(); - let latest_version = ( - versioning::VERSION_MAJOR.parse().unwrap(), - versioning::VERSION_MINOR.parse().unwrap(), - versioning::VERSION_PATCH.parse().unwrap(), - ); + let latest_version = + (versioning::VERSION_MAJOR, versioning::VERSION_MINOR, versioning::VERSION_PATCH); if indx_sched_version != Some(latest_version) { snap.push_str(&format!("index scheduler running on version {indx_sched_version:?}\n")); } diff --git a/crates/index-scheduler/src/test_utils.rs b/crates/index-scheduler/src/test_utils.rs index 5c04a66ff..0d44b3c81 100644 --- a/crates/index-scheduler/src/test_utils.rs +++ b/crates/index-scheduler/src/test_utils.rs @@ -114,12 +114,8 @@ impl IndexScheduler { auto_upgrade: true, // Don't cost much and will ensure the happy path works embedding_cache_cap: 10, }; - let version = configuration(&mut options).unwrap_or_else(|| { - ( - versioning::VERSION_MAJOR.parse().unwrap(), - versioning::VERSION_MINOR.parse().unwrap(), - versioning::VERSION_PATCH.parse().unwrap(), - ) + let version = configuration(&mut options).unwrap_or({ + (versioning::VERSION_MAJOR, versioning::VERSION_MINOR, versioning::VERSION_PATCH) }); std::fs::create_dir_all(&options.auth_path).unwrap(); diff --git a/crates/index-scheduler/src/upgrade/mod.rs b/crates/index-scheduler/src/upgrade/mod.rs index 4a3cb2f75..74c8ee696 100644 --- a/crates/index-scheduler/src/upgrade/mod.rs +++ b/crates/index-scheduler/src/upgrade/mod.rs @@ -104,10 +104,6 @@ impl UpgradeIndexScheduler for ToCurrentNoOp { } fn target_version(&self) -> (u32, u32, u32) { - ( - VERSION_MAJOR.parse().unwrap(), - VERSION_MINOR.parse().unwrap(), - VERSION_PATCH.parse().unwrap(), - ) + (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH) } } diff --git a/crates/index-scheduler/src/versioning.rs b/crates/index-scheduler/src/versioning.rs index 107b8e0ba..b0cb7fdb5 100644 --- a/crates/index-scheduler/src/versioning.rs +++ b/crates/index-scheduler/src/versioning.rs @@ -39,9 +39,9 @@ impl Versioning { } pub fn set_current_version(&self, wtxn: &mut RwTxn) -> Result<(), heed::Error> { - let major = versioning::VERSION_MAJOR.parse().unwrap(); - let minor = versioning::VERSION_MINOR.parse().unwrap(); - let patch = versioning::VERSION_PATCH.parse().unwrap(); + let major = versioning::VERSION_MAJOR; + let minor = versioning::VERSION_MINOR; + let patch = versioning::VERSION_PATCH; self.set_version(wtxn, (major, minor, patch)) } @@ -64,9 +64,9 @@ impl Versioning { }; wtxn.commit()?; - let bin_major: u32 = versioning::VERSION_MAJOR.parse().unwrap(); - let bin_minor: u32 = versioning::VERSION_MINOR.parse().unwrap(); - let bin_patch: u32 = versioning::VERSION_PATCH.parse().unwrap(); + let bin_major: u32 = versioning::VERSION_MAJOR; + let bin_minor: u32 = versioning::VERSION_MINOR; + let bin_patch: u32 = versioning::VERSION_PATCH; let to = (bin_major, bin_minor, bin_patch); if from != to { diff --git a/crates/meilisearch-types/src/tasks.rs b/crates/meilisearch-types/src/tasks.rs index d96a45992..6e10f2606 100644 --- a/crates/meilisearch-types/src/tasks.rs +++ b/crates/meilisearch-types/src/tasks.rs @@ -272,9 +272,9 @@ impl KindWithContent { KindWithContent::UpgradeDatabase { from } => Some(Details::UpgradeDatabase { from: (from.0, from.1, from.2), to: ( - versioning::VERSION_MAJOR.parse().unwrap(), - versioning::VERSION_MINOR.parse().unwrap(), - versioning::VERSION_PATCH.parse().unwrap(), + versioning::VERSION_MAJOR, + versioning::VERSION_MINOR, + versioning::VERSION_PATCH, ), }), } @@ -338,9 +338,9 @@ impl KindWithContent { KindWithContent::UpgradeDatabase { from } => Some(Details::UpgradeDatabase { from: *from, to: ( - versioning::VERSION_MAJOR.parse().unwrap(), - versioning::VERSION_MINOR.parse().unwrap(), - versioning::VERSION_PATCH.parse().unwrap(), + versioning::VERSION_MAJOR, + versioning::VERSION_MINOR, + versioning::VERSION_PATCH, ), }), } @@ -386,9 +386,9 @@ impl From<&KindWithContent> for Option
{ KindWithContent::UpgradeDatabase { from } => Some(Details::UpgradeDatabase { from: *from, to: ( - versioning::VERSION_MAJOR.parse().unwrap(), - versioning::VERSION_MINOR.parse().unwrap(), - versioning::VERSION_PATCH.parse().unwrap(), + versioning::VERSION_MAJOR, + versioning::VERSION_MINOR, + versioning::VERSION_PATCH, ), }), } diff --git a/crates/meilisearch-types/src/versioning.rs b/crates/meilisearch-types/src/versioning.rs index 07e42c2ce..b2124c04e 100644 --- a/crates/meilisearch-types/src/versioning.rs +++ b/crates/meilisearch-types/src/versioning.rs @@ -8,9 +8,7 @@ use tempfile::NamedTempFile; /// The name of the file that contains the version of the database. pub const VERSION_FILE_NAME: &str = "VERSION"; -pub static VERSION_MAJOR: &str = env!("CARGO_PKG_VERSION_MAJOR"); -pub static VERSION_MINOR: &str = env!("CARGO_PKG_VERSION_MINOR"); -pub static VERSION_PATCH: &str = env!("CARGO_PKG_VERSION_PATCH"); +pub use milli::constants::{VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH}; /// Persists the version of the current Meilisearch binary to a VERSION file pub fn create_current_version_file(db_path: &Path) -> anyhow::Result<()> { @@ -19,9 +17,9 @@ pub fn create_current_version_file(db_path: &Path) -> anyhow::Result<()> { pub fn create_version_file( db_path: &Path, - major: &str, - minor: &str, - patch: &str, + major: u32, + minor: u32, + patch: u32, ) -> anyhow::Result<()> { let version_path = db_path.join(VERSION_FILE_NAME); // In order to persist the file later we must create it in the `data.ms` and not in `/tmp` diff --git a/crates/meilisearch/src/lib.rs b/crates/meilisearch/src/lib.rs index 761726d83..40d318140 100644 --- a/crates/meilisearch/src/lib.rs +++ b/crates/meilisearch/src/lib.rs @@ -235,10 +235,7 @@ pub fn setup_meilisearch(opt: &Opt) -> anyhow::Result<(Arc, Arc< auto_upgrade: opt.experimental_dumpless_upgrade, embedding_cache_cap: opt.experimental_embedding_cache_entries, }; - let bin_major: u32 = VERSION_MAJOR.parse().unwrap(); - let bin_minor: u32 = VERSION_MINOR.parse().unwrap(); - let bin_patch: u32 = VERSION_PATCH.parse().unwrap(); - let binary_version = (bin_major, bin_minor, bin_patch); + let binary_version = (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); let empty_db = is_empty_db(&opt.db_path); let (index_scheduler, auth_controller) = if let Some(ref snapshot_path) = opt.import_snapshot { diff --git a/crates/meilisearch/tests/upgrade/mod.rs b/crates/meilisearch/tests/upgrade/mod.rs index ae6bcff40..0055a3ee1 100644 --- a/crates/meilisearch/tests/upgrade/mod.rs +++ b/crates/meilisearch/tests/upgrade/mod.rs @@ -54,7 +54,7 @@ async fn version_requires_downgrade() { std::fs::create_dir_all(&db_path).unwrap(); let major = meilisearch_types::versioning::VERSION_MAJOR; let minor = meilisearch_types::versioning::VERSION_MINOR; - let patch = meilisearch_types::versioning::VERSION_PATCH.parse::().unwrap() + 1; + let patch = meilisearch_types::versioning::VERSION_PATCH + 1; std::fs::write(db_path.join("VERSION"), format!("{major}.{minor}.{patch}")).unwrap(); let options = Opt { experimental_dumpless_upgrade: true, ..default_settings }; let err = Server::new_with_options(options).await.map(|_| ()).unwrap_err(); diff --git a/crates/meilitool/src/upgrade/mod.rs b/crates/meilitool/src/upgrade/mod.rs index 82a57317c..87ce00772 100644 --- a/crates/meilitool/src/upgrade/mod.rs +++ b/crates/meilitool/src/upgrade/mod.rs @@ -49,15 +49,10 @@ impl OfflineUpgrade { const LAST_SUPPORTED_UPGRADE_TO_VERSION: &str = "1.12.7"; let upgrade_list = [ - ( - v1_9_to_v1_10 as fn(&Path, u32, u32, u32) -> Result<(), anyhow::Error>, - "1", - "10", - "0", - ), - (v1_10_to_v1_11, "1", "11", "0"), - (v1_11_to_v1_12, "1", "12", "0"), - (v1_12_to_v1_12_3, "1", "12", "3"), + (v1_9_to_v1_10 as fn(&Path, u32, u32, u32) -> Result<(), anyhow::Error>, 1, 10, 0), + (v1_10_to_v1_11, 1, 11, 0), + (v1_11_to_v1_12, 1, 12, 0), + (v1_12_to_v1_12_3, 1, 12, 3), ]; let no_upgrade: usize = upgrade_list.len(); @@ -95,13 +90,8 @@ impl OfflineUpgrade { if start_at == no_upgrade { println!("No upgrade operation to perform, writing VERSION file"); - create_version_file( - &self.db_path, - &target_major.to_string(), - &target_minor.to_string(), - &target_patch.to_string(), - ) - .context("while writing VERSION file after the upgrade")?; + create_version_file(&self.db_path, target_major, target_minor, target_patch) + .context("while writing VERSION file after the upgrade")?; println!("Success"); return Ok(()); } diff --git a/crates/milli/src/constants.rs b/crates/milli/src/constants.rs index 39b449661..dc88bdb37 100644 --- a/crates/milli/src/constants.rs +++ b/crates/milli/src/constants.rs @@ -1,6 +1,13 @@ -pub static VERSION_MAJOR: &str = env!("CARGO_PKG_VERSION_MAJOR"); -pub static VERSION_MINOR: &str = env!("CARGO_PKG_VERSION_MINOR"); -pub static VERSION_PATCH: &str = env!("CARGO_PKG_VERSION_PATCH"); +pub const VERSION_MAJOR: u32 = parse_u32(env!("CARGO_PKG_VERSION_MAJOR")); +pub const VERSION_MINOR: u32 = parse_u32(env!("CARGO_PKG_VERSION_MINOR")); +pub const VERSION_PATCH: u32 = parse_u32(env!("CARGO_PKG_VERSION_PATCH")); + +const fn parse_u32(s: &str) -> u32 { + match u32::from_str_radix(s, 10) { + Ok(version) => version, + Err(_) => panic!("could not parse as u32"), + } +} pub const RESERVED_VECTORS_FIELD_NAME: &str = "_vectors"; pub const RESERVED_GEO_FIELD_NAME: &str = "_geo"; diff --git a/crates/milli/src/index.rs b/crates/milli/src/index.rs index d65d32e0d..a51d83ab9 100644 --- a/crates/milli/src/index.rs +++ b/crates/milli/src/index.rs @@ -262,9 +262,9 @@ impl Index { this.put_version( &mut wtxn, ( - constants::VERSION_MAJOR.parse().unwrap(), - constants::VERSION_MINOR.parse().unwrap(), - constants::VERSION_PATCH.parse().unwrap(), + constants::VERSION_MAJOR, + constants::VERSION_MINOR, + constants::VERSION_PATCH, ), )?; } diff --git a/crates/milli/src/update/upgrade/v1_13.rs b/crates/milli/src/update/upgrade/v1_13.rs index 8e5e052bd..7f6608970 100644 --- a/crates/milli/src/update/upgrade/v1_13.rs +++ b/crates/milli/src/update/upgrade/v1_13.rs @@ -1,7 +1,6 @@ use heed::RwTxn; use super::UpgradeIndex; -use crate::constants::{VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH}; use crate::database_stats::DatabaseStats; use crate::progress::Progress; use crate::{make_enum_progress, Index, Result}; @@ -51,10 +50,6 @@ impl UpgradeIndex for V1_13_1_To_Latest_V1_13 { } fn target_version(&self) -> (u32, u32, u32) { - ( - VERSION_MAJOR.parse().unwrap(), - VERSION_MINOR.parse().unwrap(), - VERSION_PATCH.parse().unwrap(), - ) + (1, 13, 3) } }