proxmox-rrd: improve dev docs
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
		| @ -120,6 +120,7 @@ impl RRDCache { | |||||||
|         RRD::new(dst, rra_list) |         RRD::new(dst, rra_list) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Sync the journal data to disk (using `fdatasync` syscall) | ||||||
|     pub fn sync_journal(&self) -> Result<(), Error> { |     pub fn sync_journal(&self) -> Result<(), Error> { | ||||||
|         self.state.read().unwrap().sync_journal() |         self.state.read().unwrap().sync_journal() | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -70,6 +70,7 @@ pub struct DataSource { | |||||||
|  |  | ||||||
| impl DataSource { | impl DataSource { | ||||||
|  |  | ||||||
|  |     /// Create a new Instance | ||||||
|     pub fn new(dst: DST) -> Self { |     pub fn new(dst: DST) -> Self { | ||||||
|         Self { |         Self { | ||||||
|             dst, |             dst, | ||||||
| @ -136,6 +137,7 @@ pub struct RRA { | |||||||
|  |  | ||||||
| impl RRA { | impl RRA { | ||||||
|  |  | ||||||
|  |     /// Creates a new instance | ||||||
|     pub fn new(cf: CF, resolution: u64, points: usize) -> Self { |     pub fn new(cf: CF, resolution: u64, points: usize) -> Self { | ||||||
|         Self { |         Self { | ||||||
|             cf, |             cf, | ||||||
| @ -145,20 +147,24 @@ impl RRA { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Data slot end time | ||||||
|     pub fn slot_end_time(&self, time: u64) -> u64 { |     pub fn slot_end_time(&self, time: u64) -> u64 { | ||||||
|         self.resolution * (time / self.resolution + 1) |         self.resolution * (time / self.resolution + 1) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Data slot start time | ||||||
|     pub fn slot_start_time(&self, time: u64) -> u64 { |     pub fn slot_start_time(&self, time: u64) -> u64 { | ||||||
|         self.resolution * (time / self.resolution) |         self.resolution * (time / self.resolution) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Data slot index | ||||||
|     pub fn slot(&self, time: u64) -> usize { |     pub fn slot(&self, time: u64) -> usize { | ||||||
|         ((time / self.resolution) as usize) % self.data.len() |         ((time / self.resolution) as usize) % self.data.len() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // directly overwrite data slots |     /// Directly overwrite data slots. | ||||||
|     // the caller need to set last_update value on the DataSource manually. |     /// | ||||||
|  |     /// The caller need to set `last_update` value on the [DataSource] manually. | ||||||
|     pub fn insert_data( |     pub fn insert_data( | ||||||
|         &mut self, |         &mut self, | ||||||
|         start: u64, |         start: u64, | ||||||
| @ -240,6 +246,11 @@ impl RRA { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Extract data | ||||||
|  |     /// | ||||||
|  |     /// Extract data from `start` to `end`. The RRA itself does not | ||||||
|  |     /// store the `last_update` time, so you need to pass this a | ||||||
|  |     /// parameter (see [DataSource]). | ||||||
|     pub fn extract_data( |     pub fn extract_data( | ||||||
|         &self, |         &self, | ||||||
|         start: u64, |         start: u64, | ||||||
| @ -288,6 +299,7 @@ pub struct RRD { | |||||||
|  |  | ||||||
| impl RRD { | impl RRD { | ||||||
|  |  | ||||||
|  |     /// Creates a new Instance | ||||||
|     pub fn new(dst: DST, rra_list: Vec<RRA>) -> RRD { |     pub fn new(dst: DST, rra_list: Vec<RRA>) -> RRD { | ||||||
|  |  | ||||||
|         let source = DataSource::new(dst); |         let source = DataSource::new(dst); | ||||||
| @ -323,6 +335,10 @@ impl RRD { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// Load data from a file |     /// Load data from a file | ||||||
|  |     /// | ||||||
|  |     /// Setting `avoid_page_cache` uses | ||||||
|  |     /// `fadvise(..,POSIX_FADV_DONTNEED)` to avoid keeping the data in | ||||||
|  |     /// the linux page cache. | ||||||
|     pub fn load(path: &Path, avoid_page_cache: bool) -> Result<Self, std::io::Error> { |     pub fn load(path: &Path, avoid_page_cache: bool) -> Result<Self, std::io::Error> { | ||||||
|  |  | ||||||
|         let mut file = std::fs::File::open(path)?; |         let mut file = std::fs::File::open(path)?; | ||||||
| @ -346,7 +362,11 @@ impl RRD { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// Store data into a file (atomic replace file) |     /// Store data into a file (atomic replace file) | ||||||
|     pub fn save( |     /// | ||||||
|  |     /// Setting `avoid_page_cache` uses | ||||||
|  |     /// `fadvise(..,POSIX_FADV_DONTNEED)` to avoid keeping the data in | ||||||
|  |     /// the linux page cache. | ||||||
|  |    pub fn save( | ||||||
|         &self, |         &self, | ||||||
|         path: &Path, |         path: &Path, | ||||||
|         options: CreateOptions, |         options: CreateOptions, | ||||||
| @ -390,6 +410,7 @@ impl RRD { | |||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Returns the last update time. | ||||||
|     pub fn last_update(&self) -> f64 { |     pub fn last_update(&self) -> f64 { | ||||||
|         self.source.last_update |         self.source.last_update | ||||||
|     } |     } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user