From 61035a3ea465a6066577b37ce873433f113fb6a7 Mon Sep 17 00:00:00 2001 From: ad hoc Date: Mon, 23 May 2022 10:54:49 +0200 Subject: [PATCH] create dump v5 --- meilisearch-http/src/task.rs | 11 +++++----- meilisearch-lib/src/dump/loaders/v3.rs | 1 + meilisearch-lib/src/dump/loaders/v4.rs | 5 +++-- meilisearch-lib/src/dump/mod.rs | 28 ++++++++++++++++---------- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/meilisearch-http/src/task.rs b/meilisearch-http/src/task.rs index f10d7e110..397fed618 100644 --- a/meilisearch-http/src/task.rs +++ b/meilisearch-http/src/task.rs @@ -24,7 +24,7 @@ enum TaskType { DocumentDeletion, SettingsUpdate, ClearAll, - Dump, + DumpCreation, } impl From for TaskType { @@ -44,7 +44,7 @@ impl From for TaskType { TaskContent::IndexDeletion => TaskType::IndexDeletion, TaskContent::IndexCreation { .. } => TaskType::IndexCreation, TaskContent::IndexUpdate { .. } => TaskType::IndexUpdate, - TaskContent::Dump { .. } => TaskType::Dump, + TaskContent::Dump { .. } => TaskType::DumpCreation, _ => unreachable!("unexpected task type"), } } @@ -220,9 +220,10 @@ impl From for TaskView { TaskType::IndexUpdate, Some(TaskDetails::IndexInfo { primary_key }), ), - TaskContent::Dump { uid } => { - (TaskType::Dump, Some(TaskDetails::Dump { dump_uid: uid })) - } + TaskContent::Dump { uid } => ( + TaskType::DumpCreation, + Some(TaskDetails::Dump { dump_uid: uid }), + ), }; // An event always has at least one event: "Created" diff --git a/meilisearch-lib/src/dump/loaders/v3.rs b/meilisearch-lib/src/dump/loaders/v3.rs index 0a2ea438b..8e76b67e0 100644 --- a/meilisearch-lib/src/dump/loaders/v3.rs +++ b/meilisearch-lib/src/dump/loaders/v3.rs @@ -66,6 +66,7 @@ pub fn load_dump( index_db_size, meta_env_size, indexing_options, + "V5", ) } diff --git a/meilisearch-lib/src/dump/loaders/v4.rs b/meilisearch-lib/src/dump/loaders/v4.rs index c898f83b1..7f0ade714 100644 --- a/meilisearch-lib/src/dump/loaders/v4.rs +++ b/meilisearch-lib/src/dump/loaders/v4.rs @@ -19,10 +19,11 @@ pub fn load_dump( index_db_size: usize, meta_env_size: usize, indexing_options: &IndexerOpts, + version: &str, ) -> anyhow::Result<()> { info!( - "Loading dump from {}, dump database version: {}, dump version: V4", - meta.dump_date, meta.db_version + "Loading dump from {}, dump database version: {}, dump version: {}", + meta.dump_date, meta.db_version, version ); let mut options = EnvOpenOptions::new(); diff --git a/meilisearch-lib/src/dump/mod.rs b/meilisearch-lib/src/dump/mod.rs index b14b356fd..084fbd63f 100644 --- a/meilisearch-lib/src/dump/mod.rs +++ b/meilisearch-lib/src/dump/mod.rs @@ -69,6 +69,8 @@ pub enum MetadataVersion { V2(Metadata), V3(Metadata), V4(Metadata), + // V5 is forward compatible with V4 but not backward compatible. + V5(Metadata), } impl MetadataVersion { @@ -80,6 +82,7 @@ impl MetadataVersion { meta_env_size: usize, indexing_options: &IndexerOpts, ) -> anyhow::Result<()> { + let version = self.version(); match self { MetadataVersion::V1(_meta) => { anyhow::bail!("The version 1 of the dumps is not supported anymore. You can re-export your dump from a version between 0.21 and 0.24, or start fresh from a version 0.25 onwards.") @@ -100,46 +103,49 @@ impl MetadataVersion { meta_env_size, indexing_options, )?, - MetadataVersion::V4(meta) => v4::load_dump( + MetadataVersion::V4(meta) | MetadataVersion::V5(meta) => v4::load_dump( meta, src, dst, index_db_size, meta_env_size, indexing_options, + version, )?, } Ok(()) } - pub fn new_v4(index_db_size: usize, update_db_size: usize) -> Self { + pub fn new_v5(index_db_size: usize, update_db_size: usize) -> Self { let meta = Metadata::new(index_db_size, update_db_size); - Self::V4(meta) + Self::V5(meta) } pub fn db_version(&self) -> &str { match self { Self::V1(meta) => &meta.db_version, - Self::V2(meta) | Self::V3(meta) | Self::V4(meta) => &meta.db_version, + Self::V2(meta) | Self::V3(meta) | Self::V4(meta) | Self::V5(meta) => &meta.db_version, } } - pub fn version(&self) -> &str { + pub fn version(&self) -> &'static str { match self { MetadataVersion::V1(_) => "V1", MetadataVersion::V2(_) => "V2", MetadataVersion::V3(_) => "V3", MetadataVersion::V4(_) => "V4", + MetadataVersion::V5(_) => "V5", } } pub fn dump_date(&self) -> Option<&OffsetDateTime> { match self { MetadataVersion::V1(_) => None, - MetadataVersion::V2(meta) | MetadataVersion::V3(meta) | MetadataVersion::V4(meta) => { - Some(&meta.dump_date) - } + MetadataVersion::V2(meta) + | MetadataVersion::V3(meta) + | MetadataVersion::V4(meta) + | MetadataVersion::V5(meta) => Some(&meta.dump_date), } } } @@ -294,7 +300,7 @@ where let temp_dump_dir = tokio::task::spawn_blocking(tempfile::TempDir::new).await??; let temp_dump_path = temp_dump_dir.path().to_owned(); - let meta = MetadataVersion::new_v4(self.index_db_size, self.task_store_size); + let meta = MetadataVersion::new_v5(self.index_db_size, self.task_store_size); let meta_path = temp_dump_path.join(META_FILE_NAME); let mut meta_file = File::create(&meta_path)?; serde_json::to_writer(&mut meta_file, &meta)?; @@ -306,11 +312,11 @@ where AuthController::dump(&self.db_path, &temp_dump_path)?; TaskStore::dump( self.env.clone(), - &self.dump_path, + &temp_dump_path, self.update_file_store.clone(), ) .await?; - self.index_resolver.dump(&self.dump_path).await?; + self.index_resolver.dump(&temp_dump_path).await?; let dump_path = self.dump_path.clone(); let dump_path = tokio::task::spawn_blocking(move || -> Result {