Skip to content

Commit 83e8ded

Browse files
authored
lib: New argument -N to suppress verification (#26)
Signed-off-by: Jan Alexander Steffens (heftig) <[email protected]>
1 parent 38d800a commit 83e8ded

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

compressor_integration_tests/tests/compressor_config_tests.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ fn run_succeeds_without_crashing() {
4646
let transactions = true;
4747
let graphs = false;
4848
let commit_changes = false;
49+
let verify = true;
4950

5051
let config = Config::new(
5152
db_url.clone(),
@@ -59,6 +60,7 @@ fn run_succeeds_without_crashing() {
5960
transactions,
6061
graphs,
6162
commit_changes,
63+
verify,
6264
)
6365
.unwrap();
6466

@@ -94,6 +96,7 @@ fn changes_commited_if_no_min_saved_rows() {
9496
let transactions = true;
9597
let graphs = false;
9698
let commit_changes = true;
99+
let verify = true;
97100

98101
let config = Config::new(
99102
db_url,
@@ -107,6 +110,7 @@ fn changes_commited_if_no_min_saved_rows() {
107110
transactions,
108111
graphs,
109112
commit_changes,
113+
verify,
110114
)
111115
.unwrap();
112116

@@ -160,6 +164,7 @@ fn changes_commited_if_min_saved_rows_exceeded() {
160164
let transactions = true;
161165
let graphs = false;
162166
let commit_changes = true;
167+
let verify = true;
163168

164169
let config = Config::new(
165170
db_url,
@@ -173,6 +178,7 @@ fn changes_commited_if_min_saved_rows_exceeded() {
173178
transactions,
174179
graphs,
175180
commit_changes,
181+
verify,
176182
)
177183
.unwrap();
178184

@@ -227,6 +233,7 @@ fn changes_not_commited_if_fewer_than_min_saved_rows() {
227233
let transactions = true;
228234
let graphs = false;
229235
let commit_changes = true;
236+
let verify = true;
230237

231238
let config = Config::new(
232239
db_url,
@@ -240,6 +247,7 @@ fn changes_not_commited_if_fewer_than_min_saved_rows() {
240247
transactions,
241248
graphs,
242249
commit_changes,
250+
verify,
243251
)
244252
.unwrap();
245253

@@ -280,6 +288,7 @@ fn run_panics_if_invalid_db_url() {
280288
let transactions = true;
281289
let graphs = false;
282290
let commit_changes = true;
291+
let verify = true;
283292

284293
let config = Config::new(
285294
db_url,
@@ -293,6 +302,7 @@ fn run_panics_if_invalid_db_url() {
293302
transactions,
294303
graphs,
295304
commit_changes,
305+
verify,
296306
)
297307
.unwrap();
298308

@@ -336,6 +346,7 @@ fn run_only_affects_given_room_id() {
336346
let transactions = true;
337347
let graphs = false;
338348
let commit_changes = true;
349+
let verify = true;
339350

340351
let config = Config::new(
341352
db_url,
@@ -349,6 +360,7 @@ fn run_only_affects_given_room_id() {
349360
transactions,
350361
graphs,
351362
commit_changes,
363+
verify,
352364
)
353365
.unwrap();
354366

@@ -406,6 +418,7 @@ fn run_respects_groups_to_compress() {
406418
let transactions = true;
407419
let graphs = false;
408420
let commit_changes = true;
421+
let verify = true;
409422

410423
let config = Config::new(
411424
db_url,
@@ -419,6 +432,7 @@ fn run_respects_groups_to_compress() {
419432
transactions,
420433
graphs,
421434
commit_changes,
435+
verify,
422436
)
423437
.unwrap();
424438

@@ -492,6 +506,7 @@ fn run_is_idempotent_when_run_on_whole_room() {
492506
let transactions = true;
493507
let graphs = false;
494508
let commit_changes = true;
509+
let verify = true;
495510

496511
let config1 = Config::new(
497512
db_url.clone(),
@@ -505,6 +520,7 @@ fn run_is_idempotent_when_run_on_whole_room() {
505520
transactions,
506521
graphs,
507522
commit_changes,
523+
verify,
508524
)
509525
.unwrap();
510526

@@ -520,6 +536,7 @@ fn run_is_idempotent_when_run_on_whole_room() {
520536
transactions,
521537
graphs,
522538
commit_changes,
539+
verify,
523540
)
524541
.unwrap();
525542

src/lib.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ pub struct Config {
109109
// Whether or not to commit changes to the database automatically
110110
// N.B. currently assumes transactions is true (to be on the safe side)
111111
commit_changes: bool,
112+
// Whether to verify the correctness of the compressed state groups by
113+
// comparing them to the original groups
114+
verify: bool,
112115
}
113116

114117
impl Config {
@@ -223,6 +226,13 @@ impl Config {
223226
.long_help(concat!("If this flag is set then the changes the compressor makes will",
224227
" be committed to the database. This should be safe to use while synapse is running",
225228
" as it assumes by default that the transactions flag is set")),
229+
).arg(
230+
Arg::with_name("no_verify")
231+
.short("N")
232+
.help("Do not double-check that the compression was performed correctly")
233+
.long_help(concat!("If this flag is set then the verification of the compressed",
234+
" state groups, which compares them to the original groups, is skipped. This",
235+
" saves time at the cost of potentially generating mismatched state.")),
226236
).get_matches();
227237

228238
let db_url = matches
@@ -262,6 +272,8 @@ impl Config {
262272

263273
let commit_changes = matches.is_present("commit_changes");
264274

275+
let verify = !matches.is_present("no_verify");
276+
265277
Config {
266278
db_url: String::from(db_url),
267279
output_file,
@@ -274,6 +286,7 @@ impl Config {
274286
transactions,
275287
graphs,
276288
commit_changes,
289+
verify,
277290
}
278291
}
279292
}
@@ -372,7 +385,9 @@ pub fn run(mut config: Config) {
372385
}
373386
}
374387

375-
check_that_maps_match(&state_group_map, new_state_group_map);
388+
if config.verify {
389+
check_that_maps_match(&state_group_map, new_state_group_map);
390+
}
376391

377392
// If we are given an output file, we output the changes as SQL. If the
378393
// `transactions` argument is set we wrap each change to a state group in a
@@ -695,6 +710,7 @@ impl Config {
695710
transactions: bool,
696711
graphs: bool,
697712
commit_changes: bool,
713+
verify: bool,
698714
) -> Result<Config, String> {
699715
let mut output: Option<File> = None;
700716
if let Some(file) = output_file {
@@ -722,6 +738,7 @@ impl Config {
722738
transactions,
723739
graphs,
724740
commit_changes,
741+
verify,
725742
})
726743
}
727744
}
@@ -746,6 +763,7 @@ impl Config {
746763
transactions = true,
747764
graphs = false,
748765
commit_changes = false,
766+
verify = true,
749767
)]
750768
fn run_compression(
751769
db_url: String,
@@ -759,6 +777,7 @@ fn run_compression(
759777
transactions: bool,
760778
graphs: bool,
761779
commit_changes: bool,
780+
verify: bool,
762781
) -> PyResult<()> {
763782
let config = Config::new(
764783
db_url,
@@ -772,6 +791,7 @@ fn run_compression(
772791
transactions,
773792
graphs,
774793
commit_changes,
794+
verify,
775795
);
776796
match config {
777797
Err(e) => Err(PyErr::new::<exceptions::PyException, _>(e)),
@@ -1224,6 +1244,7 @@ mod pyo3_tests {
12241244
let transactions = false;
12251245
let graphs = false;
12261246
let commit_changes = false;
1247+
let verify = true;
12271248

12281249
let config = Config::new(
12291250
db_url.clone(),
@@ -1237,6 +1258,7 @@ mod pyo3_tests {
12371258
transactions,
12381259
graphs,
12391260
commit_changes,
1261+
verify,
12401262
)
12411263
.unwrap();
12421264

@@ -1270,6 +1292,7 @@ mod pyo3_tests {
12701292
let transactions = true;
12711293
let graphs = true;
12721294
let commit_changes = true;
1295+
let verify = true;
12731296

12741297
let config = Config::new(
12751298
db_url.clone(),
@@ -1283,6 +1306,7 @@ mod pyo3_tests {
12831306
transactions,
12841307
graphs,
12851308
commit_changes,
1309+
verify,
12861310
)
12871311
.unwrap();
12881312

0 commit comments

Comments
 (0)