From 824944e30e0c0599a69e467fbadaac8bef249757 Mon Sep 17 00:00:00 2001 From: Sayan Nandan Date: Mon, 9 Nov 2020 11:16:22 +0530 Subject: [PATCH] Don't use an explicit `enabled` flag in `snapshot` There is no merit in having a redundant `enabled` key under `snapshot` in the configuration file; if a `snapshot` key is present, it is inherently obvious that snapshotting is enabled Signed-off-by: Sayan Nandan --- Cargo.lock | 38 ++++++++++------------------- cli/Cargo.toml | 4 +-- examples/config-files/snapshot.toml | 1 - examples/config-files/template.toml | 5 ++++ libtdb/Cargo.toml | 2 +- server/Cargo.toml | 6 ++--- server/src/config/mod.rs | 20 ++++++++------- 7 files changed, 35 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6336419b..55c4b264 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,12 +63,6 @@ version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" -[[package]] -name = "bytes" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" - [[package]] name = "bytes" version = "0.6.0" @@ -144,12 +138,6 @@ dependencies = [ "termcolor", ] -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - [[package]] name = "fs_extra" version = "1.2.0" @@ -231,7 +219,7 @@ checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701" name = "libtdb" version = "0.4.5" dependencies = [ - "bytes 0.5.6", + "bytes", "lazy_static", "termcolor", ] @@ -262,9 +250,9 @@ checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" [[package]] name = "mio" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8f1c83949125de4a582aa2da15ae6324d91cf6a58a70ea407643941ff98f558" +checksum = "8962c171f57fcfffa53f4df1bb15ec4c8cf26a7569459c9ceb62d94aab0d9584" dependencies = [ "libc", "log", @@ -426,9 +414,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "regex" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8963b85b8ce3074fecffde43b4b0dded83ce2f367dc8d363afc56679f3ee820b" +checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c" dependencies = [ "aho-corasick", "memchr", @@ -438,9 +426,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.20" +version = "0.6.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cab7a364d15cde1e505267766a2d3c4e22a843e1a601f0fa7564c0f82ced11c" +checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" [[package]] name = "scopeguard" @@ -524,7 +512,7 @@ name = "tdb" version = "0.4.5" dependencies = [ "bincode", - "bytes 0.6.0", + "bytes", "chrono", "clap", "env_logger", @@ -601,12 +589,12 @@ dependencies = [ [[package]] name = "tokio" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71f1b20504fd0aa9dab3ae17e8c4dd9431e5e08fd6921689f9745a4004883a17" +checksum = "e5ca08accbcb46f11fd8d2d1c6158c348b7888009a1f39260bcad66f6a454250" dependencies = [ - "bytes 0.6.0", - "fnv", + "autocfg", + "bytes", "futures-core", "lazy_static", "libc", @@ -645,7 +633,7 @@ dependencies = [ name = "tsh" version = "0.4.5" dependencies = [ - "bytes 0.6.0", + "bytes", "clap", "lazy_static", "libtdb", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 734553b1..32ac558a 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -8,8 +8,8 @@ edition = "2018" [dependencies] libtdb = {path = "../libtdb"} -tokio = {version = "0.3.2", features = ["full"]} +tokio = {version = "0.3.3", features = ["full"]} bytes = "0.6.0" -regex = "1.4.1" +regex = "1.4.2" lazy_static = "1.4.0" clap = {version = "2.33.3", features=["yaml"]} \ No newline at end of file diff --git a/examples/config-files/snapshot.toml b/examples/config-files/snapshot.toml index 8e51addc..4554e324 100644 --- a/examples/config-files/snapshot.toml +++ b/examples/config-files/snapshot.toml @@ -11,7 +11,6 @@ enabled = true every = 120 [snapshot] -enabled = true # set to false to disable snapshots # Create a snapshot every hour (1 hour = 60 minutes = 60 * 60 seconds = 3600 seconds) every = 3600 # How many of the snapshots to keep diff --git a/examples/config-files/template.toml b/examples/config-files/template.toml index a5bcbc07..697aa9db 100644 --- a/examples/config-files/template.toml +++ b/examples/config-files/template.toml @@ -18,3 +18,8 @@ noart = false # after every 2 minutes enabled = true every = 120 + +# This key is *OPTIONAL* +[snapshot] +every = 3600 # Make a snapshot after every 1 hour (60min * 60sec= 3600secs) +atmost = 4 # Keep the 4 most recent snapshots diff --git a/libtdb/Cargo.toml b/libtdb/Cargo.toml index 87ad1e30..f2c72739 100644 --- a/libtdb/Cargo.toml +++ b/libtdb/Cargo.toml @@ -8,5 +8,5 @@ edition = "2018" [dependencies] lazy_static = "1.4.0" -bytes = "0.5.6" +bytes = "0.6.0" termcolor = "1.1.0" \ No newline at end of file diff --git a/server/Cargo.toml b/server/Cargo.toml index 6be4ae3e..4a16f52b 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -tokio = { version = "0.3.2", features = ["full"] } +tokio = { version = "0.3.3", features = ["full"] } bytes = "0.6.0" libtdb = {path ="../libtdb"} bincode = "1.3.1" @@ -20,11 +20,11 @@ clap = {version = "2.33.3", features=["yaml"]} env_logger = "0.8.1" log = "0.4.11" chrono = "0.4.19" -regex = "1.4.1" +regex = "1.4.2" tdb_macros = {path="../tdb-macros"} [target.'cfg(not(target_env = "msvc"))'.dependencies] jemallocator = "0.3.2" [dev-dependencies] -tokio = { version = "0.3.2", features = ["test-util"] } +tokio = { version = "0.3.3", features = ["test-util"] } diff --git a/server/src/config/mod.rs b/server/src/config/mod.rs index 812b261a..aa1a5809 100644 --- a/server/src/config/mod.rs +++ b/server/src/config/mod.rs @@ -116,8 +116,6 @@ pub struct ConfigKeyServer { /// The snapshot section in the TOML file #[derive(Deserialize, Debug, PartialEq)] pub struct ConfigKeySnapshot { - /// Whether snapshotting is enabled or not - enabled: bool, /// After how many seconds should the snapshot be created every: u64, /// The maximum number of snapshots to keep @@ -229,12 +227,7 @@ impl ParsedConfig { BGSave::default() }, snapshot: if let Some(snapshot) = cfg.snapshot { - if snapshot.enabled { - SnapshotConfig::Enabled(SnapshotPref::new(snapshot.every, snapshot.atmost)) - } else { - // TODO: Show a warning that there are unused keys - SnapshotConfig::Disabled - } + SnapshotConfig::Enabled(SnapshotPref::new(snapshot.every, snapshot.atmost)) } else { SnapshotConfig::default() }, @@ -596,7 +589,16 @@ fn test_config_file_ipv6() { fn test_config_file_template() { let file = get_toml_from_examples_dir("template.toml".to_owned()).unwrap(); let cfg = ParsedConfig::new_from_toml_str(file).unwrap(); - assert_eq!(cfg, ParsedConfig::default()); + assert_eq!( + cfg, + ParsedConfig::new( + IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), + 2003, + false, + BGSave::default(), + SnapshotConfig::Enabled(SnapshotPref::new(3600, 4)) + ) + ); } #[test]