Skip to content
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

[ISSUE #8974] add feature switch of recalling, disable by default. #9067

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand
final RecallMessageRequestHeader requestHeader =
request.decodeCommandCustomHeader(RecallMessageRequestHeader.class);

if (!brokerController.getBrokerConfig().isRecallMessageEnable()) {
response.setCode(ResponseCode.NO_PERMISSION);
response.setRemark("recall failed, operation is forbidden");
return response;
}

if (BrokerRole.SLAVE == brokerController.getMessageStoreConfig().getBrokerRole()) {
response.setCode(ResponseCode.SLAVE_NOT_AVAILABLE);
response.setRemark("recall failed, broker service not available");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void init() throws IllegalAccessException, NoSuchFieldException {
when(brokerController.getMessageStore()).thenReturn(messageStore);
when(brokerController.getBrokerConfig()).thenReturn(brokerConfig);
when(brokerConfig.getBrokerName()).thenReturn(BROKER_NAME);
when(brokerConfig.isRecallMessageEnable()).thenReturn(true);
when(brokerController.getBrokerStatsManager()).thenReturn(brokerStatsManager);
when(handlerContext.channel()).thenReturn(channel);
recallMessageProcessor = new RecallMessageProcessor(brokerController);
Expand Down Expand Up @@ -134,6 +135,14 @@ public void testHandlePutMessageResult() {
}
}

@Test
public void testProcessRequest_notEnable() throws RemotingCommandException {
when(brokerConfig.isRecallMessageEnable()).thenReturn(false);
RemotingCommand request = mockRequest(0, TOPIC, TOPIC, "id", BROKER_NAME);
RemotingCommand response = recallMessageProcessor.processRequest(handlerContext, request);
Assert.assertEquals(ResponseCode.NO_PERMISSION, response.getCode());
}

@Test
public void testProcessRequest_invalidStatus() throws RemotingCommandException {
RemotingCommand request = mockRequest(0, TOPIC, TOPIC, "id", BROKER_NAME);
Expand Down
10 changes: 10 additions & 0 deletions common/src/main/java/org/apache/rocketmq/common/BrokerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ public class BrokerConfig extends BrokerIdentity {

private boolean allowRecallWhenBrokerNotWriteable = true;

private boolean recallMessageEnable = false;

public String getConfigBlackList() {
return configBlackList;
}
Expand Down Expand Up @@ -1942,4 +1944,12 @@ public boolean isAllowRecallWhenBrokerNotWriteable() {
public void setAllowRecallWhenBrokerNotWriteable(boolean allowRecallWhenBrokerNotWriteable) {
this.allowRecallWhenBrokerNotWriteable = allowRecallWhenBrokerNotWriteable;
}

public boolean isRecallMessageEnable() {
return recallMessageEnable;
}

public void setRecallMessageEnable(boolean recallMessageEnable) {
this.recallMessageEnable = recallMessageEnable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public static BrokerController createAndStartBroker(String nsAddr) {
brokerConfig.setEnableCalcFilterBitMap(true);
brokerConfig.setAppendAckAsync(true);
brokerConfig.setAppendCkAsync(true);
brokerConfig.setRecallMessageEnable(true);
storeConfig.setEnableConsumeQueueExt(true);
brokerConfig.setLoadBalancePollNameServerInterval(500);
storeConfig.setStorePathRootDir(baseDir);
Expand Down
Loading