LCOV - code coverage report
Current view: top level - libs/tenant_size_model/src - lib.rs (source / functions) Coverage Total Hit
Test: 8ac049b474321fdc72ddcb56d7165153a1a900e8.info Lines: 75.0 % 4 3
Test Date: 2023-09-06 10:18:01 Functions: 25.5 % 55 14

            Line data    Source code
       1              : //! Synthetic size calculation
       2              : 
       3              : mod calculation;
       4              : pub mod svg;
       5              : 
       6              : /// StorageModel is the input to the synthetic size calculation. It represents
       7              : /// a tree of timelines, with just the information that's needed for the
       8              : /// calculation. This doesn't track timeline names or where each timeline
       9              : /// begins and ends, for example. Instead, it consists of "points of interest"
      10              : /// on the timelines. A point of interest could be the timeline start or end point,
      11              : /// the oldest point on a timeline that needs to be retained because of PITR
      12              : /// cutoff, or snapshot points named by the user. For each such point, and the
      13              : /// edge connecting the points (implicit in Segment), we store information about
      14              : /// whether we need to be able to recover to the point, and if known, the logical
      15              : /// size at the point.
      16              : ///
      17              : /// The segments must form a well-formed tree, with no loops.
      18            0 : #[derive(serde::Serialize)]
      19              : pub struct StorageModel {
      20              :     pub segments: Vec<Segment>,
      21              : }
      22              : 
      23              : /// Segment represents one point in the tree of branches, *and* the edge that leads
      24              : /// to it (if any). We don't need separate structs for points and edges, because each
      25              : /// point can have only one parent.
      26              : ///
      27              : /// When 'needed' is true, it means that we need to be able to reconstruct
      28              : /// any version between 'parent.lsn' and 'lsn'. If you want to represent that only
      29              : /// a single point is needed, create two Segments with the same lsn, and mark only
      30              : /// the child as needed.
      31              : ///
      32          356 : #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
      33              : pub struct Segment {
      34              :     /// Previous segment index into ['Storage::segments`], if any.
      35              :     pub parent: Option<usize>,
      36              : 
      37              :     /// LSN at this point
      38              :     pub lsn: u64,
      39              : 
      40              :     /// Logical size at this node, if known.
      41              :     pub size: Option<u64>,
      42              : 
      43              :     /// If true, the segment from parent to this node is needed by `retention_period`
      44              :     pub needed: bool,
      45              : }
      46              : 
      47              : /// Result of synthetic size calculation. Returned by StorageModel::calculate()
      48              : pub struct SizeResult {
      49              :     pub total_size: u64,
      50              : 
      51              :     // This has same length as the StorageModel::segments vector in the input.
      52              :     // Each entry in this array corresponds to the entry with same index in
      53              :     // StorageModel::segments.
      54              :     pub segments: Vec<SegmentSizeResult>,
      55              : }
      56              : 
      57          281 : #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
      58              : pub struct SegmentSizeResult {
      59              :     pub method: SegmentMethod,
      60              :     // calculated size of this subtree, using this method
      61              :     pub accum_size: u64,
      62              : }
      63              : 
      64              : /// Different methods to retain history from a particular state
      65         1384 : #[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
      66              : pub enum SegmentMethod {
      67              :     SnapshotHere, // A logical snapshot is needed after this segment
      68              :     Wal,          // Keep WAL leading up to this node
      69              :     Skipped,
      70              : }
        

Generated by: LCOV version 2.1-beta