-
Notifications
You must be signed in to change notification settings - Fork 12k
[ISSUE #10114] Support delete consumer offset by consumer group and t… #10115
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
Open
echooymxq
wants to merge
1
commit into
apache:develop
Choose a base branch
from
echooymxq:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
59 changes: 59 additions & 0 deletions
59
.../java/org/apache/rocketmq/remoting/protocol/header/DeleteConsumerOffsetRequestHeader.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,59 @@ | ||
| /* | ||
| * 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.rocketmq.remoting.protocol.header; | ||
|
|
||
| import org.apache.rocketmq.common.action.Action; | ||
| import org.apache.rocketmq.common.action.RocketMQAction; | ||
| import org.apache.rocketmq.common.resource.ResourceType; | ||
| import org.apache.rocketmq.common.resource.RocketMQResource; | ||
| import org.apache.rocketmq.remoting.annotation.CFNotNull; | ||
| import org.apache.rocketmq.remoting.exception.RemotingCommandException; | ||
| import org.apache.rocketmq.remoting.protocol.RequestCode; | ||
| import org.apache.rocketmq.remoting.rpc.RpcRequestHeader; | ||
|
|
||
| @RocketMQAction(value = RequestCode.DELETE_CONSUMER_OFFSET, action = Action.DELETE) | ||
| public class DeleteConsumerOffsetRequestHeader extends RpcRequestHeader { | ||
| @CFNotNull | ||
| @RocketMQResource(ResourceType.GROUP) | ||
| private String consumerGroup; | ||
|
|
||
| @CFNotNull | ||
| @RocketMQResource(ResourceType.TOPIC) | ||
| private String topic; | ||
|
|
||
| @Override | ||
| public void checkFields() throws RemotingCommandException { | ||
| } | ||
|
|
||
| public String getConsumerGroup() { | ||
| return consumerGroup; | ||
| } | ||
|
|
||
| public void setConsumerGroup(String consumerGroup) { | ||
| this.consumerGroup = consumerGroup; | ||
| } | ||
|
|
||
| public String getTopic() { | ||
| return topic; | ||
| } | ||
|
|
||
| public void setTopic(String topic) { | ||
| this.topic = topic; | ||
| } | ||
| } | ||
|
|
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
103 changes: 103 additions & 0 deletions
103
...s/src/main/java/org/apache/rocketmq/tools/command/offset/DeleteConsumerOffsetCommand.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,103 @@ | ||
| /* | ||
| * 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.rocketmq.tools.command.offset; | ||
|
|
||
| import java.util.Set; | ||
| import org.apache.commons.cli.CommandLine; | ||
| import org.apache.commons.cli.Option; | ||
| import org.apache.commons.cli.Options; | ||
| import org.apache.rocketmq.remoting.RPCHook; | ||
| import org.apache.rocketmq.srvutil.ServerUtil; | ||
| import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; | ||
| import org.apache.rocketmq.tools.command.CommandUtil; | ||
| import org.apache.rocketmq.tools.command.SubCommand; | ||
| import org.apache.rocketmq.tools.command.SubCommandException; | ||
|
|
||
| public class DeleteConsumerOffsetCommand implements SubCommand { | ||
|
|
||
| @Override | ||
| public String commandName() { | ||
| return "deleteConsumerOffset"; | ||
| } | ||
|
|
||
| @Override | ||
| public String commandDesc() { | ||
| return "Delete consumer offset for specified consumer group and topic."; | ||
| } | ||
|
|
||
| @Override | ||
| public Options buildCommandlineOptions(Options options) { | ||
| Option opt = new Option("g", "consumerGroup", true, "consumer group name (required)"); | ||
| opt.setRequired(true); | ||
| options.addOption(opt); | ||
|
|
||
| opt = new Option("t", "topic", true, "topic name (required)"); | ||
| opt.setRequired(true); | ||
| options.addOption(opt); | ||
|
|
||
| opt = new Option("b", "brokerAddr", true, "delete consumer offset from which broker"); | ||
| opt.setRequired(false); | ||
| options.addOption(opt); | ||
|
|
||
| opt = new Option("c", "clusterName", true, "delete consumer offset from which cluster"); | ||
| opt.setRequired(false); | ||
| options.addOption(opt); | ||
|
|
||
| return options; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException { | ||
| DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); | ||
| defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); | ||
|
|
||
| if (commandLine.hasOption('n')) { | ||
| defaultMQAdminExt.setNamesrvAddr(commandLine.getOptionValue('n').trim()); | ||
| } | ||
| try { | ||
| String group = commandLine.getOptionValue('g').trim(); | ||
| String topic = commandLine.getOptionValue('t').trim(); | ||
| defaultMQAdminExt.start(); | ||
|
|
||
| if (commandLine.hasOption('b')) { | ||
| String addr = commandLine.getOptionValue('b').trim(); | ||
|
|
||
| defaultMQAdminExt.deleteConsumerOffset(addr, group, topic); | ||
| System.out.printf("delete consumer offset for group [%s] topic [%s] from broker [%s] success.%n", | ||
| group, topic, addr); | ||
| return; | ||
| } else if (commandLine.hasOption('c')) { | ||
| String clusterName = commandLine.getOptionValue('c').trim(); | ||
|
|
||
| Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName); | ||
| for (String master : masterSet) { | ||
| defaultMQAdminExt.deleteConsumerOffset(master, group, topic); | ||
| System.out.printf( | ||
| "delete consumer offset for group [%s] topic [%s] from broker [%s] in cluster [%s] success.%n", | ||
| group, topic, master, clusterName); | ||
| } | ||
| return; | ||
| } | ||
| ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options); | ||
| } catch (Exception e) { | ||
| throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); | ||
| } finally { | ||
| defaultMQAdminExt.shutdown(); | ||
| } | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
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.
Using
assertto check for null values is not ideal. Users must add the JVM startup parameter-eaduring configuration for it to take effect; otherwise, there is a risk of NPE errors.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.
@Kris20030907 There are many similar issues in MQClientAPIImpl. We may need to open a separate issue for discussion.
Uh oh!
There was an error while loading. Please reload this page.
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.
Yep, I think this is necessary; other projects have encountered similar issues in production environments.
cc.@RongtongJin
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.
@Kris20030907 From your perspective, i'd like to ask whether this features is necessary for users. we have encountered many users with similar demands in the production environment.
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.
This is just an optimization point. Without adding the
-eaparameter, the assert logic here will not take effect. People who are unaware of this feature might be misled when troubleshooting, because IDEA automatically adds this parameter, which may differ from the actual environment.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.
@Kris20030907 The feature I'm referring to specifically is
delete consumer offset.😂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.
got it, No users have raised this request yet, but I think it could be a good option.