8000 fix(inkless:switch): keep consolidated records past a lowered seal [KC-837] by giuseppelillo · Pull Request #884 · aiven/inkless · GitHub
[go: up one dir, main page]

Skip to content

fix(inkless:switch): keep consolidated records past a lowered seal [KC-837] - #884

Closed
giuseppelillo wants to merge 1 commit into
mainfrom
claude/verify-kc-837-issue-d0a8eb
Closed

giuseppelillo wants to merge 1 commit into
mainfrom
claude/verify-kc-837-issue-d0a8eb

Conversation

@giuseppelillo
@giuseppelillo giuseppelillo commented Nov 19, 2026 •
Copy link
Copy Markdown
Contributor

lower-seal moves the committed seal from S to S' < S, but the diskless log still starts at S. Consolidation fetches at S' and appends the first diskless batch at S, so every replica's leader epoch cache maps [S', S) to the last classic epoch. hasConsolidatedDisklessSuffixFromSeal read the epoch at the seal, got that classic epoch, and reported the consolidated records as a classic tail. maybeTruncateSwitchedFollower and maybeReconcileSwitchedLeader then truncated them to S', and divergenceFromCommittedHistory recreated the replica on a new leader epoch.

This hit every replica in phase 2. The leader that the seal was lowered to has the diskless leader epoch at S' from makeLeader, but the restart that the recovery needs bumps its leader epoch. The consolidated batch then replaces that entry with the diskless leader epoch at S.

hasConsolidatedDisklessSuffixFromSeal now starts its proof at the first local batch that holds an offset at or past the seal. A batch that spans the seal still starts the proof at the seal. A classic record past the seal still fails the check. The check reads the log, not a cache entry that only consolidation writes, so it gives the same answer after a log directory move or a rebuild from remote storage.

Test plan

  • ReplicaManagerInklessTest.testSwitchedReplicaKeepsConsolidatedRecordsAfterLoweredSeal applies a phase 2 delta with a new leader epoch to a replica with classic records [0, 7), a lowered seal 7, and consolidated records [10, 13) in the diskless leader epoch. Its cache maps 7 to epoch 0. The replica keeps its log as a leader, as a leader whose cache had a later epoch at 7 before the append, and as a follower.
  • testSwitchedFollowerTruncatesOnlyClassicTailPastLoweredSeal applies a phase 1 follower delta. The follower keeps [10, 13) when its classic records end at the seal, and truncates to the seal when it holds a classic tail [7, 9).
  • With the previous check, the four cases that keep the log fail, and the classic-tail case passes.
  • ReplicaManagerInklessTest and ConsolidationFetcherThreadTest pass.
  • No cluster test takes a lowered seal through phase 2.

🤖 Generated with Claude Code

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The repaired epoch boundary can be lost during future-log promotion or log-directory moves, allowing a later leader-epoch change to truncate or recreate the consolidated log.

2 open issues
What changed in this PR

This PR fixes lowered-seal recovery by starting the diskless leader epoch at the committed seal, even when the first consolidated batch starts later. This helps replicas retain valid consolidated records across leader-epoch changes.

Changes:

  • Assign the diskless epoch at the seal before appending a batch that starts past it.
  • Add regression tests for epoch assignment and record retention on leaders and followers.
  • Document the lowered-seal behavior.
File Description
docs/​inkless/​DISKLESS_CONSOLIDATION.md Explain epoch-cache repair when the first batch starts past the seal.
docs/​inkless/​CLASSIC_TO_DISKLESS_SWITCH.md Document consolidated-record retention after lowering the seal.
core/​src/​test/​scala/​unit/​kafka/​server/​ReplicaManagerInklessTest.scala Test record retention across leader and follower transitions.
core/​src/​test/​scala/​io/​aiven/​inkless/​consolidation/​ConsolidationFetcherThreadTest.scala Test lowered-seal epoch assignment and the no-gap case.
core/​src/​main/​scala/​io/​aiven/​inkless/​consolidation/​ConsolidationFetcherThread.scala Assign the diskless epoch at the seal before appending across a gap.

Review effort: Balanced

@giuseppelillo giuseppelillo changed the title fix(inkless:switch): start the diskless leader epoch at a lowered seal [KC-837] fix(inkless:switch): keep consolidated records past a lowered seal [KC-837] Nov 19, 2026
…C-837]

`lower-seal` moves the committed seal from `S` to `S' < S`, but the
diskless log still starts at `S`. Consolidation fetches at `S'` and
appends the first diskless batch at `S`, so every replica's leader epoch
cache maps `[S', S)` to the last classic epoch.
`hasConsolidatedDisklessSuffixFromSeal` read the epoch at the seal, got
that classic epoch, and reported the consolidated records as a classic
tail. `maybeTruncateSwitchedFollower` and `maybeReconcileSwitchedLeader`
then truncated them to `S'`, and `divergenceFromCommittedHistory`
recreated the replica on a new leader epoch.

This hit every replica in phase 2. The leader that the seal was lowered
to has the diskless leader epoch at `S'` from `makeLeader`, but the
restart that the recovery needs bumps its leader epoch. The consolidated
batch then replaces that entry with the diskless leader epoch at `S`.

`hasConsolidatedDisklessSuffixFromSeal` now starts its proof at the
first local batch that holds an offset at or past the seal. A batch that
spans the seal still starts the proof at the seal. A classic record past
the seal still fails the check. The check reads the log, not a cache
entry that only consolidation writes, so it gives the same answer after
a log directory move or a rebuild from remote storage.

Testing

- `ReplicaManagerInklessTest.testSwitchedReplicaKeepsConsolidatedRecordsAfterLoweredSeal`
  applies a phase 2 delta with a new leader epoch to a replica with
  classic records `[0, 7)`, a lowered seal `7`, and consolidated records
  `[10, 13)` in the diskless leader epoch. Its cache maps `7` to epoch
  `0`. The replica keeps its log as a leader, as a leader whose cache had
  a later epoch at `7` before the append, and as a follower.
- `testSwitchedFollowerTruncatesOnlyClassicTailPastLoweredSeal` applies a
  phase 1 follower delta. The follower keeps `[10, 13)` when its classic
  records end at the seal, and truncates to the seal when it holds a
  classic tail `[7, 9)`.
- With the previous check, the four cases that keep the log fail, and the
  classic-tail case passes.
- No cluster test takes a lowered seal through phase 2.

Assisted-by: Claude Opus 5.5
8000
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unhandled storage failures and retention races during phase-two validation can abort metadata updates after fetchers are stopped, leaving healthy replicas unable to resume fetching.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment on lines +4645 to +4646
val localSuffixStart = math.max(seal, log.localLogStartOffset())
val suffixStart = math.max(localSuffixStart, firstBatchBaseOffset(log, localSuffixStart))
// Returns the base offset of the first local batch that holds an offset at or past startOffset, or startOffset
// if the log holds none.
private def firstBatchBaseOffset(log: UnifiedLog, startOffset: Long): Long = {
val batches = log.read(startOffset, 1, FetchIsolation.LOG_END, true).records.batches().iterator()
@giuseppelillo
Copy link
Copy Markdown
Contributor Author

Closing: KC-837 only follows a phase 1 last-known-leader election that lost records, and a manual procedure (forcing local retention past the old seal) heals it, so it will be documented instead of fixed in code. A new PR will cover it.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0