Remove `helpers` crate

This commit is contained in:
Loïc Lecrenier 2022-09-21 10:22:32 +02:00
parent d94339a858
commit b6fe6838d3
4 changed files with 1 additions and 101 deletions

View File

@ -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]

View File

@ -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?

View File

@ -1,15 +0,0 @@
[package]
name = "helpers"
version = "0.33.4"
authors = ["Clément Renault <clement@meilisearch.com>"]
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 }

View File

@ -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) }
}