LCOV - code coverage report
Current view: top level - pageserver/src/tenant - gc_result.rs (source / functions) Coverage Total Hit
Test: 49aa928ec5b4b510172d8b5c6d154da28e70a46c.info Lines: 70.8 % 24 17
Test Date: 2024-11-13 18:23:39 Functions: 20.0 % 5 1

            Line data    Source code
       1              : use anyhow::Result;
       2              : use serde::Serialize;
       3              : use std::ops::AddAssign;
       4              : use std::time::Duration;
       5              : 
       6              : ///
       7              : /// Result of performing GC
       8              : ///
       9            0 : #[derive(Default, Serialize, Debug)]
      10              : pub struct GcResult {
      11              :     pub layers_total: u64,
      12              :     pub layers_needed_by_cutoff: u64,
      13              :     pub layers_needed_by_pitr: u64,
      14              :     pub layers_needed_by_branches: u64,
      15              :     pub layers_needed_by_leases: u64,
      16              :     pub layers_not_updated: u64,
      17              :     pub layers_removed: u64, // # of layer files removed because they have been made obsolete by newer ondisk files.
      18              : 
      19              :     #[serde(serialize_with = "serialize_duration_as_millis")]
      20              :     pub elapsed: Duration,
      21              : 
      22              :     /// The layers which were garbage collected.
      23              :     ///
      24              :     /// Used in `/v1/tenant/:tenant_id/timeline/:timeline_id/do_gc` to wait for the layers to be
      25              :     /// dropped in tests.
      26              :     #[cfg(feature = "testing")]
      27              :     #[serde(skip)]
      28              :     pub(crate) doomed_layers: Vec<crate::tenant::storage_layer::Layer>,
      29              : }
      30              : 
      31              : // helper function for `GcResult`, serializing a `Duration` as an integer number of milliseconds
      32            0 : fn serialize_duration_as_millis<S>(d: &Duration, serializer: S) -> Result<S::Ok, S::Error>
      33            0 : where
      34            0 :     S: serde::Serializer,
      35            0 : {
      36            0 :     d.as_millis().serialize(serializer)
      37            0 : }
      38              : 
      39              : impl AddAssign for GcResult {
      40            4 :     fn add_assign(&mut self, other: Self) {
      41            4 :         self.layers_total += other.layers_total;
      42            4 :         self.layers_needed_by_pitr += other.layers_needed_by_pitr;
      43            4 :         self.layers_needed_by_cutoff += other.layers_needed_by_cutoff;
      44            4 :         self.layers_needed_by_branches += other.layers_needed_by_branches;
      45            4 :         self.layers_needed_by_leases += other.layers_needed_by_leases;
      46            4 :         self.layers_not_updated += other.layers_not_updated;
      47            4 :         self.layers_removed += other.layers_removed;
      48            4 : 
      49            4 :         self.elapsed += other.elapsed;
      50            4 : 
      51            4 :         #[cfg(feature = "testing")]
      52            4 :         {
      53            4 :             let mut other = other;
      54            4 :             self.doomed_layers.append(&mut other.doomed_layers);
      55            4 :         }
      56            4 :     }
      57              : }
        

Generated by: LCOV version 2.1-beta