proxmox-rrd: split out load_rrd (cleanup)

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Dietmar Maurer 2021-10-13 10:24:46 +02:00 committed by Thomas Lamprecht
parent 03664514ab
commit 400f081487
1 changed files with 18 additions and 19 deletions

View File

@ -194,15 +194,8 @@ impl RRDCache {
path.push(&entry.rel_path); path.push(&entry.rel_path);
create_path(path.parent().unwrap(), Some(self.dir_options.clone()), Some(self.dir_options.clone()))?; create_path(path.parent().unwrap(), Some(self.dir_options.clone()), Some(self.dir_options.clone()))?;
let mut rrd = match RRD::load(&path) { let mut rrd = Self::load_rrd(&path, entry.dst);
Ok(rrd) => rrd,
Err(err) => {
if err.kind() != std::io::ErrorKind::NotFound {
log::warn!("overwriting RRD file {:?}, because of load error: {}", path, err);
}
Self::create_default_rrd(entry.dst)
},
};
if entry.time > get_last_update(&entry.rel_path, &rrd) { if entry.time > get_last_update(&entry.rel_path, &rrd) {
rrd.update(entry.time, entry.value); rrd.update(entry.time, entry.value);
} }
@ -235,7 +228,19 @@ impl RRDCache {
Ok(()) Ok(())
} }
/// Update data in RAM and write file back to disk (if `save` is set) fn load_rrd(path: &Path, dst: DST) -> RRD {
match RRD::load(path) {
Ok(rrd) => rrd,
Err(err) => {
if err.kind() != std::io::ErrorKind::NotFound {
log::warn!("overwriting RRD file {:?}, because of load error: {}", path, err);
}
Self::create_default_rrd(dst)
},
}
}
/// Update data in RAM and write file back to disk (journal)
pub fn update_value( pub fn update_value(
&self, &self,
rel_path: &str, rel_path: &str,
@ -261,15 +266,9 @@ impl RRDCache {
let mut path = self.basedir.clone(); let mut path = self.basedir.clone();
path.push(rel_path); path.push(rel_path);
create_path(path.parent().unwrap(), Some(self.dir_options.clone()), Some(self.dir_options.clone()))?; create_path(path.parent().unwrap(), Some(self.dir_options.clone()), Some(self.dir_options.clone()))?;
let mut rrd = match RRD::load(&path) {
Ok(rrd) => rrd, let mut rrd = Self::load_rrd(&path, dst);
Err(err) => {
if err.kind() != std::io::ErrorKind::NotFound {
log::warn!("overwriting RRD file {:?}, because of load error: {}", path, err);
}
Self::create_default_rrd(dst)
},
};
rrd.update(now, value); rrd.update(now, value);
state.rrd_map.insert(rel_path.into(), rrd); state.rrd_map.insert(rel_path.into(), rrd);
} }