-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
KAFKA-18601: Assume a baseline of 3.3 for server protocol versions #18845
Merged
ijuma
merged 33 commits into
apache:trunk
from
ijuma:kafka-18601-assume-baseline-3.3-for-server
Feb 19, 2025
+969
−1,337
Merged
Changes from 16 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
e654cdb
KAFKA-18601: Assume a baseline of 3.3 for server protocol versions
ijuma 059866e
Fix a few tests and tweak error messages
ijuma 86d1053
Minor improvements, address review comments and fix tests
ijuma 97e2c43
Formatting fixes
ijuma b60fbe4
Minor tweak
ijuma 4338a21
Merge remote-tracking branch 'apache-github/trunk' into kafka-18601-a…
ijuma 9fb5b3d
Remove `ibp` parameter from `BootstrapDirectory`
ijuma 3203398
Address a couple of minor review comments
ijuma b31bc04
Merge remote-tracking branch 'apache-github/trunk' into kafka-18601-a…
ijuma 8531c36
Address review comments
ijuma 8a81124
Replace IBP_3_3_IV3 with MINIMUM_VERSION where applicable
ijuma cdd7c9a
Set `topicId` a bit more consistently in `PartitionTest`
ijuma 942bd2a
Improve comments and remove code that is no longer needed
ijuma 2f32f35
Address review comments
ijuma b93ba62
Don't set metadata version to the `MINIMUM_VERSION` and rely only on …
ijuma d8f5346
Add fallback in case we read a feature level we don't understand (for…
ijuma 27e33c4
Simplify code based on code review
ijuma 2d40e5b
Remove metadata version default
ijuma 32a4a94
More IBP_3_3_IV3 -> MINIMUM_VERSION
ijuma 4b331af
Reject broker registration without metadata.version and fix tests
ijuma 70667a4
Update MetadataBatchLoader.resetToImage to set `hasSeenRecord` based …
ijuma d66ef98
Merge remote-tracking branch 'apache-github/trunk' into kafka-18601-a…
ijuma efaf362
Merge remote-tracking branch 'apache-github/trunk' into kafka-18601-a…
ijuma a551f46
Fix test failures
ijuma 5834410
Make FeaturesImage.metadataVersion optional and fail-fast instead of …
ijuma afb9d97
Minor tweak
ijuma d5860c4
More 3_3_IV3 -> MINIMUM_VERSION
ijuma 4505d0a
Fix several tests
ijuma 7fcb280
Fix ReconfigurableQuorumIntegrationTest and QuorumControllerTest by a…
ijuma d505508
Minor clean-ups in `ReconfigurableQuorumIntegrationTest`
ijuma 07a728b
"3-3-IV3" -> `MINIMUM_VERSION.toString`
ijuma 52fd223
Remove metadata version fallback from `FeaturesDelta` - snapshots hap…
ijuma 6c5a0f9
Address review feedback.
ijuma 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -16,23 +16,18 @@ | |
*/ | ||
package kafka.server | ||
|
||
import java.util | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
import java.util.concurrent.{CompletableFuture, ConcurrentHashMap} | ||
import kafka.utils.Logging | ||
import org.apache.kafka.clients.ClientResponse | ||
import org.apache.kafka.common.TopicIdPartition | ||
import org.apache.kafka.common.TopicPartition | ||
import org.apache.kafka.common.Uuid | ||
import org.apache.kafka.common.errors.OperationNotAttemptedException | ||
import org.apache.kafka.common.message.AlterPartitionRequestData | ||
import org.apache.kafka.common.metrics.Metrics | ||
import org.apache.kafka.common.protocol.Errors | ||
import org.apache.kafka.common.requests.RequestHeader | ||
import org.apache.kafka.common.requests.{AlterPartitionRequest, AlterPartitionResponse} | ||
import org.apache.kafka.common.utils.Time | ||
import org.apache.kafka.metadata.{LeaderAndIsr, LeaderRecoveryState} | ||
import org.apache.kafka.server.common.{ControllerRequestCompletionHandler, MetadataVersion, NodeToControllerChannelManager} | ||
import org.apache.kafka.server.common.{ControllerRequestCompletionHandler, NodeToControllerChannelManager, TopicIdPartition} | ||
import org.apache.kafka.server.util.Scheduler | ||
|
||
import scala.collection.mutable | ||
|
@@ -92,8 +87,7 @@ object AlterPartitionManager { | |
scheduler = scheduler, | ||
time = time, | ||
brokerId = config.brokerId, | ||
brokerEpochSupplier = brokerEpochSupplier, | ||
metadataVersionSupplier = () => metadataCache.metadataVersion() | ||
brokerEpochSupplier = brokerEpochSupplier | ||
) | ||
} | ||
} | ||
|
@@ -104,7 +98,6 @@ class DefaultAlterPartitionManager( | |
val time: Time, | ||
val brokerId: Int, | ||
val brokerEpochSupplier: () => Long, | ||
val metadataVersionSupplier: () => MetadataVersion | ||
) extends AlterPartitionManager with Logging { | ||
|
||
// Used to allow only one pending ISR update per partition (visible for testing). | ||
|
@@ -114,7 +107,7 @@ class DefaultAlterPartitionManager( | |
// and re-created, we cannot have two entries in this Map especially if we cannot | ||
// use an AlterPartition request version which supports topic ids in the end because | ||
// the two updates with the same name would be merged together. | ||
private[server] val unsentIsrUpdates: util.Map[TopicPartition, AlterPartitionItem] = new ConcurrentHashMap[TopicPartition, AlterPartitionItem]() | ||
private[server] val unsentIsrUpdates = new ConcurrentHashMap[TopicIdPartition, AlterPartitionItem]() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please update the docs according to the change? |
||
|
||
// Used to allow only one in-flight request at a time | ||
private val inflightRequest: AtomicBoolean = new AtomicBoolean(false) | ||
|
@@ -133,7 +126,7 @@ class DefaultAlterPartitionManager( | |
): CompletableFuture[LeaderAndIsr] = { | ||
val future = new CompletableFuture[LeaderAndIsr]() | ||
val alterPartitionItem = AlterPartitionItem(topicIdPartition, leaderAndIsr, future) | ||
val enqueued = unsentIsrUpdates.putIfAbsent(alterPartitionItem.topicIdPartition.topicPartition, alterPartitionItem) == null | ||
val enqueued = unsentIsrUpdates.putIfAbsent(alterPartitionItem.topicIdPartition, alterPartitionItem) == null | ||
if (enqueued) { | ||
maybePropagateIsrChanges() | ||
} else { | ||
|
@@ -161,7 +154,7 @@ class DefaultAlterPartitionManager( | |
|
||
private def sendRequest(inflightAlterPartitionItems: Seq[AlterPartitionItem]): Unit = { | ||
val brokerEpoch = brokerEpochSupplier() | ||
val (request, topicNamesByIds) = buildRequest(inflightAlterPartitionItems, brokerEpoch) | ||
val request = buildRequest(inflightAlterPartitionItems, brokerEpoch) | ||
debug(s"Sending AlterPartition to controller $request") | ||
|
||
// We will not timeout AlterPartition request, instead letting it retry indefinitely | ||
|
@@ -182,11 +175,9 @@ class DefaultAlterPartitionManager( | |
Errors.UNSUPPORTED_VERSION | ||
} else { | ||
handleAlterPartitionResponse( | ||
response.requestHeader, | ||
response.responseBody.asInstanceOf[AlterPartitionResponse], | ||
brokerEpoch, | ||
inflightAlterPartitionItems, | ||
topicNamesByIds | ||
inflightAlterPartitionItems | ||
) | ||
} | ||
} finally { | ||
|
@@ -218,59 +209,40 @@ class DefaultAlterPartitionManager( | |
* supported by the controller. The final decision is taken when the AlterPartitionRequest | ||
* is built in the network client based on the advertised api versions of the controller. | ||
* | ||
* @return A tuple containing the AlterPartitionRequest.Builder and a mapping from | ||
* topic id to topic name. This mapping is used in the response handling. | ||
* @return an AlterPartitionRequest.Builder with the provided parameters. | ||
*/ | ||
private def buildRequest( | ||
inflightAlterPartitionItems: Seq[AlterPartitionItem], | ||
brokerEpoch: Long | ||
ijuma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
): (AlterPartitionRequest.Builder, mutable.Map[Uuid, String]) = { | ||
val metadataVersion = metadataVersionSupplier() | ||
// We build this mapping in order to map topic id back to their name when we | ||
// receive the response. We cannot rely on the metadata cache for this because | ||
// the metadata cache is updated after the partition state so it might not know | ||
// yet about a topic id already used here. | ||
val topicNamesByIds = mutable.HashMap[Uuid, String]() | ||
|
||
): AlterPartitionRequest.Builder = { | ||
val message = new AlterPartitionRequestData() | ||
.setBrokerId(brokerId) | ||
.setBrokerEpoch(brokerEpoch) | ||
|
||
inflightAlterPartitionItems.groupBy(_.topicIdPartition.topic).foreach { case (topicName, items) => | ||
val topicId = items.head.topicIdPartition.topicId | ||
topicNamesByIds(topicId) = topicName | ||
|
||
// Both the topic name and the topic id are set here because at this stage | ||
// we don't know which version of the request will be used. | ||
val topicData = new AlterPartitionRequestData.TopicData() | ||
.setTopicName(topicName) | ||
.setTopicId(topicId) | ||
inflightAlterPartitionItems.groupBy(_.topicIdPartition.topicId).foreach { case (topicId, items) => | ||
val topicData = new AlterPartitionRequestData.TopicData().setTopicId(topicId) | ||
ijuma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
message.topics.add(topicData) | ||
|
||
items.foreach { item => | ||
val partitionData = new AlterPartitionRequestData.PartitionData() | ||
.setPartitionIndex(item.topicIdPartition.partition) | ||
.setPartitionIndex(item.topicIdPartition.partitionId) | ||
.setLeaderEpoch(item.leaderAndIsr.leaderEpoch) | ||
.setNewIsrWithEpochs(item.leaderAndIsr.isrWithBrokerEpoch) | ||
.setPartitionEpoch(item.leaderAndIsr.partitionEpoch) | ||
|
||
if (metadataVersion.isLeaderRecoverySupported) { | ||
partitionData.setLeaderRecoveryState(item.leaderAndIsr.leaderRecoveryState.value) | ||
} | ||
partitionData.setLeaderRecoveryState(item.leaderAndIsr.leaderRecoveryState.value) | ||
|
||
topicData.partitions.add(partitionData) | ||
} | ||
} | ||
|
||
(new AlterPartitionRequest.Builder(message), topicNamesByIds) | ||
new AlterPartitionRequest.Builder(message) | ||
} | ||
|
||
private def handleAlterPartitionResponse( | ||
requestHeader: RequestHeader, | ||
alterPartitionResp: AlterPartitionResponse, | ||
sentBrokerEpoch: Long, | ||
inflightAlterPartitionItems: Seq[AlterPartitionItem], | ||
topicNamesByIds: mutable.Map[Uuid, String] | ||
): Errors = { | ||
val data = alterPartitionResp.data | ||
|
||
|
@@ -284,37 +256,31 @@ class DefaultAlterPartitionManager( | |
|
||
case Errors.NONE => | ||
// Collect partition-level responses to pass to the callbacks | ||
val partitionResponses = new mutable.HashMap[TopicPartition, Either[Errors, LeaderAndIsr]]() | ||
val partitionResponses = new mutable.HashMap[TopicIdPartition, Either[Errors, LeaderAndIsr]]() | ||
data.topics.forEach { topic => | ||
// Topic IDs are used since version 2 of the AlterPartition API. | ||
val topicName = if (requestHeader.apiVersion > 1) topicNamesByIds.get(topic.topicId).orNull else topic.topicName | ||
if (topicName == null || topicName.isEmpty) { | ||
error(s"Received an unexpected topic $topic in the alter partition response, ignoring it.") | ||
} else { | ||
topic.partitions.forEach { partition => | ||
val tp = new TopicPartition(topicName, partition.partitionIndex) | ||
val apiError = Errors.forCode(partition.errorCode) | ||
debug(s"Controller successfully handled AlterPartition request for $tp: $partition") | ||
if (apiError == Errors.NONE) { | ||
LeaderRecoveryState.optionalOf(partition.leaderRecoveryState).toScala match { | ||
case Some(leaderRecoveryState) => | ||
partitionResponses(tp) = Right( | ||
new LeaderAndIsr( | ||
partition.leaderId, | ||
partition.leaderEpoch, | ||
partition.isr, | ||
leaderRecoveryState, | ||
partition.partitionEpoch | ||
) | ||
topic.partitions.forEach { partition => | ||
val tp = new TopicIdPartition(topic.topicId, partition.partitionIndex) | ||
val apiError = Errors.forCode(partition.errorCode) | ||
debug(s"Controller successfully handled AlterPartition request for $tp: $partition") | ||
if (apiError == Errors.NONE) { | ||
LeaderRecoveryState.optionalOf(partition.leaderRecoveryState).toScala match { | ||
case Some(leaderRecoveryState) => | ||
partitionResponses(tp) = Right( | ||
new LeaderAndIsr( | ||
partition.leaderId, | ||
partition.leaderEpoch, | ||
partition.isr, | ||
leaderRecoveryState, | ||
partition.partitionEpoch | ||
) | ||
) | ||
|
||
case None => | ||
error(s"Controller returned an invalid leader recovery state (${partition.leaderRecoveryState}) for $tp: $partition") | ||
partitionResponses(tp) = Left(Errors.UNKNOWN_SERVER_ERROR) | ||
} | ||
} else { | ||
partitionResponses(tp) = Left(apiError) | ||
case None => | ||
error(s"Controller returned an invalid leader recovery state (${partition.leaderRecoveryState}) for $tp: $partition") | ||
partitionResponses(tp) = Left(Errors.UNKNOWN_SERVER_ERROR) | ||
} | ||
} else { | ||
partitionResponses(tp) = Left(apiError) | ||
} | ||
} | ||
} | ||
|
@@ -323,11 +289,11 @@ class DefaultAlterPartitionManager( | |
// partition was somehow erroneously excluded from the response. Note that these callbacks are run from | ||
// the leaderIsrUpdateLock write lock in Partition#sendAlterPartitionRequest | ||
inflightAlterPartitionItems.foreach { inflightAlterPartition => | ||
partitionResponses.get(inflightAlterPartition.topicIdPartition.topicPartition) match { | ||
partitionResponses.get(inflightAlterPartition.topicIdPartition) match { | ||
case Some(leaderAndIsrOrError) => | ||
// Regardless of callback outcome, we need to clear from the unsent updates map to unblock further | ||
// updates. We clear it now to allow the callback to submit a new update if needed. | ||
unsentIsrUpdates.remove(inflightAlterPartition.topicIdPartition.topicPartition) | ||
unsentIsrUpdates.remove(inflightAlterPartition.topicIdPartition) | ||
leaderAndIsrOrError match { | ||
case Left(error) => inflightAlterPartition.future.completeExceptionally(error.exception) | ||
case Right(leaderAndIsr) => inflightAlterPartition.future.complete(leaderAndIsr) | ||
|
This file contains 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove
metadataCache
from theapply
method