From f01c1e0ce93fde1e2a9cbdea0decd4ecd951889b Mon Sep 17 00:00:00 2001 From: Lukas Wagner Date: Tue, 6 Aug 2024 14:59:52 +0200 Subject: [PATCH] rrd: cache: add `update_value_ignore_old` This function is the same as the regular `update_value`, but it sets the `new_only` flag when updating the value in the rrd map. This avoids "time in past" messages being logged in case a data point happens to be added twice. This new function will just silently reject values that have an older timestamp than the most recent one. Signed-off-by: Lukas Wagner --- proxmox-rrd/src/cache.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/proxmox-rrd/src/cache.rs b/proxmox-rrd/src/cache.rs index 13571929..75a422c0 100644 --- a/proxmox-rrd/src/cache.rs +++ b/proxmox-rrd/src/cache.rs @@ -190,6 +190,32 @@ impl Cache { time: f64, value: f64, dst: DataSourceType, + ) -> Result<(), Error> { + self.update_value_impl(rel_path, time, value, dst, false) + } + + /// Update data in RAM and write file back to disk (journal) + /// + /// This method is equivalent to `update_value`, but it ignores + /// the call if `time` is older than any previously stored data point. + /// A journal entry will still be created, but then also ignored when applying. + pub fn update_value_ignore_old( + &self, + rel_path: &str, + time: f64, + value: f64, + dst: DataSourceType, + ) -> Result<(), Error> { + self.update_value_impl(rel_path, time, value, dst, true) + } + + fn update_value_impl( + &self, + rel_path: &str, + time: f64, + value: f64, + dst: DataSourceType, + new_only: bool, ) -> Result<(), Error> { let journal_applied = self.apply_journal()?; @@ -202,7 +228,7 @@ impl Cache { self.rrd_map .write() .unwrap() - .update(rel_path, time, value, dst, false)?; + .update(rel_path, time, value, dst, new_only)?; } Ok(())