mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 12:27:13 +02:00
add the version in the index-scheduler
This commit is contained in:
parent
27bf2f1298
commit
b9e9fc376a
8 changed files with 212 additions and 67 deletions
|
@ -1,25 +1,28 @@
|
|||
use std::path::Path;
|
||||
|
||||
use anyhow::bail;
|
||||
use meilisearch_types::heed;
|
||||
use meilisearch_types::heed::{Env, RwTxn};
|
||||
use meilisearch_types::tasks::{Details, KindWithContent, Status, Task};
|
||||
use meilisearch_types::versioning::{VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH};
|
||||
use time::OffsetDateTime;
|
||||
use tracing::info;
|
||||
|
||||
use crate::queue::TaskQueue;
|
||||
use crate::IndexSchedulerOptions;
|
||||
|
||||
pub fn upgrade_task_queue(
|
||||
opt: &IndexSchedulerOptions,
|
||||
trait UpgradeIndexScheduler {
|
||||
fn upgrade(&self, env: &Env, wtxn: &mut RwTxn, original: (u32, u32, u32))
|
||||
-> anyhow::Result<()>;
|
||||
fn target_version(&self) -> (u32, u32, u32);
|
||||
}
|
||||
|
||||
pub fn upgrade_index_scheduler(
|
||||
env: &Env,
|
||||
from: (u32, u32, u32),
|
||||
to: (u32, u32, u32),
|
||||
) -> anyhow::Result<()> {
|
||||
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 current_major = to.0;
|
||||
let current_minor = to.1;
|
||||
let current_patch = to.2;
|
||||
|
||||
let upgrade_functions =
|
||||
[(v1_12_to_current as fn(&Path) -> anyhow::Result<()>, "Upgrading from v1.12 to v1.13")];
|
||||
let upgrade_functions: &[&dyn UpgradeIndexScheduler] = &[&V1_12_ToCurrent {}];
|
||||
|
||||
let start = match from {
|
||||
(1, 12, _) => 0,
|
||||
|
@ -41,20 +44,23 @@ pub fn upgrade_task_queue(
|
|||
}
|
||||
};
|
||||
|
||||
let mut current_version = from;
|
||||
|
||||
info!("Upgrading the task queue");
|
||||
for (upgrade, upgrade_name) in upgrade_functions[start..].iter() {
|
||||
info!("{upgrade_name}");
|
||||
(upgrade)(&opt.tasks_path)?;
|
||||
for upgrade in upgrade_functions[start..].iter() {
|
||||
let target = upgrade.target_version();
|
||||
info!(
|
||||
"Upgrading from v{}.{}.{} to v{}.{}.{}",
|
||||
from.0, from.1, from.2, current_version.0, current_version.1, current_version.2
|
||||
);
|
||||
let mut wtxn = env.write_txn()?;
|
||||
upgrade.upgrade(env, &mut wtxn, from)?;
|
||||
wtxn.commit()?;
|
||||
current_version = target;
|
||||
}
|
||||
|
||||
let env = unsafe {
|
||||
heed::EnvOpenOptions::new()
|
||||
.max_dbs(TaskQueue::nb_db())
|
||||
.map_size(opt.task_db_size)
|
||||
.open(&opt.tasks_path)
|
||||
}?;
|
||||
let mut wtxn = env.write_txn()?;
|
||||
let queue = TaskQueue::new(&env, &mut wtxn)?;
|
||||
let queue = TaskQueue::new(env, &mut wtxn)?;
|
||||
let uid = queue.next_task_id(&wtxn)?;
|
||||
queue.register(
|
||||
&mut wtxn,
|
||||
|
@ -72,12 +78,28 @@ pub fn upgrade_task_queue(
|
|||
},
|
||||
)?;
|
||||
wtxn.commit()?;
|
||||
// Should be pretty much instantaneous since we're the only one reading this env
|
||||
env.prepare_for_closing().wait();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The task queue is 100% compatible with the previous versions
|
||||
fn v1_12_to_current(_path: &Path) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
#[allow(non_camel_case_types)]
|
||||
struct V1_12_ToCurrent {}
|
||||
|
||||
impl UpgradeIndexScheduler for V1_12_ToCurrent {
|
||||
fn upgrade(
|
||||
&self,
|
||||
_env: &Env,
|
||||
_wtxn: &mut RwTxn,
|
||||
_original: (u32, u32, u32),
|
||||
) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn target_version(&self) -> (u32, u32, u32) {
|
||||
(
|
||||
VERSION_MAJOR.parse().unwrap(),
|
||||
VERSION_MINOR.parse().unwrap(),
|
||||
VERSION_PATCH.parse().unwrap(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue