-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-15355: Message schema changes #14290
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
Changes from 5 commits
2ca98af
cea4f12
e280bbb
d05e23e
04a79cd
27e815f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.kafka.common.requests; | ||
|
|
||
| import org.apache.kafka.common.message.AssignReplicasToDirsRequestData; | ||
| import org.apache.kafka.common.message.AssignReplicasToDirsResponseData; | ||
| import org.apache.kafka.common.protocol.ApiKeys; | ||
| import org.apache.kafka.common.protocol.ByteBufferAccessor; | ||
| import org.apache.kafka.common.protocol.Errors; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
|
|
||
| public class AssignReplicasToDirsRequest extends AbstractRequest { | ||
|
|
||
| public static class Builder extends AbstractRequest.Builder<AssignReplicasToDirsRequest> { | ||
|
|
||
| private final AssignReplicasToDirsRequestData data; | ||
|
|
||
| public Builder(AssignReplicasToDirsRequestData data) { | ||
| super(ApiKeys.ASSIGN_REPLICAS_TO_DIRS); | ||
| this.data = data; | ||
| } | ||
|
|
||
| @Override | ||
| public AssignReplicasToDirsRequest build(short version) { | ||
| return new AssignReplicasToDirsRequest(data, version); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return data.toString(); | ||
| } | ||
| } | ||
|
|
||
| private final AssignReplicasToDirsRequestData data; | ||
|
|
||
| public AssignReplicasToDirsRequest(AssignReplicasToDirsRequestData data, short version) { | ||
| super(ApiKeys.ASSIGN_REPLICAS_TO_DIRS, version); | ||
| this.data = data; | ||
| } | ||
|
|
||
| @Override | ||
| public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) { | ||
| return new AssignReplicasToDirsResponse( | ||
| new AssignReplicasToDirsResponseData() | ||
| .setThrottleTimeMs(throttleTimeMs) | ||
| .setErrorCode(Errors.forException(e).code()) | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public AssignReplicasToDirsRequestData data() { | ||
| return data; | ||
| } | ||
|
|
||
| public static AssignReplicasToDirsRequest parse(ByteBuffer buffer, short version) { | ||
| return new AssignReplicasToDirsRequest(new AssignReplicasToDirsRequestData( | ||
| new ByteBufferAccessor(buffer), version), version); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.common.requests; | ||
|
|
||
| import org.apache.kafka.common.message.AssignReplicasToDirsResponseData; | ||
| import org.apache.kafka.common.protocol.ApiKeys; | ||
| import org.apache.kafka.common.protocol.ByteBufferAccessor; | ||
| import org.apache.kafka.common.protocol.Errors; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Map; | ||
|
|
||
| public class AssignReplicasToDirsResponse extends AbstractResponse { | ||
|
|
||
| private final AssignReplicasToDirsResponseData data; | ||
|
|
||
| public AssignReplicasToDirsResponse(AssignReplicasToDirsResponseData data) { | ||
| super(ApiKeys.ASSIGN_REPLICAS_TO_DIRS); | ||
| this.data = data; | ||
| } | ||
|
|
||
| @Override | ||
| public AssignReplicasToDirsResponseData data() { | ||
| return data; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<Errors, Integer> errorCounts() { | ||
| return Collections.singletonMap(Errors.forCode(data.errorCode()), 1); | ||
| } | ||
|
|
||
| @Override | ||
| public int throttleTimeMs() { | ||
| return data.throttleTimeMs(); | ||
| } | ||
|
|
||
| @Override | ||
| public void maybeSetThrottleTimeMs(int throttleTimeMs) { | ||
| data.setThrottleTimeMs(throttleTimeMs); | ||
| } | ||
|
|
||
| public static AssignReplicasToDirsResponse parse(ByteBuffer buffer, short version) { | ||
| return new AssignReplicasToDirsResponse(new AssignReplicasToDirsResponseData( | ||
| new ByteBufferAccessor(buffer), version)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one or more | ||
| // contributor license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright ownership. | ||
| // The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| // (the "License"); you may not use this file except in compliance with | ||
| // the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| { | ||
| "apiKey": 73, | ||
| "type": "request", | ||
| "listeners": ["controller"], | ||
| "name": "AssignReplicasToDirsRequest", | ||
| "validVersions": "0", | ||
| "flexibleVersions": "0+", | ||
| "fields": [ | ||
| { "name": "BrokerId", "type": "int32", "versions": "0+", "entityType": "brokerId", | ||
| "about": "The ID of the requesting broker" }, | ||
| { "name": "BrokerEpoch", "type": "int64", "versions": "0+", "default": "-1", | ||
| "about": "The epoch of the requesting broker" }, | ||
| { "name": "Directories", "type": "[]DirectoryData", "versions": "0+", "fields": [ | ||
| { "name": "Id", "type": "uuid", "versions": "0+", "about": "The ID of the directory" }, | ||
| { "name": "Topics", "type": "[]TopicData", "versions": "0+", "fields": [ | ||
| { "name": "TopicId", "type": "uuid", "versions": "0+", | ||
| "about": "The ID of the assigned topic" }, | ||
| { "name": "Partitions", "type": "[]PartitionData", "versions": "0+", "fields": [ | ||
| { "name": "PartitionIndex", "type": "int32", "versions": "0+", | ||
| "about": "The partition index" } | ||
| ]} | ||
| ]} | ||
| ]} | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one or more | ||
| // contributor license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright ownership. | ||
| // The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| // (the "License"); you may not use this file except in compliance with | ||
| // the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| { | ||
| "apiKey": 73, | ||
| "type": "response", | ||
| "name": "AssignReplicasToDirsResponse", | ||
| "validVersions": "0", | ||
| "flexibleVersions": "0+", | ||
| "fields": [ | ||
| { "name": "ThrottleTimeMs", "type": "int32", "versions": "0+", | ||
| "about": "The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota." }, | ||
| { "name": "ErrorCode", "type": "int16", "versions": "0+", | ||
| "about": "The top level response error code" }, | ||
| { "name": "Directories", "type": "[]DirectoryData", "versions": "0+", "fields": [ | ||
| { "name": "Id", "type": "uuid", "versions": "0+", "about": "The ID of the directory" }, | ||
| { "name": "Topics", "type": "[]TopicData", "versions": "0+", "fields": [ | ||
| { "name": "TopicId", "type": "uuid", "versions": "0+", | ||
| "about": "The ID of the assigned topic" }, | ||
| { "name": "Partitions", "type": "[]PartitionData", "versions": "0+", "fields": [ | ||
| { "name": "PartitionIndex", "type": "int32", "versions": "0+", | ||
| "about": "The partition index" }, | ||
| { "name": "ErrorCode", "type": "int16", "versions": "0+", | ||
| "about": "The partition level error code" } | ||
| ]} | ||
| ]} | ||
| ]} | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
| "type": "request", | ||
| "listeners": ["controller"], | ||
| "name": "BrokerHeartbeatRequest", | ||
| "validVersions": "0", | ||
| "validVersions": "0-1", | ||
|
Contributor
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. For my understanding, is there a benefit to updating the API version when you are adding a tagged (optional) field only?
Member
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. I guess this is more confusing now after the discussion around whether to burn the tag for Replicas or not. So this is a good question. KIP-482 does say part of the motivation for tagged fields is to add them without bumping the record version:
I'd rather we don't have two different definitions for same record version. That can lead to unnecessary confusion. It also feels weird to bump the version for PartitionRecord but not for PartitionChangeRecord. I also don't see any downside with bumping the version. I wonder what @cmccabe 's take is on this.
Contributor
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. I thought about this over the weekend and I am happy to approve the pull request in its current state and then circle back to this at a later point in time. I think that it won't break anything whichever way you decide to go forward. |
||
| "flexibleVersions": "0+", | ||
| "fields": [ | ||
| { "name": "BrokerId", "type": "int32", "versions": "0+", "entityType": "brokerId", | ||
|
|
@@ -30,6 +30,8 @@ | |
| { "name": "WantFence", "type": "bool", "versions": "0+", | ||
| "about": "True if the broker wants to be fenced, false otherwise." }, | ||
| { "name": "WantShutDown", "type": "bool", "versions": "0+", | ||
| "about": "True if the broker wants to be shut down, false otherwise." } | ||
| "about": "True if the broker wants to be shut down, false otherwise." }, | ||
| { "name": "OfflineLogDirs", "type": "[]uuid", "versions": "1+", "taggedVersions": "1+", "tag": "0", | ||
|
Member
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. Shall this |
||
| "about": "Log directories that failed and went offline." } | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,14 +14,16 @@ | |||||||||||||||||||||||||||||||||||||||||
| // limitations under the License. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // Version 1 adds Zk broker epoch to the request if the broker is migrating from Zk mode to KRaft mode. | ||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // Version 2 adds the PreviousBrokerEpoch for the KIP-966 | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // Version 3 adds LogDirs for KIP-858 | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| "apiKey":62, | ||||||||||||||||||||||||||||||||||||||||||
| "type": "request", | ||||||||||||||||||||||||||||||||||||||||||
| "listeners": ["controller"], | ||||||||||||||||||||||||||||||||||||||||||
| "name": "BrokerRegistrationRequest", | ||||||||||||||||||||||||||||||||||||||||||
| "validVersions": "0-2", | ||||||||||||||||||||||||||||||||||||||||||
| "validVersions": "0-3", | ||||||||||||||||||||||||||||||||||||||||||
|
Contributor
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. What's the reasoning behind doing two bumps of this API version within the same Kafka release? 3.6 is currently on
Member
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. Hi @aiven-anton. The api protocol may change more than once within the same release. The RPC version is bumped for each change. Refer to MetadataVersion and its documentation. kafka/server-common/src/main/java/org/apache/kafka/server/common/MetadataVersion.java Lines 26 to 45 in f05b342
Contributor
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. @soarez Ah, thanks for pointing this out 🙏 |
||||||||||||||||||||||||||||||||||||||||||
| "flexibleVersions": "0+", | ||||||||||||||||||||||||||||||||||||||||||
| "fields": [ | ||||||||||||||||||||||||||||||||||||||||||
| { "name": "BrokerId", "type": "int32", "versions": "0+", "entityType": "brokerId", | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -57,6 +59,8 @@ | |||||||||||||||||||||||||||||||||||||||||
| { "name": "IsMigratingZkBroker", "type": "bool", "versions": "1+", "default": "false", | ||||||||||||||||||||||||||||||||||||||||||
| "about": "If the required configurations for ZK migration are present, this value is set to true" }, | ||||||||||||||||||||||||||||||||||||||||||
| { "name": "PreviousBrokerEpoch", "type": "int64", "versions": "2+", "default": "-1", | ||||||||||||||||||||||||||||||||||||||||||
| "about": "The epoch before a clean shutdown." } | ||||||||||||||||||||||||||||||||||||||||||
| "about": "The epoch before a clean shutdown." }, | ||||||||||||||||||||||||||||||||||||||||||
| { "name": "LogDirs", "type": "[]uuid", "versions": "3+", | ||||||||||||||||||||||||||||||||||||||||||
| "about": "Log directories configured in this broker which are available." } | ||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
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.
Because
AbstractRequest.doParseRequest()andAbstractResponse.parseResponse()now exceed 150 lines.