aboutsummaryrefslogtreecommitdiff
path: root/src/garage/cli
diff options
context:
space:
mode:
authorAlex <alex@adnab.me>2024-03-08 12:56:40 +0000
committerAlex <alex@adnab.me>2024-03-08 12:56:40 +0000
commit238545e56486b857fab41e0703fc9bccbcd50a2c (patch)
treea487693805f9a24aca1953d9628cf1f557234a61 /src/garage/cli
parentafee8c2207e2c79975734f1c1fea41b8b942aaa4 (diff)
parentec34728b27312a25aa01765a6a311d17d2963935 (diff)
downloadgarage-238545e56486b857fab41e0703fc9bccbcd50a2c.tar.gz
garage-238545e56486b857fab41e0703fc9bccbcd50a2c.zip
Merge pull request 'Refactoring of db engines' (#765) from factor-db-open into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/765
Diffstat (limited to 'src/garage/cli')
-rw-r--r--src/garage/cli/convert_db.rs54
1 files changed, 7 insertions, 47 deletions
diff --git a/src/garage/cli/convert_db.rs b/src/garage/cli/convert_db.rs
index 6b854ccb..2aadb1d6 100644
--- a/src/garage/cli/convert_db.rs
+++ b/src/garage/cli/convert_db.rs
@@ -51,53 +51,13 @@ pub(crate) fn do_conversion(args: ConvertDbOpt) -> Result<()> {
return Err(Error("input and output database engine must differ".into()));
}
- let input = open_db(args.input_path, args.input_engine, &args.db_open)?;
- let output = open_db(args.output_path, args.output_engine, &args.db_open)?;
+ let opt = OpenOpt {
+ lmdb_map_size: args.db_open.lmdb.map_size.map(|x| x.as_u64() as usize),
+ ..Default::default()
+ };
+
+ let input = open_db(&args.input_path, args.input_engine, &opt)?;
+ let output = open_db(&args.output_path, args.output_engine, &opt)?;
output.import(&input)?;
Ok(())
}
-
-fn open_db(path: PathBuf, engine: Engine, open: &OpenDbOpt) -> Result<Db> {
- match engine {
- #[cfg(feature = "sled")]
- Engine::Sled => {
- let db = sled_adapter::sled::Config::default().path(&path).open()?;
- Ok(sled_adapter::SledDb::init(db))
- }
- #[cfg(feature = "sqlite")]
- Engine::Sqlite => {
- let db = sqlite_adapter::rusqlite::Connection::open(&path)?;
- db.pragma_update(None, "journal_mode", "WAL")?;
- db.pragma_update(None, "synchronous", "NORMAL")?;
- Ok(sqlite_adapter::SqliteDb::init(db))
- }
- #[cfg(feature = "lmdb")]
- Engine::Lmdb => {
- std::fs::create_dir_all(&path).map_err(|e| {
- Error(format!("Unable to create LMDB data directory: {}", e).into())
- })?;
-
- let map_size = match open.lmdb.map_size {
- Some(c) => c.as_u64() as usize,
- None => lmdb_adapter::recommended_map_size(),
- };
-
- let mut env_builder = lmdb_adapter::heed::EnvOpenOptions::new();
- env_builder.max_dbs(100);
- env_builder.map_size(map_size);
- unsafe {
- env_builder.flag(lmdb_adapter::heed::flags::Flags::MdbNoMetaSync);
- }
- let db = env_builder.open(&path)?;
- Ok(lmdb_adapter::LmdbDb::init(db))
- }
-
- // Pattern is unreachable when all supported DB engines are compiled into binary. The allow
- // attribute is added so that we won't have to change this match in case stop building
- // support for one or more engines by default.
- #[allow(unreachable_patterns)]
- engine => Err(Error(
- format!("Engine support not available in this build: {}", engine).into(),
- )),
- }
-}