aboutsummaryrefslogtreecommitdiff
path: root/src/util/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/config.rs')
-rw-r--r--src/util/config.rs105
1 files changed, 93 insertions, 12 deletions
diff --git a/src/util/config.rs b/src/util/config.rs
index 1da95b2f..ad5c8e1f 100644
--- a/src/util/config.rs
+++ b/src/util/config.rs
@@ -1,4 +1,5 @@
//! Contains type and functions related to Garage configuration file
+use std::convert::TryFrom;
use std::io::Read;
use std::net::SocketAddr;
use std::path::PathBuf;
@@ -6,6 +7,7 @@ use std::path::PathBuf;
use serde::{de, Deserialize};
use crate::error::Error;
+use crate::socket_address::UnixOrTCPSocketAddress;
/// Represent the whole configuration
#[derive(Deserialize, Debug, Clone)]
@@ -13,10 +15,20 @@ pub struct Config {
/// Path where to store metadata. Should be fast, but low volume
pub metadata_dir: PathBuf,
/// Path where to store data. Can be slower, but need higher volume
- pub data_dir: PathBuf,
+ pub data_dir: DataDirEnum,
+
+ /// Whether to fsync after all metadata transactions (disabled by default)
+ #[serde(default)]
+ pub metadata_fsync: bool,
+ /// Whether to fsync after all data block writes (disabled by default)
+ #[serde(default)]
+ pub data_fsync: bool,
/// Size of data blocks to save to disk
- #[serde(default = "default_block_size")]
+ #[serde(
+ deserialize_with = "deserialize_capacity",
+ default = "default_block_size"
+ )]
pub block_size: usize,
/// Replication mode. Supported values:
@@ -66,12 +78,19 @@ pub struct Config {
pub db_engine: String,
/// Sled cache size, in bytes
- #[serde(default = "default_sled_cache_capacity")]
- pub sled_cache_capacity: u64,
+ #[serde(
+ deserialize_with = "deserialize_capacity",
+ default = "default_sled_cache_capacity"
+ )]
+ pub sled_cache_capacity: usize,
/// Sled flush interval in milliseconds
#[serde(default = "default_sled_flush_every_ms")]
pub sled_flush_every_ms: u64,
+ /// LMDB map size
+ #[serde(deserialize_with = "deserialize_capacity", default)]
+ pub lmdb_map_size: usize,
+
// -- APIs
/// Configuration for S3 api
pub s3_api: S3ApiConfig,
@@ -87,11 +106,31 @@ pub struct Config {
pub admin: AdminConfig,
}
+/// Value for data_dir: either a single directory or a list of dirs with attributes
+#[derive(Deserialize, Debug, Clone)]
+#[serde(untagged)]
+pub enum DataDirEnum {
+ Single(PathBuf),
+ Multiple(Vec<DataDir>),
+}
+
+#[derive(Deserialize, Debug, Clone)]
+pub struct DataDir {
+ /// Path to the data directory
+ pub path: PathBuf,
+ /// Capacity of the drive (required if read_only is false)
+ #[serde(default)]
+ pub capacity: Option<String>,
+ /// Whether this is a legacy read-only path (capacity should be None)
+ #[serde(default)]
+ pub read_only: bool,
+}
+
/// Configuration for S3 api
#[derive(Deserialize, Debug, Clone)]
pub struct S3ApiConfig {
/// Address and port to bind for api serving
- pub api_bind_addr: Option<SocketAddr>,
+ pub api_bind_addr: Option<UnixOrTCPSocketAddress>,
/// S3 region to use
pub s3_region: String,
/// Suffix to remove from domain name to find bucket. If None,
@@ -103,14 +142,14 @@ pub struct S3ApiConfig {
#[derive(Deserialize, Debug, Clone)]
pub struct K2VApiConfig {
/// Address and port to bind for api serving
- pub api_bind_addr: SocketAddr,
+ pub api_bind_addr: UnixOrTCPSocketAddress,
}
/// Configuration for serving files as normal web server
#[derive(Deserialize, Debug, Clone)]
pub struct WebConfig {
/// Address and port to bind for web serving
- pub bind_addr: SocketAddr,
+ pub bind_addr: UnixOrTCPSocketAddress,
/// Suffix to remove from domain name to find bucket
pub root_domain: String,
}
@@ -119,7 +158,7 @@ pub struct WebConfig {
#[derive(Deserialize, Debug, Clone, Default)]
pub struct AdminConfig {
/// Address and port to bind for admin API serving
- pub api_bind_addr: Option<SocketAddr>,
+ pub api_bind_addr: Option<UnixOrTCPSocketAddress>,
/// Bearer token to use to scrape metrics
pub metrics_token: Option<String>,
@@ -183,10 +222,10 @@ pub struct KubernetesDiscoveryConfig {
}
fn default_db_engine() -> String {
- "sled".into()
+ "lmdb".into()
}
-fn default_sled_cache_capacity() -> u64 {
+fn default_sled_cache_capacity() -> usize {
128 * 1024 * 1024
}
fn default_sled_flush_every_ms() -> u64 {
@@ -266,8 +305,6 @@ fn deserialize_compression<'de, D>(deserializer: D) -> Result<Option<i32>, D::Er
where
D: de::Deserializer<'de>,
{
- use std::convert::TryFrom;
-
struct OptionVisitor;
impl<'de> serde::de::Visitor<'de> for OptionVisitor {
@@ -312,6 +349,50 @@ where
deserializer.deserialize_any(OptionVisitor)
}
+fn deserialize_capacity<'de, D>(deserializer: D) -> Result<usize, D::Error>
+where
+ D: de::Deserializer<'de>,
+{
+ struct CapacityVisitor;
+
+ impl<'de> serde::de::Visitor<'de> for CapacityVisitor {
+ type Value = usize;
+ fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
+ formatter.write_str("int or '<capacity>'")
+ }
+
+ fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
+ where
+ E: de::Error,
+ {
+ value
+ .parse::<bytesize::ByteSize>()
+ .map(|x| x.as_u64())
+ .map_err(|e| E::custom(format!("invalid capacity value: {}", e)))
+ .and_then(|v| {
+ usize::try_from(v)
+ .map_err(|_| E::custom("capacity value out of bound".to_owned()))
+ })
+ }
+
+ fn visit_i64<E>(self, v: i64) -> Result<Self::Value, E>
+ where
+ E: de::Error,
+ {
+ usize::try_from(v).map_err(|_| E::custom("capacity value out of bound".to_owned()))
+ }
+
+ fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
+ where
+ E: de::Error,
+ {
+ usize::try_from(v).map_err(|_| E::custom("capacity value out of bound".to_owned()))
+ }
+ }
+
+ deserializer.deserialize_any(CapacityVisitor)
+}
+
#[cfg(test)]
mod tests {
use crate::error::Error;