mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-11-04 09:56:28 +00:00 
			
		
		
		
	Merge #641
641: Remove `helpers` crate r=Kerollmops a=loiclec # Pull Request ## What does this PR do? Remove the `helpers` crates, because (I think) we don't use it. This should have been part of https://github.com/meilisearch/milli/pull/636 , but I forgot about it then :) Co-authored-by: Loïc Lecrenier <loic@meilisearch.com>
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
				
			|||||||
[workspace]
 | 
					[workspace]
 | 
				
			||||||
resolver = "2"
 | 
					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"]
 | 
					default-members = ["milli"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[profile.dev]
 | 
					[profile.dev]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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 `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 `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 `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.
 | 
					 - The `json-depth-checker` crate is used to indicate if a JSON must be flattened.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## How to use it?
 | 
					## How to use it?
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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 }
 | 
					 | 
				
			||||||
@@ -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) }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user