-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-8639: Replace AddPartitionsToTxn with Automated Protocol #8326
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -176,7 +176,7 @@ private static class TopicPartitionEntry { | |
| this.inflightBatchesBySequence = new TreeSet<>(Comparator.comparingInt(ProducerBatch::baseSequence)); | ||
| } | ||
|
|
||
| public void resetSequenceNumbers(Consumer<ProducerBatch> resetSequence) { | ||
| void resetSequenceNumbers(Consumer<ProducerBatch> resetSequence) { | ||
| TreeSet<ProducerBatch> newInflights = new TreeSet<>(Comparator.comparingInt(ProducerBatch::baseSequence)); | ||
| for (ProducerBatch inflightBatch : inflightBatchesBySequence) { | ||
| resetSequence.accept(inflightBatch); | ||
|
|
@@ -509,13 +509,9 @@ ProducerIdAndEpoch producerIdAndEpoch() { | |
| return producerIdAndEpoch; | ||
| } | ||
|
|
||
| boolean hasProducerId(long producerId) { | ||
| return producerIdAndEpoch.producerId == producerId; | ||
| } | ||
|
|
||
| boolean matchesProducerIdAndEpoch(ProducerBatch batch) { | ||
| boolean producerIdOrEpochNotMatch(ProducerBatch batch) { | ||
| ProducerIdAndEpoch idAndEpoch = this.producerIdAndEpoch; | ||
| return idAndEpoch.producerId == batch.producerId() && idAndEpoch.epoch == batch.producerEpoch(); | ||
| return idAndEpoch.producerId != batch.producerId() || idAndEpoch.epoch != batch.producerEpoch(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -691,7 +687,7 @@ public synchronized void handleCompletedBatch(ProducerBatch batch, ProduceRespon | |
| updateLastAckedOffset(response, batch); | ||
| removeInFlightBatch(batch); | ||
|
|
||
| if (!matchesProducerIdAndEpoch(batch) && !hasInflightBatches(batch.topicPartition)) { | ||
| if (producerIdOrEpochNotMatch(batch) && !hasInflightBatches(batch.topicPartition)) { | ||
| // If the batch was on a different ID and/or epoch (due to an epoch bump) and all its in-flight batches | ||
| // have completed, reset the partition sequence so that the next batch (with the new epoch) starts from 0 | ||
| topicPartitionBookkeeper.startSequencesAtBeginning(batch.topicPartition, this.producerIdAndEpoch); | ||
|
|
@@ -723,7 +719,7 @@ synchronized void handleFailedBatch(ProducerBatch batch, RuntimeException except | |
| return; | ||
| } | ||
|
|
||
| if (!matchesProducerIdAndEpoch(batch)) { | ||
| if (producerIdOrEpochNotMatch(batch)) { | ||
| log.debug("Ignoring failed batch {} with producer id {}, epoch {}, and sequence number {} " + | ||
| "since the producerId has been reset internally", batch, batch.producerId(), | ||
| batch.producerEpoch(), batch.baseSequence(), exception); | ||
|
|
@@ -1140,13 +1136,14 @@ private void lookupCoordinator(FindCoordinatorRequest.CoordinatorType type, Stri | |
| enqueueRequest(new FindCoordinatorHandler(builder)); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| private TxnRequestHandler addPartitionsToTransactionHandler() { | ||
| pendingPartitionsInTransaction.addAll(newPartitionsInTransaction); | ||
| newPartitionsInTransaction.clear(); | ||
| AddPartitionsToTxnRequest.Builder builder = new AddPartitionsToTxnRequest.Builder(transactionalId, | ||
| producerIdAndEpoch.producerId, producerIdAndEpoch.epoch, new ArrayList<>(pendingPartitionsInTransaction)); | ||
| AddPartitionsToTxnRequest.Builder builder = | ||
|
Author
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. Mostly side cleanup |
||
| new AddPartitionsToTxnRequest.Builder(transactionalId, | ||
| producerIdAndEpoch.producerId, | ||
| producerIdAndEpoch.epoch, | ||
| new ArrayList<>(pendingPartitionsInTransaction)); | ||
| return new AddPartitionsToTxnHandler(builder); | ||
| } | ||
|
|
||
|
|
||
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 |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |
| */ | ||
| package org.apache.kafka.common.protocol; | ||
|
|
||
| import org.apache.kafka.common.message.AddPartitionsToTxnRequestData; | ||
| import org.apache.kafka.common.message.AddPartitionsToTxnResponseData; | ||
| import org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData; | ||
| import org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData; | ||
| import org.apache.kafka.common.message.ApiMessageType; | ||
|
|
@@ -108,8 +110,6 @@ | |
| import org.apache.kafka.common.protocol.types.Struct; | ||
| import org.apache.kafka.common.protocol.types.Type; | ||
| import org.apache.kafka.common.record.RecordBatch; | ||
| import org.apache.kafka.common.requests.AddPartitionsToTxnRequest; | ||
| import org.apache.kafka.common.requests.AddPartitionsToTxnResponse; | ||
| import org.apache.kafka.common.requests.AlterReplicaLogDirsRequest; | ||
| import org.apache.kafka.common.requests.AlterReplicaLogDirsResponse; | ||
| import org.apache.kafka.common.requests.DescribeConfigsRequest; | ||
|
|
@@ -148,7 +148,7 @@ public enum ApiKeys { | |
| OFFSET_COMMIT(8, "OffsetCommit", OffsetCommitRequestData.SCHEMAS, OffsetCommitResponseData.SCHEMAS), | ||
| OFFSET_FETCH(9, "OffsetFetch", OffsetFetchRequestData.SCHEMAS, OffsetFetchResponseData.SCHEMAS), | ||
| FIND_COORDINATOR(10, "FindCoordinator", FindCoordinatorRequestData.SCHEMAS, | ||
| FindCoordinatorResponseData.SCHEMAS), | ||
| FindCoordinatorResponseData.SCHEMAS), | ||
| JOIN_GROUP(11, "JoinGroup", JoinGroupRequestData.SCHEMAS, JoinGroupResponseData.SCHEMAS), | ||
| HEARTBEAT(12, "Heartbeat", HeartbeatRequestData.SCHEMAS, HeartbeatResponseData.SCHEMAS), | ||
| LEAVE_GROUP(13, "LeaveGroup", LeaveGroupRequestData.SCHEMAS, LeaveGroupResponseData.SCHEMAS), | ||
|
|
@@ -173,14 +173,14 @@ public Struct parseResponse(short version, ByteBuffer buffer) { | |
| OFFSET_FOR_LEADER_EPOCH(23, "OffsetForLeaderEpoch", false, OffsetsForLeaderEpochRequest.schemaVersions(), | ||
| OffsetsForLeaderEpochResponse.schemaVersions()), | ||
| ADD_PARTITIONS_TO_TXN(24, "AddPartitionsToTxn", false, RecordBatch.MAGIC_VALUE_V2, | ||
| AddPartitionsToTxnRequest.schemaVersions(), AddPartitionsToTxnResponse.schemaVersions()), | ||
| AddPartitionsToTxnRequestData.SCHEMAS, AddPartitionsToTxnResponseData.SCHEMAS), | ||
| ADD_OFFSETS_TO_TXN(25, "AddOffsetsToTxn", false, RecordBatch.MAGIC_VALUE_V2, AddOffsetsToTxnRequestData.SCHEMAS, | ||
| AddOffsetsToTxnResponseData.SCHEMAS), | ||
| AddOffsetsToTxnResponseData.SCHEMAS), | ||
| END_TXN(26, "EndTxn", false, RecordBatch.MAGIC_VALUE_V2, EndTxnRequestData.SCHEMAS, EndTxnResponseData.SCHEMAS), | ||
| WRITE_TXN_MARKERS(27, "WriteTxnMarkers", true, RecordBatch.MAGIC_VALUE_V2, WriteTxnMarkersRequestData.SCHEMAS, | ||
| WriteTxnMarkersResponseData.SCHEMAS), | ||
| TXN_OFFSET_COMMIT(28, "TxnOffsetCommit", false, RecordBatch.MAGIC_VALUE_V2, TxnOffsetCommitRequestData.SCHEMAS, | ||
| TxnOffsetCommitResponseData.SCHEMAS), | ||
| TxnOffsetCommitResponseData.SCHEMAS), | ||
| DESCRIBE_ACLS(29, "DescribeAcls", DescribeAclsRequestData.SCHEMAS, DescribeAclsResponseData.SCHEMAS), | ||
| CREATE_ACLS(30, "CreateAcls", CreateAclsRequestData.SCHEMAS, CreateAclsResponseData.SCHEMAS), | ||
| DELETE_ACLS(31, "DeleteAcls", DeleteAclsRequestData.SCHEMAS, DeleteAclsResponseData.SCHEMAS), | ||
|
|
@@ -196,22 +196,28 @@ public Struct parseResponse(short version, ByteBuffer buffer) { | |
| SaslAuthenticateResponseData.SCHEMAS), | ||
| CREATE_PARTITIONS(37, "CreatePartitions", CreatePartitionsRequestData.SCHEMAS, | ||
| CreatePartitionsResponseData.SCHEMAS), | ||
| CREATE_DELEGATION_TOKEN(38, "CreateDelegationToken", CreateDelegationTokenRequestData.SCHEMAS, CreateDelegationTokenResponseData.SCHEMAS), | ||
| RENEW_DELEGATION_TOKEN(39, "RenewDelegationToken", RenewDelegationTokenRequestData.SCHEMAS, RenewDelegationTokenResponseData.SCHEMAS), | ||
| EXPIRE_DELEGATION_TOKEN(40, "ExpireDelegationToken", ExpireDelegationTokenRequestData.SCHEMAS, ExpireDelegationTokenResponseData.SCHEMAS), | ||
| DESCRIBE_DELEGATION_TOKEN(41, "DescribeDelegationToken", DescribeDelegationTokenRequestData.SCHEMAS, DescribeDelegationTokenResponseData.SCHEMAS), | ||
| CREATE_DELEGATION_TOKEN(38, "CreateDelegationToken", CreateDelegationTokenRequestData.SCHEMAS, | ||
|
Author
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. Fix the alignment |
||
| CreateDelegationTokenResponseData.SCHEMAS), | ||
| RENEW_DELEGATION_TOKEN(39, "RenewDelegationToken", RenewDelegationTokenRequestData.SCHEMAS, | ||
| RenewDelegationTokenResponseData.SCHEMAS), | ||
| EXPIRE_DELEGATION_TOKEN(40, "ExpireDelegationToken", ExpireDelegationTokenRequestData.SCHEMAS, | ||
| ExpireDelegationTokenResponseData.SCHEMAS), | ||
| DESCRIBE_DELEGATION_TOKEN(41, "DescribeDelegationToken", DescribeDelegationTokenRequestData.SCHEMAS, | ||
| DescribeDelegationTokenResponseData.SCHEMAS), | ||
| DELETE_GROUPS(42, "DeleteGroups", DeleteGroupsRequestData.SCHEMAS, DeleteGroupsResponseData.SCHEMAS), | ||
| ELECT_LEADERS(43, "ElectLeaders", ElectLeadersRequestData.SCHEMAS, | ||
| ElectLeadersResponseData.SCHEMAS), | ||
| INCREMENTAL_ALTER_CONFIGS(44, "IncrementalAlterConfigs", IncrementalAlterConfigsRequestData.SCHEMAS, | ||
| IncrementalAlterConfigsResponseData.SCHEMAS), | ||
| IncrementalAlterConfigsResponseData.SCHEMAS), | ||
| ALTER_PARTITION_REASSIGNMENTS(45, "AlterPartitionReassignments", AlterPartitionReassignmentsRequestData.SCHEMAS, | ||
| AlterPartitionReassignmentsResponseData.SCHEMAS), | ||
| AlterPartitionReassignmentsResponseData.SCHEMAS), | ||
| LIST_PARTITION_REASSIGNMENTS(46, "ListPartitionReassignments", ListPartitionReassignmentsRequestData.SCHEMAS, | ||
| ListPartitionReassignmentsResponseData.SCHEMAS), | ||
| ListPartitionReassignmentsResponseData.SCHEMAS), | ||
| OFFSET_DELETE(47, "OffsetDelete", OffsetDeleteRequestData.SCHEMAS, OffsetDeleteResponseData.SCHEMAS), | ||
| DESCRIBE_CLIENT_QUOTAS(48, "DescribeClientQuotas", DescribeClientQuotasRequestData.SCHEMAS, DescribeClientQuotasResponseData.SCHEMAS), | ||
| ALTER_CLIENT_QUOTAS(49, "AlterClientQuotas", AlterClientQuotasRequestData.SCHEMAS, AlterClientQuotasResponseData.SCHEMAS); | ||
| DESCRIBE_CLIENT_QUOTAS(48, "DescribeClientQuotas", DescribeClientQuotasRequestData.SCHEMAS, | ||
| DescribeClientQuotasResponseData.SCHEMAS), | ||
| ALTER_CLIENT_QUOTAS(49, "AlterClientQuotas", AlterClientQuotasRequestData.SCHEMAS, | ||
| AlterClientQuotasResponseData.SCHEMAS); | ||
|
|
||
| private static final ApiKeys[] ID_TO_TYPE; | ||
| private static final int MIN_API_KEY = 0; | ||
|
|
||
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.
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.
Simplify boolean logic