forked from apache/kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAFKA-16713: Define initial set of RPCs for KIP-932 (apache#16022)
This PR defines the initial set of RPCs for KIP-932. The RPCs for the admin client and state management are not in this PR. Reviewers: Apoorv Mittal <[email protected]>, Manikumar Reddy <[email protected]>
- Loading branch information
1 parent
8507693
commit 8f82f14
Showing
35 changed files
with
2,100 additions
and
9 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
clients/src/main/java/org/apache/kafka/common/ShareGroupState.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,56 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.Arrays; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* The share group state. | ||
*/ | ||
public enum ShareGroupState { | ||
UNKNOWN("Unknown"), | ||
STABLE("Stable"), | ||
DEAD("Dead"), | ||
EMPTY("Empty"); | ||
|
||
private final static Map<String, ShareGroupState> NAME_TO_ENUM = Arrays.stream(values()) | ||
.collect(Collectors.toMap(state -> state.name.toUpperCase(Locale.ROOT), Function.identity())); | ||
|
||
private final String name; | ||
|
||
ShareGroupState(String name) { | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* Case-insensitive share group state lookup by string name. | ||
*/ | ||
public static ShareGroupState parse(String name) { | ||
ShareGroupState state = NAME_TO_ENUM.get(name.toUpperCase(Locale.ROOT)); | ||
return state == null ? UNKNOWN : state; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
clients/src/main/java/org/apache/kafka/common/errors/FencedStateEpochException.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,28 @@ | ||
/* | ||
* 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.errors; | ||
|
||
/** | ||
* Thrown when the share coordinator rejected the request because the share-group state epoch did not match. | ||
*/ | ||
public class FencedStateEpochException extends ApiException { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public FencedStateEpochException(String message) { | ||
super(message); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
clients/src/main/java/org/apache/kafka/common/errors/InvalidRecordStateException.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,30 @@ | ||
/* | ||
* 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.errors; | ||
|
||
/** | ||
* Thrown when the acknowledgement of delivery of a record could not be completed because the record | ||
* state is invalid. | ||
*/ | ||
public class InvalidRecordStateException extends ApiException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public InvalidRecordStateException(String message) { | ||
super(message); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
clients/src/main/java/org/apache/kafka/common/errors/InvalidShareSessionEpochException.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,28 @@ | ||
/* | ||
* 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.errors; | ||
|
||
/** | ||
* Thrown when the share session epoch is invalid. | ||
*/ | ||
public class InvalidShareSessionEpochException extends RetriableException { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public InvalidShareSessionEpochException(String message) { | ||
super(message); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
clients/src/main/java/org/apache/kafka/common/errors/ShareSessionNotFoundException.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,28 @@ | ||
/* | ||
* 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.errors; | ||
|
||
/** | ||
* Thrown when the share session was not found. | ||
*/ | ||
public class ShareSessionNotFoundException extends RetriableException { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public ShareSessionNotFoundException(String message) { | ||
super(message); | ||
} | ||
} |
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
127 changes: 127 additions & 0 deletions
127
clients/src/main/java/org/apache/kafka/common/requests/ShareAcknowledgeRequest.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,127 @@ | ||
/* | ||
* 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.TopicIdPartition; | ||
import org.apache.kafka.common.Uuid; | ||
import org.apache.kafka.common.message.ShareAcknowledgeRequestData; | ||
import org.apache.kafka.common.message.ShareAcknowledgeResponseData; | ||
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.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ShareAcknowledgeRequest extends AbstractRequest { | ||
|
||
public static class Builder extends AbstractRequest.Builder<ShareAcknowledgeRequest> { | ||
|
||
private final ShareAcknowledgeRequestData data; | ||
|
||
public Builder(ShareAcknowledgeRequestData data) { | ||
this(data, false); | ||
} | ||
|
||
public Builder(ShareAcknowledgeRequestData data, boolean enableUnstableLastVersion) { | ||
super(ApiKeys.SHARE_ACKNOWLEDGE, enableUnstableLastVersion); | ||
this.data = data; | ||
} | ||
|
||
public static ShareAcknowledgeRequest.Builder forConsumer(String groupId, ShareFetchMetadata metadata, | ||
Map<TopicIdPartition, List<ShareAcknowledgeRequestData.AcknowledgementBatch>> acknowledgementsMap) { | ||
ShareAcknowledgeRequestData data = new ShareAcknowledgeRequestData(); | ||
data.setGroupId(groupId); | ||
if (metadata != null) { | ||
data.setMemberId(metadata.memberId().toString()); | ||
data.setShareSessionEpoch(metadata.epoch()); | ||
} | ||
|
||
// Build a map of topics to acknowledge keyed by topic ID, and within each a map of partitions keyed by index | ||
Map<Uuid, Map<Integer, ShareAcknowledgeRequestData.AcknowledgePartition>> ackMap = new HashMap<>(); | ||
|
||
for (Map.Entry<TopicIdPartition, List<ShareAcknowledgeRequestData.AcknowledgementBatch>> acknowledgeEntry : acknowledgementsMap.entrySet()) { | ||
TopicIdPartition tip = acknowledgeEntry.getKey(); | ||
Map<Integer, ShareAcknowledgeRequestData.AcknowledgePartition> partMap = ackMap.computeIfAbsent(tip.topicId(), k -> new HashMap<>()); | ||
ShareAcknowledgeRequestData.AcknowledgePartition ackPartition = partMap.get(tip.partition()); | ||
if (ackPartition == null) { | ||
ackPartition = new ShareAcknowledgeRequestData.AcknowledgePartition() | ||
.setPartitionIndex(tip.partition()); | ||
partMap.put(tip.partition(), ackPartition); | ||
} | ||
ackPartition.setAcknowledgementBatches(acknowledgeEntry.getValue()); | ||
} | ||
|
||
// Finally, build up the data to fetch | ||
data.setTopics(new ArrayList<>()); | ||
ackMap.forEach((topicId, partMap) -> { | ||
ShareAcknowledgeRequestData.AcknowledgeTopic ackTopic = new ShareAcknowledgeRequestData.AcknowledgeTopic() | ||
.setTopicId(topicId) | ||
.setPartitions(new ArrayList<>()); | ||
data.topics().add(ackTopic); | ||
|
||
partMap.forEach((index, ackPartition) -> ackTopic.partitions().add(ackPartition)); | ||
}); | ||
|
||
return new ShareAcknowledgeRequest.Builder(data, true); | ||
} | ||
|
||
public ShareAcknowledgeRequestData data() { | ||
return data; | ||
} | ||
|
||
@Override | ||
public ShareAcknowledgeRequest build(short version) { | ||
return new ShareAcknowledgeRequest(data, version); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return data.toString(); | ||
} | ||
} | ||
|
||
private final ShareAcknowledgeRequestData data; | ||
|
||
public ShareAcknowledgeRequest(ShareAcknowledgeRequestData data, short version) { | ||
super(ApiKeys.SHARE_ACKNOWLEDGE, version); | ||
this.data = data; | ||
} | ||
|
||
@Override | ||
public ShareAcknowledgeRequestData data() { | ||
return data; | ||
} | ||
|
||
@Override | ||
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) { | ||
Errors error = Errors.forException(e); | ||
return new ShareAcknowledgeResponse(new ShareAcknowledgeResponseData() | ||
.setThrottleTimeMs(throttleTimeMs) | ||
.setErrorCode(error.code())); | ||
} | ||
|
||
public static ShareAcknowledgeRequest parse(ByteBuffer buffer, short version) { | ||
return new ShareAcknowledgeRequest( | ||
new ShareAcknowledgeRequestData(new ByteBufferAccessor(buffer), version), | ||
version | ||
); | ||
} | ||
} |
Oops, something went wrong.