Skip to content

feat(inkless): Seal the local log when a topic is migrated from classic to diskless#533

Merged
jeqo merged 5 commits intomainfrom
giuseppelillo/diskless-migration-sealing
Mar 13, 2026
Merged

feat(inkless): Seal the local log when a topic is migrated from classic to diskless#533
jeqo merged 5 commits intomainfrom
giuseppelillo/diskless-migration-sealing

Conversation

@giuseppelillo
Copy link
Copy Markdown
Contributor

@giuseppelillo giuseppelillo commented Mar 12, 2026

Sealing is applied for both existing leaders and newly elected leaders.

@giuseppelillo giuseppelillo force-pushed the giuseppelillo/diskless-migration-sealing branch 2 times, most recently from 4e56634 to fc4d461 Compare March 12, 2026 15:33
…ic to diskless

Sealing is applied for both existing leaders and newly elected leaders.
@giuseppelillo giuseppelillo force-pushed the giuseppelillo/diskless-migration-sealing branch from fc4d461 to 4e41e53 Compare March 12, 2026 15:56
@giuseppelillo giuseppelillo changed the title feat(inkless): seal the log when diskless is enabled feat(inkless): Seal the local log when a topic is migrated from classic to diskless Mar 12, 2026
@giuseppelillo giuseppelillo marked this pull request as ready for review March 12, 2026 16:27
Copy link
Copy Markdown
Contributor

@jeqo jeqo left a comment

Choose a reason for hiding this comment

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

Looks solid. Just a minor suggestion.

): LogAppendInfo = {
val (info, leaderHWIncremented) = inReadLock(leaderIsrUpdateLock) {
if (_sealed) {
throw new NotLeaderOrFollowerException(
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.

Worth noting here that this exception is used on purpose to force clients to refresh metadata and retry (as this is not explicit from the code)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right it's not very useful to request clients to refresh metadata. I've changed to BrokerNotAvailableException so that clients can retry but they are not forced to refresh the metadata.

Copy link
Copy Markdown
Contributor

@jeqo jeqo Mar 13, 2026

Choose a reason for hiding this comment

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

Right. It's not ideal, but that's the only way of keeping the client retrying until migration completes IIUC. Otherwise it fails at the client side, and they crash.
In the expected scenario, these round-trips should give enough room for migration to complete.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's also this aspect to consider: #533 (comment)

But I would not change the catch logic. So we either force a metadata refresh for every produce request or we accept that there will be failures in metrics during a migration. I lean towards the latter option.

Copy link
Copy Markdown
Contributor

@AnatolyPopov AnatolyPopov left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks, looks exactly as we discussed 👍 But leaving without approve for review from others.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds “sealing” behavior to prevent any further local-log writes when a topic transitions from classic to diskless, covering both existing leaders (at the time the config flips) and partitions that (re)become leaders while diskless is enabled.

Changes:

  • Add sealing detection in BrokerMetadataPublisher when diskless.enable flips to true.
  • Add ReplicaManager.sealTopicPartitions plus logic to seal partitions during leader transitions for diskless topics.
  • Introduce a sealed flag in Partition that rejects appends; add unit tests validating sealing behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
core/src/main/scala/kafka/server/metadata/BrokerMetadataPublisher.scala Detects classic→diskless via topic config delta and seals existing leaders.
core/src/main/scala/kafka/server/ReplicaManager.scala Adds sealing helper and seals partitions when applying leader deltas for diskless topics.
core/src/main/scala/kafka/cluster/Partition.scala Adds sealed state, seal API, and rejects appendRecordsToLeader when sealed.
core/src/test/scala/unit/kafka/server/metadata/BrokerMetadataPublisherTest.scala Tests sealing is triggered on diskless.enable config change.
core/src/test/scala/unit/kafka/server/ReplicaManagerTest.scala Tests sealTopicPartitions and sealing during applyDelta.
core/src/test/scala/unit/kafka/cluster/PartitionTest.scala Tests Partition.seal behavior and append rejection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

1. Add partition to set of changed partitions also when it's sealed
2. Log the sealing only when it actually happens
3. Fix test for correct follower->leader scenario

// TODO: Add more fetch tests combinations, edge cases ara not covered yet.

@Test
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.

Should we move these new tests into @Nested class Inkless instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They already are, but the indentation of this test was wrong, fixed it now.

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.

Right! indentation trick me. Thanks for fixing it!

Copy link
Copy Markdown
Contributor

@jeqo jeqo left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @giuseppelillo!

As discussed internally, we can add metrics for sealed partitions in a follow-up 👍🏽

@jeqo jeqo merged commit d9bf220 into main Mar 13, 2026
5 checks passed
@jeqo jeqo deleted the giuseppelillo/diskless-migration-sealing branch March 13, 2026 12:47
AnatolyPopov pushed a commit that referenced this pull request Mar 23, 2026
…ic to diskless (#533)

Sealing is applied for both existing leaders and newly elected leaders.

(cherry picked from commit d9bf220)

# Conflicts:
#	core/src/main/scala/kafka/server/ReplicaManager.scala
#	core/src/test/scala/unit/kafka/cluster/PartitionTest.scala
jeqo pushed a commit that referenced this pull request Mar 23, 2026
…ic to diskless (#533)

Sealing is applied for both existing leaders and newly elected leaders.
jeqo pushed a commit that referenced this pull request Mar 23, 2026
…ic to diskless (#533)

Sealing is applied for both existing leaders and newly elected leaders.

(cherry picked from commit d9bf220)

# Conflicts:
#	core/src/main/scala/kafka/server/ReplicaManager.scala
#	core/src/test/scala/unit/kafka/cluster/PartitionTest.scala
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.

4 participants