Line data Source code
1 : use chrono::NaiveDateTime;
2 : use serde::{Deserialize, Serialize};
3 : use utils::id::TimelineId;
4 : use utils::lsn::Lsn;
5 :
6 : /// Tenant-shard scoped manifest
7 0 : #[derive(Clone, Serialize, Deserialize, PartialEq, Eq)]
8 : pub struct TenantManifest {
9 : /// Debugging aid describing the version of this manifest.
10 : /// Can also be used for distinguishing breaking changes later on.
11 : pub version: usize,
12 :
13 : /// The list of offloaded timelines together with enough information
14 : /// to not have to actually load them.
15 : ///
16 : /// Note: the timelines mentioned in this list might be deleted, i.e.
17 : /// we don't hold an invariant that the references aren't dangling.
18 : /// Existence of index-part.json is the actual indicator of timeline existence.
19 : pub offloaded_timelines: Vec<OffloadedTimelineManifest>,
20 : }
21 :
22 : /// The remote level representation of an offloaded timeline.
23 : ///
24 : /// Very similar to [`pageserver_api::models::OffloadedTimelineInfo`],
25 : /// but the two datastructures serve different needs, this is for a persistent disk format
26 : /// that must be backwards compatible, while the other is only for informative purposes.
27 0 : #[derive(Clone, Serialize, Deserialize, Copy, PartialEq, Eq)]
28 : pub struct OffloadedTimelineManifest {
29 : pub timeline_id: TimelineId,
30 : /// Whether the timeline has a parent it has been branched off from or not
31 : pub ancestor_timeline_id: Option<TimelineId>,
32 : /// Whether to retain the branch lsn at the ancestor or not
33 : pub ancestor_retain_lsn: Option<Lsn>,
34 : /// The time point when the timeline was archived
35 : pub archived_at: NaiveDateTime,
36 : }
37 :
38 : pub const LATEST_TENANT_MANIFEST_VERSION: usize = 1;
39 :
40 : impl TenantManifest {
41 452 : pub(crate) fn empty() -> Self {
42 452 : Self {
43 452 : version: LATEST_TENANT_MANIFEST_VERSION,
44 452 : offloaded_timelines: vec![],
45 452 : }
46 452 : }
47 0 : pub fn from_json_bytes(bytes: &[u8]) -> Result<Self, serde_json::Error> {
48 0 : serde_json::from_slice::<Self>(bytes)
49 0 : }
50 :
51 4 : pub(crate) fn to_json_bytes(&self) -> serde_json::Result<Vec<u8>> {
52 4 : serde_json::to_vec(self)
53 4 : }
54 : }
|