From b43137b508691be18516f7c6557f2f02f39f217e Mon Sep 17 00:00:00 2001 From: many Date: Mon, 7 Sep 2020 15:51:34 +0200 Subject: [PATCH 1/2] add version guard in copy_and_compact_to_path function --- meilisearch-core/src/database.rs | 35 ++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/meilisearch-core/src/database.rs b/meilisearch-core/src/database.rs index 5f4efef96..5dc6d8a76 100644 --- a/meilisearch-core/src/database.rs +++ b/meilisearch-core/src/database.rs @@ -40,6 +40,7 @@ pub struct Database { indexes_store: heed::Database, indexes: RwLock>)>>, update_fn: Arc, + database_version: (u32, u32, u32), } pub struct DatabaseOptions { @@ -165,7 +166,7 @@ fn update_awaiter( /// Ensures Meilisearch version is compatible with the database, returns an error versions mismatch. /// If create is set to true, a VERSION file is created with the current version. -fn version_guard(path: &Path, create: bool) -> MResult<()> { +fn version_guard(path: &Path, create: bool) -> MResult<(u32, u32, u32)> { let current_version_major = env!("CARGO_PKG_VERSION_MAJOR"); let current_version_minor = env!("CARGO_PKG_VERSION_MINOR"); let current_version_patch = env!("CARGO_PKG_VERSION_PATCH"); @@ -186,9 +187,16 @@ fn version_guard(path: &Path, create: bool) -> MResult<()> { // the first is always the complete match, safe to unwrap because we have a match let version_major = version.get(1).unwrap().as_str(); let version_minor = version.get(2).unwrap().as_str(); + let version_patch = version.get(3).unwrap().as_str(); if version_major != current_version_major || version_minor != current_version_minor { - return Err(Error::VersionMismatch(format!("{}.{}.XX", version_major, version_minor))); + Err(Error::VersionMismatch(format!("{}.{}.XX", version_major, version_minor))) + } else { + Ok(( + version_major.parse().or_else(|e| Err(Error::VersionMismatch(format!("error parsing database version: {}", e))))?, + version_minor.parse().or_else(|e| Err(Error::VersionMismatch(format!("error parsing database version: {}", e))))?, + version_patch.parse().or_else(|e| Err(Error::VersionMismatch(format!("error parsing database version: {}", e))))? + )) } } Err(error) => { @@ -202,17 +210,22 @@ fn version_guard(path: &Path, create: bool) -> MResult<()> { current_version_major, current_version_minor, current_version_patch).as_bytes())?; + + Ok(( + current_version_major.parse().or_else(|e| Err(Error::VersionMismatch(format!("error parsing database version: {}", e))))?, + current_version_minor.parse().or_else(|e| Err(Error::VersionMismatch(format!("error parsing database version: {}", e))))?, + current_version_patch.parse().or_else(|e| Err(Error::VersionMismatch(format!("error parsing database version: {}", e))))? + )) } else { // when no version file is found and we were not told to create one, this // means that the version is inferior to the one this feature was added in. - return Err(Error::VersionMismatch("<0.12.0".to_string())); + Err(Error::VersionMismatch("<0.12.0".to_string())) } } - _ => return Err(error.into()) + _ => Err(error.into()) } } } - Ok(()) } impl Database { @@ -224,7 +237,7 @@ impl Database { fs::create_dir_all(&path)?; // create file only if main db wasn't created before (first run) - version_guard(path.as_ref(), !main_path.exists() && !update_path.exists())?; + let database_version = version_guard(path.as_ref(), !main_path.exists() && !update_path.exists())?; fs::create_dir_all(&main_path)?; let env = heed::EnvOpenOptions::new() @@ -302,6 +315,7 @@ impl Database { indexes_store, indexes: RwLock::new(indexes), update_fn, + database_version, }) } @@ -469,9 +483,18 @@ impl Database { let env_path = path.join("main"); let env_update_path = path.join("update"); + let env_version_path = path.join("VERSION"); fs::create_dir(&env_path)?; fs::create_dir(&env_update_path)?; + + // write Database Version + let (current_version_major, current_version_minor, current_version_patch) = self.database_version; + let mut version_file = File::create(&env_version_path)?; + version_file.write_all(format!("{}.{}.{}", + current_version_major, + current_version_minor, + current_version_patch).as_bytes())?; let env_path = env_path.join("data.mdb"); let env_file = self.env.copy_to_path(&env_path, CompactionOption::Enabled)?; From 87a76c2a609cfb38a45b6167c01205f50a162035 Mon Sep 17 00:00:00 2001 From: many Date: Tue, 8 Sep 2020 18:00:25 +0200 Subject: [PATCH 2/2] bump version and update changelog --- CHANGELOG.md | 4 ++++ Cargo.lock | 12 ++++++------ meilisearch-core/Cargo.toml | 10 +++++----- meilisearch-error/Cargo.toml | 2 +- meilisearch-http/Cargo.toml | 10 +++++----- meilisearch-schema/Cargo.toml | 4 ++-- meilisearch-tokenizer/Cargo.toml | 2 +- meilisearch-types/Cargo.toml | 2 +- 8 files changed, 25 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee3ca1d6f..2faa3a310 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v0.14.1 + + - Fix version mismatch in snapshot importation (#959) + ## v0.14.0 - Fix facet distribution case (#797) diff --git a/Cargo.lock b/Cargo.lock index 09eae9e43..7752a6aa1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1493,7 +1493,7 @@ checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" [[package]] name = "meilisearch-core" -version = "0.14.0" +version = "0.14.1" dependencies = [ "arc-swap", "assert_matches", @@ -1540,14 +1540,14 @@ dependencies = [ [[package]] name = "meilisearch-error" -version = "0.14.0" +version = "0.14.1" dependencies = [ "actix-http", ] [[package]] name = "meilisearch-http" -version = "0.14.0" +version = "0.14.1" dependencies = [ "actix-cors", "actix-http", @@ -1596,7 +1596,7 @@ dependencies = [ [[package]] name = "meilisearch-schema" -version = "0.14.0" +version = "0.14.1" dependencies = [ "indexmap", "meilisearch-error", @@ -1607,7 +1607,7 @@ dependencies = [ [[package]] name = "meilisearch-tokenizer" -version = "0.14.0" +version = "0.14.1" dependencies = [ "deunicode", "slice-group-by", @@ -1615,7 +1615,7 @@ dependencies = [ [[package]] name = "meilisearch-types" -version = "0.14.0" +version = "0.14.1" dependencies = [ "serde", "zerocopy", diff --git a/meilisearch-core/Cargo.toml b/meilisearch-core/Cargo.toml index e4f0c5b00..a220e6e34 100644 --- a/meilisearch-core/Cargo.toml +++ b/meilisearch-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "meilisearch-core" -version = "0.14.0" +version = "0.14.1" license = "MIT" authors = ["Kerollmops "] edition = "2018" @@ -24,10 +24,10 @@ intervaltree = "0.2.5" itertools = "0.9.0" levenshtein_automata = { version = "0.2.0", features = ["fst_automaton"] } log = "0.4.8" -meilisearch-error = { path = "../meilisearch-error", version = "0.14.0" } -meilisearch-schema = { path = "../meilisearch-schema", version = "0.14.0" } -meilisearch-tokenizer = { path = "../meilisearch-tokenizer", version = "0.14.0" } -meilisearch-types = { path = "../meilisearch-types", version = "0.14.0" } +meilisearch-error = { path = "../meilisearch-error", version = "0.14.1" } +meilisearch-schema = { path = "../meilisearch-schema", version = "0.14.1" } +meilisearch-tokenizer = { path = "../meilisearch-tokenizer", version = "0.14.1" } +meilisearch-types = { path = "../meilisearch-types", version = "0.14.1" } once_cell = "1.3.1" ordered-float = { version = "1.0.2", features = ["serde"] } pest = { git = "https://github.com/MarinPostma/pest.git", tag = "meilisearch-patch1" } diff --git a/meilisearch-error/Cargo.toml b/meilisearch-error/Cargo.toml index e7ae14062..2be552f3d 100644 --- a/meilisearch-error/Cargo.toml +++ b/meilisearch-error/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "meilisearch-error" -version = "0.14.0" +version = "0.14.1" authors = ["marin "] edition = "2018" diff --git a/meilisearch-http/Cargo.toml b/meilisearch-http/Cargo.toml index 31263ae17..6dce9a700 100644 --- a/meilisearch-http/Cargo.toml +++ b/meilisearch-http/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "meilisearch-http" description = "MeiliSearch HTTP server" -version = "0.14.0" +version = "0.14.1" license = "MIT" authors = [ "Quentin de Quelen ", @@ -33,10 +33,10 @@ http = "0.1.19" indexmap = { version = "1.3.2", features = ["serde-1"] } log = "0.4.8" main_error = "0.1.0" -meilisearch-core = { path = "../meilisearch-core", version = "0.14.0" } -meilisearch-error = { path = "../meilisearch-error", version = "0.14.0" } -meilisearch-schema = { path = "../meilisearch-schema", version = "0.14.0" } -meilisearch-tokenizer = {path = "../meilisearch-tokenizer", version = "0.14.0"} +meilisearch-core = { path = "../meilisearch-core", version = "0.14.1" } +meilisearch-error = { path = "../meilisearch-error", version = "0.14.1" } +meilisearch-schema = { path = "../meilisearch-schema", version = "0.14.1" } +meilisearch-tokenizer = {path = "../meilisearch-tokenizer", version = "0.14.1"} mime = "0.3.16" rand = "0.7.3" regex = "1.3.6" diff --git a/meilisearch-schema/Cargo.toml b/meilisearch-schema/Cargo.toml index 1f3f3f11b..68a602d1c 100644 --- a/meilisearch-schema/Cargo.toml +++ b/meilisearch-schema/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "meilisearch-schema" -version = "0.14.0" +version = "0.14.1" license = "MIT" authors = ["Kerollmops "] edition = "2018" [dependencies] indexmap = { version = "1.3.2", features = ["serde-1"] } -meilisearch-error = { path = "../meilisearch-error", version = "0.14.0" } +meilisearch-error = { path = "../meilisearch-error", version = "0.14.1" } serde = { version = "1.0.105", features = ["derive"] } serde_json = { version = "1.0.50", features = ["preserve_order"] } zerocopy = "0.3.0" diff --git a/meilisearch-tokenizer/Cargo.toml b/meilisearch-tokenizer/Cargo.toml index 78aecae72..b8c71992d 100644 --- a/meilisearch-tokenizer/Cargo.toml +++ b/meilisearch-tokenizer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "meilisearch-tokenizer" -version = "0.14.0" +version = "0.14.1" license = "MIT" authors = ["Kerollmops "] edition = "2018" diff --git a/meilisearch-types/Cargo.toml b/meilisearch-types/Cargo.toml index 70b98f04c..2a6509b61 100644 --- a/meilisearch-types/Cargo.toml +++ b/meilisearch-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "meilisearch-types" -version = "0.14.0" +version = "0.14.1" license = "MIT" authors = ["Clément Renault "] edition = "2018"