Enforcing bundle ordering in index rebuild (re #13)

This commit is contained in:
Dennis Schwerdel 2017-04-16 21:36:09 +02:00
parent ca7153117b
commit cc4a9f40ee
3 changed files with 7 additions and 2 deletions

View File

@ -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

View File

@ -255,6 +255,7 @@ fn print_config(config: &Config) {
fn print_analysis(analysis: &HashMap<u32, BundleAnalysis>) {
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<u32, BundleAnalysis>) {
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<u32, BundleAnalysis>) {
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));
}
}

View File

@ -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}));