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