From cc4a9f40ee350f4ce25f11421617e827646e17cb Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Sun, 16 Apr 2017 21:36:09 +0200 Subject: [PATCH] Enforcing bundle ordering in index rebuild (re #13) --- CHANGELOG.md | 1 + src/cli/mod.rs | 4 +++- src/repository/integrity.rs | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f68f9b..3c7c9d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project follows [semantic versioning](http://semver.org). * [added] Ability to read/write tar file from/to stdin/stdout * [added] Added date to bundles * [modified] Logging to stderr +* [modified] Enforce deterministic bundle ordering * [fixed] Only print "repairing bundles" if actually repairing bundles * [fixed] Only put mode bits of st_mode into metadata diff --git a/src/cli/mod.rs b/src/cli/mod.rs index fdc8c76..a82b416 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -255,6 +255,7 @@ fn print_config(config: &Config) { fn print_analysis(analysis: &HashMap) { let mut reclaim_space = [0; 11]; + let mut rewrite_size = [0; 11]; let mut data_total = 0; for bundle in analysis.values() { data_total += bundle.info.encoded_size; @@ -262,6 +263,7 @@ fn print_analysis(analysis: &HashMap) { for i in 0..11 { if bundle.get_usage_ratio() <= i as f32 * 0.1 { reclaim_space[i] += bundle.get_unused_size(); + rewrite_size[i] += bundle.get_used_size(); } } } @@ -271,7 +273,7 @@ fn print_analysis(analysis: &HashMap) { println!("Reclaimable space (depending on vacuum ratio)"); #[allow(unknown_lints,needless_range_loop)] for i in 0..11 { - println!(" - ratio={:3}: {:>10}, {:4.1} %", i*10, to_file_size(reclaim_space[i] as u64), reclaim_space[i] as f32 / data_total as f32 * 100.0); + println!(" - ratio={:3}: {:>10}, {:4.1} %, rewriting {:>10}", i*10, to_file_size(reclaim_space[i] as u64), reclaim_space[i] as f32 / data_total as f32 * 100.0, to_file_size(rewrite_size[i] as u64)); } } diff --git a/src/repository/integrity.rs b/src/repository/integrity.rs index 079be58..984dd27 100644 --- a/src/repository/integrity.rs +++ b/src/repository/integrity.rs @@ -348,7 +348,9 @@ impl Repository { pub fn rebuild_index(&mut self) -> Result<(), RepositoryError> { info!("Rebuilding index from bundles"); self.index.clear(); - for (num, id) in self.bundle_map.bundles() { + let mut bundles = self.bundle_map.bundles(); + bundles.sort_by_key(|&(_, ref v)| v.clone()); + for (num, id) in bundles { let chunks = try!(self.bundles.get_chunk_list(&id)); for (i, (hash, _len)) in chunks.into_inner().into_iter().enumerate() { try!(self.index.set(&hash, &Location{bundle: num as u32, chunk: i as u32}));