Skip to content

Commit

Permalink
Improve subb-fragments performances
Browse files Browse the repository at this point in the history
  • Loading branch information
delehef committed Oct 27, 2022
1 parent 73db80b commit 67673e3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ libc = "0.2"
log = "0.4"
maplit = "1.0"
memmap2 = "0.5"
multi-map = "1.3"
notify-rust = { version = "4", optional = true }
num-format = "0.4"
regex = "1"
Expand Down
17 changes: 9 additions & 8 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use fuser::*;
use libc::*;
use log::*;
use maplit::*;
use multi_map::MultiMap;
use regex::Regex;
use smartstring::SmartString;
use std::cell::RefCell;
Expand Down Expand Up @@ -447,7 +448,7 @@ pub struct FustaFS {

pending_appends: BTreeMap<String, PendingAppend>,

subfragments: Vec<SubFragment>,
subfragments: MultiMap<String, u64, SubFragment>, // name -> inode -> SubFragment

dirty: bool,
}
Expand Down Expand Up @@ -495,8 +496,8 @@ impl FustaFS {
metadata,
settings,
current_ino: FIRST_INO,
pending_appends: BTreeMap::new(),
subfragments: Vec::new(),
pending_appends: Default::default(),
subfragments: Default::default(),
dirty: false,
};

Expand Down Expand Up @@ -725,7 +726,7 @@ impl FustaFS {
}

fn subfragment_from_ino(&self, ino: u64) -> Option<&SubFragment> {
self.subfragments.iter().find(|sf| sf.attrs.ino == ino)
self.subfragments.get_alt(&ino)
}

fn make_info_buffer(&mut self) {
Expand Down Expand Up @@ -901,17 +902,17 @@ impl FustaFS {
let end = str::parse::<isize>(&caps[3])
.map_err(|_| format!("{}: `{}` is not an integer", &error_message, &caps[2]))?;
let (start, end) = clear_coordinates(start, end);
let key = format!("{}:{}-{}", fragment_id, start, end);

self.subfragments
.iter()
.find(|sf| sf.fragment == fragment_id && sf.start == start && sf.end == end)
.get(&key)
.map(|sf| sf.attrs)
.or_else(|| {
let size = (end - start) as u64;
let mut attrs = FustaFS::make_file_attrs(ino, 0o444);
attrs.size = size;
let sf = SubFragment::new(&fragment_id, start, end, attrs);
self.subfragments.push(sf);
self.subfragments.insert(key, ino, sf);
Some(attrs)
})
.ok_or_else(|| unimplemented!())
Expand All @@ -928,7 +929,7 @@ impl FustaFS {
let mut attrs = FustaFS::make_file_attrs(ino, 0o444);
attrs.size = fragment_len as u64;
let sf = SubFragment::new(&fragment_id, 0, fragment_len.try_into().unwrap(), attrs);
self.subfragments.push(sf);
self.subfragments.insert(name.to_owned(), ino, sf);
Ok(attrs)
}
}
Expand Down

0 comments on commit 67673e3

Please sign in to comment.