Skip to content

Commit

Permalink
tracker: let the write snapshot granularity be configured
Browse files Browse the repository at this point in the history
with the VERNEUIL_WRITE_SNAPSHOT_GRANULARITY environment variable.

The value must be strictly positive, and ideally not too small;
the code currently imposes a min value of 64 bytes.

Currently an environment variable because there's no clear need for
making this configurable via json, but shouldn't be too hard to fix:
the Tracker object tracks the current value in an instance field.

TESTED=test.sh, without size override and with `export VERNEUIL_WRITE_SNAPSHOT_GRANULARITY={16384,131072}`
  • Loading branch information
pkhuong committed Jan 22, 2024
1 parent c5b2bdf commit c51f61d
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/tracker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ mod snapshot_file_contents;
/// learn about well-known chunks before writers.
pub(crate) const DEFAULT_WRITE_SNAPSHOT_GRANULARITY: u64 = 1 << 16;

/// The write snapshot granularity is configurable, but zero wouldn't work,
/// and too small would be amazingly wasteful.
const MIN_WRITE_SNAPSHOT_GRANULARITY: u64 = 64;

/// Don't generate a base fingerprint chunk for a list of fingerprints
/// shorter than `BASE_CHUNK_MIN_LENGTH`.
///
Expand All @@ -58,10 +62,57 @@ const BASE_CHUNK_MIN_LENGTH: usize = 600;
/// essentially never the same.
const BUNDLED_CHUNK_OFFSETS: [u64; 1] = [0];

const VERNEUIL_WRITE_SNAPSHOT_ENV_VAR: &str = "VERNEUIL_WRITE_SNAPSHOT_GRANULARITY";

/// We snapshot db files in content-addressed chunks of this many
/// bytes.
pub(crate) fn write_snapshot_granularity() -> u64 {
DEFAULT_WRITE_SNAPSHOT_GRANULARITY
fn compute_snapshot_granularity() -> Option<u64> {
let os_value = std::env::var_os(VERNEUIL_WRITE_SNAPSHOT_ENV_VAR)?;
let value = if let Some(value) = os_value.to_str() {
value
} else {
tracing::warn!(
?os_value,
VERNEUIL_WRITE_SNAPSHOT_ENV_VAR,
"invalid value for verneuil write snapshot granularity"
);
return None;
};

if value.is_empty() {
return None;
}
match value.parse::<u64>() {
Ok(value) if value >= MIN_WRITE_SNAPSHOT_GRANULARITY => {
tracing::info!(
?value,
VERNEUIL_WRITE_SNAPSHOT_ENV_VAR,
"Overriding verneuil write snapshot granularity"
);
Some(value)
}
Ok(value) => {
tracing::warn!(?value, MIN_WRITE_SNAPSHOT_GRANULARITY, VERNEUIL_WRITE_SNAPSHOT_ENV_VAR, "Found overly small override verneuil write snapshot granularity; using min value");
Some(MIN_WRITE_SNAPSHOT_GRANULARITY)
}
Err(e) => {
tracing::warn!(
?value,
?e,
VERNEUIL_WRITE_SNAPSHOT_ENV_VAR,
"Failed to parse verneuil write snapshot granularity"
);
None
}
}
}

lazy_static::lazy_static! {
static ref GRANULARITY : u64 = compute_snapshot_granularity().unwrap_or(DEFAULT_WRITE_SNAPSHOT_GRANULARITY);
}

*GRANULARITY
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down

0 comments on commit c51f61d

Please sign in to comment.