Line data Source code
1 : //! In-memory index to track the tenant files on the remote storage.
2 : //!
3 : //! Able to restore itself from the storage index parts, that are located in every timeline's remote directory and contain all data about
4 : //! remote timeline layers and its metadata.
5 :
6 : use std::collections::HashMap;
7 :
8 : use chrono::NaiveDateTime;
9 : use pageserver_api::models::AuxFilePolicy;
10 : use pageserver_api::models::RelSizeMigration;
11 : use pageserver_api::shard::ShardIndex;
12 : use serde::{Deserialize, Serialize};
13 : use utils::id::TimelineId;
14 : use utils::lsn::Lsn;
15 :
16 : use super::is_same_remote_layer_path;
17 : use crate::tenant::Generation;
18 : use crate::tenant::metadata::TimelineMetadata;
19 : use crate::tenant::storage_layer::LayerName;
20 : use crate::tenant::timeline::import_pgdata;
21 :
22 : /// In-memory representation of an `index_part.json` file
23 : ///
24 : /// Contains the data about all files in the timeline, present remotely and its metadata.
25 : ///
26 : /// This type needs to be backwards and forwards compatible. When changing the fields,
27 : /// remember to add a test case for the changed version.
28 : #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
29 : pub struct IndexPart {
30 : /// Debugging aid describing the version of this type.
31 : #[serde(default)]
32 : version: usize,
33 :
34 : #[serde(default)]
35 : #[serde(skip_serializing_if = "Option::is_none")]
36 : pub deleted_at: Option<NaiveDateTime>,
37 :
38 : #[serde(default)]
39 : #[serde(skip_serializing_if = "Option::is_none")]
40 : pub archived_at: Option<NaiveDateTime>,
41 :
42 : /// This field supports import-from-pgdata ("fast imports" platform feature).
43 : /// We don't currently use fast imports, so, this field is None for all production timelines.
44 : /// See <https://github.com/neondatabase/neon/pull/9218> for more information.
45 : #[serde(default)]
46 : #[serde(skip_serializing_if = "Option::is_none")]
47 : pub import_pgdata: Option<import_pgdata::index_part_format::Root>,
48 :
49 : /// Layer filenames and metadata. For an index persisted in remote storage, all layers must
50 : /// exist in remote storage.
51 : pub layer_metadata: HashMap<LayerName, LayerFileMetadata>,
52 :
53 : /// Because of the trouble of eyeballing the legacy "metadata" field, we copied the
54 : /// "disk_consistent_lsn" out. After version 7 this is no longer needed, but the name cannot be
55 : /// reused.
56 : pub(super) disk_consistent_lsn: Lsn,
57 :
58 : // TODO: rename as "metadata" next week, keep the alias = "metadata_bytes", bump version Adding
59 : // the "alias = metadata" was forgotten in #7693, so we have to use "rewrite = metadata_bytes"
60 : // for backwards compatibility.
61 : #[serde(
62 : rename = "metadata_bytes",
63 : alias = "metadata",
64 : with = "crate::tenant::metadata::modern_serde"
65 : )]
66 : pub metadata: TimelineMetadata,
67 :
68 : #[serde(default)]
69 : pub(crate) lineage: Lineage,
70 :
71 : #[serde(skip_serializing_if = "Option::is_none", default)]
72 : pub(crate) gc_blocking: Option<GcBlocking>,
73 :
74 : /// Describes the kind of aux files stored in the timeline.
75 : ///
76 : /// The value is modified during file ingestion when the latest wanted value communicated via tenant config is applied if it is acceptable.
77 : /// A V1 setting after V2 files have been committed is not accepted.
78 : ///
79 : /// None means no aux files have been written to the storage before the point
80 : /// when this flag is introduced.
81 : ///
82 : /// This flag is not used any more as all tenants have been transitioned to the new aux file policy.
83 : #[serde(skip_serializing_if = "Option::is_none", default)]
84 : pub(crate) last_aux_file_policy: Option<AuxFilePolicy>,
85 :
86 : #[serde(skip_serializing_if = "Option::is_none", default)]
87 : pub(crate) rel_size_migration: Option<RelSizeMigration>,
88 :
89 : /// Not used anymore -- kept here for backwards compatibility. Merged into the `gc_compaction` field.
90 : #[serde(skip_serializing_if = "Option::is_none", default)]
91 : l2_lsn: Option<Lsn>,
92 :
93 : /// State for the garbage-collecting compaction pass.
94 : ///
95 : /// Garbage-collecting compaction (gc-compaction) prunes `Value`s that are outside
96 : /// the PITR window and not needed by child timelines.
97 : ///
98 : /// A commonly used synonym for this compaction pass is
99 : /// "bottommost-compaction" because the affected LSN range
100 : /// is the "bottom" of the (key,lsn) map.
101 : ///
102 : /// Gc-compaction is a quite expensive operation; that's why we use
103 : /// trigger condition.
104 : /// This field here holds the state pertaining to that trigger condition
105 : /// and (in future) to the progress of the gc-compaction, so that it's
106 : /// resumable across restarts & migrations.
107 : ///
108 : /// Note that the underlying algorithm is _also_ called `gc-compaction`
109 : /// in most places & design docs; but in fact it is more flexible than
110 : /// just the specific use case here; it needs a new name.
111 : #[serde(skip_serializing_if = "Option::is_none", default)]
112 : pub(crate) gc_compaction: Option<GcCompactionState>,
113 :
114 : /// The timestamp when the timeline was marked invisible in synthetic size calculations.
115 : #[serde(skip_serializing_if = "Option::is_none", default)]
116 : pub(crate) marked_invisible_at: Option<NaiveDateTime>,
117 : }
118 :
119 0 : #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
120 : pub struct GcCompactionState {
121 : /// The upper bound of the last completed garbage-collecting compaction, aka. L2 LSN.
122 : pub(crate) last_completed_lsn: Lsn,
123 : }
124 :
125 : impl IndexPart {
126 : /// When adding or modifying any parts of `IndexPart`, increment the version so that it can be
127 : /// used to understand later versions.
128 : ///
129 : /// Version is currently informative only.
130 : /// Version history
131 : /// - 2: added `deleted_at`
132 : /// - 3: no longer deserialize `timeline_layers` (serialized format is the same, but timeline_layers
133 : /// is always generated from the keys of `layer_metadata`)
134 : /// - 4: timeline_layers is fully removed.
135 : /// - 5: lineage was added
136 : /// - 6: last_aux_file_policy is added.
137 : /// - 7: metadata_bytes is no longer written, but still read
138 : /// - 8: added `archived_at`
139 : /// - 9: +gc_blocking
140 : /// - 10: +import_pgdata
141 : /// - 11: +rel_size_migration
142 : /// - 12: +l2_lsn
143 : /// - 13: +gc_compaction
144 : /// - 14: +marked_invisible_at
145 : const LATEST_VERSION: usize = 14;
146 :
147 : // Versions we may see when reading from a bucket.
148 : pub const KNOWN_VERSIONS: &'static [usize] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
149 :
150 : pub const FILE_NAME: &'static str = "index_part.json";
151 :
152 274 : pub fn empty(metadata: TimelineMetadata) -> Self {
153 274 : IndexPart {
154 274 : version: Self::LATEST_VERSION,
155 274 : layer_metadata: Default::default(),
156 274 : disk_consistent_lsn: metadata.disk_consistent_lsn(),
157 274 : metadata,
158 274 : deleted_at: None,
159 274 : archived_at: None,
160 274 : lineage: Default::default(),
161 274 : gc_blocking: None,
162 274 : last_aux_file_policy: None,
163 274 : import_pgdata: None,
164 274 : rel_size_migration: None,
165 274 : l2_lsn: None,
166 274 : gc_compaction: None,
167 274 : marked_invisible_at: None,
168 274 : }
169 274 : }
170 :
171 0 : pub fn version(&self) -> usize {
172 0 : self.version
173 0 : }
174 :
175 : /// If you want this under normal operations, read it from self.metadata:
176 : /// this method is just for the scrubber to use when validating an index.
177 0 : pub fn duplicated_disk_consistent_lsn(&self) -> Lsn {
178 0 : self.disk_consistent_lsn
179 0 : }
180 :
181 14 : pub fn from_json_bytes(bytes: &[u8]) -> Result<Self, serde_json::Error> {
182 14 : serde_json::from_slice::<IndexPart>(bytes)
183 14 : }
184 :
185 774 : pub fn to_json_bytes(&self) -> serde_json::Result<Vec<u8>> {
186 774 : serde_json::to_vec(self)
187 774 : }
188 :
189 : #[cfg(test)]
190 14 : pub(crate) fn example() -> Self {
191 14 : Self::empty(TimelineMetadata::example())
192 14 : }
193 :
194 : /// Returns true if the index contains a reference to the given layer (i.e. file path).
195 : ///
196 : /// TODO: there should be a variant of LayerName for the physical remote path that contains
197 : /// information about the shard and generation, to avoid passing in metadata.
198 25650 : pub fn references(&self, name: &LayerName, metadata: &LayerFileMetadata) -> bool {
199 25650 : let Some(index_metadata) = self.layer_metadata.get(name) else {
200 12740 : return false;
201 : };
202 12910 : is_same_remote_layer_path(name, metadata, name, index_metadata)
203 25650 : }
204 :
205 : /// Check for invariants in the index: this is useful when uploading an index to ensure that if
206 : /// we encounter a bug, we do not persist buggy metadata.
207 1397 : pub(crate) fn validate(&self) -> Result<(), String> {
208 1397 : if self.import_pgdata.is_none()
209 1397 : && self.metadata.ancestor_timeline().is_none()
210 1039 : && self.layer_metadata.is_empty()
211 : {
212 : // Unless we're in the middle of a raw pgdata import, or this is a child timeline,the index must
213 : // always have at least one layer.
214 0 : return Err("Index has no ancestor and no layers".to_string());
215 1397 : }
216 :
217 1397 : Ok(())
218 1397 : }
219 : }
220 :
221 : /// Metadata gathered for each of the layer files.
222 : ///
223 : /// Fields have to be `Option`s because remote [`IndexPart`]'s can be from different version, which
224 : /// might have less or more metadata depending if upgrading or rolling back an upgrade.
225 0 : #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
226 : pub struct LayerFileMetadata {
227 : pub file_size: u64,
228 :
229 : #[serde(default = "Generation::none")]
230 : #[serde(skip_serializing_if = "Generation::is_none")]
231 : pub generation: Generation,
232 :
233 : #[serde(default = "ShardIndex::unsharded")]
234 : #[serde(skip_serializing_if = "ShardIndex::is_unsharded")]
235 : pub shard: ShardIndex,
236 : }
237 :
238 : impl LayerFileMetadata {
239 1612 : pub fn new(file_size: u64, generation: Generation, shard: ShardIndex) -> Self {
240 1612 : LayerFileMetadata {
241 1612 : file_size,
242 1612 : generation,
243 1612 : shard,
244 1612 : }
245 1612 : }
246 : /// Helper to get both generation and file size in a tuple
247 0 : pub fn generation_file_size(&self) -> (Generation, u64) {
248 0 : (self.generation, self.file_size)
249 0 : }
250 : }
251 :
252 : /// Limited history of earlier ancestors.
253 : ///
254 : /// A timeline can have more than 1 earlier ancestor, in the rare case that it was repeatedly
255 : /// reparented by having an later timeline be detached from it's ancestor.
256 0 : #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Default)]
257 : pub(crate) struct Lineage {
258 : /// Has the `reparenting_history` been truncated to [`Lineage::REMEMBER_AT_MOST`].
259 : #[serde(skip_serializing_if = "is_false", default)]
260 : reparenting_history_truncated: bool,
261 :
262 : /// Earlier ancestors, truncated when [`Self::reparenting_history_truncated`]
263 : ///
264 : /// These are stored in case we want to support WAL based DR on the timeline. There can be many
265 : /// of these and at most one [`Self::original_ancestor`]. There cannot be more reparentings
266 : /// after [`Self::original_ancestor`] has been set.
267 : #[serde(skip_serializing_if = "Vec::is_empty", default)]
268 : reparenting_history: Vec<TimelineId>,
269 :
270 : /// The ancestor from which this timeline has been detached from and when.
271 : ///
272 : /// If you are adding support for detaching from a hierarchy, consider changing the ancestry
273 : /// into a `Vec<(TimelineId, Lsn)>` to be a path instead.
274 : // FIXME: this is insufficient even for path of two timelines for future wal recovery
275 : // purposes:
276 : //
277 : // assuming a "old main" which has received most of the WAL, and has a branch "new main",
278 : // starting a bit before "old main" last_record_lsn. the current version works fine,
279 : // because we will know to replay wal and branch at the recorded Lsn to do wal recovery.
280 : //
281 : // then assuming "new main" would similarly receive a branch right before its last_record_lsn,
282 : // "new new main". the current implementation would just store ("new main", ancestor_lsn, _)
283 : // here. however, we cannot recover from WAL using only that information, we would need the
284 : // whole ancestry here:
285 : //
286 : // ```json
287 : // [
288 : // ["old main", ancestor_lsn("new main"), _],
289 : // ["new main", ancestor_lsn("new new main"), _]
290 : // ]
291 : // ```
292 : #[serde(skip_serializing_if = "Option::is_none", default)]
293 : original_ancestor: Option<(TimelineId, Lsn, NaiveDateTime)>,
294 : }
295 :
296 3154 : fn is_false(b: &bool) -> bool {
297 3154 : !b
298 3154 : }
299 :
300 : impl Lineage {
301 : const REMEMBER_AT_MOST: usize = 100;
302 :
303 0 : pub(crate) fn record_previous_ancestor(&mut self, old_ancestor: &TimelineId) -> bool {
304 0 : if self.reparenting_history.last() == Some(old_ancestor) {
305 : // do not re-record it
306 0 : false
307 : } else {
308 : #[cfg(feature = "testing")]
309 : {
310 0 : let existing = self
311 0 : .reparenting_history
312 0 : .iter()
313 0 : .position(|x| x == old_ancestor);
314 0 : assert_eq!(
315 : existing, None,
316 0 : "we cannot reparent onto and off and onto the same timeline twice"
317 : );
318 : }
319 0 : let drop_oldest = self.reparenting_history.len() + 1 >= Self::REMEMBER_AT_MOST;
320 :
321 0 : self.reparenting_history_truncated |= drop_oldest;
322 0 : if drop_oldest {
323 0 : self.reparenting_history.remove(0);
324 0 : }
325 0 : self.reparenting_history.push(*old_ancestor);
326 0 : true
327 : }
328 0 : }
329 :
330 : /// Returns true if anything changed.
331 0 : pub(crate) fn record_detaching(&mut self, branchpoint: &(TimelineId, Lsn)) -> bool {
332 0 : if let Some((id, lsn, _)) = self.original_ancestor {
333 0 : assert_eq!(
334 0 : &(id, lsn),
335 : branchpoint,
336 0 : "detaching attempt has to be for the same ancestor we are already detached from"
337 : );
338 0 : false
339 : } else {
340 0 : self.original_ancestor =
341 0 : Some((branchpoint.0, branchpoint.1, chrono::Utc::now().naive_utc()));
342 0 : true
343 : }
344 0 : }
345 :
346 : /// The queried lsn is most likely the basebackup lsn, and this answers question "is it allowed
347 : /// to start a read/write primary at this lsn".
348 : ///
349 : /// Returns true if the Lsn was previously our branch point.
350 0 : pub(crate) fn is_previous_ancestor_lsn(&self, lsn: Lsn) -> bool {
351 0 : self.original_ancestor
352 0 : .is_some_and(|(_, ancestor_lsn, _)| ancestor_lsn == lsn)
353 0 : }
354 :
355 : /// Returns true if the timeline originally had an ancestor, and no longer has one.
356 0 : pub(crate) fn is_detached_from_ancestor(&self) -> bool {
357 0 : self.original_ancestor.is_some()
358 0 : }
359 :
360 : /// Returns original ancestor timeline id and lsn that this timeline has been detached from.
361 0 : pub(crate) fn detached_previous_ancestor(&self) -> Option<(TimelineId, Lsn)> {
362 0 : self.original_ancestor.map(|(id, lsn, _)| (id, lsn))
363 0 : }
364 :
365 0 : pub(crate) fn is_reparented(&self) -> bool {
366 0 : !self.reparenting_history.is_empty()
367 0 : }
368 : }
369 :
370 0 : #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
371 : pub(crate) struct GcBlocking {
372 : pub(crate) started_at: NaiveDateTime,
373 : pub(crate) reasons: enumset::EnumSet<GcBlockingReason>,
374 : }
375 :
376 0 : #[derive(Debug, enumset::EnumSetType, serde::Serialize, serde::Deserialize)]
377 : #[enumset(serialize_repr = "list")]
378 : pub(crate) enum GcBlockingReason {
379 : Manual,
380 : DetachAncestor,
381 : }
382 :
383 : impl GcBlocking {
384 0 : pub(super) fn started_now_for(reason: GcBlockingReason) -> Self {
385 0 : GcBlocking {
386 0 : started_at: chrono::Utc::now().naive_utc(),
387 0 : reasons: enumset::EnumSet::only(reason),
388 0 : }
389 0 : }
390 :
391 : /// Returns true if the given reason is one of the reasons why the gc is blocked.
392 0 : pub(crate) fn blocked_by(&self, reason: GcBlockingReason) -> bool {
393 0 : self.reasons.contains(reason)
394 0 : }
395 :
396 : /// Returns a version of self with the given reason.
397 0 : pub(super) fn with_reason(&self, reason: GcBlockingReason) -> Self {
398 0 : assert!(!self.blocked_by(reason));
399 0 : let mut reasons = self.reasons;
400 0 : reasons.insert(reason);
401 :
402 0 : Self {
403 0 : started_at: self.started_at,
404 0 : reasons,
405 0 : }
406 0 : }
407 :
408 : /// Returns a version of self without the given reason. Assumption is that if
409 : /// there are no more reasons, we can unblock the gc by returning `None`.
410 0 : pub(super) fn without_reason(&self, reason: GcBlockingReason) -> Option<Self> {
411 0 : assert!(self.blocked_by(reason));
412 :
413 0 : if self.reasons.len() == 1 {
414 0 : None
415 : } else {
416 0 : let mut reasons = self.reasons;
417 0 : assert!(reasons.remove(reason));
418 0 : assert!(!reasons.is_empty());
419 :
420 0 : Some(Self {
421 0 : started_at: self.started_at,
422 0 : reasons,
423 0 : })
424 : }
425 0 : }
426 : }
427 :
428 : #[cfg(test)]
429 : mod tests {
430 : use postgres_ffi::PgMajorVersion;
431 : use std::str::FromStr;
432 : use utils::id::TimelineId;
433 :
434 : use super::*;
435 :
436 : #[test]
437 1 : fn v1_indexpart_is_parsed() {
438 1 : let example = r#"{
439 1 : "version":1,
440 1 : "timeline_layers":["000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9"],
441 1 : "layer_metadata":{
442 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9": { "file_size": 25600000 },
443 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
447 1 : }"#;
448 :
449 1 : let expected = IndexPart {
450 1 : // note this is not verified, could be anything, but exists for humans debugging.. could be the git version instead?
451 1 : version: 1,
452 1 : layer_metadata: HashMap::from([
453 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9".parse().unwrap(), LayerFileMetadata {
454 1 : file_size: 25600000,
455 1 : generation: Generation::none(),
456 1 : shard: ShardIndex::unsharded()
457 1 : }),
458 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51".parse().unwrap(), LayerFileMetadata {
459 1 : // serde_json should always parse this but this might be a double with jq for
460 1 : // example.
461 1 : file_size: 9007199254741001,
462 1 : generation: Generation::none(),
463 1 : shard: ShardIndex::unsharded()
464 1 : })
465 1 : ]),
466 1 : disk_consistent_lsn: "0/16960E8".parse::<Lsn>().unwrap(),
467 1 : metadata: TimelineMetadata::from_bytes(&[113,11,159,210,0,54,0,4,0,0,0,0,1,105,96,232,1,0,0,0,0,1,105,96,112,0,0,0,0,0,0,0,0,0,0,0,0,0,1,105,96,112,0,0,0,0,1,105,96,112,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]).unwrap(),
468 1 : deleted_at: None,
469 1 : archived_at: None,
470 1 : lineage: Lineage::default(),
471 1 : gc_blocking: None,
472 1 : last_aux_file_policy: None,
473 1 : import_pgdata: None,
474 1 : rel_size_migration: None,
475 1 : l2_lsn: None,
476 1 : gc_compaction: None,
477 1 : marked_invisible_at: None,
478 1 : };
479 :
480 1 : let part = IndexPart::from_json_bytes(example.as_bytes()).unwrap();
481 1 : assert_eq!(part, expected);
482 1 : }
483 :
484 : #[test]
485 1 : fn v1_indexpart_is_parsed_with_optional_missing_layers() {
486 1 : let example = r#"{
487 1 : "version":1,
488 1 : "timeline_layers":["000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9"],
489 1 : "missing_layers":["This shouldn't fail deserialization"],
490 1 : "layer_metadata":{
491 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9": { "file_size": 25600000 },
492 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51": { "file_size": 9007199254741001 }
493 1 : },
494 1 : "disk_consistent_lsn":"0/16960E8",
495 1 : "metadata_bytes":[113,11,159,210,0,54,0,4,0,0,0,0,1,105,96,232,1,0,0,0,0,1,105,96,112,0,0,0,0,0,0,0,0,0,0,0,0,0,1,105,96,112,0,0,0,0,1,105,96,112,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
496 1 : }"#;
497 :
498 1 : let expected = IndexPart {
499 1 : // note this is not verified, could be anything, but exists for humans debugging.. could be the git version instead?
500 1 : version: 1,
501 1 : layer_metadata: HashMap::from([
502 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9".parse().unwrap(), LayerFileMetadata {
503 1 : file_size: 25600000,
504 1 : generation: Generation::none(),
505 1 : shard: ShardIndex::unsharded()
506 1 : }),
507 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51".parse().unwrap(), LayerFileMetadata {
508 1 : // serde_json should always parse this but this might be a double with jq for
509 1 : // example.
510 1 : file_size: 9007199254741001,
511 1 : generation: Generation::none(),
512 1 : shard: ShardIndex::unsharded()
513 1 : })
514 1 : ]),
515 1 : disk_consistent_lsn: "0/16960E8".parse::<Lsn>().unwrap(),
516 1 : metadata: TimelineMetadata::from_bytes(&[113,11,159,210,0,54,0,4,0,0,0,0,1,105,96,232,1,0,0,0,0,1,105,96,112,0,0,0,0,0,0,0,0,0,0,0,0,0,1,105,96,112,0,0,0,0,1,105,96,112,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]).unwrap(),
517 1 : deleted_at: None,
518 1 : archived_at: None,
519 1 : lineage: Lineage::default(),
520 1 : gc_blocking: None,
521 1 : last_aux_file_policy: None,
522 1 : import_pgdata: None,
523 1 : rel_size_migration: None,
524 1 : l2_lsn: None,
525 1 : gc_compaction: None,
526 1 : marked_invisible_at: None,
527 1 : };
528 :
529 1 : let part = IndexPart::from_json_bytes(example.as_bytes()).unwrap();
530 1 : assert_eq!(part, expected);
531 1 : }
532 :
533 : #[test]
534 1 : fn v2_indexpart_is_parsed_with_deleted_at() {
535 1 : let example = r#"{
536 1 : "version":2,
537 1 : "timeline_layers":["000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9"],
538 1 : "missing_layers":["This shouldn't fail deserialization"],
539 1 : "layer_metadata":{
540 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9": { "file_size": 25600000 },
541 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51": { "file_size": 9007199254741001 }
542 1 : },
543 1 : "disk_consistent_lsn":"0/16960E8",
544 1 : "metadata_bytes":[113,11,159,210,0,54,0,4,0,0,0,0,1,105,96,232,1,0,0,0,0,1,105,96,112,0,0,0,0,0,0,0,0,0,0,0,0,0,1,105,96,112,0,0,0,0,1,105,96,112,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
545 1 : "deleted_at": "2023-07-31T09:00:00.123"
546 1 : }"#;
547 :
548 1 : let expected = IndexPart {
549 1 : // note this is not verified, could be anything, but exists for humans debugging.. could be the git version instead?
550 1 : version: 2,
551 1 : layer_metadata: HashMap::from([
552 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9".parse().unwrap(), LayerFileMetadata {
553 1 : file_size: 25600000,
554 1 : generation: Generation::none(),
555 1 : shard: ShardIndex::unsharded()
556 1 : }),
557 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51".parse().unwrap(), LayerFileMetadata {
558 1 : // serde_json should always parse this but this might be a double with jq for
559 1 : // example.
560 1 : file_size: 9007199254741001,
561 1 : generation: Generation::none(),
562 1 : shard: ShardIndex::unsharded()
563 1 : })
564 1 : ]),
565 1 : disk_consistent_lsn: "0/16960E8".parse::<Lsn>().unwrap(),
566 1 : metadata: TimelineMetadata::from_bytes(&[113,11,159,210,0,54,0,4,0,0,0,0,1,105,96,232,1,0,0,0,0,1,105,96,112,0,0,0,0,0,0,0,0,0,0,0,0,0,1,105,96,112,0,0,0,0,1,105,96,112,0,0,0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ux_file_policy: None,
572 1 : import_pgdata: None,
573 1 : rel_size_migration: None,
574 1 : l2_lsn: None,
575 1 : gc_compaction: None,
576 1 : marked_invisible_at: None,
577 1 : };
578 :
579 1 : let part = IndexPart::from_json_bytes(example.as_bytes()).unwrap();
580 1 : assert_eq!(part, expected);
581 1 : }
582 :
583 : #[test]
584 1 : fn empty_layers_are_parsed() {
585 1 : let empty_layers_json = r#"{
586 1 : "version":1,
587 1 : "timeline_layers":[],
588 1 : "layer_metadata":{},
589 1 : "disk_consistent_lsn":"0/2532648",
590 1 : "metadata_bytes":[136,151,49,208,0,70,0,4,0,0,0,0,2,83,38,72,1,0,0,0,0,2,83,38,32,1,87,198,240,135,97,119,45,125,38,29,155,161,140,141,255,210,0,0,0,0,2,83,38,72,0,0,0,0,1,73,240,192,0,0,0,0,1,73,240,192,0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
591 1 : }"#;
592 :
593 1 : let expected = IndexPart {
594 1 : version: 1,
595 1 : layer_metadata: HashMap::new(),
596 1 : disk_consistent_lsn: "0/2532648".parse::<Lsn>().unwrap(),
597 1 : metadata: TimelineMetadata::from_bytes(&[
598 1 : 136, 151, 49, 208, 0, 70, 0, 4, 0, 0, 0, 0, 2, 83, 38, 72, 1, 0, 0, 0, 0, 2, 83,
599 1 : 38, 32, 1, 87, 198, 240, 135, 97, 119, 45, 125, 38, 29, 155, 161, 140, 141, 255,
600 1 : 210, 0, 0, 0, 0, 2, 83, 38, 72, 0, 0, 0, 0, 1, 73, 240, 192, 0, 0, 0, 0, 1, 73,
601 1 : 240, 192, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
602 1 : 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
603 1 : 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
604 1 : 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
605 1 : 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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 0, 0, 0, 0, 0, 0, 0,
617 1 : 0, 0,
618 1 : ])
619 1 : .unwrap(),
620 1 : deleted_at: None,
621 1 : archived_at: None,
622 1 : lineage: Lineage::default(),
623 1 : gc_blocking: None,
624 1 : last_aux_file_policy: None,
625 1 : import_pgdata: None,
626 1 : rel_size_migration: None,
627 1 : l2_lsn: None,
628 1 : gc_compaction: None,
629 1 : marked_invisible_at: None,
630 1 : };
631 :
632 1 : let empty_layers_parsed = IndexPart::from_json_bytes(empty_layers_json.as_bytes()).unwrap();
633 :
634 1 : assert_eq!(empty_layers_parsed, expected);
635 1 : }
636 :
637 : #[test]
638 1 : fn v4_indexpart_is_parsed() {
639 1 : let example = r#"{
640 1 : "version":4,
641 1 : "layer_metadata":{
642 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9": { "file_size": 25600000 },
643 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51": { "file_size": 9007199254741001 }
644 1 : },
645 1 : "disk_consistent_lsn":"0/16960E8",
646 1 : "metadata_bytes":[113,11,159,210,0,54,0,4,0,0,0,0,1,105,96,232,1,0,0,0,0,1,105,96,112,0,0,0,0,0,0,0,0,0,0,0,0,0,1,105,96,112,0,0,0,0,1,105,96,112,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
647 1 : "deleted_at": "2023-07-31T09:00:00.123"
648 1 : }"#;
649 :
650 1 : let expected = IndexPart {
651 1 : version: 4,
652 1 : layer_metadata: HashMap::from([
653 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9".parse().unwrap(), LayerFileMetadata {
654 1 : file_size: 25600000,
655 1 : generation: Generation::none(),
656 1 : shard: ShardIndex::unsharded()
657 1 : }),
658 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51".parse().unwrap(), LayerFileMetadata {
659 1 : // serde_json should always parse this but this might be a double with jq for
660 1 : // example.
661 1 : file_size: 9007199254741001,
662 1 : generation: Generation::none(),
663 1 : shard: Shard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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]).unwrap(),
668 1 : deleted_at: Some(parse_naive_datetime("2023-07-31T09:00:00.123000000")),
669 1 : archived_at: None,
670 1 : lineage: Lineage::default(),
671 1 : gc_blocking: None,
672 1 : last_aux_file_policy: None,
673 1 : import_pgdata: None,
674 1 : rel_size_migration: None,
675 1 : l2_lsn: None,
676 1 : gc_compaction: None,
677 1 : marked_invisible_at: None,
678 1 : };
679 :
680 1 : let part = IndexPart::from_json_bytes(example.as_bytes()).unwrap();
681 1 : assert_eq!(part, expected);
682 1 : }
683 :
684 : #[test]
685 1 : fn v5_indexpart_is_parsed() {
686 1 : let example = r#"{
687 1 : "version":5,
688 1 : "layer_metadata":{
689 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000014EF420-00000000014EF499":{"file_size":23289856,"generation":1},
690 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000014EF499-00000000015A7619":{"file_size":1015808,"generation":1}},
691 1 : "disk_consistent_lsn":"0/15A7618",
692 1 : "metadata_bytes":[226,88,25,241,0,46,0,4,0,0,0,0,1,90,118,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,78,244,32,0,0,0,0,1,78,244,32,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
693 1 : "lineage":{
694 1 : "original_ancestor":["e2bfd8c633d713d279e6fcd2bcc15b6d","0/15A7618","2024-05-07T18:52:36.322426563"],
695 1 : "reparenting_history":["e1bfd8c633d713d279e6fcd2bcc15b6d"]
696 1 : }
697 1 : }"#;
698 :
699 1 : let expected = IndexPart {
700 1 : version: 5,
701 1 : layer_metadata: HashMap::from([
702 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000014EF420-00000000014EF499".parse().unwrap(), LayerFileMetadata {
703 1 : file_size: 23289856,
704 1 : generation: Generation::new(1),
705 1 : shard: ShardIndex::unsharded(),
706 1 : }),
707 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000014EF499-00000000015A7619".parse().unwrap(), LayerFileMetadata {
708 1 : file_size: 1015808,
709 1 : generation: Generation::new(1),
710 1 : shard: ShardIndex::unsharded(),
711 1 : })
712 1 : ]),
713 1 : disk_consistent_lsn: Lsn::from_str("0/15A7618").unwrap(),
714 1 : metadata: TimelineMetadata::from_bytes(&[226,88,25,241,0,46,0,4,0,0,0,0,1,90,118,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,78,244,32,0,0,0,0,1,78,244,32,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]).unwrap(),
715 1 : deleted_at: None,
716 1 : archived_at: None,
717 1 : lineage: Lineage {
718 1 : reparenting_history_truncated: false,
719 1 : reparenting_history: vec![TimelineId::from_str("e1bfd8c633d713d279e6fcd2bcc15b6d").unwrap()],
720 1 : original_ancestor: Some((TimelineId::from_str("e2bfd8c633d713d279e6fcd2bcc15b6d").unwrap(), Lsn::from_str("0/15A7618").unwrap(), parse_naive_datetime("2024-05-07T18:52:36.322426563"))),
721 1 : },
722 1 : gc_blocking: None,
723 1 : last_aux_file_policy: None,
724 1 : import_pgdata: None,
725 1 : rel_size_migration: None,
726 1 : l2_lsn: None,
727 1 : gc_compaction: None,
728 1 : marked_invisible_at: None,
729 1 : };
730 :
731 1 : let part = IndexPart::from_json_bytes(example.as_bytes()).unwrap();
732 1 : assert_eq!(part, expected);
733 1 : }
734 :
735 : #[test]
736 1 : fn v6_indexpart_is_parsed() {
737 1 : let example = r#"{
738 1 : "version":6,
739 1 : "layer_metadata":{
740 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9": { "file_size": 25600000 },
741 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51": { "file_size": 9007199254741001 }
742 1 : },
743 1 : "disk_consistent_lsn":"0/16960E8",
744 1 : "metadata_bytes":[113,11,159,210,0,54,0,4,0,0,0,0,1,105,96,232,1,0,0,0,0,1,105,96,112,0,0,0,0,0,0,0,0,0,0,0,0,0,1,105,96,112,0,0,0,0,1,105,96,112,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36.322426563"],
748 1 : "reparenting_history":["e1bfd8c633d713d279e6fcd2bcc15b6d"]
749 1 : },
750 1 : "last_aux_file_policy": "V2"
751 1 : }"#;
752 :
753 1 : let expected = IndexPart {
754 1 : version: 6,
755 1 : layer_metadata: HashMap::from([
756 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9".parse().unwrap(), LayerFileMetadata {
757 1 : file_size: 25600000,
758 1 : generation: Generation::none(),
759 1 : shard: ShardIndex::unsharded()
760 1 : }),
761 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51".parse().unwrap(), LayerFileMetadata {
762 1 : // serde_json should always parse this but this might be a double with jq for
763 1 : // example.
764 1 : file_size: 9007199254741001,
765 1 : generation: Generation::none(),
766 1 : shard: ShardIndex::unsharded()
767 1 : })
768 1 : ]),
769 1 : disk_consistent_lsn: "0/16960E8".parse::<Lsn>().unwrap(),
770 1 : metadata: TimelineMetadata::from_bytes(&[113,11,159,210,0,54,0,4,0,0,0,0,1,105,96,232,1,0,0,0,0,1,105,96,112,0,0,0,0,0,0,0,0,0,0,0,0,0,1,105,96,112,0,0,0,0,1,105,96,112,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]).unwrap(),
771 1 : deleted_at: Some(parse_naive_datetime("2023-07-31T09:00:00.123000000")),
772 1 : archived_at: None,
773 1 : lineage: Lineage {
774 1 : reparenting_history_truncated: false,
775 1 : reparenting_history: vec![TimelineId::from_str("e1bfd8c633d713d279e6fcd2bcc15b6d").unwrap()],
776 1 : original_ancestor: Some((TimelineId::from_str("e2bfd8c633d713d279e6fcd2bcc15b6d").unwrap(), Lsn::from_str("0/15A7618").unwrap(), parse_naive_datetime("2024-05-07T18:52:36.322426563"))),
777 1 : },
778 1 : gc_blocking: None,
779 1 : last_aux_file_policy: Some(AuxFilePolicy::V2),
780 1 : import_pgdata: None,
781 1 : rel_size_migration: None,
782 1 : l2_lsn: None,
783 1 : gc_compaction: None,
784 1 : marked_invisible_at: None,
785 1 : };
786 :
787 1 : let part = IndexPart::from_json_bytes(example.as_bytes()).unwrap();
788 1 : assert_eq!(part, expected);
789 1 : }
790 :
791 : #[test]
792 1 : fn v7_indexpart_is_parsed() {
793 1 : let example = r#"{
794 1 : "version": 7,
795 1 : "layer_metadata":{
796 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9": { "file_size": 25600000 },
797 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51": { "file_size": 9007199254741001 }
798 1 : },
799 1 : "disk_consistent_lsn":"0/16960E8",
800 1 : "metadata": {
801 1 : "disk_consistent_lsn": "0/16960E8",
802 1 : "prev_record_lsn": "0/1696070",
803 1 : "ancestor_timeline": "e45a7f37d3ee2ff17dc14bf4f4e3f52e",
804 1 : "ancestor_lsn": "0/0",
805 1 : "latest_gc_cutoff_lsn": "0/1696070",
806 1 : "initdb_lsn": "0/1696070",
807 1 : "pg_version": 14
808 1 : },
809 1 : "deleted_at": "2023-07-31T09:00:00.123"
810 1 : }"#;
811 :
812 1 : let expected = IndexPart {
813 1 : version: 7,
814 1 : layer_metadata: HashMap::from([
815 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9".parse().unwrap(), LayerFileMetadata {
816 1 : file_size: 25600000,
817 1 : generation: Generation::none(),
818 1 : shard: ShardIndex::unsharded()
819 1 : }),
820 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51".parse().unwrap(), LayerFileMetadata {
821 1 : file_size: 9007199254741001,
822 1 : generation: Generation::none(),
823 1 : shard: ShardIndex::unsharded()
824 1 : })
825 1 : ]),
826 1 : disk_consistent_lsn: "0/16960E8".parse::<Lsn>().unwrap(),
827 1 : metadata: TimelineMetadata::new(
828 1 : Lsn::from_str("0/16960E8").unwrap(),
829 1 : Some(Lsn::from_str("0/1696070").unwrap()),
830 1 : Some(TimelineId::from_str("e45a7f37d3ee2ff17dc14bf4f4e3f52e").unwrap()),
831 1 : Lsn::INVALID,
832 1 : Lsn::from_str("0/1696070").unwrap(),
833 1 : Lsn::from_str("0/1696070").unwrap(),
834 1 : PgMajorVersion::PG14,
835 1 : ).with_recalculated_checksum().unwrap(),
836 1 : deleted_at: Some(parse_naive_datetime("2023-07-31T09:00:00.123000000")),
837 1 : archived_at: None,
838 1 : lineage: Default::default(),
839 1 : gc_blocking: None,
840 1 : last_aux_file_policy: Default::default(),
841 1 : import_pgdata: None,
842 1 : rel_size_migration: None,
843 1 : l2_lsn: None,
844 1 : gc_compaction: None,
845 1 : marked_invisible_at: None,
846 1 : };
847 :
848 1 : let part = IndexPart::from_json_bytes(example.as_bytes()).unwrap();
849 1 : assert_eq!(part, expected);
850 1 : }
851 :
852 : #[test]
853 1 : fn v8_indexpart_is_parsed() {
854 1 : let example = r#"{
855 1 : "version": 8,
856 1 : "layer_metadata":{
857 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9": { "file_size": 25600000 },
858 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51": { "file_size": 9007199254741001 }
859 1 : },
860 1 : "disk_consistent_lsn":"0/16960E8",
861 1 : "metadata": {
862 1 : "disk_consistent_lsn": "0/16960E8",
863 1 : "prev_record_lsn": "0/1696070",
864 1 : "ancestor_timeline": "e45a7f37d3ee2ff17dc14bf4f4e3f52e",
865 1 : "ancestor_lsn": "0/0",
866 1 : "latest_gc_cutoff_lsn": "0/1696070",
867 1 : "initdb_lsn": "0/1696070",
868 1 : "pg_version": 14
869 1 : },
870 1 : "deleted_at": "2023-07-31T09:00:00.123",
871 1 : "archived_at": "2023-04-29T09:00:00.123"
872 1 : }"#;
873 :
874 1 : let expected = IndexPart {
875 1 : version: 8,
876 1 : layer_metadata: HashMap::from([
877 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9".parse().unwrap(), LayerFileMetadata {
878 1 : file_size: 25600000,
879 1 : generation: Generation::none(),
880 1 : shard: ShardIndex::unsharded()
881 1 : }),
882 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51".parse().unwrap(), LayerFileMetadata {
883 1 : file_size: 9007199254741001,
884 1 : generation: Generation::none(),
885 1 : shard: ShardIndex::unsharded()
886 1 : })
887 1 : ]),
888 1 : disk_consistent_lsn: "0/16960E8".parse::<Lsn>().unwrap(),
889 1 : metadata: TimelineMetadata::new(
890 1 : Lsn::from_str("0/16960E8").unwrap(),
891 1 : Some(Lsn::from_str("0/1696070").unwrap()),
892 1 : Some(TimelineId::from_str("e45a7f37d3ee2ff17dc14bf4f4e3f52e").unwrap()),
893 1 : Lsn::INVALID,
894 1 : Lsn::from_str("0/1696070").unwrap(),
895 1 : Lsn::from_str("0/1696070").unwrap(),
896 1 : PgMajorVersion::PG14,
897 1 : ).with_recalculated_checksum().unwrap(),
898 1 : deleted_at: Some(parse_naive_datetime("2023-07-31T09:00:00.123000000")),
899 1 : archived_at: Some(parse_naive_datetime("2023-04-29T09:00:00.123000000")),
900 1 : lineage: Default::default(),
901 1 : gc_blocking: None,
902 1 : last_aux_file_policy: Default::default(),
903 1 : import_pgdata: None,
904 1 : rel_size_migration: None,
905 1 : l2_lsn: None,
906 1 : gc_compaction: None,
907 1 : marked_invisible_at: None,
908 1 : };
909 :
910 1 : let part = IndexPart::from_json_bytes(example.as_bytes()).unwrap();
911 1 : assert_eq!(part, expected);
912 1 : }
913 :
914 : #[test]
915 1 : fn v9_indexpart_is_parsed() {
916 1 : let example = r#"{
917 1 : "version": 9,
918 1 : "layer_metadata":{
919 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9": { "file_size": 25600000 },
920 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51": { "file_size": 9007199254741001 }
921 1 : },
922 1 : "disk_consistent_lsn":"0/16960E8",
923 1 : "metadata": {
924 1 : "disk_consistent_lsn": "0/16960E8",
925 1 : "prev_record_lsn": "0/1696070",
926 1 : "ancestor_timeline": "e45a7f37d3ee2ff17dc14bf4f4e3f52e",
927 1 : "ancestor_lsn": "0/0",
928 1 : "latest_gc_cutoff_lsn": "0/1696070",
929 1 : "initdb_lsn": "0/1696070",
930 1 : "pg_version": 14
931 1 : },
932 1 : "gc_blocking": {
933 1 : "started_at": "2024-07-19T09:00:00.123",
934 1 : "reasons": ["DetachAncestor"]
935 1 : }
936 1 : }"#;
937 :
938 1 : let expected = IndexPart {
939 1 : version: 9,
940 1 : layer_metadata: HashMap::from([
941 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9".parse().unwrap(), LayerFileMetadata {
942 1 : file_size: 25600000,
943 1 : generation: Generation::none(),
944 1 : shard: ShardIndex::unsharded()
945 1 : }),
946 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51".parse().unwrap(), LayerFileMetadata {
947 1 : file_size: 9007199254741001,
948 1 : generation: Generation::none(),
949 1 : shard: ShardIndex::unsharded()
950 1 : })
951 1 : ]),
952 1 : disk_consistent_lsn: "0/16960E8".parse::<Lsn>().unwrap(),
953 1 : metadata: TimelineMetadata::new(
954 1 : Lsn::from_str("0/16960E8").unwrap(),
955 1 : Some(Lsn::from_str("0/1696070").unwrap()),
956 1 : Some(TimelineId::from_str("e45a7f37d3ee2ff17dc14bf4f4e3f52e").unwrap()),
957 1 : Lsn::INVALID,
958 1 : Lsn::from_str("0/1696070").unwrap(),
959 1 : Lsn::from_str("0/1696070").unwrap(),
960 1 : PgMajorVersion::PG14,
961 1 : ).with_recalculated_checksum().unwrap(),
962 1 : deleted_at: None,
963 1 : lineage: Default::default(),
964 1 : gc_blocking: Some(GcBlocking {
965 1 : started_at: parse_naive_datetime("2024-07-19T09:00:00.123000000"),
966 1 : reasons: enumset::EnumSet::from_iter([GcBlockingReason::DetachAncestor]),
967 1 : }),
968 1 : last_aux_file_policy: Default::default(),
969 1 : archived_at: None,
970 1 : import_pgdata: None,
971 1 : rel_size_migration: None,
972 1 : l2_lsn: None,
973 1 : gc_compaction: None,
974 1 : marked_invisible_at: None,
975 1 : };
976 :
977 1 : let part = IndexPart::from_json_bytes(example.as_bytes()).unwrap();
978 1 : assert_eq!(part, expected);
979 1 : }
980 :
981 : #[test]
982 1 : fn v10_importpgdata_is_parsed() {
983 1 : let example = r#"{
984 1 : "version": 10,
985 1 : "layer_metadata":{
986 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9": { "file_size": 25600000 },
987 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51": { "file_size": 9007199254741001 }
988 1 : },
989 1 : "disk_consistent_lsn":"0/16960E8",
990 1 : "metadata": {
991 1 : "disk_consistent_lsn": "0/16960E8",
992 1 : "prev_record_lsn": "0/1696070",
993 1 : "ancestor_timeline": "e45a7f37d3ee2ff17dc14bf4f4e3f52e",
994 1 : "ancestor_lsn": "0/0",
995 1 : "latest_gc_cutoff_lsn": "0/1696070",
996 1 : "initdb_lsn": "0/1696070",
997 1 : "pg_version": 14
998 1 : },
999 1 : "gc_blocking": {
1000 1 : "started_at": "2024-07-19T09:00:00.123",
1001 1 : "reasons": ["DetachAncestor"]
1002 1 : },
1003 1 : "import_pgdata": {
1004 1 : "V1": {
1005 1 : "Done": {
1006 1 : "idempotency_key": "specified-by-client-218a5213-5044-4562-a28d-d024c5f057f5",
1007 1 : "started_at": "2024-11-13T09:23:42.123",
1008 1 : "finished_at": "2024-11-13T09:42:23.123"
1009 1 : }
1010 1 : }
1011 1 : }
1012 1 : }"#;
1013 :
1014 1 : let expected = IndexPart {
1015 1 : version: 10,
1016 1 : layer_metadata: HashMap::from([
1017 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9".parse().unwrap(), LayerFileMetadata {
1018 1 : file_size: 25600000,
1019 1 : generation: Generation::none(),
1020 1 : shard: ShardIndex::unsharded()
1021 1 : }),
1022 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51".parse().unwrap(), LayerFileMetadata {
1023 1 : file_size: 9007199254741001,
1024 1 : generation: Generation::none(),
1025 1 : shard: ShardIndex::unsharded()
1026 1 : })
1027 1 : ]),
1028 1 : disk_consistent_lsn: "0/16960E8".parse::<Lsn>().unwrap(),
1029 1 : metadata: TimelineMetadata::new(
1030 1 : Lsn::from_str("0/16960E8").unwrap(),
1031 1 : Some(Lsn::from_str("0/1696070").unwrap()),
1032 1 : Some(TimelineId::from_str("e45a7f37d3ee2ff17dc14bf4f4e3f52e").unwrap()),
1033 1 : Lsn::INVALID,
1034 1 : Lsn::from_str("0/1696070").unwrap(),
1035 1 : Lsn::from_str("0/1696070").unwrap(),
1036 1 : PgMajorVersion::PG14,
1037 1 : ).with_recalculated_checksum().unwrap(),
1038 1 : deleted_at: None,
1039 1 : lineage: Default::default(),
1040 1 : gc_blocking: Some(GcBlocking {
1041 1 : started_at: parse_naive_datetime("2024-07-19T09:00:00.123000000"),
1042 1 : reasons: enumset::EnumSet::from_iter([GcBlockingReason::DetachAncestor]),
1043 1 : }),
1044 1 : last_aux_file_policy: Default::default(),
1045 1 : archived_at: None,
1046 1 : import_pgdata: Some(import_pgdata::index_part_format::Root::V1(import_pgdata::index_part_format::V1::Done(import_pgdata::index_part_format::Done{
1047 1 : started_at: parse_naive_datetime("2024-11-13T09:23:42.123000000"),
1048 1 : finished_at: parse_naive_datetime("2024-11-13T09:42:23.123000000"),
1049 1 : idempotency_key: import_pgdata::index_part_format::IdempotencyKey::new("specified-by-client-218a5213-5044-4562-a28d-d024c5f057f5".to_string()),
1050 1 : }))),
1051 1 : rel_size_migration: None,
1052 1 : l2_lsn: None,
1053 1 : gc_compaction: None,
1054 1 : marked_invisible_at: None,
1055 1 : };
1056 :
1057 1 : let part = IndexPart::from_json_bytes(example.as_bytes()).unwrap();
1058 1 : assert_eq!(part, expected);
1059 1 : }
1060 :
1061 : #[test]
1062 1 : fn v11_rel_size_migration_is_parsed() {
1063 1 : let example = r#"{
1064 1 : "version": 11,
1065 1 : "layer_metadata":{
1066 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9": { "file_size": 25600000 },
1067 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51": { "file_size": 9007199254741001 }
1068 1 : },
1069 1 : "disk_consistent_lsn":"0/16960E8",
1070 1 : "metadata": {
1071 1 : "disk_consistent_lsn": "0/16960E8",
1072 1 : "prev_record_lsn": "0/1696070",
1073 1 : "ancestor_timeline": "e45a7f37d3ee2ff17dc14bf4f4e3f52e",
1074 1 : "ancestor_lsn": "0/0",
1075 1 : "latest_gc_cutoff_lsn": "0/1696070",
1076 1 : "initdb_lsn": "0/1696070",
1077 1 : "pg_version": 14
1078 1 : },
1079 1 : "gc_blocking": {
1080 1 : "started_at": "2024-07-19T09:00:00.123",
1081 1 : "reasons": ["DetachAncestor"]
1082 1 : },
1083 1 : "import_pgdata": {
1084 1 : "V1": {
1085 1 : "Done": {
1086 1 : "idempotency_key": "specified-by-client-218a5213-5044-4562-a28d-d024c5f057f5",
1087 1 : "started_at": "2024-11-13T09:23:42.123",
1088 1 : "finished_at": "2024-11-13T09:42:23.123"
1089 1 : }
1090 1 : }
1091 1 : },
1092 1 : "rel_size_migration": "legacy"
1093 1 : }"#;
1094 :
1095 1 : let expected = IndexPart {
1096 1 : version: 11,
1097 1 : layer_metadata: HashMap::from([
1098 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9".parse().unwrap(), LayerFileMetadata {
1099 1 : file_size: 25600000,
1100 1 : generation: Generation::none(),
1101 1 : shard: ShardIndex::unsharded()
1102 1 : }),
1103 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51".parse().unwrap(), LayerFileMetadata {
1104 1 : file_size: 9007199254741001,
1105 1 : generation: Generation::none(),
1106 1 : shard: ShardIndex::unsharded()
1107 1 : })
1108 1 : ]),
1109 1 : disk_consistent_lsn: "0/16960E8".parse::<Lsn>().unwrap(),
1110 1 : metadata: TimelineMetadata::new(
1111 1 : Lsn::from_str("0/16960E8").unwrap(),
1112 1 : Some(Lsn::from_str("0/1696070").unwrap()),
1113 1 : Some(TimelineId::from_str("e45a7f37d3ee2ff17dc14bf4f4e3f52e").unwrap()),
1114 1 : Lsn::INVALID,
1115 1 : Lsn::from_str("0/1696070").unwrap(),
1116 1 : Lsn::from_str("0/1696070").unwrap(),
1117 1 : PgMajorVersion::PG14,
1118 1 : ).with_recalculated_checksum().unwrap(),
1119 1 : deleted_at: None,
1120 1 : lineage: Default::default(),
1121 1 : gc_blocking: Some(GcBlocking {
1122 1 : started_at: parse_naive_datetime("2024-07-19T09:00:00.123000000"),
1123 1 : reasons: enumset::EnumSet::from_iter([GcBlockingReason::DetachAncestor]),
1124 1 : }),
1125 1 : last_aux_file_policy: Default::default(),
1126 1 : archived_at: None,
1127 1 : import_pgdata: Some(import_pgdata::index_part_format::Root::V1(import_pgdata::index_part_format::V1::Done(import_pgdata::index_part_format::Done{
1128 1 : started_at: parse_naive_datetime("2024-11-13T09:23:42.123000000"),
1129 1 : finished_at: parse_naive_datetime("2024-11-13T09:42:23.123000000"),
1130 1 : idempotency_key: import_pgdata::index_part_format::IdempotencyKey::new("specified-by-client-218a5213-5044-4562-a28d-d024c5f057f5".to_string()),
1131 1 : }))),
1132 1 : rel_size_migration: Some(RelSizeMigration::Legacy),
1133 1 : l2_lsn: None,
1134 1 : gc_compaction: None,
1135 1 : marked_invisible_at: None,
1136 1 : };
1137 :
1138 1 : let part = IndexPart::from_json_bytes(example.as_bytes()).unwrap();
1139 1 : assert_eq!(part, expected);
1140 1 : }
1141 :
1142 : #[test]
1143 1 : fn v12_v13_l2_gc_ompaction_is_parsed() {
1144 1 : let example = r#"{
1145 1 : "version": 13,
1146 1 : "layer_metadata":{
1147 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9": { "file_size": 25600000 },
1148 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51": { "file_size": 9007199254741001 }
1149 1 : },
1150 1 : "disk_consistent_lsn":"0/16960E8",
1151 1 : "metadata": {
1152 1 : "disk_consistent_lsn": "0/16960E8",
1153 1 : "prev_record_lsn": "0/1696070",
1154 1 : "ancestor_timeline": "e45a7f37d3ee2ff17dc14bf4f4e3f52e",
1155 1 : "ancestor_lsn": "0/0",
1156 1 : "latest_gc_cutoff_lsn": "0/1696070",
1157 1 : "initdb_lsn": "0/1696070",
1158 1 : "pg_version": 14
1159 1 : },
1160 1 : "gc_blocking": {
1161 1 : "started_at": "2024-07-19T09:00:00.123",
1162 1 : "reasons": ["DetachAncestor"]
1163 1 : },
1164 1 : "import_pgdata": {
1165 1 : "V1": {
1166 1 : "Done": {
1167 1 : "idempotency_key": "specified-by-client-218a5213-5044-4562-a28d-d024c5f057f5",
1168 1 : "started_at": "2024-11-13T09:23:42.123",
1169 1 : "finished_at": "2024-11-13T09:42:23.123"
1170 1 : }
1171 1 : }
1172 1 : },
1173 1 : "rel_size_migration": "legacy",
1174 1 : "l2_lsn": "0/16960E8",
1175 1 : "gc_compaction": {
1176 1 : "last_completed_lsn": "0/16960E8"
1177 1 : }
1178 1 : }"#;
1179 :
1180 1 : let expected = IndexPart {
1181 1 : version: 13,
1182 1 : layer_metadata: HashMap::from([
1183 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9".parse().unwrap(), LayerFileMetadata {
1184 1 : file_size: 25600000,
1185 1 : generation: Generation::none(),
1186 1 : shard: ShardIndex::unsharded()
1187 1 : }),
1188 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51".parse().unwrap(), LayerFileMetadata {
1189 1 : file_size: 9007199254741001,
1190 1 : generation: Generation::none(),
1191 1 : shard: ShardIndex::unsharded()
1192 1 : })
1193 1 : ]),
1194 1 : disk_consistent_lsn: "0/16960E8".parse::<Lsn>().unwrap(),
1195 1 : metadata: TimelineMetadata::new(
1196 1 : Lsn::from_str("0/16960E8").unwrap(),
1197 1 : Some(Lsn::from_str("0/1696070").unwrap()),
1198 1 : Some(TimelineId::from_str("e45a7f37d3ee2ff17dc14bf4f4e3f52e").unwrap()),
1199 1 : Lsn::INVALID,
1200 1 : Lsn::from_str("0/1696070").unwrap(),
1201 1 : Lsn::from_str("0/1696070").unwrap(),
1202 1 : PgMajorVersion::PG14,
1203 1 : ).with_recalculated_checksum().unwrap(),
1204 1 : deleted_at: None,
1205 1 : lineage: Default::default(),
1206 1 : gc_blocking: Some(GcBlocking {
1207 1 : started_at: parse_naive_datetime("2024-07-19T09:00:00.123000000"),
1208 1 : reasons: enumset::EnumSet::from_iter([GcBlockingReason::DetachAncestor]),
1209 1 : }),
1210 1 : last_aux_file_policy: Default::default(),
1211 1 : archived_at: None,
1212 1 : import_pgdata: Some(import_pgdata::index_part_format::Root::V1(import_pgdata::index_part_format::V1::Done(import_pgdata::index_part_format::Done{
1213 1 : started_at: parse_naive_datetime("2024-11-13T09:23:42.123000000"),
1214 1 : finished_at: parse_naive_datetime("2024-11-13T09:42:23.123000000"),
1215 1 : idempotency_key: import_pgdata::index_part_format::IdempotencyKey::new("specified-by-client-218a5213-5044-4562-a28d-d024c5f057f5".to_string()),
1216 1 : }))),
1217 1 : rel_size_migration: Some(RelSizeMigration::Legacy),
1218 1 : l2_lsn: Some("0/16960E8".parse::<Lsn>().unwrap()),
1219 1 : gc_compaction: Some(GcCompactionState {
1220 1 : last_completed_lsn: "0/16960E8".parse::<Lsn>().unwrap(),
1221 1 : }),
1222 1 : marked_invisible_at: None,
1223 1 : };
1224 :
1225 1 : let part = IndexPart::from_json_bytes(example.as_bytes()).unwrap();
1226 1 : assert_eq!(part, expected);
1227 1 : }
1228 :
1229 : #[test]
1230 1 : fn v14_marked_invisible_at_is_parsed() {
1231 1 : let example = r#"{
1232 1 : "version": 14,
1233 1 : "layer_metadata":{
1234 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9": { "file_size": 25600000 },
1235 1 : "000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51": { "file_size": 9007199254741001 }
1236 1 : },
1237 1 : "disk_consistent_lsn":"0/16960E8",
1238 1 : "metadata": {
1239 1 : "disk_consistent_lsn": "0/16960E8",
1240 1 : "prev_record_lsn": "0/1696070",
1241 1 : "ancestor_timeline": "e45a7f37d3ee2ff17dc14bf4f4e3f52e",
1242 1 : "ancestor_lsn": "0/0",
1243 1 : "latest_gc_cutoff_lsn": "0/1696070",
1244 1 : "initdb_lsn": "0/1696070",
1245 1 : "pg_version": 14
1246 1 : },
1247 1 : "gc_blocking": {
1248 1 : "started_at": "2024-07-19T09:00:00.123",
1249 1 : "reasons": ["DetachAncestor"]
1250 1 : },
1251 1 : "import_pgdata": {
1252 1 : "V1": {
1253 1 : "Done": {
1254 1 : "idempotency_key": "specified-by-client-218a5213-5044-4562-a28d-d024c5f057f5",
1255 1 : "started_at": "2024-11-13T09:23:42.123",
1256 1 : "finished_at": "2024-11-13T09:42:23.123"
1257 1 : }
1258 1 : }
1259 1 : },
1260 1 : "rel_size_migration": "legacy",
1261 1 : "l2_lsn": "0/16960E8",
1262 1 : "gc_compaction": {
1263 1 : "last_completed_lsn": "0/16960E8"
1264 1 : },
1265 1 : "marked_invisible_at": "2023-07-31T09:00:00.123"
1266 1 : }"#;
1267 :
1268 1 : let expected = IndexPart {
1269 1 : version: 14,
1270 1 : layer_metadata: HashMap::from([
1271 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__0000000001696070-00000000016960E9".parse().unwrap(), LayerFileMetadata {
1272 1 : file_size: 25600000,
1273 1 : generation: Generation::none(),
1274 1 : shard: ShardIndex::unsharded()
1275 1 : }),
1276 1 : ("000000000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF__00000000016B59D8-00000000016B5A51".parse().unwrap(), LayerFileMetadata {
1277 1 : file_size: 9007199254741001,
1278 1 : generation: Generation::none(),
1279 1 : shard: ShardIndex::unsharded()
1280 1 : })
1281 1 : ]),
1282 1 : disk_consistent_lsn: "0/16960E8".parse::<Lsn>().unwrap(),
1283 1 : metadata: TimelineMetadata::new(
1284 1 : Lsn::from_str("0/16960E8").unwrap(),
1285 1 : Some(Lsn::from_str("0/1696070").unwrap()),
1286 1 : Some(TimelineId::from_str("e45a7f37d3ee2ff17dc14bf4f4e3f52e").unwrap()),
1287 1 : Lsn::INVALID,
1288 1 : Lsn::from_str("0/1696070").unwrap(),
1289 1 : Lsn::from_str("0/1696070").unwrap(),
1290 1 : PgMajorVersion::PG14,
1291 1 : ).with_recalculated_checksum().unwrap(),
1292 1 : deleted_at: None,
1293 1 : lineage: Default::default(),
1294 1 : gc_blocking: Some(GcBlocking {
1295 1 : started_at: parse_naive_datetime("2024-07-19T09:00:00.123000000"),
1296 1 : reasons: enumset::EnumSet::from_iter([GcBlockingReason::DetachAncestor]),
1297 1 : }),
1298 1 : last_aux_file_policy: Default::default(),
1299 1 : archived_at: None,
1300 1 : import_pgdata: Some(import_pgdata::index_part_format::Root::V1(import_pgdata::index_part_format::V1::Done(import_pgdata::index_part_format::Done{
1301 1 : started_at: parse_naive_datetime("2024-11-13T09:23:42.123000000"),
1302 1 : finished_at: parse_naive_datetime("2024-11-13T09:42:23.123000000"),
1303 1 : idempotency_key: import_pgdata::index_part_format::IdempotencyKey::new("specified-by-client-218a5213-5044-4562-a28d-d024c5f057f5".to_string()),
1304 1 : }))),
1305 1 : rel_size_migration: Some(RelSizeMigration::Legacy),
1306 1 : l2_lsn: Some("0/16960E8".parse::<Lsn>().unwrap()),
1307 1 : gc_compaction: Some(GcCompactionState {
1308 1 : last_completed_lsn: "0/16960E8".parse::<Lsn>().unwrap(),
1309 1 : }),
1310 1 : marked_invisible_at: Some(parse_naive_datetime("2023-07-31T09:00:00.123000000")),
1311 1 : };
1312 :
1313 1 : let part = IndexPart::from_json_bytes(example.as_bytes()).unwrap();
1314 1 : assert_eq!(part, expected);
1315 1 : }
1316 :
1317 22 : fn parse_naive_datetime(s: &str) -> NaiveDateTime {
1318 22 : chrono::NaiveDateTime::parse_from_str(s, "%Y-%m-%dT%H:%M:%S.%f").unwrap()
1319 22 : }
1320 : }
|