Repository navigation
fix(inkless): repair missing control-plane rows on CreatePartitions retry [KC-420] #752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
viktorsomogyi
merged 4 commits into
main
from
svv/fix-create-partitions-missing-logs-rows
Aug 18, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9f28516
fix(inkless): repair missing control-plane rows on CreatePartitions r…
viktorsomogyi c648893
fix(inkless): drop TOPIC_ALREADY_EXISTS from CreatePartitions diskles…
viktorsomogyi 93e024f
fix(inkless): use one metadata image for CreatePartitions retry class…
viktorsomogyi 0b3e61f
test(inkless:consolidation): cover LATEST when the seal is a sentinel…
viktorsomogyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
8000
|
@@ -53,7 +53,7 @@ import org.apache.kafka.common.Uuid | |
| import org.apache.kafka.controller.ControllerRequestContext.requestTimeoutMsToDeadlineNs | ||
| import org.apache.kafka.controller.{Controller, ControllerRequestContext} | ||
| import org.apache.kafka.image.publisher.ControllerRegistrationsPublisher | ||
| import org.apache.kafka.metadata.{BrokerHeartbeatReply, BrokerRegistrationReply} | ||
| import org.apache.kafka.metadata.{BrokerHeartbeatReply, BrokerRegistrationReply, PartitionRegistration} | ||
| import org.apache.kafka.common.security.auth.KafkaPrincipal | ||
| import org.apache.kafka.common.security.auth.SecurityProtocol | ||
| import org.apache.kafka.raft.RaftManager | ||
|
|
@@ -986,41 +986,98 @@ class ControllerApis( | |
| CompletableFuture.completedFuture(()) | ||
|
|
||
| case Some(cp) => | ||
| val successfulCreations = (topics.asScala zip results.asScala) | ||
| // It's OK if we retry creating for already existing topics, | ||
| // this may save some trouble when Inkless creation failed for some reason and the user retries. | ||
| .filter { case (_, res) => res.errorCode() == Errors.NONE.code() || res.errorCode() == Errors.TOPIC_ALREADY_EXISTS.code() } | ||
| val eligibleRequests = (topics.asScala zip results.asScala) | ||
| // NONE is the first increase. INVALID_PARTITIONS is a retry after KRaft already applied, | ||
| // except a decrease, which uses the same error code and must not write. | ||
| // disklessPartitionCreateRequests drops those. | ||
| .filter { case (_, res) => | ||
| val code = res.errorCode() | ||
| code == Errors.NONE.code() || code == Errors.INVALID_PARTITIONS.code() | ||
| } | ||
| // In contrast to the topic creation, we only create new partitions to existing topics. | ||
| // Hence, the topics themselves must be in the metadata already, no need to wait. | ||
| .filter { case (req, _) => inklessMetadataView.isDisklessTopic(req.name()) } | ||
| .map { case (req, _) => req } | ||
| .toSet | ||
| val topicNames = successfulCreations.map(_.name()).toList.asJava | ||
| val topicNames = eligibleRequests.map(_._1.name()).distinct.toList.asJava | ||
| controller.findTopicIds(context, topicNames).thenApply { topicIds => | ||
| val createPartitionRequests = successfulCreations.flatMap { req => | ||
| val createPartitionRequests = eligibleRequests.flatMap { case (req, res) => | ||
| val topicName = req.name() | ||
| val topicIdOrError = topicIds.get(topicName) | ||
| if (topicIdOrError.isError) { | ||
| // The chances for this are slim: only when someone concurrently deleted the topic | ||
| // right after the partitions were created in the quorum metadata. | ||
| logger.error("Error finding topic ID for topic {}: partitions will not be created", topicName) | ||
| None | ||
| Seq.empty | ||
| } else { | ||
| val topicId = topicIdOrError.result() | ||
| // The cached range is only usable when it belongs to the topic the controller just mutated. | ||
| // Otherwise create the full range and rely on init_diskless_log_v1 to resolve overlap (KC-387). | ||
| val firstPartition = priorTopicStates.get(topicName) match { | ||
| case Some(state) if state.topicId == topicId => math.min(state.numPartitions, req.count()) | ||
| case _ => 0 | ||
| } | ||
| Some(new CreateTopicAndPartitionsRequest(topicId, topicName, firstPartition, req.count())) | ||
| disklessPartitionCreateRequests(topicId, topicName, req.count(), res.errorCode(), priorTopicStates) | ||
| } | ||
| }.toSet | ||
| if (createPartitionRequests.nonEmpty) { | ||
| cp.createTopicAndPartitions(createPartitionRequests.asJava) | ||
| } | ||
| cp.createTopicAndPartitions(createPartitionRequests.asJava) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Rows to insert after a diskless partition-count change. | ||
| * | ||
| * INVALID_PARTITIONS is only a retry when `count` is at least the image's partition count. | ||
| * A smaller count is a rejected decrease. The published image can lag, so a partition absent from | ||
| * it is treated as born-diskless; V23 is what actually refuses a placeholder over a switching row | ||
| * (KC-387). | ||
| */ | ||
| private def disklessPartitionCreateRequests( | ||
| topicId: Uuid, | ||
| topicName: String, | ||
| count: Int, | ||
| errorCode: Short, | ||
| priorTopicStates: Map[String, TopicState] | ||
| ): Seq[CreateTopicAndPartitionsRequest] = { | ||
| val retry = errorCode != Errors.NONE.code() | ||
| val imagePartitions = Option(metadataCache.currentImage().topics().getTopic(topicId)) | ||
| .map(_.partitions()) | ||
| .getOrElse(util.Collections.emptyMap[Integer, PartitionRegistration]()) | ||
| if (retry && count < imagePartitions.size()) { | ||
| Seq.empty | ||
| } else { | ||
| val firstPartition = | ||
| if (retry) 0 | ||
| else priorTopicStates.get(topicName) match { | ||
| case Some(state) if state.topicId == topicId => math.min(state.numPartitions, count) | ||
| case _ => 0 | ||
| } | ||
| val partitions = bornDisklessPartitions(imagePartitions, count).filter(_ >= firstPartition) | ||
| contiguousRanges(partitions).map { case (from, until) => | ||
| new CreateTopicAndPartitionsRequest(topicId, topicName, from, until) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // A partition missing from the image is treated as born-diskless: it was just added, or the | ||
| // image has not caught up. A lagging image can therefore still classify a switching partition | ||
| // as born-diskless. | ||
| private def bornDisklessPartitions( | ||
| imagePartitions: util.Map[Integer, PartitionRegistration], | ||
| count: Int | ||
| ): Seq[Int] = { | ||
| (0 until count).filter { partition => | ||
| val startOffset = Option(imagePartitions.get(partition)) | ||
| .map(_.classicToDisklessStartOffset) | ||
| .getOrElse(PartitionRegistration.NO_CLASSIC_TO_DISKLESS_START_OFFSET) | ||
| startOffset == PartitionRegistration.NO_CLASSIC_TO_DISKLESS_START_OFFSET | ||
| } | ||
| } | ||
|
|
||
| private def contiguousRanges(partitions: Seq[Int]): Seq[(Int, Int)] = { | ||
| partitions.sorted.foldLeft(Vector.empty[(Int, Int)]) { (ranges, partition) => | ||
| ranges.lastOption match { | ||
| case Some((from, until)) if partition == until => ranges.init :+ (from, until + 1) | ||
| case _ => ranges :+ (partition, partition + 1) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| def handleControllerRegistration(request: RequestChannel.Request): CompletableFuture[Unit] = { | ||
| val registrationRequest = request.body[ControllerRegistrationRequest] | ||
| authHelper.authorizeClusterOperation(request, CLUSTER_ACTION) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.