lib: New argument -N to suppress verification (#26)
Signed-off-by: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
This commit is contained in:
committed by
GitHub
parent
38d800a775
commit
83e8dedfa9
@@ -46,6 +46,7 @@ fn run_succeeds_without_crashing() {
|
|||||||
let transactions = true;
|
let transactions = true;
|
||||||
let graphs = false;
|
let graphs = false;
|
||||||
let commit_changes = false;
|
let commit_changes = false;
|
||||||
|
let verify = true;
|
||||||
|
|
||||||
let config = Config::new(
|
let config = Config::new(
|
||||||
db_url.clone(),
|
db_url.clone(),
|
||||||
@@ -59,6 +60,7 @@ fn run_succeeds_without_crashing() {
|
|||||||
transactions,
|
transactions,
|
||||||
graphs,
|
graphs,
|
||||||
commit_changes,
|
commit_changes,
|
||||||
|
verify,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -94,6 +96,7 @@ fn changes_commited_if_no_min_saved_rows() {
|
|||||||
let transactions = true;
|
let transactions = true;
|
||||||
let graphs = false;
|
let graphs = false;
|
||||||
let commit_changes = true;
|
let commit_changes = true;
|
||||||
|
let verify = true;
|
||||||
|
|
||||||
let config = Config::new(
|
let config = Config::new(
|
||||||
db_url,
|
db_url,
|
||||||
@@ -107,6 +110,7 @@ fn changes_commited_if_no_min_saved_rows() {
|
|||||||
transactions,
|
transactions,
|
||||||
graphs,
|
graphs,
|
||||||
commit_changes,
|
commit_changes,
|
||||||
|
verify,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -160,6 +164,7 @@ fn changes_commited_if_min_saved_rows_exceeded() {
|
|||||||
let transactions = true;
|
let transactions = true;
|
||||||
let graphs = false;
|
let graphs = false;
|
||||||
let commit_changes = true;
|
let commit_changes = true;
|
||||||
|
let verify = true;
|
||||||
|
|
||||||
let config = Config::new(
|
let config = Config::new(
|
||||||
db_url,
|
db_url,
|
||||||
@@ -173,6 +178,7 @@ fn changes_commited_if_min_saved_rows_exceeded() {
|
|||||||
transactions,
|
transactions,
|
||||||
graphs,
|
graphs,
|
||||||
commit_changes,
|
commit_changes,
|
||||||
|
verify,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -227,6 +233,7 @@ fn changes_not_commited_if_fewer_than_min_saved_rows() {
|
|||||||
let transactions = true;
|
let transactions = true;
|
||||||
let graphs = false;
|
let graphs = false;
|
||||||
let commit_changes = true;
|
let commit_changes = true;
|
||||||
|
let verify = true;
|
||||||
|
|
||||||
let config = Config::new(
|
let config = Config::new(
|
||||||
db_url,
|
db_url,
|
||||||
@@ -240,6 +247,7 @@ fn changes_not_commited_if_fewer_than_min_saved_rows() {
|
|||||||
transactions,
|
transactions,
|
||||||
graphs,
|
graphs,
|
||||||
commit_changes,
|
commit_changes,
|
||||||
|
verify,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -280,6 +288,7 @@ fn run_panics_if_invalid_db_url() {
|
|||||||
let transactions = true;
|
let transactions = true;
|
||||||
let graphs = false;
|
let graphs = false;
|
||||||
let commit_changes = true;
|
let commit_changes = true;
|
||||||
|
let verify = true;
|
||||||
|
|
||||||
let config = Config::new(
|
let config = Config::new(
|
||||||
db_url,
|
db_url,
|
||||||
@@ -293,6 +302,7 @@ fn run_panics_if_invalid_db_url() {
|
|||||||
transactions,
|
transactions,
|
||||||
graphs,
|
graphs,
|
||||||
commit_changes,
|
commit_changes,
|
||||||
|
verify,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -336,6 +346,7 @@ fn run_only_affects_given_room_id() {
|
|||||||
let transactions = true;
|
let transactions = true;
|
||||||
let graphs = false;
|
let graphs = false;
|
||||||
let commit_changes = true;
|
let commit_changes = true;
|
||||||
|
let verify = true;
|
||||||
|
|
||||||
let config = Config::new(
|
let config = Config::new(
|
||||||
db_url,
|
db_url,
|
||||||
@@ -349,6 +360,7 @@ fn run_only_affects_given_room_id() {
|
|||||||
transactions,
|
transactions,
|
||||||
graphs,
|
graphs,
|
||||||
commit_changes,
|
commit_changes,
|
||||||
|
verify,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -406,6 +418,7 @@ fn run_respects_groups_to_compress() {
|
|||||||
let transactions = true;
|
let transactions = true;
|
||||||
let graphs = false;
|
let graphs = false;
|
||||||
let commit_changes = true;
|
let commit_changes = true;
|
||||||
|
let verify = true;
|
||||||
|
|
||||||
let config = Config::new(
|
let config = Config::new(
|
||||||
db_url,
|
db_url,
|
||||||
@@ -419,6 +432,7 @@ fn run_respects_groups_to_compress() {
|
|||||||
transactions,
|
transactions,
|
||||||
graphs,
|
graphs,
|
||||||
commit_changes,
|
commit_changes,
|
||||||
|
verify,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -492,6 +506,7 @@ fn run_is_idempotent_when_run_on_whole_room() {
|
|||||||
let transactions = true;
|
let transactions = true;
|
||||||
let graphs = false;
|
let graphs = false;
|
||||||
let commit_changes = true;
|
let commit_changes = true;
|
||||||
|
let verify = true;
|
||||||
|
|
||||||
let config1 = Config::new(
|
let config1 = Config::new(
|
||||||
db_url.clone(),
|
db_url.clone(),
|
||||||
@@ -505,6 +520,7 @@ fn run_is_idempotent_when_run_on_whole_room() {
|
|||||||
transactions,
|
transactions,
|
||||||
graphs,
|
graphs,
|
||||||
commit_changes,
|
commit_changes,
|
||||||
|
verify,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -520,6 +536,7 @@ fn run_is_idempotent_when_run_on_whole_room() {
|
|||||||
transactions,
|
transactions,
|
||||||
graphs,
|
graphs,
|
||||||
commit_changes,
|
commit_changes,
|
||||||
|
verify,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|||||||
24
src/lib.rs
24
src/lib.rs
@@ -109,6 +109,9 @@ pub struct Config {
|
|||||||
// Whether or not to commit changes to the database automatically
|
// Whether or not to commit changes to the database automatically
|
||||||
// N.B. currently assumes transactions is true (to be on the safe side)
|
// N.B. currently assumes transactions is true (to be on the safe side)
|
||||||
commit_changes: bool,
|
commit_changes: bool,
|
||||||
|
// Whether to verify the correctness of the compressed state groups by
|
||||||
|
// comparing them to the original groups
|
||||||
|
verify: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@@ -223,6 +226,13 @@ impl Config {
|
|||||||
.long_help(concat!("If this flag is set then the changes the compressor makes will",
|
.long_help(concat!("If this flag is set then the changes the compressor makes will",
|
||||||
" be committed to the database. This should be safe to use while synapse is running",
|
" be committed to the database. This should be safe to use while synapse is running",
|
||||||
" as it assumes by default that the transactions flag is set")),
|
" as it assumes by default that the transactions flag is set")),
|
||||||
|
).arg(
|
||||||
|
Arg::with_name("no_verify")
|
||||||
|
.short("N")
|
||||||
|
.help("Do not double-check that the compression was performed correctly")
|
||||||
|
.long_help(concat!("If this flag is set then the verification of the compressed",
|
||||||
|
" state groups, which compares them to the original groups, is skipped. This",
|
||||||
|
" saves time at the cost of potentially generating mismatched state.")),
|
||||||
).get_matches();
|
).get_matches();
|
||||||
|
|
||||||
let db_url = matches
|
let db_url = matches
|
||||||
@@ -262,6 +272,8 @@ impl Config {
|
|||||||
|
|
||||||
let commit_changes = matches.is_present("commit_changes");
|
let commit_changes = matches.is_present("commit_changes");
|
||||||
|
|
||||||
|
let verify = !matches.is_present("no_verify");
|
||||||
|
|
||||||
Config {
|
Config {
|
||||||
db_url: String::from(db_url),
|
db_url: String::from(db_url),
|
||||||
output_file,
|
output_file,
|
||||||
@@ -274,6 +286,7 @@ impl Config {
|
|||||||
transactions,
|
transactions,
|
||||||
graphs,
|
graphs,
|
||||||
commit_changes,
|
commit_changes,
|
||||||
|
verify,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -372,7 +385,9 @@ pub fn run(mut config: Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.verify {
|
||||||
check_that_maps_match(&state_group_map, new_state_group_map);
|
check_that_maps_match(&state_group_map, new_state_group_map);
|
||||||
|
}
|
||||||
|
|
||||||
// If we are given an output file, we output the changes as SQL. If the
|
// If we are given an output file, we output the changes as SQL. If the
|
||||||
// `transactions` argument is set we wrap each change to a state group in a
|
// `transactions` argument is set we wrap each change to a state group in a
|
||||||
@@ -695,6 +710,7 @@ impl Config {
|
|||||||
transactions: bool,
|
transactions: bool,
|
||||||
graphs: bool,
|
graphs: bool,
|
||||||
commit_changes: bool,
|
commit_changes: bool,
|
||||||
|
verify: bool,
|
||||||
) -> Result<Config, String> {
|
) -> Result<Config, String> {
|
||||||
let mut output: Option<File> = None;
|
let mut output: Option<File> = None;
|
||||||
if let Some(file) = output_file {
|
if let Some(file) = output_file {
|
||||||
@@ -722,6 +738,7 @@ impl Config {
|
|||||||
transactions,
|
transactions,
|
||||||
graphs,
|
graphs,
|
||||||
commit_changes,
|
commit_changes,
|
||||||
|
verify,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -746,6 +763,7 @@ impl Config {
|
|||||||
transactions = true,
|
transactions = true,
|
||||||
graphs = false,
|
graphs = false,
|
||||||
commit_changes = false,
|
commit_changes = false,
|
||||||
|
verify = true,
|
||||||
)]
|
)]
|
||||||
fn run_compression(
|
fn run_compression(
|
||||||
db_url: String,
|
db_url: String,
|
||||||
@@ -759,6 +777,7 @@ fn run_compression(
|
|||||||
transactions: bool,
|
transactions: bool,
|
||||||
graphs: bool,
|
graphs: bool,
|
||||||
commit_changes: bool,
|
commit_changes: bool,
|
||||||
|
verify: bool,
|
||||||
) -> PyResult<()> {
|
) -> PyResult<()> {
|
||||||
let config = Config::new(
|
let config = Config::new(
|
||||||
db_url,
|
db_url,
|
||||||
@@ -772,6 +791,7 @@ fn run_compression(
|
|||||||
transactions,
|
transactions,
|
||||||
graphs,
|
graphs,
|
||||||
commit_changes,
|
commit_changes,
|
||||||
|
verify,
|
||||||
);
|
);
|
||||||
match config {
|
match config {
|
||||||
Err(e) => Err(PyErr::new::<exceptions::PyException, _>(e)),
|
Err(e) => Err(PyErr::new::<exceptions::PyException, _>(e)),
|
||||||
@@ -1224,6 +1244,7 @@ mod pyo3_tests {
|
|||||||
let transactions = false;
|
let transactions = false;
|
||||||
let graphs = false;
|
let graphs = false;
|
||||||
let commit_changes = false;
|
let commit_changes = false;
|
||||||
|
let verify = true;
|
||||||
|
|
||||||
let config = Config::new(
|
let config = Config::new(
|
||||||
db_url.clone(),
|
db_url.clone(),
|
||||||
@@ -1237,6 +1258,7 @@ mod pyo3_tests {
|
|||||||
transactions,
|
transactions,
|
||||||
graphs,
|
graphs,
|
||||||
commit_changes,
|
commit_changes,
|
||||||
|
verify,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -1270,6 +1292,7 @@ mod pyo3_tests {
|
|||||||
let transactions = true;
|
let transactions = true;
|
||||||
let graphs = true;
|
let graphs = true;
|
||||||
let commit_changes = true;
|
let commit_changes = true;
|
||||||
|
let verify = true;
|
||||||
|
|
||||||
let config = Config::new(
|
let config = Config::new(
|
||||||
db_url.clone(),
|
db_url.clone(),
|
||||||
@@ -1283,6 +1306,7 @@ mod pyo3_tests {
|
|||||||
transactions,
|
transactions,
|
||||||
graphs,
|
graphs,
|
||||||
commit_changes,
|
commit_changes,
|
||||||
|
verify,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user