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 45 : #[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 54 : #[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 20320 : #[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 2493 : pub(crate) fn new(
45 2493 : name: LayerFileName,
46 2493 : metadata: IndexLayerMetadata,
47 2493 : access_time: SystemTime,
48 2493 : ) -> Self {
49 2493 : Self {
50 2493 : name,
51 2493 : metadata,
52 2493 : access_time,
53 2493 : }
54 2493 : }
55 : }
56 :
57 : impl HeatMapTimeline {
58 8 : pub(crate) fn new(timeline_id: TimelineId, layers: Vec<HeatMapLayer>) -> Self {
59 8 : Self {
60 8 : timeline_id,
61 8 : layers,
62 8 : }
63 8 : }
64 : }
|