Skip to content

Commit

Permalink
feat: change some SYSTEM_ERROR to more meaningful error code
Browse files Browse the repository at this point in the history
Change-Id: I4b6ffa5aa18325eeadc29941c5788244c2770423
  • Loading branch information
absolute8511 committed Dec 5, 2024
1 parent f4c4984 commit 74a660c
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ protected RemotingCommand msgCheck(final ChannelHandlerContext ctx,

TopicValidator.ValidateTopicResult result = TopicValidator.validateTopic(requestHeader.getTopic());
if (!result.isValid()) {
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark(result.getRemark());
return response;
}
Expand Down Expand Up @@ -522,7 +522,7 @@ protected RemotingCommand msgCheck(final ChannelHandlerContext ctx,
RemotingHelper.parseChannelRemoteAddr(ctx.channel()));

LOGGER.warn(errorInfo);
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark(errorInfo);

return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ private RemotingCommand getSubscriptionGroup(ChannelHandlerContext ctx,
SubscriptionGroupConfig groupConfig = this.brokerController.getSubscriptionGroupManager().getSubscriptionGroupTable().get(requestHeader.getGroup());
if (groupConfig == null) {
LOGGER.error("No group in this broker, client: {} group: {}", ctx.channel().remoteAddress(), requestHeader.getGroup());
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.SUBSCRIPTION_GROUP_NOT_EXIST);
response.setRemark("No group in this broker");
return response;
}
Expand Down Expand Up @@ -513,13 +513,13 @@ private synchronized RemotingCommand updateAndCreateTopic(ChannelHandlerContext
try {
TopicValidator.ValidateTopicResult result = TopicValidator.validateTopic(topic);
if (!result.isValid()) {
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark(result.getRemark());
return response;
}
if (brokerController.getBrokerConfig().isValidateSystemTopicWhenUpdateTopic()) {
if (TopicValidator.isSystemTopic(topic)) {
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark("The topic[" + topic + "] is conflict with system topic.");
return response;
}
Expand All @@ -540,7 +540,7 @@ private synchronized RemotingCommand updateAndCreateTopic(ChannelHandlerContext
String msgTypeAttrKey = AttributeParser.ATTR_ADD_PLUS_SIGN + TopicAttributes.TOPIC_MESSAGE_TYPE_ATTRIBUTE.getName();
String msgTypeAttrValue = topicConfig.getAttributes().get(msgTypeAttrKey);
if (msgTypeAttrValue != null && msgTypeAttrValue.equals(TopicMessageType.MIXED.getValue())) {
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark("MIXED message type is not supported.");
return response;
}
Expand Down Expand Up @@ -603,13 +603,13 @@ private synchronized RemotingCommand updateAndCreateTopicList(ChannelHandlerCont
String topic = topicConfig.getTopicName();
TopicValidator.ValidateTopicResult result = TopicValidator.validateTopic(topic);
if (!result.isValid()) {
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark(result.getRemark());
return response;
}
if (brokerController.getBrokerConfig().isValidateSystemTopicWhenUpdateTopic()) {
if (TopicValidator.isSystemTopic(topic)) {
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark("The topic[" + topic + "] is conflict with system topic.");
return response;
}
Expand All @@ -619,7 +619,7 @@ private synchronized RemotingCommand updateAndCreateTopicList(ChannelHandlerCont
String msgTypeAttrKey = AttributeParser.ATTR_ADD_PLUS_SIGN + TopicAttributes.TOPIC_MESSAGE_TYPE_ATTRIBUTE.getName();
String msgTypeAttrValue = topicConfig.getAttributes().get(msgTypeAttrKey);
if (msgTypeAttrValue != null && msgTypeAttrValue.equals(TopicMessageType.MIXED.getValue())) {
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark("MIXED message type is not supported.");
return response;
}
Expand Down Expand Up @@ -673,13 +673,13 @@ private synchronized RemotingCommand updateAndCreateStaticTopic(ChannelHandlerCo

TopicValidator.ValidateTopicResult result = TopicValidator.validateTopic(topic);
if (!result.isValid()) {
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark(result.getRemark());
return response;
}
if (brokerController.getBrokerConfig().isValidateSystemTopicWhenUpdateTopic()) {
if (TopicValidator.isSystemTopic(topic)) {
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark("The topic[" + topic + "] is conflict with system topic.");
return response;
}
Expand Down Expand Up @@ -720,14 +720,14 @@ private synchronized RemotingCommand deleteTopic(ChannelHandlerContext ctx,
String topic = requestHeader.getTopic();

if (UtilAll.isBlank(topic)) {
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark("The specified topic is blank.");
return response;
}

if (brokerController.getBrokerConfig().isValidateSystemTopicWhenUpdateTopic()) {
if (TopicValidator.isSystemTopic(topic)) {
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark("The topic[" + topic + "] is conflict with system topic.");
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ private RemotingCommand updateConsumerOffset(ChannelHandlerContext ctx, Remoting
}

if (queueId == null) {
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark("QueueId is null, topic is " + topic);
return response;
}

if (offset == null) {
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark("Offset is null, topic is " + topic);
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public RemotingCommand processRequest(final ChannelHandlerContext ctx,
String errorInfo = String.format("queueId[%d] is illegal, topic:[%s] topicConfig.readQueueNums:[%d] consumer:[%s]",
requestHeader.getQueueId(), requestHeader.getTopic(), topicConfig.getReadQueueNums(), channel.remoteAddress());
POP_LOGGER.warn(errorInfo);
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark(errorInfo);
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private RemotingCommand processRequest(final Channel channel, RemotingCommand re
String errorInfo = String.format("queueId[%d] is illegal, topic:[%s] topicConfig.readQueueNums:[%d] consumer:[%s]",
requestHeader.getQueueId(), requestHeader.getTopic(), topicConfig.getReadQueueNums(), channel.remoteAddress());
LOG.warn(errorInfo);
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark(errorInfo);
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private RemotingCommand processRequest(final Channel channel, RemotingCommand re
String errorInfo = String.format("queueId[%d] is illegal, topic:[%s] topicConfig.readQueueNums:[%d] consumer:[%s]",
requestHeader.getQueueId(), requestHeader.getTopic(), topicConfig.getReadQueueNums(), channel.remoteAddress());
POP_LOGGER.warn(errorInfo);
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark(errorInfo);
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public RemotingCommand processRequest(final ChannelHandlerContext ctx, RemotingC
return response;
}
if (requestHeader.getMaxMsgNums() > 32) {
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark(String.format("the broker[%s] pop message's num is greater than 32",
this.brokerController.getBrokerConfig().getBrokerIP1()));
return response;
Expand Down Expand Up @@ -288,7 +288,7 @@ public RemotingCommand processRequest(final ChannelHandlerContext ctx, RemotingC
requestHeader.getQueueId(), requestHeader.getTopic(), topicConfig.getReadQueueNums(),
channel.remoteAddress());
POP_LOGGER.warn(errorInfo);
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark(errorInfo);
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ private RemotingCommand processRequest(final Channel channel, RemotingCommand re
String errorInfo = String.format("queueId[%d] is illegal, topic:[%s] topicConfig.readQueueNums:[%d] consumer:[%s]",
requestHeader.getQueueId(), requestHeader.getTopic(), topicConfig.getReadQueueNums(), channel.remoteAddress());
LOGGER.warn(errorInfo);
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setCode(ResponseCode.INVALID_PARAMETER);
response.setRemark(errorInfo);
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class ResponseCode extends RemotingSysResponseCode {

public static final int FILTER_DATA_NOT_LATEST = 28;

public static final int INVALID_PARAMETER = 29;

public static final int TRANSACTION_SHOULD_COMMIT = 200;

public static final int TRANSACTION_SHOULD_ROLLBACK = 201;
Expand Down

0 comments on commit 74a660c

Please sign in to comment.