diff --git a/Cargo.toml b/Cargo.toml index 6a618c381..98e17acd2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["milli", "filter-parser", "flatten-serde-json", "json-depth-checker", "benchmarks", "helpers", "cli"] +members = ["milli", "filter-parser", "flatten-serde-json", "json-depth-checker", "benchmarks", "cli"] default-members = ["milli"] [profile.dev] diff --git a/README.md b/README.md index 93f4b2e6c..d69c43656 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ This repository contains crates to quickly debug the engine: - The `cli` crate is a simple command-line interface that helps run [flamegraph] on top of it. - The `filter-parser` crate contains the parser for the Meilisearch filter syntax. - The `flatten-serde-json` crate contains the library that flattens serde-json `Value` objects like Elasticsearch does. - - The `helpers` crate is only used to do operations on the database. - The `json-depth-checker` crate is used to indicate if a JSON must be flattened. ## How to use it? diff --git a/helpers/Cargo.toml b/helpers/Cargo.toml deleted file mode 100644 index b1034d092..000000000 --- a/helpers/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "helpers" -version = "0.33.4" -authors = ["Clément Renault "] -edition = "2018" -description = "A small tool to do operations on the database" -publish = false - -[dependencies] -anyhow = "1.0.56" -byte-unit = { version = "4.0.14", default-features = false, features = ["std"] } -milli = { path = "../milli" } -mimalloc = { version = "0.1.29", default-features = false } -stderrlog = "0.5.1" -structopt = { version = "0.3.26", default-features = false } diff --git a/helpers/src/main.rs b/helpers/src/main.rs deleted file mode 100644 index d1050e937..000000000 --- a/helpers/src/main.rs +++ /dev/null @@ -1,84 +0,0 @@ -use std::path::PathBuf; - -use byte_unit::Byte; -use milli::heed::{CompactionOption, Env, EnvOpenOptions}; -use structopt::StructOpt; -use Command::*; - -#[global_allocator] -static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; - -#[derive(Debug, StructOpt)] -/// Some helpers commands for milli. -pub struct Opt { - /// The database path where the database is located. - /// It is created if it doesn't already exist. - #[structopt(long = "db", parse(from_os_str))] - database: PathBuf, - - /// The maximum size the database can take on disk. It is recommended to specify - /// the whole disk space (value must be a multiple of a page size). - #[structopt(long = "db-size", default_value = "100 GiB")] - database_size: Byte, - - /// Verbose mode (-v, -vv, -vvv, etc.) - #[structopt(short, long, parse(from_occurrences))] - verbose: usize, - - #[structopt(subcommand)] - command: Command, -} - -#[derive(Debug, StructOpt)] -enum Command { - /// Outputs the main LMDB database to stdout. - CopyMainDatabase { - /// Wether to enable or not the compaction of the database. - #[structopt(long, short = "c")] - enable_compaction: bool, - }, -} - -fn main() -> anyhow::Result<()> { - let opt = Opt::from_args(); - - stderrlog::new() - .verbosity(opt.verbose) - .show_level(false) - .timestamp(stderrlog::Timestamp::Off) - .init()?; - - let mut options = EnvOpenOptions::new(); - options.map_size(opt.database_size.get_bytes() as usize); - - // Return an error if the database does not exist. - if !opt.database.exists() { - anyhow::bail!("The database ({}) does not exist.", opt.database.display()); - } - - let env = options.open(opt.database)?; - - match opt.command { - CopyMainDatabase { enable_compaction } => { - use CompactionOption::*; - let compaction = if enable_compaction { Enabled } else { Disabled }; - copy_main_database_to_stdout(env, compaction) - } - } -} - -#[cfg(target_family = "unix")] -fn copy_main_database_to_stdout(env: Env, compaction: CompactionOption) -> anyhow::Result<()> { - use std::os::unix::io::AsRawFd; - - let stdout = std::io::stdout().as_raw_fd(); - unsafe { env.copy_to_fd(stdout, compaction).map_err(Into::into) } -} - -#[cfg(target_family = "windows")] -fn copy_main_database_to_stdout(env: Env, compaction: CompactionOption) -> anyhow::Result<()> { - use std::os::windows::io::AsRawHandle; - - let stdout = std::io::stdout().as_raw_handle(); - unsafe { env.copy_to_fd(stdout, compaction).map_err(Into::into) } -}