Put back check that a timeline must have ancestor or some layer files.

This commit is contained in:
Heikki Linnakangas
2022-11-25 21:48:30 +02:00
parent 3eb85957df
commit fdfa86b5b0
2 changed files with 16 additions and 6 deletions

View File

@@ -471,7 +471,7 @@ impl Tenant {
.create_timeline_data(
timeline_id,
up_to_date_metadata.clone(),
ancestor,
ancestor.clone(),
None,
)
.with_context(|| {
@@ -499,6 +499,13 @@ impl Tenant {
.context("failed to reconcile with remote")?
}
// Sanity check: a timeline should have some content.
anyhow::ensure!(
ancestor.is_some() ||
timeline.layers.read().unwrap().iter_historic_layers().next().is_some(),
"Timeline has no ancestor and no layer files"
);
// Save the metadata file to local disk.
if !picked_local {
save_metadata(

View File

@@ -20,6 +20,7 @@ def test_broken_timeline(neon_env_builder: NeonEnvBuilder):
".*is not active. Current state: Broken.*",
".*will not become active. Current state: Broken.*",
".*failed to load metadata.*",
".*could not load tenant.*load local timeline.*",
]
)
@@ -86,12 +87,14 @@ def test_broken_timeline(neon_env_builder: NeonEnvBuilder):
f"As expected, compute startup failed eagerly for timeline with corrupt metadata: {err}"
)
# Second timeline has no ancestors, only the metadata file and no layer files
# This will fail with an error like "extracting base backup failed" and cause
# "could not find data for key"
with pytest.raises(Exception, match=".*could not find data for key.*") as err:
# Second timeline has no ancestors, only the metadata file and no layer files.
# That is checked explicitly in the pageserver, and causes the tenant to be marked
# as broken.
with pytest.raises(
Exception, match=f"Tenant {tenant2} will not become active. Current state: Broken"
) as err:
pg2.start()
log.info(f"As expected, compute startup failed eagerly for timeline with missing layers: {err}")
log.info(f"As expected, compute startup failed for timeline with missing layers: {err}")
# Third timeline will also fail during basebackup, because the layer file is corrupt.
# (We don't check layer file contents on startup, when loading the timeline)