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