-
Notifications
You must be signed in to change notification settings - Fork 14k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAFKA-12620 Allocate producer ids on the controller (#10504)
Introduce new AllocateProducerIds RPC and IBP 3.0-IV0 as part of KIP-730. This change adds a new AllocateProducerIds RPC which is used by the broker to request a block of producer IDs from the controller. The new IBP added will determine if the broker should talk directly to ZooKeeper (IBP < 3.0) or it if should use the new RPC to talk to the controller (IBP >= 3.0). Per-broker property overrides for ClusterTests were also added (in order to test mixed IBPs in a cluster) Reviewers: Colin P. McCabe <cmccabe@apache.org>
- Loading branch information
Showing
32 changed files
with
868 additions
and
154 deletions.
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
72 changes: 72 additions & 0 deletions
72
clients/src/main/java/org/apache/kafka/common/requests/AllocateProducerIdsRequest.java
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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.AllocateProducerIdsRequestData; | ||
import org.apache.kafka.common.message.AllocateProducerIdsResponseData; | ||
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 AllocateProducerIdsRequest extends AbstractRequest { | ||
private final AllocateProducerIdsRequestData data; | ||
|
||
public AllocateProducerIdsRequest(AllocateProducerIdsRequestData data, short version) { | ||
super(ApiKeys.ALLOCATE_PRODUCER_IDS, version); | ||
this.data = data; | ||
} | ||
|
||
@Override | ||
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) { | ||
return new AllocateProducerIdsResponse(new AllocateProducerIdsResponseData() | ||
.setThrottleTimeMs(throttleTimeMs) | ||
.setErrorCode(Errors.forException(e).code())); | ||
} | ||
|
||
@Override | ||
public AllocateProducerIdsRequestData data() { | ||
return data; | ||
} | ||
|
||
public static class Builder extends AbstractRequest.Builder<AllocateProducerIdsRequest> { | ||
|
||
private final AllocateProducerIdsRequestData data; | ||
|
||
public Builder(AllocateProducerIdsRequestData data) { | ||
super(ApiKeys.ALLOCATE_PRODUCER_IDS); | ||
this.data = data; | ||
} | ||
|
||
@Override | ||
public AllocateProducerIdsRequest build(short version) { | ||
return new AllocateProducerIdsRequest(data, version); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return data.toString(); | ||
} | ||
} | ||
|
||
public static AllocateProducerIdsRequest parse(ByteBuffer buffer, short version) { | ||
return new AllocateProducerIdsRequest(new AllocateProducerIdsRequestData( | ||
new ByteBufferAccessor(buffer), version), version); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
clients/src/main/java/org/apache/kafka/common/requests/AllocateProducerIdsResponse.java
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* 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.AllocateProducerIdsResponseData; | ||
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 AllocateProducerIdsResponse extends AbstractResponse { | ||
|
||
private final AllocateProducerIdsResponseData data; | ||
|
||
public AllocateProducerIdsResponse(AllocateProducerIdsResponseData data) { | ||
super(ApiKeys.ALLOCATE_PRODUCER_IDS); | ||
this.data = data; | ||
} | ||
|
||
@Override | ||
public AllocateProducerIdsResponseData data() { | ||
return data; | ||
} | ||
|
||
/** | ||
* The number of each type of error in the response, including {@link Errors#NONE} and top-level errors as well as | ||
* more specifically scoped errors (such as topic or partition-level errors). | ||
* | ||
* @return A count of errors. | ||
*/ | ||
@Override | ||
public Map<Errors, Integer> errorCounts() { | ||
return Collections.singletonMap(Errors.forCode(data.errorCode()), 1); | ||
} | ||
|
||
@Override | ||
public int throttleTimeMs() { | ||
return data.throttleTimeMs(); | ||
} | ||
|
||
public static AllocateProducerIdsResponse parse(ByteBuffer buffer, short version) { | ||
return new AllocateProducerIdsResponse(new AllocateProducerIdsResponseData( | ||
new ByteBufferAccessor(buffer), version)); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
clients/src/main/resources/common/message/AllocateProducerIdsRequest.json
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// 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 implie | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
{ | ||
"apiKey": 67, | ||
"type": "request", | ||
"listeners": ["controller", "zkBroker"], | ||
"name": "AllocateProducerIdsRequest", | ||
"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" } | ||
] | ||
} |
32 changes: 32 additions & 0 deletions
32
clients/src/main/resources/common/message/AllocateProducerIdsResponse.json
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// 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": 67, | ||
"type": "response", | ||
"name": "AllocateProducerIdsResponse", | ||
"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": "ProducerIdStart", "type": "int64", "versions": "0+", "entityType": "producerId", | ||
"about": "The first producer ID in this range, inclusive"}, | ||
{ "name": "ProducerIdLen", "type": "int32", "versions": "0+", | ||
"about": "The number of producer IDs in this range"} | ||
] | ||
} |
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
Oops, something went wrong.