Skip rebuilding field distribution if not coming from v1.12

This commit is contained in:
Louis Dureuil 2025-01-13 09:31:27 +01:00
parent c3b18fede9
commit c25781f720
No known key found for this signature in database
4 changed files with 36 additions and 7 deletions

View File

@ -21,7 +21,12 @@ pub struct OfflineUpgrade {
impl OfflineUpgrade { impl OfflineUpgrade {
pub fn upgrade(self) -> anyhow::Result<()> { pub fn upgrade(self) -> anyhow::Result<()> {
let upgrade_list = [ let upgrade_list = [
(v1_9_to_v1_10 as fn(&Path) -> Result<(), anyhow::Error>, "1", "10", "0"), (
v1_9_to_v1_10 as fn(&Path, &str, &str, &str) -> Result<(), anyhow::Error>,
"1",
"10",
"0",
),
(v1_10_to_v1_11, "1", "11", "0"), (v1_10_to_v1_11, "1", "11", "0"),
(v1_11_to_v1_12, "1", "12", "0"), (v1_11_to_v1_12, "1", "12", "0"),
(v1_12_to_v1_12_3, "1", "12", "3"), (v1_12_to_v1_12_3, "1", "12", "3"),
@ -63,7 +68,7 @@ impl OfflineUpgrade {
#[allow(clippy::needless_range_loop)] #[allow(clippy::needless_range_loop)]
for index in start_at..=ends_at { for index in start_at..=ends_at {
let (func, major, minor, patch) = upgrade_list[index]; let (func, major, minor, patch) = upgrade_list[index];
(func)(&self.db_path)?; (func)(&self.db_path, current_major, current_minor, current_patch)?;
println!("Done"); println!("Done");
// We're writing the version file just in case an issue arise _while_ upgrading. // We're writing the version file just in case an issue arise _while_ upgrading.
// We don't want the DB to fail in an unknown state. // We don't want the DB to fail in an unknown state.

View File

@ -151,7 +151,12 @@ fn date_round_trip(
Ok(()) Ok(())
} }
pub fn v1_9_to_v1_10(db_path: &Path) -> anyhow::Result<()> { pub fn v1_9_to_v1_10(
db_path: &Path,
_origin_major: &str,
_origin_minor: &str,
_origin_patch: &str,
) -> anyhow::Result<()> {
println!("Upgrading from v1.9.0 to v1.10.0"); println!("Upgrading from v1.9.0 to v1.10.0");
// 2 changes here // 2 changes here

View File

@ -14,7 +14,12 @@ use meilisearch_types::milli::index::db_name;
use crate::uuid_codec::UuidCodec; use crate::uuid_codec::UuidCodec;
use crate::{try_opening_database, try_opening_poly_database}; use crate::{try_opening_database, try_opening_poly_database};
pub fn v1_10_to_v1_11(db_path: &Path) -> anyhow::Result<()> { pub fn v1_10_to_v1_11(
db_path: &Path,
_origin_major: &str,
_origin_minor: &str,
_origin_patch: &str,
) -> anyhow::Result<()> {
println!("Upgrading from v1.10.0 to v1.11.0"); println!("Upgrading from v1.10.0 to v1.11.0");
let index_scheduler_path = db_path.join("tasks"); let index_scheduler_path = db_path.join("tasks");

View File

@ -23,7 +23,12 @@ use uuid::Uuid;
use crate::try_opening_database; use crate::try_opening_database;
use crate::uuid_codec::UuidCodec; use crate::uuid_codec::UuidCodec;
pub fn v1_11_to_v1_12(db_path: &Path) -> anyhow::Result<()> { pub fn v1_11_to_v1_12(
db_path: &Path,
_origin_major: &str,
_origin_minor: &str,
_origin_patch: &str,
) -> anyhow::Result<()> {
println!("Upgrading from v1.11.0 to v1.12.0"); println!("Upgrading from v1.11.0 to v1.12.0");
convert_update_files(db_path)?; convert_update_files(db_path)?;
@ -31,10 +36,19 @@ pub fn v1_11_to_v1_12(db_path: &Path) -> anyhow::Result<()> {
Ok(()) Ok(())
} }
pub fn v1_12_to_v1_12_3(db_path: &Path) -> anyhow::Result<()> { pub fn v1_12_to_v1_12_3(
db_path: &Path,
origin_major: &str,
origin_minor: &str,
origin_patch: &str,
) -> anyhow::Result<()> {
println!("Upgrading from v1.12.{{0, 1, 2}} to v1.12.3"); println!("Upgrading from v1.12.{{0, 1, 2}} to v1.12.3");
rebuild_field_distribution(db_path)?; if origin_minor == "12" {
rebuild_field_distribution(db_path)?;
} else {
println!("Not rebuilding field distribution as it wasn't corrupted coming from v{origin_major}.{origin_minor}.{origin_patch}");
}
Ok(()) Ok(())
} }