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 <nandansayan@outlook.com>
next
Sayan Nandan 4 years ago
parent d23c4ee947
commit 824944e30e
No known key found for this signature in database
GPG Key ID: C31EFD7DDA12AEE0

38
Cargo.lock generated

@ -63,12 +63,6 @@ version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
name = "bytes"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "0.6.0" version = "0.6.0"
@ -144,12 +138,6 @@ dependencies = [
"termcolor", "termcolor",
] ]
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]] [[package]]
name = "fs_extra" name = "fs_extra"
version = "1.2.0" version = "1.2.0"
@ -231,7 +219,7 @@ checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701"
name = "libtdb" name = "libtdb"
version = "0.4.5" version = "0.4.5"
dependencies = [ dependencies = [
"bytes 0.5.6", "bytes",
"lazy_static", "lazy_static",
"termcolor", "termcolor",
] ]
@ -262,9 +250,9 @@ checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
[[package]] [[package]]
name = "mio" name = "mio"
version = "0.7.4" version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8f1c83949125de4a582aa2da15ae6324d91cf6a58a70ea407643941ff98f558" checksum = "8962c171f57fcfffa53f4df1bb15ec4c8cf26a7569459c9ceb62d94aab0d9584"
dependencies = [ dependencies = [
"libc", "libc",
"log", "log",
@ -426,9 +414,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.4.1" version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8963b85b8ce3074fecffde43b4b0dded83ce2f367dc8d363afc56679f3ee820b" checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@ -438,9 +426,9 @@ dependencies = [
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.6.20" version = "0.6.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cab7a364d15cde1e505267766a2d3c4e22a843e1a601f0fa7564c0f82ced11c" checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189"
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
@ -524,7 +512,7 @@ name = "tdb"
version = "0.4.5" version = "0.4.5"
dependencies = [ dependencies = [
"bincode", "bincode",
"bytes 0.6.0", "bytes",
"chrono", "chrono",
"clap", "clap",
"env_logger", "env_logger",
@ -601,12 +589,12 @@ dependencies = [
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "0.3.2" version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71f1b20504fd0aa9dab3ae17e8c4dd9431e5e08fd6921689f9745a4004883a17" checksum = "e5ca08accbcb46f11fd8d2d1c6158c348b7888009a1f39260bcad66f6a454250"
dependencies = [ dependencies = [
"bytes 0.6.0", "autocfg",
"fnv", "bytes",
"futures-core", "futures-core",
"lazy_static", "lazy_static",
"libc", "libc",
@ -645,7 +633,7 @@ dependencies = [
name = "tsh" name = "tsh"
version = "0.4.5" version = "0.4.5"
dependencies = [ dependencies = [
"bytes 0.6.0", "bytes",
"clap", "clap",
"lazy_static", "lazy_static",
"libtdb", "libtdb",

@ -8,8 +8,8 @@ edition = "2018"
[dependencies] [dependencies]
libtdb = {path = "../libtdb"} libtdb = {path = "../libtdb"}
tokio = {version = "0.3.2", features = ["full"]} tokio = {version = "0.3.3", features = ["full"]}
bytes = "0.6.0" bytes = "0.6.0"
regex = "1.4.1" regex = "1.4.2"
lazy_static = "1.4.0" lazy_static = "1.4.0"
clap = {version = "2.33.3", features=["yaml"]} clap = {version = "2.33.3", features=["yaml"]}

@ -11,7 +11,6 @@ enabled = true
every = 120 every = 120
[snapshot] [snapshot]
enabled = true # set to false to disable snapshots
# Create a snapshot every hour (1 hour = 60 minutes = 60 * 60 seconds = 3600 seconds) # Create a snapshot every hour (1 hour = 60 minutes = 60 * 60 seconds = 3600 seconds)
every = 3600 every = 3600
# How many of the snapshots to keep # How many of the snapshots to keep

@ -18,3 +18,8 @@ noart = false
# after every 2 minutes # after every 2 minutes
enabled = true enabled = true
every = 120 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

@ -8,5 +8,5 @@ edition = "2018"
[dependencies] [dependencies]
lazy_static = "1.4.0" lazy_static = "1.4.0"
bytes = "0.5.6" bytes = "0.6.0"
termcolor = "1.1.0" termcolor = "1.1.0"

@ -7,7 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
tokio = { version = "0.3.2", features = ["full"] } tokio = { version = "0.3.3", features = ["full"] }
bytes = "0.6.0" bytes = "0.6.0"
libtdb = {path ="../libtdb"} libtdb = {path ="../libtdb"}
bincode = "1.3.1" bincode = "1.3.1"
@ -20,11 +20,11 @@ clap = {version = "2.33.3", features=["yaml"]}
env_logger = "0.8.1" env_logger = "0.8.1"
log = "0.4.11" log = "0.4.11"
chrono = "0.4.19" chrono = "0.4.19"
regex = "1.4.1" regex = "1.4.2"
tdb_macros = {path="../tdb-macros"} tdb_macros = {path="../tdb-macros"}
[target.'cfg(not(target_env = "msvc"))'.dependencies] [target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator = "0.3.2" jemallocator = "0.3.2"
[dev-dependencies] [dev-dependencies]
tokio = { version = "0.3.2", features = ["test-util"] } tokio = { version = "0.3.3", features = ["test-util"] }

@ -116,8 +116,6 @@ pub struct ConfigKeyServer {
/// The snapshot section in the TOML file /// The snapshot section in the TOML file
#[derive(Deserialize, Debug, PartialEq)] #[derive(Deserialize, Debug, PartialEq)]
pub struct ConfigKeySnapshot { pub struct ConfigKeySnapshot {
/// Whether snapshotting is enabled or not
enabled: bool,
/// After how many seconds should the snapshot be created /// After how many seconds should the snapshot be created
every: u64, every: u64,
/// The maximum number of snapshots to keep /// The maximum number of snapshots to keep
@ -229,12 +227,7 @@ impl ParsedConfig {
BGSave::default() BGSave::default()
}, },
snapshot: if let Some(snapshot) = cfg.snapshot { snapshot: if let Some(snapshot) = cfg.snapshot {
if snapshot.enabled {
SnapshotConfig::Enabled(SnapshotPref::new(snapshot.every, snapshot.atmost)) SnapshotConfig::Enabled(SnapshotPref::new(snapshot.every, snapshot.atmost))
} else {
// TODO: Show a warning that there are unused keys
SnapshotConfig::Disabled
}
} else { } else {
SnapshotConfig::default() SnapshotConfig::default()
}, },
@ -596,7 +589,16 @@ fn test_config_file_ipv6() {
fn test_config_file_template() { fn test_config_file_template() {
let file = get_toml_from_examples_dir("template.toml".to_owned()).unwrap(); let file = get_toml_from_examples_dir("template.toml".to_owned()).unwrap();
let cfg = ParsedConfig::new_from_toml_str(file).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] #[test]

Loading…
Cancel
Save