LCOV - code coverage report
Current view: top level - pageserver/src/tenant/secondary - heatmap.rs (source / functions) Coverage Total Hit
Test: b837401fb09d2d9818b70e630fdb67e9799b7b0d.info Lines: 0.0 % 32 0
Test Date: 2024-04-18 15:32:49 Functions: 0.0 % 37 0

            Line data    Source code
       1              : use std::time::SystemTime;
       2              : 
       3              : use crate::tenant::{
       4              :     remote_timeline_client::index::IndexLayerMetadata, storage_layer::LayerFileName,
       5              : };
       6              : 
       7              : use serde::{Deserialize, Serialize};
       8              : use serde_with::{serde_as, DisplayFromStr, TimestampSeconds};
       9              : 
      10              : use utils::{generation::Generation, id::TimelineId};
      11              : 
      12            0 : #[derive(Serialize, Deserialize)]
      13              : pub(super) struct HeatMapTenant {
      14              :     /// Generation of the attached location that uploaded the heatmap: this is not required
      15              :     /// for correctness, but acts as a hint to secondary locations in order to detect thrashing
      16              :     /// in the unlikely event that two attached locations are both uploading conflicting heatmaps.
      17              :     pub(super) generation: Generation,
      18              : 
      19              :     pub(super) timelines: Vec<HeatMapTimeline>,
      20              : }
      21              : 
      22              : #[serde_as]
      23            0 : #[derive(Serialize, Deserialize)]
      24              : pub(crate) struct HeatMapTimeline {
      25              :     #[serde_as(as = "DisplayFromStr")]
      26              :     pub(super) timeline_id: TimelineId,
      27              : 
      28              :     pub(super) layers: Vec<HeatMapLayer>,
      29              : }
      30              : 
      31              : #[serde_as]
      32            0 : #[derive(Serialize, Deserialize)]
      33              : pub(crate) struct HeatMapLayer {
      34              :     pub(super) name: LayerFileName,
      35              :     pub(super) metadata: IndexLayerMetadata,
      36              : 
      37              :     #[serde_as(as = "TimestampSeconds<i64>")]
      38              :     pub(super) access_time: SystemTime,
      39              :     // TODO: an actual 'heat' score that would let secondary locations prioritize downloading
      40              :     // the hottest layers, rather than trying to simply mirror whatever layers are on-disk on the primary.
      41              : }
      42              : 
      43              : impl HeatMapLayer {
      44            0 :     pub(crate) fn new(
      45            0 :         name: LayerFileName,
      46            0 :         metadata: IndexLayerMetadata,
      47            0 :         access_time: SystemTime,
      48            0 :     ) -> Self {
      49            0 :         Self {
      50            0 :             name,
      51            0 :             metadata,
      52            0 :             access_time,
      53            0 :         }
      54            0 :     }
      55              : }
      56              : 
      57              : impl HeatMapTimeline {
      58            0 :     pub(crate) fn new(timeline_id: TimelineId, layers: Vec<HeatMapLayer>) -> Self {
      59            0 :         Self {
      60            0 :             timeline_id,
      61            0 :             layers,
      62            0 :         }
      63            0 :     }
      64              : }
      65              : 
      66              : pub(crate) struct HeatMapStats {
      67              :     pub(crate) bytes: u64,
      68              :     pub(crate) layers: usize,
      69              : }
      70              : 
      71              : impl HeatMapTenant {
      72            0 :     pub(crate) fn get_stats(&self) -> HeatMapStats {
      73            0 :         let mut stats = HeatMapStats {
      74            0 :             bytes: 0,
      75            0 :             layers: 0,
      76            0 :         };
      77            0 :         for timeline in &self.timelines {
      78            0 :             for layer in &timeline.layers {
      79            0 :                 stats.layers += 1;
      80            0 :                 stats.bytes += layer.metadata.file_size;
      81            0 :             }
      82              :         }
      83              : 
      84            0 :         stats
      85            0 :     }
      86              : }
        

Generated by: LCOV version 2.1-beta