-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KIP-229: DeleteGroups API #4479
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 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b282a21
KIP-229: DeleteGroups API (WIP)
vahidhashemian 10aab1a
Addressed the first round of feedback
vahidhashemian 6d3a0b7
Remove the top level error code in GroupCoordinator
vahidhashemian bcad73a
Consolidated the broker side deletion logic into GroupCoordinator
vahidhashemian a602d3c
Improved the checks for GROUP_ID_NOT_FOUND
vahidhashemian 8fb935f
Acquired the group lock before checking group state
vahidhashemian eabc8b3
Added a unit test for groupNotExists
vahidhashemian ca60b65
Added one more assertion in the new unit test
vahidhashemian 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
31 changes: 31 additions & 0 deletions
31
clients/src/main/java/org/apache/kafka/common/errors/GroupIdNotFoundException.java
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 |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| public class GroupIdNotFoundException extends ApiException { | ||
| private final String groupId; | ||
|
|
||
| public GroupIdNotFoundException(String groupId) { | ||
| super("The group id " + groupId + " was not found"); | ||
| this.groupId = groupId; | ||
| } | ||
|
|
||
| public String groupId() { | ||
| return groupId; | ||
| } | ||
|
|
||
| } |
31 changes: 31 additions & 0 deletions
31
clients/src/main/java/org/apache/kafka/common/errors/GroupNotEmptyException.java
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 |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| public class GroupNotEmptyException extends ApiException { | ||
| private final String groupId; | ||
|
|
||
| public GroupNotEmptyException(String groupId) { | ||
| super("The group " + groupId + " is not empty"); | ||
| this.groupId = groupId; | ||
| } | ||
|
|
||
| public String groupId() { | ||
| return groupId; | ||
| } | ||
|
|
||
| } |
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
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
117 changes: 117 additions & 0 deletions
117
clients/src/main/java/org/apache/kafka/common/requests/DeleteGroupsRequest.java
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 |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /* | ||
| * 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.protocol.ApiKeys; | ||
| import org.apache.kafka.common.protocol.Errors; | ||
| import org.apache.kafka.common.protocol.types.ArrayOf; | ||
| import org.apache.kafka.common.protocol.types.Field; | ||
| import org.apache.kafka.common.protocol.types.Schema; | ||
| import org.apache.kafka.common.protocol.types.Struct; | ||
| import org.apache.kafka.common.utils.Utils; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import static org.apache.kafka.common.protocol.types.Type.STRING; | ||
|
|
||
| public class DeleteGroupsRequest extends AbstractRequest { | ||
| private static final String GROUPS_KEY_NAME = "groups"; | ||
|
|
||
| /* DeleteGroups api */ | ||
| private static final Schema DELETE_GROUPS_REQUEST_V0 = new Schema( | ||
| new Field(GROUPS_KEY_NAME, new ArrayOf(STRING), "An array of groups to be deleted.")); | ||
|
|
||
| public static Schema[] schemaVersions() { | ||
| return new Schema[]{DELETE_GROUPS_REQUEST_V0}; | ||
| } | ||
|
|
||
| private final Set<String> groups; | ||
|
|
||
| public static class Builder extends AbstractRequest.Builder<DeleteGroupsRequest> { | ||
| private final Set<String> groups; | ||
|
|
||
| public Builder(Set<String> groups) { | ||
| super(ApiKeys.DELETE_GROUPS); | ||
| this.groups = groups; | ||
| } | ||
|
|
||
| @Override | ||
| public DeleteGroupsRequest build(short version) { | ||
| return new DeleteGroupsRequest(groups, version); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| StringBuilder bld = new StringBuilder(); | ||
| bld.append("(type=DeleteGroupsRequest"). | ||
| append(", groups=(").append(Utils.join(groups, ", ")).append(")"). | ||
| append(")"); | ||
| return bld.toString(); | ||
| } | ||
| } | ||
|
|
||
| private DeleteGroupsRequest(Set<String> groups, short version) { | ||
| super(version); | ||
| this.groups = groups; | ||
| } | ||
|
|
||
| public DeleteGroupsRequest(Struct struct, short version) { | ||
| super(version); | ||
| Object[] groupsArray = struct.getArray(GROUPS_KEY_NAME); | ||
| Set<String> groups = new HashSet<>(groupsArray.length); | ||
| for (Object group : groupsArray) | ||
| groups.add((String) group); | ||
|
|
||
| this.groups = groups; | ||
| } | ||
|
|
||
| @Override | ||
| protected Struct toStruct() { | ||
| Struct struct = new Struct(ApiKeys.DELETE_GROUPS.requestSchema(version())); | ||
| struct.set(GROUPS_KEY_NAME, groups.toArray()); | ||
| return struct; | ||
| } | ||
|
|
||
| @Override | ||
| public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) { | ||
| Errors error = Errors.forException(e); | ||
| Map<String, Errors> groupErrors = new HashMap<>(); | ||
| for (String group : groups) | ||
| groupErrors.put(group, error); | ||
|
|
||
| switch (version()) { | ||
| case 0: | ||
| return new DeleteGroupsResponse(throttleTimeMs, groupErrors); | ||
| default: | ||
| throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", | ||
| version(), this.getClass().getSimpleName(), ApiKeys.DELETE_GROUPS.latestVersion())); | ||
|
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. nit: instead of the class name, maybe use |
||
| } | ||
| } | ||
|
|
||
| public Set<String> groups() { | ||
| return groups; | ||
| } | ||
|
|
||
| public static DeleteGroupsRequest parse(ByteBuffer buffer, short version) { | ||
| return new DeleteGroupsRequest(ApiKeys.DELETE_GROUPS.parseRequest(version, buffer), version); | ||
| } | ||
|
|
||
| } | ||
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.
nit: may as well initialize with the right size