Skip to content

Commit d0f6e6d

Browse files
author
Vlad Volodkin
committed
Add versioning of the configuration format in mount_from_config example
Signed-off-by: Vlad Volodkin <[email protected]>
1 parent dcbbcc1 commit d0f6e6d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

mountpoint-s3-fs/examples/config.json.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"config_version": "0.0.1",
23
"mountpoint": "/exmpl/mountpoint",
34
"metadata_store_dir": "/exmpl/tmpdir",
45
"event_log_dir": "/exmpl/event_log_dir",

mountpoint-s3-fs/examples/mount_from_config.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use serde::Deserialize;
2424
use tempfile::tempdir_in;
2525
use tracing::info;
2626

27+
const CONFIG_VERSION: &str = "0.0.1";
28+
2729
#[derive(Debug, Deserialize)]
2830
#[serde(tag = "type")]
2931
enum ThroughputConfig {
@@ -36,6 +38,8 @@ enum ThroughputConfig {
3638
#[derive(Debug, Deserialize)]
3739
#[serde(deny_unknown_fields)]
3840
struct ConfigOptions {
41+
/// Version of the configuration format
42+
config_version: String,
3943
/// Directory to mount the bucket at
4044
mountpoint: String,
4145
/// AWS region of the bucket, e.g. "us-east-2"
@@ -165,6 +169,17 @@ impl ConfigOptions {
165169
}
166170
}
167171
}
172+
173+
fn validate_version(&self) -> Result<()> {
174+
if self.config_version != CONFIG_VERSION {
175+
Err(anyhow!(
176+
"Unsupported version of the configuration format, supported version is {}",
177+
CONFIG_VERSION
178+
))
179+
} else {
180+
Ok(())
181+
}
182+
}
168183
}
169184

170185
fn load_config<P: AsRef<Path>>(path: P) -> Result<ConfigOptions> {
@@ -248,6 +263,7 @@ fn main() -> Result<()> {
248263
let args = Args::parse();
249264
// Read the config
250265
let config = load_config(&args.config).context("Failed to load config")?;
266+
config.validate_version()?;
251267
// Set up the error logger
252268
let error_logger = FileErrorLogger::new(&config.event_log_dir, || {
253269
// trigger graceful shutdown (with umount) by sending a signal to self

0 commit comments

Comments
 (0)