aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-09-06 17:09:43 +0200
committerAlex Auvolat <alex@adnab.me>2022-09-06 17:09:43 +0200
commitb886c75450e3ee6a7c2b0a8265d7ada20a4d9d75 (patch)
treeac5470d56a73e14698bb1b3d24ee173e720d55c1 /src/model
parent48ffaaadfc790142ed9556f5227913fa8c32d2ed (diff)
downloadgarage-b886c75450e3ee6a7c2b0a8265d7ada20a4d9d75.tar.gz
garage-b886c75450e3ee6a7c2b0a8265d7ada20a4d9d75.zip
Make all DB engines optional build features
Diffstat (limited to 'src/model')
-rw-r--r--src/model/Cargo.toml3
-rw-r--r--src/model/garage.rs30
2 files changed, 31 insertions, 2 deletions
diff --git a/src/model/Cargo.toml b/src/model/Cargo.toml
index 7b831538..cb0017b2 100644
--- a/src/model/Cargo.toml
+++ b/src/model/Cargo.toml
@@ -46,3 +46,6 @@ netapp = "0.4"
[features]
k2v = [ "garage_util/k2v" ]
+lmdb = [ "garage_db/lmdb" ]
+sled = [ "garage_db/sled" ]
+sqlite = [ "garage_db/sqlite" ]
diff --git a/src/model/garage.rs b/src/model/garage.rs
index 15769a17..19eecb1e 100644
--- a/src/model/garage.rs
+++ b/src/model/garage.rs
@@ -80,6 +80,8 @@ impl Garage {
let mut db_path = config.metadata_dir.clone();
std::fs::create_dir_all(&db_path).expect("Unable to create Garage meta data directory");
let db = match config.db_engine.as_str() {
+ // ---- Sled DB ----
+ #[cfg(feature = "sled")]
"sled" => {
db_path.push("db");
info!("Opening Sled database at: {}", db_path.display());
@@ -91,6 +93,10 @@ impl Garage {
.expect("Unable to open sled DB");
db::sled_adapter::SledDb::init(db)
}
+ #[cfg(not(feature = "sled"))]
+ "sled" => return Err(Error::Message("sled db not available in this build".into())),
+ // ---- Sqlite DB ----
+ #[cfg(feature = "sqlite")]
"sqlite" | "sqlite3" | "rusqlite" => {
db_path.push("db.sqlite");
info!("Opening Sqlite database at: {}", db_path.display());
@@ -98,6 +104,14 @@ impl Garage {
.expect("Unable to open sqlite DB");
db::sqlite_adapter::SqliteDb::init(db)
}
+ #[cfg(not(feature = "sqlite"))]
+ "sqlite" | "sqlite3" | "rusqlite" => {
+ return Err(Error::Message(
+ "sqlite db not available in this build".into(),
+ ))
+ }
+ // ---- LMDB DB ----
+ #[cfg(feature = "lmdb")]
"lmdb" | "heed" => {
db_path.push("db.lmdb");
info!("Opening LMDB database at: {}", db_path.display());
@@ -111,10 +125,22 @@ impl Garage {
.expect("Unable to open LMDB DB");
db::lmdb_adapter::LmdbDb::init(db)
}
+ #[cfg(not(feature = "lmdb"))]
+ "lmdb" | "heed" => return Err(Error::Message("lmdb db not available in this build".into())),
+ // ---- Unavailable DB engine ----
e => {
return Err(Error::Message(format!(
- "Unsupported DB engine: {} (options: sled, sqlite, lmdb)",
- e
+ "Unsupported DB engine: {} (options: {})",
+ e,
+ vec![
+ #[cfg(feature = "sled")]
+ "sled",
+ #[cfg(feature = "sqlite")]
+ "sqlite",
+ #[cfg(feature = "lmdb")]
+ "lmdb",
+ ]
+ .join(", ")
)));
}
};