backup/chunk_store.rs: only use one directory level

This commit is contained in:
Dietmar Maurer 2019-01-04 10:35:22 +01:00
parent 030cc2a903
commit bc616633d5
2 changed files with 24 additions and 47 deletions

View File

@ -59,8 +59,6 @@ fn digest_to_prefix(digest: &[u8]) -> PathBuf {
buf.push(HEX_CHARS[(digest[0] as usize) >> 4]); buf.push(HEX_CHARS[(digest[0] as usize) >> 4]);
buf.push(HEX_CHARS[(digest[0] as usize) &0xf]); buf.push(HEX_CHARS[(digest[0] as usize) &0xf]);
buf.push('/' as u8);
buf.push(HEX_CHARS[(digest[1] as usize) >> 4]); buf.push(HEX_CHARS[(digest[1] as usize) >> 4]);
buf.push(HEX_CHARS[(digest[1] as usize) & 0xf]); buf.push(HEX_CHARS[(digest[1] as usize) & 0xf]);
buf.push('/' as u8); buf.push('/' as u8);
@ -94,28 +92,21 @@ impl ChunkStore {
bail!("unable to create chunk store '{}' subdir {:?} - {}", name, chunk_dir, err); bail!("unable to create chunk store '{}' subdir {:?} - {}", name, chunk_dir, err);
} }
// create 256*256 subdirs // create 64*1024 subdirs
let mut last_percentage = 0; let mut last_percentage = 0;
for i in 0..256 { for i in 0..64*1024 {
let mut l1path = chunk_dir.clone(); let mut l1path = chunk_dir.clone();
l1path.push(format!("{:02x}",i)); l1path.push(format!("{:04x}", i));
if let Err(err) = std::fs::create_dir(&l1path) { if let Err(err) = std::fs::create_dir(&l1path) {
bail!("unable to create chunk store '{}' subdir {:?} - {}", name, l1path, err); bail!("unable to create chunk store '{}' subdir {:?} - {}", name, l1path, err);
} }
for j in 0..256 { let percentage = (i*100)/(64*1024);
let mut l2path = l1path.clone();
l2path.push(format!("{:02x}",j));
if let Err(err) = std::fs::create_dir(&l2path) {
bail!("unable to create chunk store '{}' subdir {:?} - {}", name, l2path, err);
}
let percentage = ((i*256+j)*100)/(256*256);
if percentage != last_percentage { if percentage != last_percentage {
eprintln!("Percentage done: {}", percentage); eprintln!("Percentage done: {}", percentage);
last_percentage = percentage; last_percentage = percentage;
} }
} }
}
Self::open(name, base) Self::open(name, base)
} }
@ -229,36 +220,23 @@ impl ChunkStore {
let mut last_percentage = 0; let mut last_percentage = 0;
for i in 0..256 { for i in 0..64*1024 {
let l1name = PathBuf::from(format!("{:02x}", i));
let l1_handle = match nix::dir::Dir::openat(
base_fd, &l1name, OFlag::O_RDONLY, Mode::empty()) {
Ok(h) => h,
Err(err) => bail!("unable to open store '{}' dir {:?}/{:?} - {}",
self.name, self.chunk_dir, l1name, err),
};
let l1_fd = l1_handle.as_raw_fd(); let percentage = (i*100)/(64*1024);
for j in 0..256 {
let l2name = PathBuf::from(format!("{:02x}", j));
let percentage = ((i*256+j)*100)/(256*256);
if percentage != last_percentage { if percentage != last_percentage {
eprintln!("Percentage done: {}", percentage); eprintln!("Percentage done: {}", percentage);
last_percentage = percentage; last_percentage = percentage;
} }
//println!("SCAN {:?} {:?}", l1name, l2name);
let mut l2_handle = match Dir::openat( let l1name = PathBuf::from(format!("{:04x}", i));
l1_fd, &l2name, OFlag::O_RDONLY, Mode::empty()) { match nix::dir::Dir::openat(base_fd, &l1name, OFlag::O_RDONLY, Mode::empty()) {
Ok(h) => h, Ok(mut h) => {
Err(err) => bail!( //println!("SCAN {:?} {:?}", l1name);
"unable to open store '{}' dir {:?}/{:?}/{:?} - {}", self.sweep_old_files(&mut h, status)?;
self.name, self.chunk_dir, l1name, l2name, err),
};
self.sweep_old_files(&mut l2_handle, status)?;
} }
Err(err) => bail!("unable to open store '{}' dir {:?}/{:?} - {}",
self.name, self.chunk_dir, l1name, err),
};
} }
Ok(()) Ok(())
} }

View File

@ -123,14 +123,13 @@ impl DataStore {
for path in image_list { for path in image_list {
if let Some(ext) = path.extension() { if let Some(ext) = path.extension() {
if ext == "iidx" { if ext == "iidx" {
let index = self.open_image_reader(path)?; let index = self.open_image_reader(&path)?;
index.mark_used_chunks(status)?; index.mark_used_chunks(status)?;
} else if ext == "aidx" { } else if ext == "aidx" {
let index = self.open_archive_reader(path)?; let index = self.open_archive_reader(&path)?;
index.mark_used_chunks(status)?; index.mark_used_chunks(status)?;
} }
} }
} }
Ok(()) Ok(())