Commit 4a4a457
authored
fix(pageserver): frozen->L0 flush failure causes data loss (neondatabase#12043)
This patch is a fixup for
- neondatabase#6788
Background
----------
That PR 6788 added artificial advancement of `disk_consistent_lsn`
and `remote_consistent_lsn` for shards that weren't written to
while other shards _were_ written to.
See the PR description for more context.
At the time of that PR, Pageservers shards were doing WAL filtering.
Nowadays, the WAL filtering happens in Safekeepers.
Shards learn about the WAL gaps via
`InterpretedWalRecords::next_record_lsn`.
The Bug
-------
That artificial advancement code also runs if the flush failed.
So, we advance the disk_consistent_lsn / remote_consistent_lsn,
without having the corresponding L0 to the `index_part.json`.
The frozen layer remains in the layer map until detach,
so we continue to serve data correctly.
We're not advancing flush loop variable `flushed_to_lsn` either,
so, subsequent flush requests will retry the flush and repair the
situation if they succeed.
But if there aren't any successful retries, eventually the tenant
will be detached and when it is attached somewhere else, the
`index_part.json` and therefore layer map...
1. ... does not contain the frozen layer that failed to flush and
2. ... won't re-ingest that WAL either because walreceiver
starts up with the advanced disk_consistent_lsn/remote_consistent_lsn.
The result is that the read path will have a gap in the reconstruct
data for the keys whose modifications were lost, resulting in
a) either walredo failure
b) or an incorrect page@lsn image if walredo doesn't error.
The Fix
-------
The fix is to only do the artificial advancement if `result.is_ok()`.
Misc
----
As an aside, I took some time to re-review the flush loop and its
callers.
I found one more bug related to error handling that I filed here:
- neondatabase#12025
## Problem
## Summary of changes1 parent e78d1e2 commit 4a4a457
2 files changed
+83
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5832 | 5832 | | |
5833 | 5833 | | |
5834 | 5834 | | |
| 5835 | + | |
5835 | 5836 | | |
5836 | 5837 | | |
5837 | 5838 | | |
| |||
5899 | 5900 | | |
5900 | 5901 | | |
5901 | 5902 | | |
| 5903 | + | |
5902 | 5904 | | |
5903 | 5905 | | |
5904 | 5906 | | |
| |||
5960 | 5962 | | |
5961 | 5963 | | |
5962 | 5964 | | |
5963 | | - | |
5964 | | - | |
| 5965 | + | |
5965 | 5966 | | |
5966 | 5967 | | |
5967 | 5968 | | |
| |||
6083 | 6084 | | |
6084 | 6085 | | |
6085 | 6086 | | |
| 6087 | + | |
6086 | 6088 | | |
6087 | 6089 | | |
6088 | 6090 | | |
| |||
9418 | 9420 | | |
9419 | 9421 | | |
9420 | 9422 | | |
| 9423 | + | |
| 9424 | + | |
| 9425 | + | |
| 9426 | + | |
| 9427 | + | |
| 9428 | + | |
| 9429 | + | |
| 9430 | + | |
| 9431 | + | |
| 9432 | + | |
| 9433 | + | |
| 9434 | + | |
| 9435 | + | |
| 9436 | + | |
| 9437 | + | |
| 9438 | + | |
| 9439 | + | |
| 9440 | + | |
| 9441 | + | |
| 9442 | + | |
| 9443 | + | |
| 9444 | + | |
| 9445 | + | |
| 9446 | + | |
| 9447 | + | |
| 9448 | + | |
| 9449 | + | |
| 9450 | + | |
| 9451 | + | |
| 9452 | + | |
| 9453 | + | |
| 9454 | + | |
| 9455 | + | |
| 9456 | + | |
| 9457 | + | |
| 9458 | + | |
| 9459 | + | |
| 9460 | + | |
| 9461 | + | |
| 9462 | + | |
| 9463 | + | |
| 9464 | + | |
| 9465 | + | |
| 9466 | + | |
| 9467 | + | |
| 9468 | + | |
| 9469 | + | |
| 9470 | + | |
| 9471 | + | |
| 9472 | + | |
| 9473 | + | |
| 9474 | + | |
| 9475 | + | |
| 9476 | + | |
| 9477 | + | |
| 9478 | + | |
| 9479 | + | |
| 9480 | + | |
| 9481 | + | |
| 9482 | + | |
| 9483 | + | |
| 9484 | + | |
| 9485 | + | |
| 9486 | + | |
| 9487 | + | |
| 9488 | + | |
| 9489 | + | |
| 9490 | + | |
| 9491 | + | |
| 9492 | + | |
| 9493 | + | |
9421 | 9494 | | |
9422 | 9495 | | |
9423 | 9496 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4767 | 4767 | | |
4768 | 4768 | | |
4769 | 4769 | | |
4770 | | - | |
| 4770 | + | |
| 4771 | + | |
| 4772 | + | |
| 4773 | + | |
4771 | 4774 | | |
4772 | 4775 | | |
4773 | 4776 | | |
| |||
4946 | 4949 | | |
4947 | 4950 | | |
4948 | 4951 | | |
| 4952 | + | |
| 4953 | + | |
| 4954 | + | |
| 4955 | + | |
4949 | 4956 | | |
4950 | 4957 | | |
4951 | 4958 | | |
| |||
0 commit comments