mirror of
https://git.deuxfleurs.fr/Deuxfleurs/garage.git
synced 2024-11-25 09:31:00 +00:00
Make all DB engines optional build features
This commit is contained in:
parent
48ffaaadfc
commit
b886c75450
5 changed files with 50 additions and 7 deletions
|
@ -21,9 +21,9 @@ err-derive = "0.3"
|
||||||
hexdump = "0.1"
|
hexdump = "0.1"
|
||||||
tracing = "0.1.30"
|
tracing = "0.1.30"
|
||||||
|
|
||||||
heed = { version = "0.11", default-features = false, features = ["lmdb"] }
|
heed = { version = "0.11", default-features = false, features = ["lmdb"], optional = true }
|
||||||
rusqlite = "0.27"
|
rusqlite = { version = "0.27", optional = true }
|
||||||
sled = "0.34"
|
sled = { version = "0.34", optional = true }
|
||||||
|
|
||||||
# cli deps
|
# cli deps
|
||||||
clap = { version = "3.1.18", optional = true, features = ["derive", "env"] }
|
clap = { version = "3.1.18", optional = true, features = ["derive", "env"] }
|
||||||
|
@ -35,3 +35,5 @@ mktemp = "0.4"
|
||||||
[features]
|
[features]
|
||||||
bundled-libs = [ "rusqlite/bundled" ]
|
bundled-libs = [ "rusqlite/bundled" ]
|
||||||
cli = ["clap", "pretty_env_logger"]
|
cli = ["clap", "pretty_env_logger"]
|
||||||
|
lmdb = [ "heed" ]
|
||||||
|
sqlite = [ "rusqlite" ]
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
#[cfg(feature = "sqlite")]
|
||||||
extern crate tracing;
|
extern crate tracing;
|
||||||
|
|
||||||
|
#[cfg(feature = "lmdb")]
|
||||||
pub mod lmdb_adapter;
|
pub mod lmdb_adapter;
|
||||||
|
#[cfg(feature = "sled")]
|
||||||
pub mod sled_adapter;
|
pub mod sled_adapter;
|
||||||
|
#[cfg(feature = "sqlite")]
|
||||||
pub mod sqlite_adapter;
|
pub mod sqlite_adapter;
|
||||||
|
|
||||||
pub mod counted_tree_hack;
|
pub mod counted_tree_hack;
|
||||||
|
|
|
@ -74,9 +74,17 @@ base64 = "0.13"
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [ "bundled-libs", "metrics" ]
|
default = [ "bundled-libs", "metrics", "sled" ]
|
||||||
kubernetes-discovery = [ "garage_rpc/kubernetes-discovery" ]
|
|
||||||
k2v = [ "garage_util/k2v", "garage_api/k2v" ]
|
k2v = [ "garage_util/k2v", "garage_api/k2v" ]
|
||||||
|
|
||||||
|
# Database engines, Sled is still our default even though we don't like it
|
||||||
|
sled = [ "garage_model/sled" ]
|
||||||
|
lmdb = [ "garage_model/lmdb" ]
|
||||||
|
sqlite = [ "garage_model/sqlite" ]
|
||||||
|
|
||||||
|
# Automatic registration and discovery via Kubernetes API
|
||||||
|
kubernetes-discovery = [ "garage_rpc/kubernetes-discovery" ]
|
||||||
# Prometheus exporter (/metrics endpoint).
|
# Prometheus exporter (/metrics endpoint).
|
||||||
metrics = [ "garage_api/metrics", "opentelemetry-prometheus", "prometheus" ]
|
metrics = [ "garage_api/metrics", "opentelemetry-prometheus", "prometheus" ]
|
||||||
# Exporter for the OpenTelemetry Collector.
|
# Exporter for the OpenTelemetry Collector.
|
||||||
|
|
|
@ -46,3 +46,6 @@ netapp = "0.4"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
k2v = [ "garage_util/k2v" ]
|
k2v = [ "garage_util/k2v" ]
|
||||||
|
lmdb = [ "garage_db/lmdb" ]
|
||||||
|
sled = [ "garage_db/sled" ]
|
||||||
|
sqlite = [ "garage_db/sqlite" ]
|
||||||
|
|
|
@ -80,6 +80,8 @@ impl Garage {
|
||||||
let mut db_path = config.metadata_dir.clone();
|
let mut db_path = config.metadata_dir.clone();
|
||||||
std::fs::create_dir_all(&db_path).expect("Unable to create Garage meta data directory");
|
std::fs::create_dir_all(&db_path).expect("Unable to create Garage meta data directory");
|
||||||
let db = match config.db_engine.as_str() {
|
let db = match config.db_engine.as_str() {
|
||||||
|
// ---- Sled DB ----
|
||||||
|
#[cfg(feature = "sled")]
|
||||||
"sled" => {
|
"sled" => {
|
||||||
db_path.push("db");
|
db_path.push("db");
|
||||||
info!("Opening Sled database at: {}", db_path.display());
|
info!("Opening Sled database at: {}", db_path.display());
|
||||||
|
@ -91,6 +93,10 @@ impl Garage {
|
||||||
.expect("Unable to open sled DB");
|
.expect("Unable to open sled DB");
|
||||||
db::sled_adapter::SledDb::init(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" => {
|
"sqlite" | "sqlite3" | "rusqlite" => {
|
||||||
db_path.push("db.sqlite");
|
db_path.push("db.sqlite");
|
||||||
info!("Opening Sqlite database at: {}", db_path.display());
|
info!("Opening Sqlite database at: {}", db_path.display());
|
||||||
|
@ -98,6 +104,14 @@ impl Garage {
|
||||||
.expect("Unable to open sqlite DB");
|
.expect("Unable to open sqlite DB");
|
||||||
db::sqlite_adapter::SqliteDb::init(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" => {
|
"lmdb" | "heed" => {
|
||||||
db_path.push("db.lmdb");
|
db_path.push("db.lmdb");
|
||||||
info!("Opening LMDB database at: {}", db_path.display());
|
info!("Opening LMDB database at: {}", db_path.display());
|
||||||
|
@ -111,10 +125,22 @@ impl Garage {
|
||||||
.expect("Unable to open LMDB DB");
|
.expect("Unable to open LMDB DB");
|
||||||
db::lmdb_adapter::LmdbDb::init(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 => {
|
e => {
|
||||||
return Err(Error::Message(format!(
|
return Err(Error::Message(format!(
|
||||||
"Unsupported DB engine: {} (options: sled, sqlite, lmdb)",
|
"Unsupported DB engine: {} (options: {})",
|
||||||
e
|
e,
|
||||||
|
vec![
|
||||||
|
#[cfg(feature = "sled")]
|
||||||
|
"sled",
|
||||||
|
#[cfg(feature = "sqlite")]
|
||||||
|
"sqlite",
|
||||||
|
#[cfg(feature = "lmdb")]
|
||||||
|
"lmdb",
|
||||||
|
]
|
||||||
|
.join(", ")
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue