Do not estimate meta size

This commit is contained in:
Dennis Schwerdel 2017-04-08 10:18:46 +02:00 committed by Dennis Schwerdel
parent 289a412a12
commit c1e4cb2bdf
4 changed files with 38 additions and 20 deletions

View File

@ -22,7 +22,7 @@
* Benchmarks * Benchmarks
* Full fuse method coverage * Full fuse method coverage
* Clippy * Clippy
* Do not estimate meta size * Central repository layout class
## Other ## Other
* Homepage * Homepage

View File

@ -154,15 +154,8 @@ impl Repository {
) -> Result<Inode, RepositoryError> { ) -> Result<Inode, RepositoryError> {
let path = path.as_ref(); let path = path.as_ref();
let mut inode = try!(self.create_inode(path, reference)); let mut inode = try!(self.create_inode(path, reference));
let meta_size = inode.estimate_meta_size(); let mut meta_size = 0;
inode.cum_size = inode.size + meta_size; inode.cum_size = inode.size;
if let Some(ref_inode) = reference {
if !ref_inode.is_same_meta_quick(&inode) {
backup.changed_data_size += inode.size + meta_size;
}
} else {
backup.changed_data_size += inode.size + meta_size;
}
if inode.file_type == FileType::Directory { if inode.file_type == FileType::Directory {
inode.cum_dirs = 1; inode.cum_dirs = 1;
let mut children = BTreeMap::new(); let mut children = BTreeMap::new();
@ -197,14 +190,30 @@ impl Repository {
Err(err) => return Err(err) Err(err) => return Err(err)
}; };
let chunks = try!(self.put_inode(&child_inode)); let chunks = try!(self.put_inode(&child_inode));
children.insert(name, chunks);
inode.cum_size += child_inode.cum_size; inode.cum_size += child_inode.cum_size;
for &(_, len) in chunks.iter() {
meta_size += len as u64;
}
inode.cum_dirs += child_inode.cum_dirs; inode.cum_dirs += child_inode.cum_dirs;
inode.cum_files += child_inode.cum_files; inode.cum_files += child_inode.cum_files;
children.insert(name, chunks);
} }
inode.children = Some(children); inode.children = Some(children);
} else { } else {
inode.cum_files = 1; inode.cum_files = 1;
if let Some(FileData::ChunkedIndirect(ref chunks)) = inode.data {
for &(_, len) in chunks.iter() {
meta_size += len as u64;
}
}
}
inode.cum_size += meta_size;
if let Some(ref_inode) = reference {
if !ref_inode.is_same_meta_quick(&inode) {
backup.changed_data_size += inode.size + meta_size;
}
} else {
backup.changed_data_size += inode.size + meta_size;
} }
Ok(inode) Ok(inode)
} }
@ -226,6 +235,9 @@ impl Repository {
let elapsed = Local::now().signed_duration_since(start); let elapsed = Local::now().signed_duration_since(start);
backup.date = start.timestamp(); backup.date = start.timestamp();
backup.total_data_size = root_inode.cum_size; backup.total_data_size = root_inode.cum_size;
for &(_, len) in backup.root.iter() {
backup.total_data_size += len as u64;
}
backup.file_count = root_inode.cum_files; backup.file_count = root_inode.cum_files;
backup.dir_count = root_inode.cum_dirs; backup.dir_count = root_inode.cum_dirs;
backup.duration = elapsed.num_milliseconds() as f32 / 1_000.0; backup.duration = elapsed.num_milliseconds() as f32 / 1_000.0;

View File

@ -265,11 +265,6 @@ impl Inode {
pub fn decode(data: &[u8]) -> Result<Self, InodeError> { pub fn decode(data: &[u8]) -> Result<Self, InodeError> {
Ok(try!(msgpack::decode(&data))) Ok(try!(msgpack::decode(&data)))
} }
#[inline]
pub fn estimate_meta_size(&self) -> u64 {
1000
}
} }

View File

@ -68,10 +68,15 @@ impl Repository {
let path = try!(entry.path()).to_path_buf(); let path = try!(entry.path()).to_path_buf();
match self.import_tar_entry(&mut entry) { match self.import_tar_entry(&mut entry) {
Ok(mut inode) => { Ok(mut inode) => {
inode.cum_size = inode.size + inode.estimate_meta_size(); inode.cum_size = inode.size;
if inode.file_type == FileType::Directory { if inode.file_type == FileType::Directory {
inode.cum_dirs = 1; inode.cum_dirs = 1;
} else { } else {
if let Some(FileData::ChunkedIndirect(ref chunks)) = inode.data {
for &(_, len) in chunks.iter() {
inode.cum_size += len as u64;
}
}
inode.cum_files = 1; inode.cum_files = 1;
} }
if let Some(parent_path) = path.parent() { if let Some(parent_path) = path.parent() {
@ -106,10 +111,13 @@ impl Repository {
if let Some(parent_path) = path.parent() { if let Some(parent_path) = path.parent() {
if let Some(&mut (ref mut parent_inode, ref mut children)) = inodes.get_mut(parent_path) { if let Some(&mut (ref mut parent_inode, ref mut children)) = inodes.get_mut(parent_path) {
children.remove(&inode.name); children.remove(&inode.name);
parent_inode.children.as_mut().unwrap().insert(inode.name.clone(), chunks);
parent_inode.cum_size += inode.cum_size; parent_inode.cum_size += inode.cum_size;
for &(_, len) in chunks.iter() {
parent_inode.cum_size += len as u64;
}
parent_inode.cum_files += inode.cum_files; parent_inode.cum_files += inode.cum_files;
parent_inode.cum_dirs += inode.cum_dirs; parent_inode.cum_dirs += inode.cum_dirs;
parent_inode.children.as_mut().unwrap().insert(inode.name.clone(), chunks);
continue continue
} }
} }
@ -124,17 +132,20 @@ impl Repository {
file_type: FileType::Directory, file_type: FileType::Directory,
mode: 0o755, mode: 0o755,
name: "archive".to_string(), name: "archive".to_string(),
cum_size: 1000, cum_size: 0,
cum_files: 0, cum_files: 0,
cum_dirs: 1, cum_dirs: 1,
..Default::default() ..Default::default()
}; };
let mut children = BTreeMap::new(); let mut children = BTreeMap::new();
for (inode, chunks) in roots { for (inode, chunks) in roots {
children.insert(inode.name, chunks);
root_inode.cum_size += inode.cum_size; root_inode.cum_size += inode.cum_size;
for &(_, len) in chunks.iter() {
root_inode.cum_size += len as u64;
}
root_inode.cum_files += inode.cum_files; root_inode.cum_files += inode.cum_files;
root_inode.cum_dirs += inode.cum_dirs; root_inode.cum_dirs += inode.cum_dirs;
children.insert(inode.name, chunks);
} }
root_inode.children = Some(children); root_inode.children = Some(children);
let chunks = try!(self.put_inode(&root_inode)); let chunks = try!(self.put_inode(&root_inode));