Skip to content

Commit

Permalink
pageserver: fix layer reconciliation with generations
Browse files Browse the repository at this point in the history
This was wrongly assuming generations should be the same: the local
metadata will actually always have the current generation set, and
in this situation we want to UseLocal if the sizes match, but take
the metadata (generation) from the remote metadata.
  • Loading branch information
jcsp committed Sep 6, 2023
1 parent 966b5e3 commit 606a392
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
17 changes: 12 additions & 5 deletions pageserver/src/tenant/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1724,11 +1724,18 @@ impl Timeline {
for (name, decision) in decided {
let decision = match decision {
Ok(UseRemote { local, remote }) => {
path.push(name.file_name());
init::cleanup_local_file_for_remote(&path, &local, &remote)?;
path.pop();

UseRemote { local, remote }
// Remote is authoritative, but we may still choose to retain
// the local file if the contents appear to match
if local.file_size() == remote.file_size() {
// Use the local file, but take the remote metadata so that we pick up
// the correct generation.
UseLocal(remote)
} else {
path.push(name.file_name());
init::cleanup_local_file_for_remote(&path, &local, &remote)?;
path.pop();
UseRemote { local, remote }
}
}
Ok(decision) => decision,
Err(FutureLayer { local }) => {
Expand Down
6 changes: 1 addition & 5 deletions pageserver/src/tenant/timeline/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,7 @@ pub(super) fn reconcile(
Err(FutureLayer { local })
} else {
Ok(match (local, remote) {
(Some(local), Some(remote)) if local != remote => {
assert_eq!(local.generation, remote.generation);

UseRemote { local, remote }
}
(Some(local), Some(remote)) if local != remote => UseRemote { local, remote },
(Some(x), Some(_)) => UseLocal(x),
(None, Some(x)) => Evicted(x),
(Some(x), None) => NeedsUpload(x),
Expand Down

0 comments on commit 606a392

Please sign in to comment.