From f124ac3c878d3f349476c19cc63bd67f9acbe0db Mon Sep 17 00:00:00 2001 From: chengxiangwang Date: Wed, 19 Dec 2018 15:45:16 +0800 Subject: [PATCH 1/7] add logic of putting message that exceeds max-check-times to system topic TRANS_CHECK_MAXTIME_TOPIC --- .../processor/AdminBrokerProcessor.java | 8 +++ .../broker/topic/TopicConfigManager.java | 40 ++++++++++++ ...ractTransactionalMessageCheckListener.java | 5 ++ ...aultTransactionalMessageCheckListener.java | 65 ++++++++++++++++++- .../org/apache/rocketmq/common/MixAll.java | 1 + .../rocketmq/common/protocol/RequestCode.java | 5 ++ 6 files changed, 121 insertions(+), 3 deletions(-) diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java index f23cca62d9e..98c376826bc 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java @@ -216,6 +216,8 @@ public RemotingCommand processRequest(ChannelHandlerContext ctx, return getBrokerAclConfigVersion(ctx, request); case RequestCode.UPDATE_GLOBAL_WHITE_ADDRS_CONFIG: return updateGlobalWhiteAddrsConfig(ctx, request); + case RequestCode.RESUME_CHECK_HALF_MESSAGE: + return resumeCheckHalfMessage(ctx, request); default: break; } @@ -1518,4 +1520,10 @@ private RemotingCommand queryConsumeQueue(ChannelHandlerContext ctx, return response; } + + + private RemotingCommand resumeCheckHalfMessage(ChannelHandlerContext ctx, RemotingCommand request) { + return null; + } + } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java b/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java index ed353da4bb9..8652e0bb1b5 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java @@ -270,6 +270,46 @@ public TopicConfig createTopicInSendMessageBackMethod( return topicConfig; } + public TopicConfig createTopicOfTranCheckMaxTime(final int clientDefaultTopicQueueNums, final int perm) { + TopicConfig topicConfig = this.topicConfigTable.get(MixAll.TRANS_CHECK_MAX_TIME_TOPIC); + if (topicConfig != null) + return topicConfig; + + boolean createNew = false; + + try { + if (this.lockTopicConfigTable.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { + try { + topicConfig = this.topicConfigTable.get(MixAll.TRANS_CHECK_MAX_TIME_TOPIC); + if (topicConfig != null) + return topicConfig; + + topicConfig = new TopicConfig(MixAll.TRANS_CHECK_MAX_TIME_TOPIC); + topicConfig.setReadQueueNums(clientDefaultTopicQueueNums); + topicConfig.setWriteQueueNums(clientDefaultTopicQueueNums); + topicConfig.setPerm(perm); + topicConfig.setTopicSysFlag(0); + + log.info("create new topic {}", topicConfig); + this.topicConfigTable.put(MixAll.TRANS_CHECK_MAX_TIME_TOPIC, topicConfig); + createNew = true; + this.dataVersion.nextVersion(); + this.persist(); + } finally { + this.lockTopicConfigTable.unlock(); + } + } + } catch (InterruptedException e) { + log.error("create TRANS_CHECK_MAX_TIME_TOPIC exception", e); + } + + if (createNew) { + this.brokerController.registerBrokerAll(false, true,true); + } + + return topicConfig; + } + public void updateTopicUnitFlag(final String topic, final boolean unit) { TopicConfig topicConfig = this.topicConfigTable.get(topic); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/transaction/AbstractTransactionalMessageCheckListener.java b/broker/src/main/java/org/apache/rocketmq/broker/transaction/AbstractTransactionalMessageCheckListener.java index 659c6af16f0..62507cdfdba 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/transaction/AbstractTransactionalMessageCheckListener.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/transaction/AbstractTransactionalMessageCheckListener.java @@ -17,6 +17,7 @@ package org.apache.rocketmq.broker.transaction; import io.netty.channel.Channel; +import java.util.Random; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.common.message.MessageConst; @@ -36,6 +37,10 @@ public abstract class AbstractTransactionalMessageCheckListener { private BrokerController brokerController; + //queue nums of topic TRANS_CHECK_MAX_TIME_TOPIC + protected final static int TCMT_QUEUE_NUMS = 1; + protected final Random random = new Random(System.currentTimeMillis()); + private static ExecutorService executorService = new ThreadPoolExecutor(2, 5, 100, TimeUnit.SECONDS, new ArrayBlockingQueue(2000), new ThreadFactory() { @Override public Thread newThread(Runnable r) { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListener.java b/broker/src/main/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListener.java index 529bfe4f349..80a0309a887 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListener.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListener.java @@ -17,13 +17,25 @@ package org.apache.rocketmq.broker.transaction.queue; import org.apache.rocketmq.broker.transaction.AbstractTransactionalMessageCheckListener; +import org.apache.rocketmq.common.TopicConfig; import org.apache.rocketmq.common.constant.LoggerName; +import org.apache.rocketmq.common.constant.PermName; +import org.apache.rocketmq.common.message.MessageAccessor; +import org.apache.rocketmq.common.message.MessageConst; +import org.apache.rocketmq.common.message.MessageDecoder; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.logging.InternalLogger; import org.apache.rocketmq.logging.InternalLoggerFactory; +import org.apache.rocketmq.store.MessageExtBrokerInner; +import org.apache.rocketmq.store.PutMessageResult; +import org.apache.rocketmq.store.PutMessageStatus; + +public class DefaultTransactionalMessageCheckListener extends + AbstractTransactionalMessageCheckListener { + + private static final InternalLogger log = InternalLoggerFactory + .getLogger(LoggerName.TRANSACTION_LOGGER_NAME); -public class DefaultTransactionalMessageCheckListener extends AbstractTransactionalMessageCheckListener { - private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.TRANSACTION_LOGGER_NAME); public DefaultTransactionalMessageCheckListener() { super(); @@ -31,6 +43,53 @@ public DefaultTransactionalMessageCheckListener() { @Override public void resolveDiscardMsg(MessageExt msgExt) { - log.error("MsgExt:{} has been checked too many times, so discard it", msgExt); + log.error( + "MsgExt:{} has been checked too many times, so discard it by moving it to system topic TRANS_CHECK_MAXTIME_TOPIC", + msgExt); + + try { + MessageExtBrokerInner brokerInner = toMessageExtBrokerInner(msgExt); + PutMessageResult putMessageResult = this.getBrokerController().getMessageStore() + .putMessage(brokerInner); + if (putMessageResult != null + && putMessageResult.getPutMessageStatus() == PutMessageStatus.PUT_OK) { + log.info( + "Put checked-too-many-time half message to TRANS_CHECK_MAXTIME_TOPIC OK. Restored in queueOffset={}, " + + "commitLogOffset={}, real topic={}", + msgExt.getQueueOffset(), msgExt.getCommitLogOffset(), + msgExt.getUserProperty( + MessageConst.PROPERTY_REAL_TOPIC)); + } else { + log.error( + "Put checked-too-many-time half message to TRANS_CHECK_MAXTIME_TOPIC failed, real topic={}, msgId={}", + msgExt.getTopic(), msgExt.getMsgId()); + } + } catch (Exception e) { + log.warn("Put checked-too-many-time message to TRANS_CHECK_MAXTIME_TOPIC error. {}", e); + } + + } + + private MessageExtBrokerInner toMessageExtBrokerInner(MessageExt msgExt) { + TopicConfig topicConfig = this.getBrokerController().getTopicConfigManager() + .createTopicOfTranCheckMaxTime(TCMT_QUEUE_NUMS, + PermName.PERM_READ | PermName.PERM_WRITE); + int queueId = Math.abs(random.nextInt() % 99999999) % TCMT_QUEUE_NUMS; + MessageExtBrokerInner inner = new MessageExtBrokerInner(); + inner.setTopic(topicConfig.getTopicName()); + inner.setBody(msgExt.getBody()); + inner.setFlag(msgExt.getFlag()); + MessageAccessor.setProperties(inner, msgExt.getProperties()); + inner.setPropertiesString(MessageDecoder.messageProperties2String(msgExt.getProperties())); + inner.setTagsCode(MessageExtBrokerInner.tagsString2tagsCode(msgExt.getTags())); + inner.setQueueId(queueId); + inner.setSysFlag(msgExt.getSysFlag()); + inner.setBornHost(msgExt.getBornHost()); + inner.setBornTimestamp(msgExt.getBornTimestamp()); + inner.setStoreHost(msgExt.getStoreHost()); + inner.setReconsumeTimes(msgExt.getReconsumeTimes()); + inner.setMsgId(msgExt.getMsgId()); + inner.setWaitStoreMsgOK(false); + return inner; } } diff --git a/common/src/main/java/org/apache/rocketmq/common/MixAll.java b/common/src/main/java/org/apache/rocketmq/common/MixAll.java index 550b0b6a556..0af65dff0f1 100644 --- a/common/src/main/java/org/apache/rocketmq/common/MixAll.java +++ b/common/src/main/java/org/apache/rocketmq/common/MixAll.java @@ -92,6 +92,7 @@ public class MixAll { public static final String RMQ_SYS_TRANS_HALF_TOPIC = "RMQ_SYS_TRANS_HALF_TOPIC"; public static final String RMQ_SYS_TRACE_TOPIC = "RMQ_SYS_TRACE_TOPIC"; public static final String RMQ_SYS_TRANS_OP_HALF_TOPIC = "RMQ_SYS_TRANS_OP_HALF_TOPIC"; + public static final String TRANS_CHECK_MAX_TIME_TOPIC = "TRANS_CHECK_MAX_TIME_TOPIC"; public static final String CID_SYS_RMQ_TRANS = "CID_RMQ_SYS_TRANS"; public static final String ACL_CONF_TOOLS_FILE = "/conf/tools.yml"; diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/RequestCode.java b/common/src/main/java/org/apache/rocketmq/common/protocol/RequestCode.java index b771b77b659..58c4b9fe90f 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/RequestCode.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/RequestCode.java @@ -175,4 +175,9 @@ public class RequestCode { public static final int QUERY_CONSUME_QUEUE = 321; public static final int QUERY_DATA_VERSION = 322; + + /** + * resume logic of checking half messages that have been put in TRANS_CHECK_MAXTIME_TOPIC before + */ + public static final int RESUME_CHECK_HALF_MESSAGE = 323; } From 3a1fd0fb06d367c5c8cd13b68c3f1f7fc9d1a789 Mon Sep 17 00:00:00 2001 From: chengxiangwang Date: Tue, 25 Dec 2018 17:56:48 +0800 Subject: [PATCH 2/7] add test case:testResolveDiscardMsg --- ...TransactionalMessageCheckListenerTest.java | 49 +++++++++++++++---- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java b/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java index 17bf00b4310..b758bd08225 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java @@ -16,8 +16,10 @@ */ package org.apache.rocketmq.broker.transaction.queue; +import java.net.InetSocketAddress; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.common.BrokerConfig; +import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.message.MessageAccessor; import org.apache.rocketmq.common.message.MessageConst; import org.apache.rocketmq.common.message.MessageExt; @@ -37,14 +39,18 @@ public class DefaultTransactionalMessageCheckListenerTest { private DefaultTransactionalMessageCheckListener listener; @Spy - private BrokerController brokerController = new BrokerController(new BrokerConfig(), new NettyServerConfig(), - new NettyClientConfig(), new MessageStoreConfig()); + private BrokerController brokerController = new BrokerController(new BrokerConfig(), + new NettyServerConfig(), + new NettyClientConfig(), new MessageStoreConfig()); @Before - public void init() { + public void init() throws Exception { listener = new DefaultTransactionalMessageCheckListener(); listener.setBrokerController(brokerController); + brokerController.initialize(); + brokerController.start(); + } @Test @@ -53,26 +59,51 @@ public void testResolveHalfMsg() { } @Test - public void testSendCheckMessage() throws Exception{ + public void testSendCheckMessage() throws Exception { MessageExt messageExt = createMessageExt(); listener.sendCheckMessage(messageExt); } @Test - public void sendCheckMessage(){ + public void sendCheckMessage() { listener.resolveDiscardMsg(createMessageExt()); } private MessageExtBrokerInner createMessageExt() { MessageExtBrokerInner inner = new MessageExtBrokerInner(); - MessageAccessor.putProperty(inner,MessageConst.PROPERTY_REAL_QUEUE_ID,"1"); - MessageAccessor.putProperty(inner,MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX,"1234255"); - MessageAccessor.putProperty(inner,MessageConst.PROPERTY_REAL_TOPIC,"realTopic"); - inner.setTransactionId(inner.getProperty(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX)); + MessageAccessor.putProperty(inner, MessageConst.PROPERTY_REAL_QUEUE_ID, "1"); + MessageAccessor + .putProperty(inner, MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX, "1234255"); + MessageAccessor.putProperty(inner, MessageConst.PROPERTY_REAL_TOPIC, "realTopic"); + inner.setTransactionId( + inner.getProperty(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX)); inner.setBody("check".getBytes()); inner.setMsgId("12344567890"); inner.setQueueId(0); return inner; } + @Test + public void testResolveDiscardMsg() { + MessageExt messageExt = new MessageExt(); + messageExt.setTopic(MixAll.RMQ_SYS_TRANS_HALF_TOPIC); + messageExt.setQueueId(0); + messageExt.setBody("test resolve discard msg".getBytes()); + messageExt.setStoreHost(new InetSocketAddress("127.0.0.1",10911)); + messageExt.setBornHost(new InetSocketAddress("127.0.0.1",54270)); + MessageAccessor.putProperty(messageExt, MessageConst.PROPERTY_REAL_TOPIC, "test_topic"); + MessageAccessor.putProperty(messageExt, MessageConst.PROPERTY_PRODUCER_GROUP, + "PID_TEST_DISCARD_MSG"); + MessageAccessor.putProperty(messageExt, MessageConst.PROPERTY_TRANSACTION_PREPARED, "true"); + MessageAccessor + .putProperty(messageExt, MessageConst.PROPERTY_TRANSACTION_CHECK_TIMES, "15"); + MessageAccessor + .putProperty(messageExt, MessageConst.PROPERTY_REAL_QUEUE_ID, "2"); + MessageAccessor + .putProperty(messageExt, MessageConst.PROPERTY_TAGS, "test_discard_msg"); + MessageAccessor + .putProperty(messageExt, MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX, "AC14157E4F1C18B4AAC27EB1A0F30000"); + listener.resolveDiscardMsg(messageExt); + } + } From c2d538c11b30beb5ada5dec046b8a1a536f5be2e Mon Sep 17 00:00:00 2001 From: chengxiangwang Date: Tue, 25 Dec 2018 22:14:40 +0800 Subject: [PATCH 3/7] add @After logic to test case --- .../queue/DefaultTransactionalMessageCheckListenerTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java b/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java index b758bd08225..0b08177145b 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java @@ -27,6 +27,7 @@ import org.apache.rocketmq.remoting.netty.NettyServerConfig; import org.apache.rocketmq.store.MessageExtBrokerInner; import org.apache.rocketmq.store.config.MessageStoreConfig; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -53,6 +54,10 @@ public void init() throws Exception { } + @After + public void destroy() { + brokerController.shutdown(); + } @Test public void testResolveHalfMsg() { listener.resolveHalfMsg(createMessageExt()); From 8202b7b199cc13b851cd753fddf1c2b0f4267eb9 Mon Sep 17 00:00:00 2001 From: chengxiangwang Date: Wed, 26 Dec 2018 00:09:54 +0800 Subject: [PATCH 4/7] comment brokerController.shutdown and use mock --- .../DefaultTransactionalMessageCheckListenerTest.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java b/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java index 0b08177145b..3c5869e5fd7 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java @@ -26,11 +26,13 @@ import org.apache.rocketmq.remoting.netty.NettyClientConfig; import org.apache.rocketmq.remoting.netty.NettyServerConfig; import org.apache.rocketmq.store.MessageExtBrokerInner; +import org.apache.rocketmq.store.MessageStore; import org.apache.rocketmq.store.config.MessageStoreConfig; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; @@ -38,6 +40,8 @@ public class DefaultTransactionalMessageCheckListenerTest { private DefaultTransactionalMessageCheckListener listener; + @Mock + private MessageStore messageStore; @Spy private BrokerController brokerController = new BrokerController(new BrokerConfig(), @@ -49,14 +53,13 @@ public class DefaultTransactionalMessageCheckListenerTest { public void init() throws Exception { listener = new DefaultTransactionalMessageCheckListener(); listener.setBrokerController(brokerController); - brokerController.initialize(); - brokerController.start(); + brokerController.setMessageStore(messageStore); } @After public void destroy() { - brokerController.shutdown(); +// brokerController.shutdown(); } @Test public void testResolveHalfMsg() { From 80be5e97c4b0c769522a0a5ec14def344d5bc4d3 Mon Sep 17 00:00:00 2001 From: chengxiangwang Date: Mon, 14 Jan 2019 21:12:24 +0800 Subject: [PATCH 5/7] add logic of resuming half message check --- .../processor/AdminBrokerProcessor.java | 723 ++++++++++++------ .../processor/AdminBrokerProcessorTest.java | 155 ++++ .../rocketmq/client/impl/MQClientAPIImpl.java | 27 + .../body/ResumeCheckHalfMessageResult.java | 60 ++ .../common/protocol/body/ResumeResult.java | 23 + .../ResumeCheckHalfMessageRequestHeader.java | 45 ++ pom.xml | 14 +- .../tools/admin/DefaultMQAdminExt.java | 14 + .../tools/admin/DefaultMQAdminExtImpl.java | 20 + .../rocketmq/tools/admin/MQAdminExt.java | 6 + 10 files changed, 848 insertions(+), 239 deletions(-) create mode 100644 broker/src/test/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessorTest.java create mode 100644 common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeCheckHalfMessageResult.java create mode 100644 common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeResult.java create mode 100644 common/src/main/java/org/apache/rocketmq/common/protocol/header/ResumeCheckHalfMessageRequestHeader.java diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java index 98c376826bc..1bb79e0b94e 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java @@ -37,6 +37,7 @@ import org.apache.rocketmq.broker.client.ConsumerGroupInfo; import org.apache.rocketmq.broker.filter.ConsumerFilterData; import org.apache.rocketmq.broker.filter.ExpressionMessageFilter; +import org.apache.rocketmq.broker.transaction.queue.TransactionalMessageUtil; import org.apache.rocketmq.common.MQVersion; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.PlainAccessConfig; @@ -53,7 +54,10 @@ import org.apache.rocketmq.common.protocol.header.UpdateGlobalWhiteAddrsConfigRequestHeader; import org.apache.rocketmq.logging.InternalLogger; import org.apache.rocketmq.logging.InternalLoggerFactory; +import org.apache.rocketmq.common.message.MessageAccessor; +import org.apache.rocketmq.common.message.MessageConst; import org.apache.rocketmq.common.message.MessageDecoder; +import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.message.MessageId; import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.protocol.RequestCode; @@ -73,6 +77,8 @@ import org.apache.rocketmq.common.protocol.body.QueryConsumeTimeSpanBody; import org.apache.rocketmq.common.protocol.body.QueryCorrectionOffsetBody; import org.apache.rocketmq.common.protocol.body.QueueTimeSpan; +import org.apache.rocketmq.common.protocol.body.ResumeCheckHalfMessageResult; +import org.apache.rocketmq.common.protocol.body.ResumeResult; import org.apache.rocketmq.common.protocol.body.TopicList; import org.apache.rocketmq.common.protocol.body.UnlockBatchRequestBody; import org.apache.rocketmq.common.protocol.header.CloneGroupOffsetRequestHeader; @@ -100,6 +106,7 @@ import org.apache.rocketmq.common.protocol.header.QueryCorrectionOffsetHeader; import org.apache.rocketmq.common.protocol.header.QueryTopicConsumeByWhoRequestHeader; import org.apache.rocketmq.common.protocol.header.ResetOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.ResumeCheckHalfMessageRequestHeader; import org.apache.rocketmq.common.protocol.header.SearchOffsetRequestHeader; import org.apache.rocketmq.common.protocol.header.SearchOffsetResponseHeader; import org.apache.rocketmq.common.protocol.header.ViewBrokerStatsDataRequestHeader; @@ -110,6 +117,8 @@ import org.apache.rocketmq.common.stats.StatsSnapshot; import org.apache.rocketmq.common.subscription.SubscriptionGroupConfig; import org.apache.rocketmq.filter.util.BitsArray; +import org.apache.rocketmq.logging.InternalLogger; +import org.apache.rocketmq.logging.InternalLoggerFactory; import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.exception.RemotingCommandException; import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; @@ -120,12 +129,17 @@ import org.apache.rocketmq.store.ConsumeQueue; import org.apache.rocketmq.store.ConsumeQueueExt; import org.apache.rocketmq.store.DefaultMessageStore; +import org.apache.rocketmq.store.MessageExtBrokerInner; import org.apache.rocketmq.store.MessageFilter; import org.apache.rocketmq.store.MessageStore; +import org.apache.rocketmq.store.PutMessageResult; +import org.apache.rocketmq.store.PutMessageStatus; import org.apache.rocketmq.store.SelectMappedBufferResult; public class AdminBrokerProcessor implements NettyRequestProcessor { - private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); + + private static final InternalLogger log = InternalLoggerFactory + .getLogger(LoggerName.BROKER_LOGGER_NAME); private final BrokerController brokerController; public AdminBrokerProcessor(final BrokerController brokerController) { @@ -134,7 +148,7 @@ public AdminBrokerProcessor(final BrokerController brokerController) { @Override public RemotingCommand processRequest(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { switch (request.getCode()) { case RequestCode.UPDATE_AND_CREATE_TOPIC: return this.updateAndCreateTopic(ctx, request); @@ -231,14 +245,18 @@ public boolean rejectRequest() { } private synchronized RemotingCommand updateAndCreateTopic(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final CreateTopicRequestHeader requestHeader = - (CreateTopicRequestHeader) request.decodeCommandCustomHeader(CreateTopicRequestHeader.class); - log.info("updateAndCreateTopic called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); - - if (requestHeader.getTopic().equals(this.brokerController.getBrokerConfig().getBrokerClusterName())) { - String errorMsg = "the topic[" + requestHeader.getTopic() + "] is conflict with system reserved words."; + (CreateTopicRequestHeader) request + .decodeCommandCustomHeader(CreateTopicRequestHeader.class); + log.info("updateAndCreateTopic called by {}", + RemotingHelper.parseChannelRemoteAddr(ctx.channel())); + + if (requestHeader.getTopic() + .equals(this.brokerController.getBrokerConfig().getBrokerClusterName())) { + String errorMsg = "the topic[" + requestHeader.getTopic() + + "] is conflict with system reserved words."; log.warn(errorMsg); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark(errorMsg); @@ -260,26 +278,31 @@ private synchronized RemotingCommand updateAndCreateTopic(ChannelHandlerContext topicConfig.setWriteQueueNums(requestHeader.getWriteQueueNums()); topicConfig.setTopicFilterType(requestHeader.getTopicFilterTypeEnum()); topicConfig.setPerm(requestHeader.getPerm()); - topicConfig.setTopicSysFlag(requestHeader.getTopicSysFlag() == null ? 0 : requestHeader.getTopicSysFlag()); + topicConfig.setTopicSysFlag( + requestHeader.getTopicSysFlag() == null ? 0 : requestHeader.getTopicSysFlag()); this.brokerController.getTopicConfigManager().updateTopicConfig(topicConfig); - this.brokerController.registerIncrementBrokerData(topicConfig,this.brokerController.getTopicConfigManager().getDataVersion()); + this.brokerController.registerIncrementBrokerData(topicConfig, + this.brokerController.getTopicConfigManager().getDataVersion()); return null; } private synchronized RemotingCommand deleteTopic(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); DeleteTopicRequestHeader requestHeader = - (DeleteTopicRequestHeader) request.decodeCommandCustomHeader(DeleteTopicRequestHeader.class); + (DeleteTopicRequestHeader) request + .decodeCommandCustomHeader(DeleteTopicRequestHeader.class); log.info("deleteTopic called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); this.brokerController.getTopicConfigManager().deleteTopicConfig(requestHeader.getTopic()); this.brokerController.getMessageStore() - .cleanUnusedTopic(this.brokerController.getTopicConfigManager().getTopicConfigTable().keySet()); + .cleanUnusedTopic( + this.brokerController.getTopicConfigManager().getTopicConfigTable() + .keySet()); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); @@ -421,7 +444,8 @@ private RemotingCommand getBrokerAclConfigVersion(ChannelHandlerContext ctx, Rem } private RemotingCommand getAllTopicConfig(ChannelHandlerContext ctx, RemotingCommand request) { - final RemotingCommand response = RemotingCommand.createResponseCommand(GetAllTopicConfigResponseHeader.class); + final RemotingCommand response = RemotingCommand + .createResponseCommand(GetAllTopicConfigResponseHeader.class); // final GetAllTopicConfigResponseHeader responseHeader = // (GetAllTopicConfigResponseHeader) response.readCustomHeader(); @@ -449,10 +473,12 @@ private RemotingCommand getAllTopicConfig(ChannelHandlerContext ctx, RemotingCom return response; } - private synchronized RemotingCommand updateBrokerConfig(ChannelHandlerContext ctx, RemotingCommand request) { + private synchronized RemotingCommand updateBrokerConfig(ChannelHandlerContext ctx, + RemotingCommand request) { final RemotingCommand response = RemotingCommand.createResponseCommand(null); - log.info("updateBrokerConfig called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); + log.info("updateBrokerConfig called by {}", + RemotingHelper.parseChannelRemoteAddr(ctx.channel())); byte[] body = request.getBody(); if (body != null) { @@ -460,10 +486,12 @@ private synchronized RemotingCommand updateBrokerConfig(ChannelHandlerContext ct String bodyStr = new String(body, MixAll.DEFAULT_CHARSET); Properties properties = MixAll.string2Properties(bodyStr); if (properties != null) { - log.info("updateBrokerConfig, new config: [{}] client: {} ", properties, ctx.channel().remoteAddress()); + log.info("updateBrokerConfig, new config: [{}] client: {} ", properties, + ctx.channel().remoteAddress()); this.brokerController.getConfiguration().update(properties); if (properties.containsKey("brokerPermission")) { - this.brokerController.getTopicConfigManager().getDataVersion().nextVersion(); + this.brokerController.getTopicConfigManager().getDataVersion() + .nextVersion(); this.brokerController.registerBrokerAll(false, false, true); } } else { @@ -487,8 +515,10 @@ private synchronized RemotingCommand updateBrokerConfig(ChannelHandlerContext ct private RemotingCommand getBrokerConfig(ChannelHandlerContext ctx, RemotingCommand request) { - final RemotingCommand response = RemotingCommand.createResponseCommand(GetBrokerConfigResponseHeader.class); - final GetBrokerConfigResponseHeader responseHeader = (GetBrokerConfigResponseHeader) response.readCustomHeader(); + final RemotingCommand response = RemotingCommand + .createResponseCommand(GetBrokerConfigResponseHeader.class); + final GetBrokerConfigResponseHeader responseHeader = (GetBrokerConfigResponseHeader) response + .readCustomHeader(); String content = this.brokerController.getConfiguration().getAllConfigsFormatString(); if (content != null && content.length() > 0) { @@ -511,14 +541,18 @@ private RemotingCommand getBrokerConfig(ChannelHandlerContext ctx, RemotingComma } private RemotingCommand searchOffsetByTimestamp(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { - final RemotingCommand response = RemotingCommand.createResponseCommand(SearchOffsetResponseHeader.class); - final SearchOffsetResponseHeader responseHeader = (SearchOffsetResponseHeader) response.readCustomHeader(); + RemotingCommand request) throws RemotingCommandException { + final RemotingCommand response = RemotingCommand + .createResponseCommand(SearchOffsetResponseHeader.class); + final SearchOffsetResponseHeader responseHeader = (SearchOffsetResponseHeader) response + .readCustomHeader(); final SearchOffsetRequestHeader requestHeader = - (SearchOffsetRequestHeader) request.decodeCommandCustomHeader(SearchOffsetRequestHeader.class); + (SearchOffsetRequestHeader) request + .decodeCommandCustomHeader(SearchOffsetRequestHeader.class); - long offset = this.brokerController.getMessageStore().getOffsetInQueueByTime(requestHeader.getTopic(), requestHeader.getQueueId(), - requestHeader.getTimestamp()); + long offset = this.brokerController.getMessageStore() + .getOffsetInQueueByTime(requestHeader.getTopic(), requestHeader.getQueueId(), + requestHeader.getTimestamp()); responseHeader.setOffset(offset); @@ -528,13 +562,17 @@ private RemotingCommand searchOffsetByTimestamp(ChannelHandlerContext ctx, } private RemotingCommand getMaxOffset(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { - final RemotingCommand response = RemotingCommand.createResponseCommand(GetMaxOffsetResponseHeader.class); - final GetMaxOffsetResponseHeader responseHeader = (GetMaxOffsetResponseHeader) response.readCustomHeader(); + RemotingCommand request) throws RemotingCommandException { + final RemotingCommand response = RemotingCommand + .createResponseCommand(GetMaxOffsetResponseHeader.class); + final GetMaxOffsetResponseHeader responseHeader = (GetMaxOffsetResponseHeader) response + .readCustomHeader(); final GetMaxOffsetRequestHeader requestHeader = - (GetMaxOffsetRequestHeader) request.decodeCommandCustomHeader(GetMaxOffsetRequestHeader.class); + (GetMaxOffsetRequestHeader) request + .decodeCommandCustomHeader(GetMaxOffsetRequestHeader.class); - long offset = this.brokerController.getMessageStore().getMaxOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId()); + long offset = this.brokerController.getMessageStore() + .getMaxOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId()); responseHeader.setOffset(offset); @@ -544,13 +582,17 @@ private RemotingCommand getMaxOffset(ChannelHandlerContext ctx, } private RemotingCommand getMinOffset(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { - final RemotingCommand response = RemotingCommand.createResponseCommand(GetMinOffsetResponseHeader.class); - final GetMinOffsetResponseHeader responseHeader = (GetMinOffsetResponseHeader) response.readCustomHeader(); + RemotingCommand request) throws RemotingCommandException { + final RemotingCommand response = RemotingCommand + .createResponseCommand(GetMinOffsetResponseHeader.class); + final GetMinOffsetResponseHeader responseHeader = (GetMinOffsetResponseHeader) response + .readCustomHeader(); final GetMinOffsetRequestHeader requestHeader = - (GetMinOffsetRequestHeader) request.decodeCommandCustomHeader(GetMinOffsetRequestHeader.class); + (GetMinOffsetRequestHeader) request + .decodeCommandCustomHeader(GetMinOffsetRequestHeader.class); - long offset = this.brokerController.getMessageStore().getMinOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId()); + long offset = this.brokerController.getMessageStore() + .getMinOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId()); responseHeader.setOffset(offset); response.setCode(ResponseCode.SUCCESS); @@ -559,14 +601,19 @@ private RemotingCommand getMinOffset(ChannelHandlerContext ctx, } private RemotingCommand getEarliestMsgStoretime(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { - final RemotingCommand response = RemotingCommand.createResponseCommand(GetEarliestMsgStoretimeResponseHeader.class); - final GetEarliestMsgStoretimeResponseHeader responseHeader = (GetEarliestMsgStoretimeResponseHeader) response.readCustomHeader(); + RemotingCommand request) throws RemotingCommandException { + final RemotingCommand response = RemotingCommand + .createResponseCommand(GetEarliestMsgStoretimeResponseHeader.class); + final GetEarliestMsgStoretimeResponseHeader responseHeader = (GetEarliestMsgStoretimeResponseHeader) response + .readCustomHeader(); final GetEarliestMsgStoretimeRequestHeader requestHeader = - (GetEarliestMsgStoretimeRequestHeader) request.decodeCommandCustomHeader(GetEarliestMsgStoretimeRequestHeader.class); + (GetEarliestMsgStoretimeRequestHeader) request + .decodeCommandCustomHeader(GetEarliestMsgStoretimeRequestHeader.class); long timestamp = - this.brokerController.getMessageStore().getEarliestMessageTime(requestHeader.getTopic(), requestHeader.getQueueId()); + this.brokerController.getMessageStore() + .getEarliestMessageTime(requestHeader.getTopic(), + requestHeader.getQueueId()); responseHeader.setTimestamp(timestamp); response.setCode(ResponseCode.SUCCESS); @@ -574,7 +621,8 @@ private RemotingCommand getEarliestMsgStoretime(ChannelHandlerContext ctx, return response; } - private RemotingCommand getBrokerRuntimeInfo(ChannelHandlerContext ctx, RemotingCommand request) { + private RemotingCommand getBrokerRuntimeInfo(ChannelHandlerContext ctx, + RemotingCommand request) { final RemotingCommand response = RemotingCommand.createResponseCommand(null); HashMap runtimeInfo = this.prepareRuntimeInfo(); @@ -589,14 +637,16 @@ private RemotingCommand getBrokerRuntimeInfo(ChannelHandlerContext ctx, Remoting } private RemotingCommand lockBatchMQ(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); - LockBatchRequestBody requestBody = LockBatchRequestBody.decode(request.getBody(), LockBatchRequestBody.class); + LockBatchRequestBody requestBody = LockBatchRequestBody + .decode(request.getBody(), LockBatchRequestBody.class); - Set lockOKMQSet = this.brokerController.getRebalanceLockManager().tryLockBatch( - requestBody.getConsumerGroup(), - requestBody.getMqSet(), - requestBody.getClientId()); + Set lockOKMQSet = this.brokerController.getRebalanceLockManager() + .tryLockBatch( + requestBody.getConsumerGroup(), + requestBody.getMqSet(), + requestBody.getClientId()); LockBatchResponseBody responseBody = new LockBatchResponseBody(); responseBody.setLockOKMQSet(lockOKMQSet); @@ -608,29 +658,34 @@ private RemotingCommand lockBatchMQ(ChannelHandlerContext ctx, } private RemotingCommand unlockBatchMQ(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); - UnlockBatchRequestBody requestBody = UnlockBatchRequestBody.decode(request.getBody(), UnlockBatchRequestBody.class); + UnlockBatchRequestBody requestBody = UnlockBatchRequestBody + .decode(request.getBody(), UnlockBatchRequestBody.class); this.brokerController.getRebalanceLockManager().unlockBatch( - requestBody.getConsumerGroup(), - requestBody.getMqSet(), - requestBody.getClientId()); + requestBody.getConsumerGroup(), + requestBody.getMqSet(), + requestBody.getClientId()); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } - private RemotingCommand updateAndCreateSubscriptionGroup(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + private RemotingCommand updateAndCreateSubscriptionGroup(ChannelHandlerContext ctx, + RemotingCommand request) + throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); - log.info("updateAndCreateSubscriptionGroup called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); + log.info("updateAndCreateSubscriptionGroup called by {}", + RemotingHelper.parseChannelRemoteAddr(ctx.channel())); - SubscriptionGroupConfig config = RemotingSerializable.decode(request.getBody(), SubscriptionGroupConfig.class); + SubscriptionGroupConfig config = RemotingSerializable + .decode(request.getBody(), SubscriptionGroupConfig.class); if (config != null) { - this.brokerController.getSubscriptionGroupManager().updateSubscriptionGroupConfig(config); + this.brokerController.getSubscriptionGroupManager() + .updateSubscriptionGroupConfig(config); } response.setCode(ResponseCode.SUCCESS); @@ -639,7 +694,7 @@ private RemotingCommand updateAndCreateSubscriptionGroup(ChannelHandlerContext c } private RemotingCommand getAllSubscriptionGroup(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); String content = this.brokerController.getSubscriptionGroupManager().encode(); if (content != null && content.length() > 0) { @@ -653,7 +708,8 @@ private RemotingCommand getAllSubscriptionGroup(ChannelHandlerContext ctx, return response; } } else { - log.error("No subscription group in this broker, client:{} ", ctx.channel().remoteAddress()); + log.error("No subscription group in this broker, client:{} ", + ctx.channel().remoteAddress()); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("No subscription group in this broker"); return response; @@ -666,14 +722,17 @@ private RemotingCommand getAllSubscriptionGroup(ChannelHandlerContext ctx, } private RemotingCommand deleteSubscriptionGroup(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); DeleteSubscriptionGroupRequestHeader requestHeader = - (DeleteSubscriptionGroupRequestHeader) request.decodeCommandCustomHeader(DeleteSubscriptionGroupRequestHeader.class); + (DeleteSubscriptionGroupRequestHeader) request + .decodeCommandCustomHeader(DeleteSubscriptionGroupRequestHeader.class); - log.info("deleteSubscriptionGroup called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); + log.info("deleteSubscriptionGroup called by {}", + RemotingHelper.parseChannelRemoteAddr(ctx.channel())); - this.brokerController.getSubscriptionGroupManager().deleteSubscriptionGroupConfig(requestHeader.getGroupName()); + this.brokerController.getSubscriptionGroupManager() + .deleteSubscriptionGroupConfig(requestHeader.getGroupName()); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); @@ -681,13 +740,15 @@ private RemotingCommand deleteSubscriptionGroup(ChannelHandlerContext ctx, } private RemotingCommand getTopicStatsInfo(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetTopicStatsInfoRequestHeader requestHeader = - (GetTopicStatsInfoRequestHeader) request.decodeCommandCustomHeader(GetTopicStatsInfoRequestHeader.class); + (GetTopicStatsInfoRequestHeader) request + .decodeCommandCustomHeader(GetTopicStatsInfoRequestHeader.class); final String topic = requestHeader.getTopic(); - TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); + TopicConfig topicConfig = this.brokerController.getTopicConfigManager() + .selectTopicConfig(topic); if (null == topicConfig) { response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark("topic[" + topic + "] not exist"); @@ -703,16 +764,19 @@ private RemotingCommand getTopicStatsInfo(ChannelHandlerContext ctx, TopicOffset topicOffset = new TopicOffset(); long min = this.brokerController.getMessageStore().getMinOffsetInQueue(topic, i); - if (min < 0) + if (min < 0) { min = 0; + } long max = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i); - if (max < 0) + if (max < 0) { max = 0; + } long timestamp = 0; if (max > 0) { - timestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, max - 1); + timestamp = this.brokerController.getMessageStore() + .getMessageStoreTimeStamp(topic, i, max - 1); } topicOffset.setMinOffset(min); @@ -730,13 +794,15 @@ private RemotingCommand getTopicStatsInfo(ChannelHandlerContext ctx, } private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumerConnectionListRequestHeader requestHeader = - (GetConsumerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetConsumerConnectionListRequestHeader.class); + (GetConsumerConnectionListRequestHeader) request + .decodeCommandCustomHeader(GetConsumerConnectionListRequestHeader.class); ConsumerGroupInfo consumerGroupInfo = - this.brokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup()); + this.brokerController.getConsumerManager() + .getConsumerGroupInfo(requestHeader.getConsumerGroup()); if (consumerGroupInfo != null) { ConsumerConnection bodydata = new ConsumerConnection(); bodydata.setConsumeFromWhere(consumerGroupInfo.getConsumeFromWhere()); @@ -744,7 +810,8 @@ private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, bodydata.setMessageModel(consumerGroupInfo.getMessageModel()); bodydata.getSubscriptionTable().putAll(consumerGroupInfo.getSubscriptionTable()); - Iterator> it = consumerGroupInfo.getChannelInfoTable().entrySet().iterator(); + Iterator> it = consumerGroupInfo + .getChannelInfoTable().entrySet().iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); Connection connection = new Connection(); @@ -765,21 +832,25 @@ private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, } response.setCode(ResponseCode.CONSUMER_NOT_ONLINE); - response.setRemark("the consumer group[" + requestHeader.getConsumerGroup() + "] not online"); + response.setRemark( + "the consumer group[" + requestHeader.getConsumerGroup() + "] not online"); return response; } private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetProducerConnectionListRequestHeader requestHeader = - (GetProducerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetProducerConnectionListRequestHeader.class); + (GetProducerConnectionListRequestHeader) request + .decodeCommandCustomHeader(GetProducerConnectionListRequestHeader.class); ProducerConnection bodydata = new ProducerConnection(); HashMap channelInfoHashMap = - this.brokerController.getProducerManager().getGroupChannelTable().get(requestHeader.getProducerGroup()); + this.brokerController.getProducerManager().getGroupChannelTable() + .get(requestHeader.getProducerGroup()); if (channelInfoHashMap != null) { - Iterator> it = channelInfoHashMap.entrySet().iterator(); + Iterator> it = channelInfoHashMap.entrySet() + .iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); Connection connection = new Connection(); @@ -799,27 +870,31 @@ private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx, } response.setCode(ResponseCode.SYSTEM_ERROR); - response.setRemark("the producer group[" + requestHeader.getProducerGroup() + "] not exist"); + response.setRemark( + "the producer group[" + requestHeader.getProducerGroup() + "] not exist"); return response; } private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumeStatsRequestHeader requestHeader = - (GetConsumeStatsRequestHeader) request.decodeCommandCustomHeader(GetConsumeStatsRequestHeader.class); + (GetConsumeStatsRequestHeader) request + .decodeCommandCustomHeader(GetConsumeStatsRequestHeader.class); ConsumeStats consumeStats = new ConsumeStats(); Set topics = new HashSet(); if (UtilAll.isBlank(requestHeader.getTopic())) { - topics = this.brokerController.getConsumerOffsetManager().whichTopicByConsumer(requestHeader.getConsumerGroup()); + topics = this.brokerController.getConsumerOffsetManager() + .whichTopicByConsumer(requestHeader.getConsumerGroup()); } else { topics.add(requestHeader.getTopic()); } for (String topic : topics) { - TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); + TopicConfig topicConfig = this.brokerController.getTopicConfigManager() + .selectTopicConfig(topic); if (null == topicConfig) { log.warn("consumeStats, topic config not exist, {}", topic); continue; @@ -827,11 +902,14 @@ private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, { SubscriptionData findSubscriptionData = - this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getConsumerGroup(), topic); + this.brokerController.getConsumerManager() + .findSubscriptionData(requestHeader.getConsumerGroup(), topic); if (null == findSubscriptionData - && this.brokerController.getConsumerManager().findSubscriptionDataCount(requestHeader.getConsumerGroup()) > 0) { - log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", requestHeader.getConsumerGroup(), topic); + && this.brokerController.getConsumerManager() + .findSubscriptionDataCount(requestHeader.getConsumerGroup()) > 0) { + log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", + requestHeader.getConsumerGroup(), topic); continue; } } @@ -844,23 +922,27 @@ private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, OffsetWrapper offsetWrapper = new OffsetWrapper(); - long brokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i); - if (brokerOffset < 0) + long brokerOffset = this.brokerController.getMessageStore() + .getMaxOffsetInQueue(topic, i); + if (brokerOffset < 0) { brokerOffset = 0; + } long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset( - requestHeader.getConsumerGroup(), - topic, - i); - if (consumerOffset < 0) + requestHeader.getConsumerGroup(), + topic, + i); + if (consumerOffset < 0) { consumerOffset = 0; + } offsetWrapper.setBrokerOffset(brokerOffset); offsetWrapper.setConsumerOffset(consumerOffset); long timeOffset = consumerOffset - 1; if (timeOffset >= 0) { - long lastTimestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, timeOffset); + long lastTimestamp = this.brokerController.getMessageStore() + .getMessageStoreTimeStamp(topic, i, timeOffset); if (lastTimestamp > 0) { offsetWrapper.setLastTimestamp(lastTimestamp); } @@ -869,7 +951,8 @@ private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, consumeStats.getOffsetTable().put(mq, offsetWrapper); } - double consumeTps = this.brokerController.getBrokerStatsManager().tpsGroupGetNums(requestHeader.getConsumerGroup(), topic); + double consumeTps = this.brokerController.getBrokerStatsManager() + .tpsGroupGetNums(requestHeader.getConsumerGroup(), topic); consumeTps += consumeStats.getConsumeTps(); consumeStats.setConsumeTps(consumeTps); @@ -882,7 +965,8 @@ private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, return response; } - private RemotingCommand getAllConsumerOffset(ChannelHandlerContext ctx, RemotingCommand request) { + private RemotingCommand getAllConsumerOffset(ChannelHandlerContext ctx, + RemotingCommand request) { final RemotingCommand response = RemotingCommand.createResponseCommand(null); String content = this.brokerController.getConsumerOffsetManager().encode(); @@ -897,7 +981,8 @@ private RemotingCommand getAllConsumerOffset(ChannelHandlerContext ctx, Remoting return response; } } else { - log.error("No consumer offset in this broker, client: {} ", ctx.channel().remoteAddress()); + log.error("No consumer offset in this broker, client: {} ", + ctx.channel().remoteAddress()); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("No consumer offset in this broker"); return response; @@ -913,13 +998,15 @@ private RemotingCommand getAllDelayOffset(ChannelHandlerContext ctx, RemotingCom final RemotingCommand response = RemotingCommand.createResponseCommand(null); if (!(this.brokerController.getMessageStore() instanceof DefaultMessageStore)) { - log.error("Delay offset not supported in this messagetore, client: {} ", ctx.channel().remoteAddress()); + log.error("Delay offset not supported in this messagetore, client: {} ", + ctx.channel().remoteAddress()); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("Delay offset not supported in this messagetore"); return response; } - String content = ((DefaultMessageStore) this.brokerController.getMessageStore()).getScheduleMessageService().encode(); + String content = ((DefaultMessageStore) this.brokerController.getMessageStore()) + .getScheduleMessageService().encode(); if (content != null && content.length() > 0) { try { response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET)); @@ -944,12 +1031,15 @@ private RemotingCommand getAllDelayOffset(ChannelHandlerContext ctx, RemotingCom } public RemotingCommand resetOffset(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final ResetOffsetRequestHeader requestHeader = - (ResetOffsetRequestHeader) request.decodeCommandCustomHeader(ResetOffsetRequestHeader.class); - log.info("[reset-offset] reset offset started by {}. topic={}, group={}, timestamp={}, isForce={}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), requestHeader.getGroup(), - requestHeader.getTimestamp(), requestHeader.isForce()); + (ResetOffsetRequestHeader) request + .decodeCommandCustomHeader(ResetOffsetRequestHeader.class); + log.info( + "[reset-offset] reset offset started by {}. topic={}, group={}, timestamp={}, isForce={}", + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), + requestHeader.getGroup(), + requestHeader.getTimestamp(), requestHeader.isForce()); boolean isC = false; LanguageCode language = request.getLanguage(); switch (language) { @@ -957,31 +1047,38 @@ public RemotingCommand resetOffset(ChannelHandlerContext ctx, isC = true; break; } - return this.brokerController.getBroker2Client().resetOffset(requestHeader.getTopic(), requestHeader.getGroup(), - requestHeader.getTimestamp(), requestHeader.isForce(), isC); + return this.brokerController.getBroker2Client() + .resetOffset(requestHeader.getTopic(), requestHeader.getGroup(), + requestHeader.getTimestamp(), requestHeader.isForce(), isC); } public RemotingCommand getConsumerStatus(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final GetConsumerStatusRequestHeader requestHeader = - (GetConsumerStatusRequestHeader) request.decodeCommandCustomHeader(GetConsumerStatusRequestHeader.class); + (GetConsumerStatusRequestHeader) request + .decodeCommandCustomHeader(GetConsumerStatusRequestHeader.class); log.info("[get-consumer-status] get consumer status by {}. topic={}, group={}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), requestHeader.getGroup()); + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), + requestHeader.getGroup()); - return this.brokerController.getBroker2Client().getConsumeStatus(requestHeader.getTopic(), requestHeader.getGroup(), - requestHeader.getClientAddr()); + return this.brokerController.getBroker2Client() + .getConsumeStatus(requestHeader.getTopic(), requestHeader.getGroup(), + requestHeader.getClientAddr()); } private RemotingCommand queryTopicConsumeByWho(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); QueryTopicConsumeByWhoRequestHeader requestHeader = - (QueryTopicConsumeByWhoRequestHeader) request.decodeCommandCustomHeader(QueryTopicConsumeByWhoRequestHeader.class); + (QueryTopicConsumeByWhoRequestHeader) request + .decodeCommandCustomHeader(QueryTopicConsumeByWhoRequestHeader.class); - HashSet groups = this.brokerController.getConsumerManager().queryTopicConsumeByWho(requestHeader.getTopic()); + HashSet groups = this.brokerController.getConsumerManager() + .queryTopicConsumeByWho(requestHeader.getTopic()); - Set groupInOffset = this.brokerController.getConsumerOffsetManager().whichGroupByTopic(requestHeader.getTopic()); + Set groupInOffset = this.brokerController.getConsumerOffsetManager() + .whichGroupByTopic(requestHeader.getTopic()); if (groupInOffset != null && !groupInOffset.isEmpty()) { groups.addAll(groupInOffset); } @@ -997,13 +1094,17 @@ private RemotingCommand queryTopicConsumeByWho(ChannelHandlerContext ctx, } private RemotingCommand registerFilterServer(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { - final RemotingCommand response = RemotingCommand.createResponseCommand(RegisterFilterServerResponseHeader.class); - final RegisterFilterServerResponseHeader responseHeader = (RegisterFilterServerResponseHeader) response.readCustomHeader(); + RemotingCommand request) throws RemotingCommandException { + final RemotingCommand response = RemotingCommand + .createResponseCommand(RegisterFilterServerResponseHeader.class); + final RegisterFilterServerResponseHeader responseHeader = (RegisterFilterServerResponseHeader) response + .readCustomHeader(); final RegisterFilterServerRequestHeader requestHeader = - (RegisterFilterServerRequestHeader) request.decodeCommandCustomHeader(RegisterFilterServerRequestHeader.class); + (RegisterFilterServerRequestHeader) request + .decodeCommandCustomHeader(RegisterFilterServerRequestHeader.class); - this.brokerController.getFilterServerManager().registerFilterServer(ctx.channel(), requestHeader.getFilterServerAddr()); + this.brokerController.getFilterServerManager() + .registerFilterServer(ctx.channel(), requestHeader.getFilterServerAddr()); responseHeader.setBrokerId(this.brokerController.getBrokerConfig().getBrokerId()); responseHeader.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName()); @@ -1014,13 +1115,15 @@ private RemotingCommand registerFilterServer(ChannelHandlerContext ctx, } private RemotingCommand queryConsumeTimeSpan(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); QueryConsumeTimeSpanRequestHeader requestHeader = - (QueryConsumeTimeSpanRequestHeader) request.decodeCommandCustomHeader(QueryConsumeTimeSpanRequestHeader.class); + (QueryConsumeTimeSpanRequestHeader) request + .decodeCommandCustomHeader(QueryConsumeTimeSpanRequestHeader.class); final String topic = requestHeader.getTopic(); - TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); + TopicConfig topicConfig = this.brokerController.getTopicConfigManager() + .selectTopicConfig(topic); if (null == topicConfig) { response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark("topic[" + topic + "] not exist"); @@ -1040,22 +1143,26 @@ private RemotingCommand queryConsumeTimeSpan(ChannelHandlerContext ctx, timeSpan.setMinTimeStamp(minTime); long max = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i); - long maxTime = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, max - 1); + long maxTime = this.brokerController.getMessageStore() + .getMessageStoreTimeStamp(topic, i, max - 1); timeSpan.setMaxTimeStamp(maxTime); long consumeTime; long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset( - requestHeader.getGroup(), topic, i); + requestHeader.getGroup(), topic, i); if (consumerOffset > 0) { - consumeTime = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, consumerOffset - 1); + consumeTime = this.brokerController.getMessageStore() + .getMessageStoreTimeStamp(topic, i, consumerOffset - 1); } else { consumeTime = minTime; } timeSpan.setConsumeTimeStamp(consumeTime); - long maxBrokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQueue(requestHeader.getTopic(), i); + long maxBrokerOffset = this.brokerController.getMessageStore() + .getMaxOffsetInQueue(requestHeader.getTopic(), i); if (consumerOffset < maxBrokerOffset) { - long nextTime = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, consumerOffset); + long nextTime = this.brokerController.getMessageStore() + .getMessageStoreTimeStamp(topic, i, consumerOffset); timeSpan.setDelayTime(System.currentTimeMillis() - nextTime); } timeSpanSet.add(timeSpan); @@ -1069,8 +1176,9 @@ private RemotingCommand queryConsumeTimeSpan(ChannelHandlerContext ctx, return response; } - private RemotingCommand getSystemTopicListFromBroker(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + private RemotingCommand getSystemTopicListFromBroker(ChannelHandlerContext ctx, + RemotingCommand request) + throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); Set topics = this.brokerController.getTopicConfigManager().getSystemTopic(); @@ -1095,7 +1203,8 @@ public RemotingCommand cleanExpiredConsumeQueue() { public RemotingCommand cleanUnusedTopic() { log.warn("invoke cleanUnusedTopic start."); final RemotingCommand response = RemotingCommand.createResponseCommand(null); - brokerController.getMessageStore().cleanUnusedTopic(brokerController.getTopicConfigManager().getTopicConfigTable().keySet()); + brokerController.getMessageStore().cleanUnusedTopic( + brokerController.getTopicConfigManager().getTopicConfigTable().keySet()); log.warn("invoke cleanUnusedTopic end."); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); @@ -1103,31 +1212,37 @@ public RemotingCommand cleanUnusedTopic() { } private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final GetConsumerRunningInfoRequestHeader requestHeader = - (GetConsumerRunningInfoRequestHeader) request.decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class); + (GetConsumerRunningInfoRequestHeader) request + .decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class); - return this.callConsumer(RequestCode.GET_CONSUMER_RUNNING_INFO, request, requestHeader.getConsumerGroup(), - requestHeader.getClientId()); + return this.callConsumer(RequestCode.GET_CONSUMER_RUNNING_INFO, request, + requestHeader.getConsumerGroup(), + requestHeader.getClientId()); } private RemotingCommand queryCorrectionOffset(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); QueryCorrectionOffsetHeader requestHeader = - (QueryCorrectionOffsetHeader) request.decodeCommandCustomHeader(QueryCorrectionOffsetHeader.class); + (QueryCorrectionOffsetHeader) request + .decodeCommandCustomHeader(QueryCorrectionOffsetHeader.class); Map correctionOffset = this.brokerController.getConsumerOffsetManager() - .queryMinOffsetInAllGroup(requestHeader.getTopic(), requestHeader.getFilterGroups()); + .queryMinOffsetInAllGroup(requestHeader.getTopic(), + requestHeader.getFilterGroups()); Map compareOffset = - this.brokerController.getConsumerOffsetManager().queryOffset(requestHeader.getTopic(), requestHeader.getCompareGroup()); + this.brokerController.getConsumerOffsetManager() + .queryOffset(requestHeader.getTopic(), requestHeader.getCompareGroup()); if (compareOffset != null && !compareOffset.isEmpty()) { for (Map.Entry entry : compareOffset.entrySet()) { Integer queueId = entry.getKey(); correctionOffset.put(queueId, - correctionOffset.get(queueId) > entry.getValue() ? Long.MAX_VALUE : correctionOffset.get(queueId)); + correctionOffset.get(queueId) > entry.getValue() ? Long.MAX_VALUE + : correctionOffset.get(queueId)); } } @@ -1140,15 +1255,17 @@ private RemotingCommand queryCorrectionOffset(ChannelHandlerContext ctx, } private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader) request - .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class); + .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class); - request.getExtFields().put("brokerName", this.brokerController.getBrokerConfig().getBrokerName()); + request.getExtFields() + .put("brokerName", this.brokerController.getBrokerConfig().getBrokerName()); SelectMappedBufferResult selectMappedBufferResult = null; try { MessageId messageId = MessageDecoder.decodeMessageId(requestHeader.getMsgId()); - selectMappedBufferResult = this.brokerController.getMessageStore().selectOneMessageByOffset(messageId.getOffset()); + selectMappedBufferResult = this.brokerController.getMessageStore() + .selectOneMessageByOffset(messageId.getOffset()); byte[] body = new byte[selectMappedBufferResult.getSize()]; selectMappedBufferResult.getByteBuffer().get(body); @@ -1160,26 +1277,30 @@ private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, } } - return this.callConsumer(RequestCode.CONSUME_MESSAGE_DIRECTLY, request, requestHeader.getConsumerGroup(), - requestHeader.getClientId()); + return this.callConsumer(RequestCode.CONSUME_MESSAGE_DIRECTLY, request, + requestHeader.getConsumerGroup(), + requestHeader.getClientId()); } private RemotingCommand cloneGroupOffset(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); CloneGroupOffsetRequestHeader requestHeader = - (CloneGroupOffsetRequestHeader) request.decodeCommandCustomHeader(CloneGroupOffsetRequestHeader.class); + (CloneGroupOffsetRequestHeader) request + .decodeCommandCustomHeader(CloneGroupOffsetRequestHeader.class); Set topics; if (UtilAll.isBlank(requestHeader.getTopic())) { - topics = this.brokerController.getConsumerOffsetManager().whichTopicByConsumer(requestHeader.getSrcGroup()); + topics = this.brokerController.getConsumerOffsetManager() + .whichTopicByConsumer(requestHeader.getSrcGroup()); } else { topics = new HashSet(); topics.add(requestHeader.getTopic()); } for (String topic : topics) { - TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); + TopicConfig topicConfig = this.brokerController.getTopicConfigManager() + .selectTopicConfig(topic); if (null == topicConfig) { log.warn("[cloneGroupOffset], topic config not exist, {}", topic); continue; @@ -1188,16 +1309,20 @@ private RemotingCommand cloneGroupOffset(ChannelHandlerContext ctx, if (!requestHeader.isOffline()) { SubscriptionData findSubscriptionData = - this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getSrcGroup(), topic); - if (this.brokerController.getConsumerManager().findSubscriptionDataCount(requestHeader.getSrcGroup()) > 0 - && findSubscriptionData == null) { - log.warn("[cloneGroupOffset], the consumer group[{}], topic[{}] not exist", requestHeader.getSrcGroup(), topic); + this.brokerController.getConsumerManager() + .findSubscriptionData(requestHeader.getSrcGroup(), topic); + if (this.brokerController.getConsumerManager() + .findSubscriptionDataCount(requestHeader.getSrcGroup()) > 0 + && findSubscriptionData == null) { + log.warn("[cloneGroupOffset], the consumer group[{}], topic[{}] not exist", + requestHeader.getSrcGroup(), topic); continue; } } - this.brokerController.getConsumerOffsetManager().cloneOffset(requestHeader.getSrcGroup(), requestHeader.getDestGroup(), - requestHeader.getTopic()); + this.brokerController.getConsumerOffsetManager() + .cloneOffset(requestHeader.getSrcGroup(), requestHeader.getDestGroup(), + requestHeader.getTopic()); } response.setCode(ResponseCode.SUCCESS); @@ -1206,16 +1331,20 @@ private RemotingCommand cloneGroupOffset(ChannelHandlerContext ctx, } private RemotingCommand ViewBrokerStatsData(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final ViewBrokerStatsDataRequestHeader requestHeader = - (ViewBrokerStatsDataRequestHeader) request.decodeCommandCustomHeader(ViewBrokerStatsDataRequestHeader.class); + (ViewBrokerStatsDataRequestHeader) request + .decodeCommandCustomHeader(ViewBrokerStatsDataRequestHeader.class); final RemotingCommand response = RemotingCommand.createResponseCommand(null); MessageStore messageStore = this.brokerController.getMessageStore(); - StatsItem statsItem = messageStore.getBrokerStatsManager().getStatsItem(requestHeader.getStatsName(), requestHeader.getStatsKey()); + StatsItem statsItem = messageStore.getBrokerStatsManager() + .getStatsItem(requestHeader.getStatsName(), requestHeader.getStatsKey()); if (null == statsItem) { response.setCode(ResponseCode.SYSTEM_ERROR); - response.setRemark(String.format("The stats <%s> <%s> not exist", requestHeader.getStatsName(), requestHeader.getStatsKey())); + response.setRemark( + String.format("The stats <%s> <%s> not exist", requestHeader.getStatsName(), + requestHeader.getStatsKey())); return response; } @@ -1254,27 +1383,31 @@ private RemotingCommand ViewBrokerStatsData(ChannelHandlerContext ctx, return response; } - private RemotingCommand fetchAllConsumeStatsInBroker(ChannelHandlerContext ctx, RemotingCommand request) - throws RemotingCommandException { + private RemotingCommand fetchAllConsumeStatsInBroker(ChannelHandlerContext ctx, + RemotingCommand request) + throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); GetConsumeStatsInBrokerHeader requestHeader = - (GetConsumeStatsInBrokerHeader) request.decodeCommandCustomHeader(GetConsumeStatsInBrokerHeader.class); + (GetConsumeStatsInBrokerHeader) request + .decodeCommandCustomHeader(GetConsumeStatsInBrokerHeader.class); boolean isOrder = requestHeader.isOrder(); ConcurrentMap subscriptionGroups = - brokerController.getSubscriptionGroupManager().getSubscriptionGroupTable(); + brokerController.getSubscriptionGroupManager().getSubscriptionGroupTable(); List>> brokerConsumeStatsList = - new ArrayList>>(); + new ArrayList>>(); long totalDiff = 0L; for (String group : subscriptionGroups.keySet()) { Map> subscripTopicConsumeMap = new HashMap>(); - Set topics = this.brokerController.getConsumerOffsetManager().whichTopicByConsumer(group); + Set topics = this.brokerController.getConsumerOffsetManager() + .whichTopicByConsumer(group); List consumeStatsList = new ArrayList(); for (String topic : topics) { ConsumeStats consumeStats = new ConsumeStats(); - TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); + TopicConfig topicConfig = this.brokerController.getTopicConfigManager() + .selectTopicConfig(topic); if (null == topicConfig) { log.warn("consumeStats, topic config not exist, {}", topic); continue; @@ -1285,11 +1418,14 @@ private RemotingCommand fetchAllConsumeStatsInBroker(ChannelHandlerContext ctx, } { - SubscriptionData findSubscriptionData = this.brokerController.getConsumerManager().findSubscriptionData(group, topic); + SubscriptionData findSubscriptionData = this.brokerController + .getConsumerManager().findSubscriptionData(group, topic); if (null == findSubscriptionData - && this.brokerController.getConsumerManager().findSubscriptionDataCount(group) > 0) { - log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", group, topic); + && this.brokerController.getConsumerManager() + .findSubscriptionDataCount(group) > 0) { + log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", group, + topic); continue; } } @@ -1300,29 +1436,35 @@ private RemotingCommand fetchAllConsumeStatsInBroker(ChannelHandlerContext ctx, mq.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName()); mq.setQueueId(i); OffsetWrapper offsetWrapper = new OffsetWrapper(); - long brokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i); - if (brokerOffset < 0) + long brokerOffset = this.brokerController.getMessageStore() + .getMaxOffsetInQueue(topic, i); + if (brokerOffset < 0) { brokerOffset = 0; - long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset( - group, - topic, - i); - if (consumerOffset < 0) + } + long consumerOffset = this.brokerController.getConsumerOffsetManager() + .queryOffset( + group, + topic, + i); + if (consumerOffset < 0) { consumerOffset = 0; + } offsetWrapper.setBrokerOffset(brokerOffset); offsetWrapper.setConsumerOffset(consumerOffset); long timeOffset = consumerOffset - 1; if (timeOffset >= 0) { - long lastTimestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, timeOffset); + long lastTimestamp = this.brokerController.getMessageStore() + .getMessageStoreTimeStamp(topic, i, timeOffset); if (lastTimestamp > 0) { offsetWrapper.setLastTimestamp(lastTimestamp); } } consumeStats.getOffsetTable().put(mq, offsetWrapper); } - double consumeTps = this.brokerController.getBrokerStatsManager().tpsGroupGetNums(group, topic); + double consumeTps = this.brokerController.getBrokerStatsManager() + .tpsGroupGetNums(group, topic); consumeTps += consumeStats.getConsumeTps(); consumeStats.setConsumeTps(consumeTps); totalDiff += consumeStats.computeTotalDiff(); @@ -1342,82 +1484,114 @@ private RemotingCommand fetchAllConsumeStatsInBroker(ChannelHandlerContext ctx, } private HashMap prepareRuntimeInfo() { - HashMap runtimeInfo = this.brokerController.getMessageStore().getRuntimeInfo(); + HashMap runtimeInfo = this.brokerController.getMessageStore() + .getRuntimeInfo(); runtimeInfo.put("brokerVersionDesc", MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION)); runtimeInfo.put("brokerVersion", String.valueOf(MQVersion.CURRENT_VERSION)); runtimeInfo.put("msgPutTotalYesterdayMorning", - String.valueOf(this.brokerController.getBrokerStats().getMsgPutTotalYesterdayMorning())); - runtimeInfo.put("msgPutTotalTodayMorning", String.valueOf(this.brokerController.getBrokerStats().getMsgPutTotalTodayMorning())); - runtimeInfo.put("msgPutTotalTodayNow", String.valueOf(this.brokerController.getBrokerStats().getMsgPutTotalTodayNow())); + String.valueOf( + this.brokerController.getBrokerStats().getMsgPutTotalYesterdayMorning())); + runtimeInfo.put("msgPutTotalTodayMorning", String.valueOf( + this.brokerController.getBrokerStats().getMsgPutTotalTodayMorning())); + runtimeInfo.put("msgPutTotalTodayNow", + String.valueOf(this.brokerController.getBrokerStats().getMsgPutTotalTodayNow())); runtimeInfo.put("msgGetTotalYesterdayMorning", - String.valueOf(this.brokerController.getBrokerStats().getMsgGetTotalYesterdayMorning())); - runtimeInfo.put("msgGetTotalTodayMorning", String.valueOf(this.brokerController.getBrokerStats().getMsgGetTotalTodayMorning())); - runtimeInfo.put("msgGetTotalTodayNow", String.valueOf(this.brokerController.getBrokerStats().getMsgGetTotalTodayNow())); + String.valueOf( + this.brokerController.getBrokerStats().getMsgGetTotalYesterdayMorning())); + runtimeInfo.put("msgGetTotalTodayMorning", String.valueOf( + this.brokerController.getBrokerStats().getMsgGetTotalTodayMorning())); + runtimeInfo.put("msgGetTotalTodayNow", + String.valueOf(this.brokerController.getBrokerStats().getMsgGetTotalTodayNow())); - runtimeInfo.put("sendThreadPoolQueueSize", String.valueOf(this.brokerController.getSendThreadPoolQueue().size())); + runtimeInfo.put("sendThreadPoolQueueSize", + String.valueOf(this.brokerController.getSendThreadPoolQueue().size())); runtimeInfo.put("sendThreadPoolQueueCapacity", - String.valueOf(this.brokerController.getBrokerConfig().getSendThreadPoolQueueCapacity())); + String.valueOf( + this.brokerController.getBrokerConfig().getSendThreadPoolQueueCapacity())); - runtimeInfo.put("pullThreadPoolQueueSize", String.valueOf(this.brokerController.getPullThreadPoolQueue().size())); + runtimeInfo.put("pullThreadPoolQueueSize", + String.valueOf(this.brokerController.getPullThreadPoolQueue().size())); runtimeInfo.put("pullThreadPoolQueueCapacity", - String.valueOf(this.brokerController.getBrokerConfig().getPullThreadPoolQueueCapacity())); + String.valueOf( + this.brokerController.getBrokerConfig().getPullThreadPoolQueueCapacity())); - runtimeInfo.put("queryThreadPoolQueueSize", String.valueOf(this.brokerController.getQueryThreadPoolQueue().size())); + runtimeInfo.put("queryThreadPoolQueueSize", + String.valueOf(this.brokerController.getQueryThreadPoolQueue().size())); runtimeInfo.put("queryThreadPoolQueueCapacity", - String.valueOf(this.brokerController.getBrokerConfig().getQueryThreadPoolQueueCapacity())); + String.valueOf( + this.brokerController.getBrokerConfig().getQueryThreadPoolQueueCapacity())); - runtimeInfo.put("EndTransactionQueueSize", String.valueOf(this.brokerController.getEndTransactionThreadPoolQueue().size())); + runtimeInfo.put("EndTransactionQueueSize", + String.valueOf(this.brokerController.getEndTransactionThreadPoolQueue().size())); runtimeInfo.put("EndTransactionThreadPoolQueueCapacity", - String.valueOf(this.brokerController.getBrokerConfig().getEndTransactionPoolQueueCapacity())); - - runtimeInfo.put("dispatchBehindBytes", String.valueOf(this.brokerController.getMessageStore().dispatchBehindBytes())); - runtimeInfo.put("pageCacheLockTimeMills", String.valueOf(this.brokerController.getMessageStore().lockTimeMills())); - - runtimeInfo.put("sendThreadPoolQueueHeadWaitTimeMills", String.valueOf(this.brokerController.headSlowTimeMills4SendThreadPoolQueue())); - runtimeInfo.put("pullThreadPoolQueueHeadWaitTimeMills", String.valueOf(this.brokerController.headSlowTimeMills4PullThreadPoolQueue())); - runtimeInfo.put("queryThreadPoolQueueHeadWaitTimeMills", String.valueOf(this.brokerController.headSlowTimeMills4QueryThreadPoolQueue())); - - runtimeInfo.put("earliestMessageTimeStamp", String.valueOf(this.brokerController.getMessageStore().getEarliestMessageTime())); - runtimeInfo.put("startAcceptSendRequestTimeStamp", String.valueOf(this.brokerController.getBrokerConfig().getStartAcceptSendRequestTimeStamp())); + String.valueOf(this.brokerController.getBrokerConfig() + .getEndTransactionPoolQueueCapacity())); + + runtimeInfo.put("dispatchBehindBytes", + String.valueOf(this.brokerController.getMessageStore().dispatchBehindBytes())); + runtimeInfo.put("pageCacheLockTimeMills", + String.valueOf(this.brokerController.getMessageStore().lockTimeMills())); + + runtimeInfo.put("sendThreadPoolQueueHeadWaitTimeMills", + String.valueOf(this.brokerController.headSlowTimeMills4SendThreadPoolQueue())); + runtimeInfo.put("pullThreadPoolQueueHeadWaitTimeMills", + String.valueOf(this.brokerController.headSlowTimeMills4PullThreadPoolQueue())); + runtimeInfo.put("queryThreadPoolQueueHeadWaitTimeMills", + String.valueOf(this.brokerController.headSlowTimeMills4QueryThreadPoolQueue())); + + runtimeInfo.put("earliestMessageTimeStamp", + String.valueOf(this.brokerController.getMessageStore().getEarliestMessageTime())); + runtimeInfo.put("startAcceptSendRequestTimeStamp", String.valueOf( + this.brokerController.getBrokerConfig().getStartAcceptSendRequestTimeStamp())); if (this.brokerController.getMessageStore() instanceof DefaultMessageStore) { - DefaultMessageStore defaultMessageStore = (DefaultMessageStore) this.brokerController.getMessageStore(); - runtimeInfo.put("remainTransientStoreBufferNumbs", String.valueOf(defaultMessageStore.remainTransientStoreBufferNumbs())); + DefaultMessageStore defaultMessageStore = (DefaultMessageStore) this.brokerController + .getMessageStore(); + runtimeInfo.put("remainTransientStoreBufferNumbs", + String.valueOf(defaultMessageStore.remainTransientStoreBufferNumbs())); if (defaultMessageStore.getMessageStoreConfig().isTransientStorePoolEnable()) { - runtimeInfo.put("remainHowManyDataToCommit", MixAll.humanReadableByteCount(defaultMessageStore.getCommitLog().remainHowManyDataToCommit(), false)); + runtimeInfo.put("remainHowManyDataToCommit", MixAll.humanReadableByteCount( + defaultMessageStore.getCommitLog().remainHowManyDataToCommit(), false)); } - runtimeInfo.put("remainHowManyDataToFlush", MixAll.humanReadableByteCount(defaultMessageStore.getCommitLog().remainHowManyDataToFlush(), false)); + runtimeInfo.put("remainHowManyDataToFlush", MixAll.humanReadableByteCount( + defaultMessageStore.getCommitLog().remainHowManyDataToFlush(), false)); } - java.io.File commitLogDir = new java.io.File(this.brokerController.getMessageStoreConfig().getStorePathRootDir()); + java.io.File commitLogDir = new java.io.File( + this.brokerController.getMessageStoreConfig().getStorePathRootDir()); if (commitLogDir.exists()) { - runtimeInfo.put("commitLogDirCapacity", String.format("Total : %s, Free : %s.", MixAll.humanReadableByteCount(commitLogDir.getTotalSpace(), false), MixAll.humanReadableByteCount(commitLogDir.getFreeSpace(), false))); + runtimeInfo.put("commitLogDirCapacity", String.format("Total : %s, Free : %s.", + MixAll.humanReadableByteCount(commitLogDir.getTotalSpace(), false), + MixAll.humanReadableByteCount(commitLogDir.getFreeSpace(), false))); } return runtimeInfo; } private RemotingCommand callConsumer( - final int requestCode, - final RemotingCommand request, - final String consumerGroup, - final String clientId) throws RemotingCommandException { + final int requestCode, + final RemotingCommand request, + final String consumerGroup, + final String clientId) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); - ClientChannelInfo clientChannelInfo = this.brokerController.getConsumerManager().findChannel(consumerGroup, clientId); + ClientChannelInfo clientChannelInfo = this.brokerController.getConsumerManager() + .findChannel(consumerGroup, clientId); if (null == clientChannelInfo) { response.setCode(ResponseCode.SYSTEM_ERROR); - response.setRemark(String.format("The Consumer <%s> <%s> not online", consumerGroup, clientId)); + response.setRemark( + String.format("The Consumer <%s> <%s> not online", consumerGroup, clientId)); return response; } if (clientChannelInfo.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) { response.setCode(ResponseCode.SYSTEM_ERROR); - response.setRemark(String.format("The Consumer <%s> Version <%s> too low to finish, please upgrade it to V3_1_8_SNAPSHOT", - clientId, - MQVersion.getVersionDesc(clientChannelInfo.getVersion()))); + response.setRemark(String.format( + "The Consumer <%s> Version <%s> too low to finish, please upgrade it to V3_1_8_SNAPSHOT", + clientId, + MQVersion.getVersionDesc(clientChannelInfo.getVersion()))); return response; } @@ -1426,32 +1600,39 @@ private RemotingCommand callConsumer( newRequest.setExtFields(request.getExtFields()); newRequest.setBody(request.getBody()); - return this.brokerController.getBroker2Client().callClient(clientChannelInfo.getChannel(), newRequest); + return this.brokerController.getBroker2Client() + .callClient(clientChannelInfo.getChannel(), newRequest); } catch (RemotingTimeoutException e) { response.setCode(ResponseCode.CONSUME_MSG_TIMEOUT); response - .setRemark(String.format("consumer <%s> <%s> Timeout: %s", consumerGroup, clientId, RemotingHelper.exceptionSimpleDesc(e))); + .setRemark( + String.format("consumer <%s> <%s> Timeout: %s", consumerGroup, clientId, + RemotingHelper.exceptionSimpleDesc(e))); return response; } catch (Exception e) { response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark( - String.format("invoke consumer <%s> <%s> Exception: %s", consumerGroup, clientId, RemotingHelper.exceptionSimpleDesc(e))); + String.format("invoke consumer <%s> <%s> Exception: %s", consumerGroup, + clientId, RemotingHelper.exceptionSimpleDesc(e))); return response; } } private RemotingCommand queryConsumeQueue(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { QueryConsumeQueueRequestHeader requestHeader = - (QueryConsumeQueueRequestHeader) request.decodeCommandCustomHeader(QueryConsumeQueueRequestHeader.class); + (QueryConsumeQueueRequestHeader) request + .decodeCommandCustomHeader(QueryConsumeQueueRequestHeader.class); RemotingCommand response = RemotingCommand.createResponseCommand(null); - ConsumeQueue consumeQueue = this.brokerController.getMessageStore().getConsumeQueue(requestHeader.getTopic(), - requestHeader.getQueueId()); + ConsumeQueue consumeQueue = this.brokerController.getMessageStore() + .getConsumeQueue(requestHeader.getTopic(), + requestHeader.getQueueId()); if (consumeQueue == null) { response.setCode(ResponseCode.SYSTEM_ERROR); - response.setRemark(String.format("%d@%s is not exist!", requestHeader.getQueueId(), requestHeader.getTopic())); + response.setRemark(String.format("%d@%s is not exist!", requestHeader.getQueueId(), + requestHeader.getTopic())); return response; } @@ -1464,30 +1645,37 @@ private RemotingCommand queryConsumeQueue(ChannelHandlerContext ctx, MessageFilter messageFilter = null; if (requestHeader.getConsumerGroup() != null) { - SubscriptionData subscriptionData = this.brokerController.getConsumerManager().findSubscriptionData( - requestHeader.getConsumerGroup(), requestHeader.getTopic() - ); + SubscriptionData subscriptionData = this.brokerController.getConsumerManager() + .findSubscriptionData( + requestHeader.getConsumerGroup(), requestHeader.getTopic() + ); body.setSubscriptionData(subscriptionData); if (subscriptionData == null) { - body.setFilterData(String.format("%s@%s is not online!", requestHeader.getConsumerGroup(), requestHeader.getTopic())); + body.setFilterData( + String.format("%s@%s is not online!", requestHeader.getConsumerGroup(), + requestHeader.getTopic())); } else { ConsumerFilterData filterData = this.brokerController.getConsumerFilterManager() - .get(requestHeader.getTopic(), requestHeader.getConsumerGroup()); + .get(requestHeader.getTopic(), requestHeader.getConsumerGroup()); body.setFilterData(JSON.toJSONString(filterData, true)); messageFilter = new ExpressionMessageFilter(subscriptionData, filterData, - this.brokerController.getConsumerFilterManager()); + this.brokerController.getConsumerFilterManager()); } } SelectMappedBufferResult result = consumeQueue.getIndexBuffer(requestHeader.getIndex()); if (result == null) { - response.setRemark(String.format("Index %d of %d@%s is not exist!", requestHeader.getIndex(), requestHeader.getQueueId(), requestHeader.getTopic())); + response.setRemark( + String.format("Index %d of %d@%s is not exist!", requestHeader.getIndex(), + requestHeader.getQueueId(), requestHeader.getTopic())); return response; } try { List queues = new ArrayList<>(); - for (int i = 0; i < result.getSize() && i < requestHeader.getCount() * ConsumeQueue.CQ_STORE_UNIT_SIZE; i += ConsumeQueue.CQ_STORE_UNIT_SIZE) { + for (int i = 0; i < result.getSize() + && i < requestHeader.getCount() * ConsumeQueue.CQ_STORE_UNIT_SIZE; + i += ConsumeQueue.CQ_STORE_UNIT_SIZE) { ConsumeQueueData one = new ConsumeQueueData(); one.setPhysicOffset(result.getByteBuffer().getLong()); one.setPhysicSize(result.getByteBuffer().getInt()); @@ -1505,7 +1693,8 @@ private RemotingCommand queryConsumeQueue(ChannelHandlerContext ctx, one.setBitMap(BitsArray.create(cqExtUnit.getFilterBitMap()).toString()); } if (messageFilter != null) { - one.setEval(messageFilter.isMatchedByConsumeQueue(cqExtUnit.getTagsCode(), cqExtUnit)); + one.setEval(messageFilter + .isMatchedByConsumeQueue(cqExtUnit.getTagsCode(), cqExtUnit)); } } else { one.setMsg("Cq extend not exist!addr: " + one.getTagsCode()); @@ -1522,8 +1711,66 @@ private RemotingCommand queryConsumeQueue(ChannelHandlerContext ctx, } - private RemotingCommand resumeCheckHalfMessage(ChannelHandlerContext ctx, RemotingCommand request) { - return null; + private RemotingCommand resumeCheckHalfMessage(ChannelHandlerContext ctx, + RemotingCommand request) + throws RemotingCommandException { + final ResumeCheckHalfMessageRequestHeader requestHeader = (ResumeCheckHalfMessageRequestHeader) request + .decodeCommandCustomHeader(ResumeCheckHalfMessageRequestHeader.class); + final RemotingCommand response = RemotingCommand.createResponseCommand(null); + ResumeCheckHalfMessageResult resumeCheckHalfMessageResult = new ResumeCheckHalfMessageResult(); + SelectMappedBufferResult selectMappedBufferResult = null; + Long beginTime = System.currentTimeMillis(); + try { + MessageId messageId = MessageDecoder.decodeMessageId(requestHeader.getMsgId()); + selectMappedBufferResult = this.brokerController.getMessageStore() + .selectOneMessageByOffset(messageId.getOffset()); + MessageExt msg = MessageDecoder.decode(selectMappedBufferResult.getByteBuffer()); + msg.putUserProperty(MessageConst.PROPERTY_TRANSACTION_CHECK_TIMES, String.valueOf(0)); + PutMessageResult putMessageResult = this.brokerController.getMessageStore() + .putMessage(toMessageExtBrokerInner(msg)); + if (putMessageResult != null + && putMessageResult.getPutMessageStatus() == PutMessageStatus.PUT_OK) { + log.info( + "Put message back to RMQ_SYS_TRANS_HALF_TOPIC. real topic={}", + msg.getUserProperty(MessageConst.PROPERTY_REAL_TOPIC)); + response.setCode(ResponseCode.SUCCESS); + resumeCheckHalfMessageResult.setResumeResult(ResumeResult.RESUME_SUCCESS); + resumeCheckHalfMessageResult.setSpentTimeMills(System.currentTimeMillis() - beginTime); + response.setBody(resumeCheckHalfMessageResult.encode()); + } else { + log.error("Put message back to RMQ_SYS_TRANS_HALF_TOPIC failed."); + response.setCode(ResponseCode.SYSTEM_ERROR); + response.setRemark("Put message back to RMQ_SYS_TRANS_HALF_TOPIC failed."); + } + } catch (Exception e) { + log.error("Exception was thrown when putting message back to RMQ_SYS_TRANS_HALF_TOPIC."); + response.setCode(ResponseCode.SYSTEM_ERROR); + response.setRemark("Exception was thrown when putting message back to RMQ_SYS_TRANS_HALF_TOPIC."); + } finally { + if (selectMappedBufferResult != null) { + selectMappedBufferResult.release(); + } + } + return response; + } + + private MessageExtBrokerInner toMessageExtBrokerInner(MessageExt msgExt) { + MessageExtBrokerInner inner = new MessageExtBrokerInner(); + inner.setTopic(TransactionalMessageUtil.buildHalfTopic()); + inner.setBody(msgExt.getBody()); + inner.setFlag(msgExt.getFlag()); + MessageAccessor.setProperties(inner, msgExt.getProperties()); + inner.setPropertiesString(MessageDecoder.messageProperties2String(msgExt.getProperties())); + inner.setTagsCode(MessageExtBrokerInner.tagsString2tagsCode(msgExt.getTags())); + inner.setQueueId(0); + inner.setSysFlag(msgExt.getSysFlag()); + inner.setBornHost(msgExt.getBornHost()); + inner.setBornTimestamp(msgExt.getBornTimestamp()); + inner.setStoreHost(msgExt.getStoreHost()); + inner.setReconsumeTimes(msgExt.getReconsumeTimes()); + inner.setMsgId(msgExt.getMsgId()); + inner.setWaitStoreMsgOK(false); + return inner; } } diff --git a/broker/src/test/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessorTest.java b/broker/src/test/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessorTest.java new file mode 100644 index 00000000000..90de9205226 --- /dev/null +++ b/broker/src/test/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessorTest.java @@ -0,0 +1,155 @@ +/* + * 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.broker.processor; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import io.netty.channel.ChannelHandlerContext; +import java.net.SocketAddress; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; +import org.apache.rocketmq.broker.BrokerController; +import org.apache.rocketmq.common.BrokerConfig; +import org.apache.rocketmq.common.message.MessageAccessor; +import org.apache.rocketmq.common.message.MessageConst; +import org.apache.rocketmq.common.message.MessageDecoder; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.message.MessageId; +import org.apache.rocketmq.common.protocol.RequestCode; +import org.apache.rocketmq.common.protocol.ResponseCode; +import org.apache.rocketmq.common.protocol.header.ResumeCheckHalfMessageRequestHeader; +import org.apache.rocketmq.remoting.exception.RemotingCommandException; +import org.apache.rocketmq.remoting.netty.NettyClientConfig; +import org.apache.rocketmq.remoting.netty.NettyServerConfig; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; +import org.apache.rocketmq.store.AppendMessageResult; +import org.apache.rocketmq.store.AppendMessageStatus; +import org.apache.rocketmq.store.MappedFile; +import org.apache.rocketmq.store.MessageExtBrokerInner; +import org.apache.rocketmq.store.MessageStore; +import org.apache.rocketmq.store.PutMessageResult; +import org.apache.rocketmq.store.PutMessageStatus; +import org.apache.rocketmq.store.SelectMappedBufferResult; +import org.apache.rocketmq.store.config.MessageStoreConfig; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Spy; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({MessageDecoder.class}) +public class AdminBrokerProcessorTest { + + private AdminBrokerProcessor adminBrokerProcessor; + + @Mock + private ChannelHandlerContext handlerContext; + + @Spy + private BrokerController + brokerController = new BrokerController(new BrokerConfig(), new NettyServerConfig(), new NettyClientConfig(), + new MessageStoreConfig()); + + @Mock + private MessageStore messageStore; + + + @Before + public void init() { + brokerController.setMessageStore(messageStore); + adminBrokerProcessor = new AdminBrokerProcessor(brokerController); + } + + @Test + public void testProcessRequest_success() throws RemotingCommandException, UnknownHostException { + RemotingCommand request = createResumeCheckHalfMessageCommand(); + when(messageStore.selectOneMessageByOffset(any(Long.class))).thenReturn(createSelectMappedBufferResult()); + PowerMockito.mockStatic(MessageDecoder.class); + PowerMockito.when(MessageDecoder.decode(any(ByteBuffer.class))).thenReturn(createDefaultMessageExt()); + PowerMockito.when(MessageDecoder.decodeMessageId(any(String.class))).thenReturn(createMessageId()); + when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult + (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK))); + RemotingCommand response = adminBrokerProcessor.processRequest(handlerContext, request); + assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS); + } + + @Test + public void testProcessRequest_fail() throws RemotingCommandException, UnknownHostException { + RemotingCommand request = createResumeCheckHalfMessageCommand(); + when(messageStore.selectOneMessageByOffset(any(Long.class))).thenReturn(createSelectMappedBufferResult()); + PowerMockito.mockStatic(MessageDecoder.class); + PowerMockito.when(MessageDecoder.decode(any(ByteBuffer.class))).thenReturn(createDefaultMessageExt()); + PowerMockito.when(MessageDecoder.decodeMessageId(any(String.class))).thenReturn(createMessageId()); + when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult + (PutMessageStatus.UNKNOWN_ERROR, new AppendMessageResult(AppendMessageStatus.UNKNOWN_ERROR))); + RemotingCommand response = adminBrokerProcessor.processRequest(handlerContext, request); + assertThat(response.getCode()).isEqualTo(ResponseCode.SYSTEM_ERROR); + } + + @Test + public void testProcessRequest_exception() throws RemotingCommandException, UnknownHostException { + RemotingCommand request = createResumeCheckHalfMessageCommand(); + when(messageStore.selectOneMessageByOffset(any(Long.class))).thenReturn(createSelectMappedBufferResult()); + PowerMockito.mockStatic(MessageDecoder.class); + PowerMockito.when(MessageDecoder.decode(any(ByteBuffer.class))).thenReturn(createDefaultMessageExt()); + PowerMockito.when(MessageDecoder.decodeMessageId(any(String.class))).thenThrow(new UnknownHostException()); + when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult + (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK))); + RemotingCommand response = adminBrokerProcessor.processRequest(handlerContext, request); + assertThat(response.getCode()).isEqualTo(ResponseCode.SYSTEM_ERROR); + } + + private MessageExt createDefaultMessageExt() { + MessageExt messageExt = new MessageExt(); + messageExt.setMsgId("12345678"); + messageExt.setQueueId(0); + messageExt.setCommitLogOffset(123456789L); + messageExt.setQueueOffset(1234); + MessageAccessor.putProperty(messageExt, MessageConst.PROPERTY_REAL_QUEUE_ID, "0"); + MessageAccessor.putProperty(messageExt, MessageConst.PROPERTY_REAL_TOPIC, "testTopic"); + MessageAccessor.putProperty(messageExt, MessageConst.PROPERTY_TRANSACTION_CHECK_TIMES, "15"); + return messageExt; + } + + private MessageId createMessageId() { + return new MessageId(new SocketAddress() { + }, 0); + } + + private SelectMappedBufferResult createSelectMappedBufferResult(){ + SelectMappedBufferResult result = new SelectMappedBufferResult(0, ByteBuffer.allocate(1024) ,0, new MappedFile()); + return result; + } + private ResumeCheckHalfMessageRequestHeader createResumeCheckHalfMessageRequestHeader() { + ResumeCheckHalfMessageRequestHeader header = new ResumeCheckHalfMessageRequestHeader(); + header.setMsgId("12345678"); + return header; + } + + private RemotingCommand createResumeCheckHalfMessageCommand() { + ResumeCheckHalfMessageRequestHeader header = createResumeCheckHalfMessageRequestHeader(); + RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.RESUME_CHECK_HALF_MESSAGE, header); + request.makeCustomHeaderToNet(); + return request; + } +} diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java index c3382caa280..708bfde09c6 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java @@ -82,6 +82,7 @@ import org.apache.rocketmq.common.protocol.body.QueryCorrectionOffsetBody; import org.apache.rocketmq.common.protocol.body.QueueTimeSpan; import org.apache.rocketmq.common.protocol.body.ResetOffsetBody; +import org.apache.rocketmq.common.protocol.body.ResumeCheckHalfMessageResult; import org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper; import org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper; import org.apache.rocketmq.common.protocol.body.TopicList; @@ -122,6 +123,7 @@ import org.apache.rocketmq.common.protocol.header.QueryMessageRequestHeader; import org.apache.rocketmq.common.protocol.header.QueryTopicConsumeByWhoRequestHeader; import org.apache.rocketmq.common.protocol.header.ResetOffsetRequestHeader; +import org.apache.rocketmq.common.protocol.header.ResumeCheckHalfMessageRequestHeader; import org.apache.rocketmq.common.protocol.header.SearchOffsetRequestHeader; import org.apache.rocketmq.common.protocol.header.SearchOffsetResponseHeader; import org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader; @@ -2207,4 +2209,29 @@ public void checkClientInBroker(final String brokerAddr, final String consumerGr throw new MQClientException(response.getCode(), response.getRemark()); } } + + public ResumeCheckHalfMessageResult resumeCheckHalfMessage(final String addr, String msgId, + final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { + ResumeCheckHalfMessageRequestHeader requestHeader = new ResumeCheckHalfMessageRequestHeader(); + requestHeader.setMsgId(msgId); + + RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.RESUME_CHECK_HALF_MESSAGE, requestHeader); + + RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), + request, timeoutMillis); + assert response != null; + switch (response.getCode()) { + case ResponseCode.SUCCESS: { + byte[] body = response.getBody(); + if (body != null) { + ResumeCheckHalfMessageResult info = ResumeCheckHalfMessageResult.decode(body, ResumeCheckHalfMessageResult.class); + return info; + } + } + default: + break; + } + + throw new MQClientException(response.getCode(), response.getRemark()); + } } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeCheckHalfMessageResult.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeCheckHalfMessageResult.java new file mode 100644 index 00000000000..58dabf446a8 --- /dev/null +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeCheckHalfMessageResult.java @@ -0,0 +1,60 @@ +/* + * 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.common.protocol.body; + +import org.apache.rocketmq.remoting.protocol.RemotingSerializable; + +public class ResumeCheckHalfMessageResult extends RemotingSerializable { + + private ResumeResult resumeResult; + private String remark; + private long spentTimeMills; + + + public ResumeResult getResumeResult() { + return resumeResult; + } + + public void setResumeResult(ResumeResult resumeResult) { + this.resumeResult = resumeResult; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + + public long getSpentTimeMills() { + return spentTimeMills; + } + + public void setSpentTimeMills(long spentTimeMills) { + this.spentTimeMills = spentTimeMills; + } + + @Override + public String toString() { + return "ConsumeMessageDirectlyResult [consumeResult=" + resumeResult + ", remark=" + remark + + ", spentTimeMills=" + + spentTimeMills + "]"; + } +} diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeResult.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeResult.java new file mode 100644 index 00000000000..583c737f3dd --- /dev/null +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeResult.java @@ -0,0 +1,23 @@ +/* + * 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.common.protocol.body; + +public enum ResumeResult { + RESUME_SUCCESS, + RESUME_THROW_EXCEPTION +} diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/ResumeCheckHalfMessageRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/ResumeCheckHalfMessageRequestHeader.java new file mode 100644 index 00000000000..14dacd5e8dc --- /dev/null +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/ResumeCheckHalfMessageRequestHeader.java @@ -0,0 +1,45 @@ +/* + * 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.common.protocol.header; + +import org.apache.rocketmq.remoting.CommandCustomHeader; +import org.apache.rocketmq.remoting.annotation.CFNullable; +import org.apache.rocketmq.remoting.exception.RemotingCommandException; + +public class ResumeCheckHalfMessageRequestHeader implements CommandCustomHeader { + @CFNullable + private String msgId; + + @Override + public void checkFields() throws RemotingCommandException { + + } + + public String getMsgId() { + return msgId; + } + + public void setMsgId(String msgId) { + this.msgId = msgId; + } + + @Override + public String toString() { + return "ResumeCheckHalfMessageRequestHeader [msgId=" + msgId + "]"; + } +} diff --git a/pom.xml b/pom.xml index 7ab89910ca2..175ff33434e 100644 --- a/pom.xml +++ b/pom.xml @@ -455,7 +455,19 @@ org.mockito mockito-core - 2.6.3 + 2.23.0 + test + + + org.powermock + powermock-api-mockito2 + 2.0.0 + test + + + org.powermock + powermock-module-junit4 + 2.0.0 test diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java index f00dcefa432..e564a62d122 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java @@ -45,6 +45,7 @@ import org.apache.rocketmq.common.protocol.body.ProducerConnection; import org.apache.rocketmq.common.protocol.body.QueryConsumeQueueResponseBody; import org.apache.rocketmq.common.protocol.body.QueueTimeSpan; +import org.apache.rocketmq.common.protocol.body.ResumeCheckHalfMessageResult; import org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper; import org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper; import org.apache.rocketmq.common.protocol.body.TopicList; @@ -537,4 +538,17 @@ public QueryConsumeQueueResponseBody queryConsumeQueue(String brokerAddr, String brokerAddr, topic, queueId, index, count, consumerGroup ); } + + @Override + public ResumeCheckHalfMessageResult resumeCheckHalfMessage(String msgId) + throws RemotingException, MQClientException, InterruptedException, MQBrokerException { + return this.defaultMQAdminExtImpl.resumeCheckHalfMessage(msgId); + } + + @Override + public ResumeCheckHalfMessageResult resumeCheckHalfMessage(String topic, + String msgId) + throws RemotingException, MQClientException, InterruptedException, MQBrokerException { + return this.defaultMQAdminExtImpl.resumeCheckHalfMessage(topic, msgId); + } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java index 502e9daa33b..1251aa2f284 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java @@ -49,6 +49,7 @@ import org.apache.rocketmq.common.admin.TopicStatsTable; import org.apache.rocketmq.common.help.FAQUrl; import org.apache.rocketmq.common.protocol.body.ClusterAclVersionInfo; +import org.apache.rocketmq.common.protocol.body.ResumeCheckHalfMessageResult; import org.apache.rocketmq.logging.InternalLogger; import org.apache.rocketmq.common.message.MessageClientExt; import org.apache.rocketmq.common.message.MessageConst; @@ -1025,4 +1026,23 @@ public QueryConsumeQueueResponseBody queryConsumeQueue(String brokerAddr, String brokerAddr, topic, queueId, index, count, consumerGroup, timeoutMillis ); } + + @Override + public ResumeCheckHalfMessageResult resumeCheckHalfMessage(String msgId) + throws RemotingException, MQClientException, InterruptedException, MQBrokerException { + MessageExt msg = this.viewMessage(msgId); + + return this.mqClientInstance.getMQClientAPIImpl().resumeCheckHalfMessage(RemotingUtil.socketAddress2String(msg.getStoreHost()), msgId, timeoutMillis); + } + + @Override + public ResumeCheckHalfMessageResult resumeCheckHalfMessage(final String topic, final String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { + MessageExt msg = this.viewMessage(topic, msgId); + if (msg.getProperty(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX) == null) { + return this.mqClientInstance.getMQClientAPIImpl().resumeCheckHalfMessage(RemotingUtil.socketAddress2String(msg.getStoreHost()), msgId, timeoutMillis); + } else { + MessageClientExt msgClient = (MessageClientExt) msg; + return this.mqClientInstance.getMQClientAPIImpl().resumeCheckHalfMessage(RemotingUtil.socketAddress2String(msg.getStoreHost()), msgClient.getOffsetMsgId(), timeoutMillis); + } + } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java index 930785ec1e7..02c85941234 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java @@ -43,6 +43,7 @@ import org.apache.rocketmq.common.protocol.body.ProducerConnection; import org.apache.rocketmq.common.protocol.body.QueryConsumeQueueResponseBody; import org.apache.rocketmq.common.protocol.body.QueueTimeSpan; +import org.apache.rocketmq.common.protocol.body.ResumeCheckHalfMessageResult; import org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper; import org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper; import org.apache.rocketmq.common.protocol.body.TopicList; @@ -273,4 +274,9 @@ QueryConsumeQueueResponseBody queryConsumeQueue(final String brokerAddr, final String topic, final int queueId, final long index, final int count, final String consumerGroup) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQClientException; + + ResumeCheckHalfMessageResult resumeCheckHalfMessage(String msgId) + throws RemotingException, MQClientException, InterruptedException, MQBrokerException; + + ResumeCheckHalfMessageResult resumeCheckHalfMessage(final String topic, final String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException; } From 584a31c521bb245d56b875a4cc796f2f1111fb6c Mon Sep 17 00:00:00 2001 From: chengxiangwang Date: Sun, 17 Feb 2019 10:44:44 +0800 Subject: [PATCH 6/7] add test case:resumeCheckHalfMessage --- .../processor/AdminBrokerProcessor.java | 675 +++++++----------- .../broker/topic/TopicConfigManager.java | 10 +- ...aultTransactionalMessageCheckListener.java | 34 +- .../processor/AdminBrokerProcessorTest.java | 43 +- ...TransactionalMessageCheckListenerTest.java | 29 +- .../rocketmq/client/impl/MQClientAPIImpl.java | 18 +- .../client/impl/MQClientAPIImplTest.java | 46 +- .../body/ResumeCheckHalfMessageResult.java | 60 -- .../common/protocol/body/ResumeResult.java | 23 - pom.xml | 12 - .../tools/admin/DefaultMQAdminExt.java | 5 +- .../tools/admin/DefaultMQAdminExtImpl.java | 5 +- .../rocketmq/tools/admin/MQAdminExt.java | 5 +- .../QueryMsgByUniqueKeySubCommandTest.java | 15 + 14 files changed, 351 insertions(+), 629 deletions(-) delete mode 100644 common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeCheckHalfMessageResult.java delete mode 100644 common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeResult.java diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java index 1bb79e0b94e..540d38373fb 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java @@ -77,8 +77,6 @@ import org.apache.rocketmq.common.protocol.body.QueryConsumeTimeSpanBody; import org.apache.rocketmq.common.protocol.body.QueryCorrectionOffsetBody; import org.apache.rocketmq.common.protocol.body.QueueTimeSpan; -import org.apache.rocketmq.common.protocol.body.ResumeCheckHalfMessageResult; -import org.apache.rocketmq.common.protocol.body.ResumeResult; import org.apache.rocketmq.common.protocol.body.TopicList; import org.apache.rocketmq.common.protocol.body.UnlockBatchRequestBody; import org.apache.rocketmq.common.protocol.header.CloneGroupOffsetRequestHeader; @@ -137,9 +135,7 @@ import org.apache.rocketmq.store.SelectMappedBufferResult; public class AdminBrokerProcessor implements NettyRequestProcessor { - - private static final InternalLogger log = InternalLoggerFactory - .getLogger(LoggerName.BROKER_LOGGER_NAME); + private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); private final BrokerController brokerController; public AdminBrokerProcessor(final BrokerController brokerController) { @@ -148,7 +144,7 @@ public AdminBrokerProcessor(final BrokerController brokerController) { @Override public RemotingCommand processRequest(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { switch (request.getCode()) { case RequestCode.UPDATE_AND_CREATE_TOPIC: return this.updateAndCreateTopic(ctx, request); @@ -245,18 +241,14 @@ public boolean rejectRequest() { } private synchronized RemotingCommand updateAndCreateTopic(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final CreateTopicRequestHeader requestHeader = - (CreateTopicRequestHeader) request - .decodeCommandCustomHeader(CreateTopicRequestHeader.class); - log.info("updateAndCreateTopic called by {}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel())); - - if (requestHeader.getTopic() - .equals(this.brokerController.getBrokerConfig().getBrokerClusterName())) { - String errorMsg = "the topic[" + requestHeader.getTopic() - + "] is conflict with system reserved words."; + (CreateTopicRequestHeader) request.decodeCommandCustomHeader(CreateTopicRequestHeader.class); + log.info("updateAndCreateTopic called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); + + if (requestHeader.getTopic().equals(this.brokerController.getBrokerConfig().getBrokerClusterName())) { + String errorMsg = "the topic[" + requestHeader.getTopic() + "] is conflict with system reserved words."; log.warn(errorMsg); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark(errorMsg); @@ -278,31 +270,26 @@ private synchronized RemotingCommand updateAndCreateTopic(ChannelHandlerContext topicConfig.setWriteQueueNums(requestHeader.getWriteQueueNums()); topicConfig.setTopicFilterType(requestHeader.getTopicFilterTypeEnum()); topicConfig.setPerm(requestHeader.getPerm()); - topicConfig.setTopicSysFlag( - requestHeader.getTopicSysFlag() == null ? 0 : requestHeader.getTopicSysFlag()); + topicConfig.setTopicSysFlag(requestHeader.getTopicSysFlag() == null ? 0 : requestHeader.getTopicSysFlag()); this.brokerController.getTopicConfigManager().updateTopicConfig(topicConfig); - this.brokerController.registerIncrementBrokerData(topicConfig, - this.brokerController.getTopicConfigManager().getDataVersion()); + this.brokerController.registerIncrementBrokerData(topicConfig, this.brokerController.getTopicConfigManager().getDataVersion()); return null; } private synchronized RemotingCommand deleteTopic(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); DeleteTopicRequestHeader requestHeader = - (DeleteTopicRequestHeader) request - .decodeCommandCustomHeader(DeleteTopicRequestHeader.class); + (DeleteTopicRequestHeader) request.decodeCommandCustomHeader(DeleteTopicRequestHeader.class); log.info("deleteTopic called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); this.brokerController.getTopicConfigManager().deleteTopicConfig(requestHeader.getTopic()); this.brokerController.getMessageStore() - .cleanUnusedTopic( - this.brokerController.getTopicConfigManager().getTopicConfigTable() - .keySet()); + .cleanUnusedTopic(this.brokerController.getTopicConfigManager().getTopicConfigTable().keySet()); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); @@ -444,8 +431,7 @@ private RemotingCommand getBrokerAclConfigVersion(ChannelHandlerContext ctx, Rem } private RemotingCommand getAllTopicConfig(ChannelHandlerContext ctx, RemotingCommand request) { - final RemotingCommand response = RemotingCommand - .createResponseCommand(GetAllTopicConfigResponseHeader.class); + final RemotingCommand response = RemotingCommand.createResponseCommand(GetAllTopicConfigResponseHeader.class); // final GetAllTopicConfigResponseHeader responseHeader = // (GetAllTopicConfigResponseHeader) response.readCustomHeader(); @@ -473,12 +459,10 @@ private RemotingCommand getAllTopicConfig(ChannelHandlerContext ctx, RemotingCom return response; } - private synchronized RemotingCommand updateBrokerConfig(ChannelHandlerContext ctx, - RemotingCommand request) { + private synchronized RemotingCommand updateBrokerConfig(ChannelHandlerContext ctx, RemotingCommand request) { final RemotingCommand response = RemotingCommand.createResponseCommand(null); - log.info("updateBrokerConfig called by {}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel())); + log.info("updateBrokerConfig called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); byte[] body = request.getBody(); if (body != null) { @@ -486,12 +470,10 @@ private synchronized RemotingCommand updateBrokerConfig(ChannelHandlerContext ct String bodyStr = new String(body, MixAll.DEFAULT_CHARSET); Properties properties = MixAll.string2Properties(bodyStr); if (properties != null) { - log.info("updateBrokerConfig, new config: [{}] client: {} ", properties, - ctx.channel().remoteAddress()); + log.info("updateBrokerConfig, new config: [{}] client: {} ", properties, ctx.channel().remoteAddress()); this.brokerController.getConfiguration().update(properties); if (properties.containsKey("brokerPermission")) { - this.brokerController.getTopicConfigManager().getDataVersion() - .nextVersion(); + this.brokerController.getTopicConfigManager().getDataVersion().nextVersion(); this.brokerController.registerBrokerAll(false, false, true); } } else { @@ -515,10 +497,8 @@ private synchronized RemotingCommand updateBrokerConfig(ChannelHandlerContext ct private RemotingCommand getBrokerConfig(ChannelHandlerContext ctx, RemotingCommand request) { - final RemotingCommand response = RemotingCommand - .createResponseCommand(GetBrokerConfigResponseHeader.class); - final GetBrokerConfigResponseHeader responseHeader = (GetBrokerConfigResponseHeader) response - .readCustomHeader(); + final RemotingCommand response = RemotingCommand.createResponseCommand(GetBrokerConfigResponseHeader.class); + final GetBrokerConfigResponseHeader responseHeader = (GetBrokerConfigResponseHeader) response.readCustomHeader(); String content = this.brokerController.getConfiguration().getAllConfigsFormatString(); if (content != null && content.length() > 0) { @@ -541,18 +521,14 @@ private RemotingCommand getBrokerConfig(ChannelHandlerContext ctx, RemotingComma } private RemotingCommand searchOffsetByTimestamp(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { - final RemotingCommand response = RemotingCommand - .createResponseCommand(SearchOffsetResponseHeader.class); - final SearchOffsetResponseHeader responseHeader = (SearchOffsetResponseHeader) response - .readCustomHeader(); + RemotingCommand request) throws RemotingCommandException { + final RemotingCommand response = RemotingCommand.createResponseCommand(SearchOffsetResponseHeader.class); + final SearchOffsetResponseHeader responseHeader = (SearchOffsetResponseHeader) response.readCustomHeader(); final SearchOffsetRequestHeader requestHeader = - (SearchOffsetRequestHeader) request - .decodeCommandCustomHeader(SearchOffsetRequestHeader.class); + (SearchOffsetRequestHeader) request.decodeCommandCustomHeader(SearchOffsetRequestHeader.class); - long offset = this.brokerController.getMessageStore() - .getOffsetInQueueByTime(requestHeader.getTopic(), requestHeader.getQueueId(), - requestHeader.getTimestamp()); + long offset = this.brokerController.getMessageStore().getOffsetInQueueByTime(requestHeader.getTopic(), requestHeader.getQueueId(), + requestHeader.getTimestamp()); responseHeader.setOffset(offset); @@ -562,17 +538,13 @@ private RemotingCommand searchOffsetByTimestamp(ChannelHandlerContext ctx, } private RemotingCommand getMaxOffset(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { - final RemotingCommand response = RemotingCommand - .createResponseCommand(GetMaxOffsetResponseHeader.class); - final GetMaxOffsetResponseHeader responseHeader = (GetMaxOffsetResponseHeader) response - .readCustomHeader(); + RemotingCommand request) throws RemotingCommandException { + final RemotingCommand response = RemotingCommand.createResponseCommand(GetMaxOffsetResponseHeader.class); + final GetMaxOffsetResponseHeader responseHeader = (GetMaxOffsetResponseHeader) response.readCustomHeader(); final GetMaxOffsetRequestHeader requestHeader = - (GetMaxOffsetRequestHeader) request - .decodeCommandCustomHeader(GetMaxOffsetRequestHeader.class); + (GetMaxOffsetRequestHeader) request.decodeCommandCustomHeader(GetMaxOffsetRequestHeader.class); - long offset = this.brokerController.getMessageStore() - .getMaxOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId()); + long offset = this.brokerController.getMessageStore().getMaxOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId()); responseHeader.setOffset(offset); @@ -582,17 +554,13 @@ private RemotingCommand getMaxOffset(ChannelHandlerContext ctx, } private RemotingCommand getMinOffset(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { - final RemotingCommand response = RemotingCommand - .createResponseCommand(GetMinOffsetResponseHeader.class); - final GetMinOffsetResponseHeader responseHeader = (GetMinOffsetResponseHeader) response - .readCustomHeader(); + RemotingCommand request) throws RemotingCommandException { + final RemotingCommand response = RemotingCommand.createResponseCommand(GetMinOffsetResponseHeader.class); + final GetMinOffsetResponseHeader responseHeader = (GetMinOffsetResponseHeader) response.readCustomHeader(); final GetMinOffsetRequestHeader requestHeader = - (GetMinOffsetRequestHeader) request - .decodeCommandCustomHeader(GetMinOffsetRequestHeader.class); + (GetMinOffsetRequestHeader) request.decodeCommandCustomHeader(GetMinOffsetRequestHeader.class); - long offset = this.brokerController.getMessageStore() - .getMinOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId()); + long offset = this.brokerController.getMessageStore().getMinOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId()); responseHeader.setOffset(offset); response.setCode(ResponseCode.SUCCESS); @@ -601,19 +569,14 @@ private RemotingCommand getMinOffset(ChannelHandlerContext ctx, } private RemotingCommand getEarliestMsgStoretime(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { - final RemotingCommand response = RemotingCommand - .createResponseCommand(GetEarliestMsgStoretimeResponseHeader.class); - final GetEarliestMsgStoretimeResponseHeader responseHeader = (GetEarliestMsgStoretimeResponseHeader) response - .readCustomHeader(); + RemotingCommand request) throws RemotingCommandException { + final RemotingCommand response = RemotingCommand.createResponseCommand(GetEarliestMsgStoretimeResponseHeader.class); + final GetEarliestMsgStoretimeResponseHeader responseHeader = (GetEarliestMsgStoretimeResponseHeader) response.readCustomHeader(); final GetEarliestMsgStoretimeRequestHeader requestHeader = - (GetEarliestMsgStoretimeRequestHeader) request - .decodeCommandCustomHeader(GetEarliestMsgStoretimeRequestHeader.class); + (GetEarliestMsgStoretimeRequestHeader) request.decodeCommandCustomHeader(GetEarliestMsgStoretimeRequestHeader.class); long timestamp = - this.brokerController.getMessageStore() - .getEarliestMessageTime(requestHeader.getTopic(), - requestHeader.getQueueId()); + this.brokerController.getMessageStore().getEarliestMessageTime(requestHeader.getTopic(), requestHeader.getQueueId()); responseHeader.setTimestamp(timestamp); response.setCode(ResponseCode.SUCCESS); @@ -621,8 +584,7 @@ private RemotingCommand getEarliestMsgStoretime(ChannelHandlerContext ctx, return response; } - private RemotingCommand getBrokerRuntimeInfo(ChannelHandlerContext ctx, - RemotingCommand request) { + private RemotingCommand getBrokerRuntimeInfo(ChannelHandlerContext ctx, RemotingCommand request) { final RemotingCommand response = RemotingCommand.createResponseCommand(null); HashMap runtimeInfo = this.prepareRuntimeInfo(); @@ -637,16 +599,14 @@ private RemotingCommand getBrokerRuntimeInfo(ChannelHandlerContext ctx, } private RemotingCommand lockBatchMQ(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); - LockBatchRequestBody requestBody = LockBatchRequestBody - .decode(request.getBody(), LockBatchRequestBody.class); + LockBatchRequestBody requestBody = LockBatchRequestBody.decode(request.getBody(), LockBatchRequestBody.class); - Set lockOKMQSet = this.brokerController.getRebalanceLockManager() - .tryLockBatch( - requestBody.getConsumerGroup(), - requestBody.getMqSet(), - requestBody.getClientId()); + Set lockOKMQSet = this.brokerController.getRebalanceLockManager().tryLockBatch( + requestBody.getConsumerGroup(), + requestBody.getMqSet(), + requestBody.getClientId()); LockBatchResponseBody responseBody = new LockBatchResponseBody(); responseBody.setLockOKMQSet(lockOKMQSet); @@ -658,34 +618,29 @@ private RemotingCommand lockBatchMQ(ChannelHandlerContext ctx, } private RemotingCommand unlockBatchMQ(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); - UnlockBatchRequestBody requestBody = UnlockBatchRequestBody - .decode(request.getBody(), UnlockBatchRequestBody.class); + UnlockBatchRequestBody requestBody = UnlockBatchRequestBody.decode(request.getBody(), UnlockBatchRequestBody.class); this.brokerController.getRebalanceLockManager().unlockBatch( - requestBody.getConsumerGroup(), - requestBody.getMqSet(), - requestBody.getClientId()); + requestBody.getConsumerGroup(), + requestBody.getMqSet(), + requestBody.getClientId()); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } - private RemotingCommand updateAndCreateSubscriptionGroup(ChannelHandlerContext ctx, - RemotingCommand request) - throws RemotingCommandException { + private RemotingCommand updateAndCreateSubscriptionGroup(ChannelHandlerContext ctx, RemotingCommand request) + throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); - log.info("updateAndCreateSubscriptionGroup called by {}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel())); + log.info("updateAndCreateSubscriptionGroup called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); - SubscriptionGroupConfig config = RemotingSerializable - .decode(request.getBody(), SubscriptionGroupConfig.class); + SubscriptionGroupConfig config = RemotingSerializable.decode(request.getBody(), SubscriptionGroupConfig.class); if (config != null) { - this.brokerController.getSubscriptionGroupManager() - .updateSubscriptionGroupConfig(config); + this.brokerController.getSubscriptionGroupManager().updateSubscriptionGroupConfig(config); } response.setCode(ResponseCode.SUCCESS); @@ -694,7 +649,7 @@ private RemotingCommand updateAndCreateSubscriptionGroup(ChannelHandlerContext c } private RemotingCommand getAllSubscriptionGroup(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); String content = this.brokerController.getSubscriptionGroupManager().encode(); if (content != null && content.length() > 0) { @@ -708,8 +663,7 @@ private RemotingCommand getAllSubscriptionGroup(ChannelHandlerContext ctx, return response; } } else { - log.error("No subscription group in this broker, client:{} ", - ctx.channel().remoteAddress()); + log.error("No subscription group in this broker, client:{} ", ctx.channel().remoteAddress()); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("No subscription group in this broker"); return response; @@ -722,17 +676,14 @@ private RemotingCommand getAllSubscriptionGroup(ChannelHandlerContext ctx, } private RemotingCommand deleteSubscriptionGroup(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); DeleteSubscriptionGroupRequestHeader requestHeader = - (DeleteSubscriptionGroupRequestHeader) request - .decodeCommandCustomHeader(DeleteSubscriptionGroupRequestHeader.class); + (DeleteSubscriptionGroupRequestHeader) request.decodeCommandCustomHeader(DeleteSubscriptionGroupRequestHeader.class); - log.info("deleteSubscriptionGroup called by {}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel())); + log.info("deleteSubscriptionGroup called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); - this.brokerController.getSubscriptionGroupManager() - .deleteSubscriptionGroupConfig(requestHeader.getGroupName()); + this.brokerController.getSubscriptionGroupManager().deleteSubscriptionGroupConfig(requestHeader.getGroupName()); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); @@ -740,15 +691,13 @@ private RemotingCommand deleteSubscriptionGroup(ChannelHandlerContext ctx, } private RemotingCommand getTopicStatsInfo(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetTopicStatsInfoRequestHeader requestHeader = - (GetTopicStatsInfoRequestHeader) request - .decodeCommandCustomHeader(GetTopicStatsInfoRequestHeader.class); + (GetTopicStatsInfoRequestHeader) request.decodeCommandCustomHeader(GetTopicStatsInfoRequestHeader.class); final String topic = requestHeader.getTopic(); - TopicConfig topicConfig = this.brokerController.getTopicConfigManager() - .selectTopicConfig(topic); + TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); if (null == topicConfig) { response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark("topic[" + topic + "] not exist"); @@ -764,19 +713,16 @@ private RemotingCommand getTopicStatsInfo(ChannelHandlerContext ctx, TopicOffset topicOffset = new TopicOffset(); long min = this.brokerController.getMessageStore().getMinOffsetInQueue(topic, i); - if (min < 0) { + if (min < 0) min = 0; - } long max = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i); - if (max < 0) { + if (max < 0) max = 0; - } long timestamp = 0; if (max > 0) { - timestamp = this.brokerController.getMessageStore() - .getMessageStoreTimeStamp(topic, i, max - 1); + timestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, max - 1); } topicOffset.setMinOffset(min); @@ -794,15 +740,13 @@ private RemotingCommand getTopicStatsInfo(ChannelHandlerContext ctx, } private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumerConnectionListRequestHeader requestHeader = - (GetConsumerConnectionListRequestHeader) request - .decodeCommandCustomHeader(GetConsumerConnectionListRequestHeader.class); + (GetConsumerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetConsumerConnectionListRequestHeader.class); ConsumerGroupInfo consumerGroupInfo = - this.brokerController.getConsumerManager() - .getConsumerGroupInfo(requestHeader.getConsumerGroup()); + this.brokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup()); if (consumerGroupInfo != null) { ConsumerConnection bodydata = new ConsumerConnection(); bodydata.setConsumeFromWhere(consumerGroupInfo.getConsumeFromWhere()); @@ -810,8 +754,7 @@ private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, bodydata.setMessageModel(consumerGroupInfo.getMessageModel()); bodydata.getSubscriptionTable().putAll(consumerGroupInfo.getSubscriptionTable()); - Iterator> it = consumerGroupInfo - .getChannelInfoTable().entrySet().iterator(); + Iterator> it = consumerGroupInfo.getChannelInfoTable().entrySet().iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); Connection connection = new Connection(); @@ -832,25 +775,21 @@ private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, } response.setCode(ResponseCode.CONSUMER_NOT_ONLINE); - response.setRemark( - "the consumer group[" + requestHeader.getConsumerGroup() + "] not online"); + response.setRemark("the consumer group[" + requestHeader.getConsumerGroup() + "] not online"); return response; } private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetProducerConnectionListRequestHeader requestHeader = - (GetProducerConnectionListRequestHeader) request - .decodeCommandCustomHeader(GetProducerConnectionListRequestHeader.class); + (GetProducerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetProducerConnectionListRequestHeader.class); ProducerConnection bodydata = new ProducerConnection(); HashMap channelInfoHashMap = - this.brokerController.getProducerManager().getGroupChannelTable() - .get(requestHeader.getProducerGroup()); + this.brokerController.getProducerManager().getGroupChannelTable().get(requestHeader.getProducerGroup()); if (channelInfoHashMap != null) { - Iterator> it = channelInfoHashMap.entrySet() - .iterator(); + Iterator> it = channelInfoHashMap.entrySet().iterator(); while (it.hasNext()) { ClientChannelInfo info = it.next().getValue(); Connection connection = new Connection(); @@ -870,31 +809,27 @@ private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx, } response.setCode(ResponseCode.SYSTEM_ERROR); - response.setRemark( - "the producer group[" + requestHeader.getProducerGroup() + "] not exist"); + response.setRemark("the producer group[" + requestHeader.getProducerGroup() + "] not exist"); return response; } private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumeStatsRequestHeader requestHeader = - (GetConsumeStatsRequestHeader) request - .decodeCommandCustomHeader(GetConsumeStatsRequestHeader.class); + (GetConsumeStatsRequestHeader) request.decodeCommandCustomHeader(GetConsumeStatsRequestHeader.class); ConsumeStats consumeStats = new ConsumeStats(); Set topics = new HashSet(); if (UtilAll.isBlank(requestHeader.getTopic())) { - topics = this.brokerController.getConsumerOffsetManager() - .whichTopicByConsumer(requestHeader.getConsumerGroup()); + topics = this.brokerController.getConsumerOffsetManager().whichTopicByConsumer(requestHeader.getConsumerGroup()); } else { topics.add(requestHeader.getTopic()); } for (String topic : topics) { - TopicConfig topicConfig = this.brokerController.getTopicConfigManager() - .selectTopicConfig(topic); + TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); if (null == topicConfig) { log.warn("consumeStats, topic config not exist, {}", topic); continue; @@ -902,14 +837,11 @@ private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, { SubscriptionData findSubscriptionData = - this.brokerController.getConsumerManager() - .findSubscriptionData(requestHeader.getConsumerGroup(), topic); + this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getConsumerGroup(), topic); if (null == findSubscriptionData - && this.brokerController.getConsumerManager() - .findSubscriptionDataCount(requestHeader.getConsumerGroup()) > 0) { - log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", - requestHeader.getConsumerGroup(), topic); + && this.brokerController.getConsumerManager().findSubscriptionDataCount(requestHeader.getConsumerGroup()) > 0) { + log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", requestHeader.getConsumerGroup(), topic); continue; } } @@ -922,27 +854,23 @@ private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, OffsetWrapper offsetWrapper = new OffsetWrapper(); - long brokerOffset = this.brokerController.getMessageStore() - .getMaxOffsetInQueue(topic, i); - if (brokerOffset < 0) { + long brokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i); + if (brokerOffset < 0) brokerOffset = 0; - } long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset( - requestHeader.getConsumerGroup(), - topic, - i); - if (consumerOffset < 0) { + requestHeader.getConsumerGroup(), + topic, + i); + if (consumerOffset < 0) consumerOffset = 0; - } offsetWrapper.setBrokerOffset(brokerOffset); offsetWrapper.setConsumerOffset(consumerOffset); long timeOffset = consumerOffset - 1; if (timeOffset >= 0) { - long lastTimestamp = this.brokerController.getMessageStore() - .getMessageStoreTimeStamp(topic, i, timeOffset); + long lastTimestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, timeOffset); if (lastTimestamp > 0) { offsetWrapper.setLastTimestamp(lastTimestamp); } @@ -951,8 +879,7 @@ private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, consumeStats.getOffsetTable().put(mq, offsetWrapper); } - double consumeTps = this.brokerController.getBrokerStatsManager() - .tpsGroupGetNums(requestHeader.getConsumerGroup(), topic); + double consumeTps = this.brokerController.getBrokerStatsManager().tpsGroupGetNums(requestHeader.getConsumerGroup(), topic); consumeTps += consumeStats.getConsumeTps(); consumeStats.setConsumeTps(consumeTps); @@ -965,8 +892,7 @@ private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, return response; } - private RemotingCommand getAllConsumerOffset(ChannelHandlerContext ctx, - RemotingCommand request) { + private RemotingCommand getAllConsumerOffset(ChannelHandlerContext ctx, RemotingCommand request) { final RemotingCommand response = RemotingCommand.createResponseCommand(null); String content = this.brokerController.getConsumerOffsetManager().encode(); @@ -981,8 +907,7 @@ private RemotingCommand getAllConsumerOffset(ChannelHandlerContext ctx, return response; } } else { - log.error("No consumer offset in this broker, client: {} ", - ctx.channel().remoteAddress()); + log.error("No consumer offset in this broker, client: {} ", ctx.channel().remoteAddress()); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("No consumer offset in this broker"); return response; @@ -998,15 +923,13 @@ private RemotingCommand getAllDelayOffset(ChannelHandlerContext ctx, RemotingCom final RemotingCommand response = RemotingCommand.createResponseCommand(null); if (!(this.brokerController.getMessageStore() instanceof DefaultMessageStore)) { - log.error("Delay offset not supported in this messagetore, client: {} ", - ctx.channel().remoteAddress()); + log.error("Delay offset not supported in this messagetore, client: {} ", ctx.channel().remoteAddress()); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("Delay offset not supported in this messagetore"); return response; } - String content = ((DefaultMessageStore) this.brokerController.getMessageStore()) - .getScheduleMessageService().encode(); + String content = ((DefaultMessageStore) this.brokerController.getMessageStore()).getScheduleMessageService().encode(); if (content != null && content.length() > 0) { try { response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET)); @@ -1031,15 +954,12 @@ private RemotingCommand getAllDelayOffset(ChannelHandlerContext ctx, RemotingCom } public RemotingCommand resetOffset(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final ResetOffsetRequestHeader requestHeader = - (ResetOffsetRequestHeader) request - .decodeCommandCustomHeader(ResetOffsetRequestHeader.class); - log.info( - "[reset-offset] reset offset started by {}. topic={}, group={}, timestamp={}, isForce={}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), - requestHeader.getGroup(), - requestHeader.getTimestamp(), requestHeader.isForce()); + (ResetOffsetRequestHeader) request.decodeCommandCustomHeader(ResetOffsetRequestHeader.class); + log.info("[reset-offset] reset offset started by {}. topic={}, group={}, timestamp={}, isForce={}", + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), requestHeader.getGroup(), + requestHeader.getTimestamp(), requestHeader.isForce()); boolean isC = false; LanguageCode language = request.getLanguage(); switch (language) { @@ -1047,38 +967,31 @@ public RemotingCommand resetOffset(ChannelHandlerContext ctx, isC = true; break; } - return this.brokerController.getBroker2Client() - .resetOffset(requestHeader.getTopic(), requestHeader.getGroup(), - requestHeader.getTimestamp(), requestHeader.isForce(), isC); + return this.brokerController.getBroker2Client().resetOffset(requestHeader.getTopic(), requestHeader.getGroup(), + requestHeader.getTimestamp(), requestHeader.isForce(), isC); } public RemotingCommand getConsumerStatus(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final GetConsumerStatusRequestHeader requestHeader = - (GetConsumerStatusRequestHeader) request - .decodeCommandCustomHeader(GetConsumerStatusRequestHeader.class); + (GetConsumerStatusRequestHeader) request.decodeCommandCustomHeader(GetConsumerStatusRequestHeader.class); log.info("[get-consumer-status] get consumer status by {}. topic={}, group={}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), - requestHeader.getGroup()); + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), requestHeader.getGroup()); - return this.brokerController.getBroker2Client() - .getConsumeStatus(requestHeader.getTopic(), requestHeader.getGroup(), - requestHeader.getClientAddr()); + return this.brokerController.getBroker2Client().getConsumeStatus(requestHeader.getTopic(), requestHeader.getGroup(), + requestHeader.getClientAddr()); } private RemotingCommand queryTopicConsumeByWho(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); QueryTopicConsumeByWhoRequestHeader requestHeader = - (QueryTopicConsumeByWhoRequestHeader) request - .decodeCommandCustomHeader(QueryTopicConsumeByWhoRequestHeader.class); + (QueryTopicConsumeByWhoRequestHeader) request.decodeCommandCustomHeader(QueryTopicConsumeByWhoRequestHeader.class); - HashSet groups = this.brokerController.getConsumerManager() - .queryTopicConsumeByWho(requestHeader.getTopic()); + HashSet groups = this.brokerController.getConsumerManager().queryTopicConsumeByWho(requestHeader.getTopic()); - Set groupInOffset = this.brokerController.getConsumerOffsetManager() - .whichGroupByTopic(requestHeader.getTopic()); + Set groupInOffset = this.brokerController.getConsumerOffsetManager().whichGroupByTopic(requestHeader.getTopic()); if (groupInOffset != null && !groupInOffset.isEmpty()) { groups.addAll(groupInOffset); } @@ -1094,17 +1007,13 @@ private RemotingCommand queryTopicConsumeByWho(ChannelHandlerContext ctx, } private RemotingCommand registerFilterServer(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { - final RemotingCommand response = RemotingCommand - .createResponseCommand(RegisterFilterServerResponseHeader.class); - final RegisterFilterServerResponseHeader responseHeader = (RegisterFilterServerResponseHeader) response - .readCustomHeader(); + RemotingCommand request) throws RemotingCommandException { + final RemotingCommand response = RemotingCommand.createResponseCommand(RegisterFilterServerResponseHeader.class); + final RegisterFilterServerResponseHeader responseHeader = (RegisterFilterServerResponseHeader) response.readCustomHeader(); final RegisterFilterServerRequestHeader requestHeader = - (RegisterFilterServerRequestHeader) request - .decodeCommandCustomHeader(RegisterFilterServerRequestHeader.class); + (RegisterFilterServerRequestHeader) request.decodeCommandCustomHeader(RegisterFilterServerRequestHeader.class); - this.brokerController.getFilterServerManager() - .registerFilterServer(ctx.channel(), requestHeader.getFilterServerAddr()); + this.brokerController.getFilterServerManager().registerFilterServer(ctx.channel(), requestHeader.getFilterServerAddr()); responseHeader.setBrokerId(this.brokerController.getBrokerConfig().getBrokerId()); responseHeader.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName()); @@ -1115,15 +1024,13 @@ private RemotingCommand registerFilterServer(ChannelHandlerContext ctx, } private RemotingCommand queryConsumeTimeSpan(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); QueryConsumeTimeSpanRequestHeader requestHeader = - (QueryConsumeTimeSpanRequestHeader) request - .decodeCommandCustomHeader(QueryConsumeTimeSpanRequestHeader.class); + (QueryConsumeTimeSpanRequestHeader) request.decodeCommandCustomHeader(QueryConsumeTimeSpanRequestHeader.class); final String topic = requestHeader.getTopic(); - TopicConfig topicConfig = this.brokerController.getTopicConfigManager() - .selectTopicConfig(topic); + TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); if (null == topicConfig) { response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark("topic[" + topic + "] not exist"); @@ -1143,26 +1050,22 @@ private RemotingCommand queryConsumeTimeSpan(ChannelHandlerContext ctx, timeSpan.setMinTimeStamp(minTime); long max = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i); - long maxTime = this.brokerController.getMessageStore() - .getMessageStoreTimeStamp(topic, i, max - 1); + long maxTime = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, max - 1); timeSpan.setMaxTimeStamp(maxTime); long consumeTime; long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset( - requestHeader.getGroup(), topic, i); + requestHeader.getGroup(), topic, i); if (consumerOffset > 0) { - consumeTime = this.brokerController.getMessageStore() - .getMessageStoreTimeStamp(topic, i, consumerOffset - 1); + consumeTime = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, consumerOffset - 1); } else { consumeTime = minTime; } timeSpan.setConsumeTimeStamp(consumeTime); - long maxBrokerOffset = this.brokerController.getMessageStore() - .getMaxOffsetInQueue(requestHeader.getTopic(), i); + long maxBrokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQueue(requestHeader.getTopic(), i); if (consumerOffset < maxBrokerOffset) { - long nextTime = this.brokerController.getMessageStore() - .getMessageStoreTimeStamp(topic, i, consumerOffset); + long nextTime = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, consumerOffset); timeSpan.setDelayTime(System.currentTimeMillis() - nextTime); } timeSpanSet.add(timeSpan); @@ -1176,9 +1079,8 @@ private RemotingCommand queryConsumeTimeSpan(ChannelHandlerContext ctx, return response; } - private RemotingCommand getSystemTopicListFromBroker(ChannelHandlerContext ctx, - RemotingCommand request) - throws RemotingCommandException { + private RemotingCommand getSystemTopicListFromBroker(ChannelHandlerContext ctx, RemotingCommand request) + throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); Set topics = this.brokerController.getTopicConfigManager().getSystemTopic(); @@ -1203,8 +1105,7 @@ public RemotingCommand cleanExpiredConsumeQueue() { public RemotingCommand cleanUnusedTopic() { log.warn("invoke cleanUnusedTopic start."); final RemotingCommand response = RemotingCommand.createResponseCommand(null); - brokerController.getMessageStore().cleanUnusedTopic( - brokerController.getTopicConfigManager().getTopicConfigTable().keySet()); + brokerController.getMessageStore().cleanUnusedTopic(brokerController.getTopicConfigManager().getTopicConfigTable().keySet()); log.warn("invoke cleanUnusedTopic end."); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); @@ -1212,37 +1113,31 @@ public RemotingCommand cleanUnusedTopic() { } private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final GetConsumerRunningInfoRequestHeader requestHeader = - (GetConsumerRunningInfoRequestHeader) request - .decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class); + (GetConsumerRunningInfoRequestHeader) request.decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class); - return this.callConsumer(RequestCode.GET_CONSUMER_RUNNING_INFO, request, - requestHeader.getConsumerGroup(), - requestHeader.getClientId()); + return this.callConsumer(RequestCode.GET_CONSUMER_RUNNING_INFO, request, requestHeader.getConsumerGroup(), + requestHeader.getClientId()); } private RemotingCommand queryCorrectionOffset(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); QueryCorrectionOffsetHeader requestHeader = - (QueryCorrectionOffsetHeader) request - .decodeCommandCustomHeader(QueryCorrectionOffsetHeader.class); + (QueryCorrectionOffsetHeader) request.decodeCommandCustomHeader(QueryCorrectionOffsetHeader.class); Map correctionOffset = this.brokerController.getConsumerOffsetManager() - .queryMinOffsetInAllGroup(requestHeader.getTopic(), - requestHeader.getFilterGroups()); + .queryMinOffsetInAllGroup(requestHeader.getTopic(), requestHeader.getFilterGroups()); Map compareOffset = - this.brokerController.getConsumerOffsetManager() - .queryOffset(requestHeader.getTopic(), requestHeader.getCompareGroup()); + this.brokerController.getConsumerOffsetManager().queryOffset(requestHeader.getTopic(), requestHeader.getCompareGroup()); if (compareOffset != null && !compareOffset.isEmpty()) { for (Map.Entry entry : compareOffset.entrySet()) { Integer queueId = entry.getKey(); correctionOffset.put(queueId, - correctionOffset.get(queueId) > entry.getValue() ? Long.MAX_VALUE - : correctionOffset.get(queueId)); + correctionOffset.get(queueId) > entry.getValue() ? Long.MAX_VALUE : correctionOffset.get(queueId)); } } @@ -1255,17 +1150,15 @@ private RemotingCommand queryCorrectionOffset(ChannelHandlerContext ctx, } private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader) request - .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class); + .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class); - request.getExtFields() - .put("brokerName", this.brokerController.getBrokerConfig().getBrokerName()); + request.getExtFields().put("brokerName", this.brokerController.getBrokerConfig().getBrokerName()); SelectMappedBufferResult selectMappedBufferResult = null; try { MessageId messageId = MessageDecoder.decodeMessageId(requestHeader.getMsgId()); - selectMappedBufferResult = this.brokerController.getMessageStore() - .selectOneMessageByOffset(messageId.getOffset()); + selectMappedBufferResult = this.brokerController.getMessageStore().selectOneMessageByOffset(messageId.getOffset()); byte[] body = new byte[selectMappedBufferResult.getSize()]; selectMappedBufferResult.getByteBuffer().get(body); @@ -1277,30 +1170,26 @@ private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, } } - return this.callConsumer(RequestCode.CONSUME_MESSAGE_DIRECTLY, request, - requestHeader.getConsumerGroup(), - requestHeader.getClientId()); + return this.callConsumer(RequestCode.CONSUME_MESSAGE_DIRECTLY, request, requestHeader.getConsumerGroup(), + requestHeader.getClientId()); } private RemotingCommand cloneGroupOffset(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); CloneGroupOffsetRequestHeader requestHeader = - (CloneGroupOffsetRequestHeader) request - .decodeCommandCustomHeader(CloneGroupOffsetRequestHeader.class); + (CloneGroupOffsetRequestHeader) request.decodeCommandCustomHeader(CloneGroupOffsetRequestHeader.class); Set topics; if (UtilAll.isBlank(requestHeader.getTopic())) { - topics = this.brokerController.getConsumerOffsetManager() - .whichTopicByConsumer(requestHeader.getSrcGroup()); + topics = this.brokerController.getConsumerOffsetManager().whichTopicByConsumer(requestHeader.getSrcGroup()); } else { topics = new HashSet(); topics.add(requestHeader.getTopic()); } for (String topic : topics) { - TopicConfig topicConfig = this.brokerController.getTopicConfigManager() - .selectTopicConfig(topic); + TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); if (null == topicConfig) { log.warn("[cloneGroupOffset], topic config not exist, {}", topic); continue; @@ -1309,20 +1198,16 @@ private RemotingCommand cloneGroupOffset(ChannelHandlerContext ctx, if (!requestHeader.isOffline()) { SubscriptionData findSubscriptionData = - this.brokerController.getConsumerManager() - .findSubscriptionData(requestHeader.getSrcGroup(), topic); - if (this.brokerController.getConsumerManager() - .findSubscriptionDataCount(requestHeader.getSrcGroup()) > 0 - && findSubscriptionData == null) { - log.warn("[cloneGroupOffset], the consumer group[{}], topic[{}] not exist", - requestHeader.getSrcGroup(), topic); + this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getSrcGroup(), topic); + if (this.brokerController.getConsumerManager().findSubscriptionDataCount(requestHeader.getSrcGroup()) > 0 + && findSubscriptionData == null) { + log.warn("[cloneGroupOffset], the consumer group[{}], topic[{}] not exist", requestHeader.getSrcGroup(), topic); continue; } } - this.brokerController.getConsumerOffsetManager() - .cloneOffset(requestHeader.getSrcGroup(), requestHeader.getDestGroup(), - requestHeader.getTopic()); + this.brokerController.getConsumerOffsetManager().cloneOffset(requestHeader.getSrcGroup(), requestHeader.getDestGroup(), + requestHeader.getTopic()); } response.setCode(ResponseCode.SUCCESS); @@ -1331,20 +1216,16 @@ private RemotingCommand cloneGroupOffset(ChannelHandlerContext ctx, } private RemotingCommand ViewBrokerStatsData(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { final ViewBrokerStatsDataRequestHeader requestHeader = - (ViewBrokerStatsDataRequestHeader) request - .decodeCommandCustomHeader(ViewBrokerStatsDataRequestHeader.class); + (ViewBrokerStatsDataRequestHeader) request.decodeCommandCustomHeader(ViewBrokerStatsDataRequestHeader.class); final RemotingCommand response = RemotingCommand.createResponseCommand(null); MessageStore messageStore = this.brokerController.getMessageStore(); - StatsItem statsItem = messageStore.getBrokerStatsManager() - .getStatsItem(requestHeader.getStatsName(), requestHeader.getStatsKey()); + StatsItem statsItem = messageStore.getBrokerStatsManager().getStatsItem(requestHeader.getStatsName(), requestHeader.getStatsKey()); if (null == statsItem) { response.setCode(ResponseCode.SYSTEM_ERROR); - response.setRemark( - String.format("The stats <%s> <%s> not exist", requestHeader.getStatsName(), - requestHeader.getStatsKey())); + response.setRemark(String.format("The stats <%s> <%s> not exist", requestHeader.getStatsName(), requestHeader.getStatsKey())); return response; } @@ -1383,31 +1264,27 @@ private RemotingCommand ViewBrokerStatsData(ChannelHandlerContext ctx, return response; } - private RemotingCommand fetchAllConsumeStatsInBroker(ChannelHandlerContext ctx, - RemotingCommand request) - throws RemotingCommandException { + private RemotingCommand fetchAllConsumeStatsInBroker(ChannelHandlerContext ctx, RemotingCommand request) + throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); GetConsumeStatsInBrokerHeader requestHeader = - (GetConsumeStatsInBrokerHeader) request - .decodeCommandCustomHeader(GetConsumeStatsInBrokerHeader.class); + (GetConsumeStatsInBrokerHeader) request.decodeCommandCustomHeader(GetConsumeStatsInBrokerHeader.class); boolean isOrder = requestHeader.isOrder(); ConcurrentMap subscriptionGroups = - brokerController.getSubscriptionGroupManager().getSubscriptionGroupTable(); + brokerController.getSubscriptionGroupManager().getSubscriptionGroupTable(); List>> brokerConsumeStatsList = - new ArrayList>>(); + new ArrayList>>(); long totalDiff = 0L; for (String group : subscriptionGroups.keySet()) { Map> subscripTopicConsumeMap = new HashMap>(); - Set topics = this.brokerController.getConsumerOffsetManager() - .whichTopicByConsumer(group); + Set topics = this.brokerController.getConsumerOffsetManager().whichTopicByConsumer(group); List consumeStatsList = new ArrayList(); for (String topic : topics) { ConsumeStats consumeStats = new ConsumeStats(); - TopicConfig topicConfig = this.brokerController.getTopicConfigManager() - .selectTopicConfig(topic); + TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); if (null == topicConfig) { log.warn("consumeStats, topic config not exist, {}", topic); continue; @@ -1418,14 +1295,11 @@ private RemotingCommand fetchAllConsumeStatsInBroker(ChannelHandlerContext ctx, } { - SubscriptionData findSubscriptionData = this.brokerController - .getConsumerManager().findSubscriptionData(group, topic); + SubscriptionData findSubscriptionData = this.brokerController.getConsumerManager().findSubscriptionData(group, topic); if (null == findSubscriptionData - && this.brokerController.getConsumerManager() - .findSubscriptionDataCount(group) > 0) { - log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", group, - topic); + && this.brokerController.getConsumerManager().findSubscriptionDataCount(group) > 0) { + log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", group, topic); continue; } } @@ -1436,35 +1310,29 @@ private RemotingCommand fetchAllConsumeStatsInBroker(ChannelHandlerContext ctx, mq.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName()); mq.setQueueId(i); OffsetWrapper offsetWrapper = new OffsetWrapper(); - long brokerOffset = this.brokerController.getMessageStore() - .getMaxOffsetInQueue(topic, i); - if (brokerOffset < 0) { + long brokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i); + if (brokerOffset < 0) brokerOffset = 0; - } - long consumerOffset = this.brokerController.getConsumerOffsetManager() - .queryOffset( - group, - topic, - i); - if (consumerOffset < 0) { + long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset( + group, + topic, + i); + if (consumerOffset < 0) consumerOffset = 0; - } offsetWrapper.setBrokerOffset(brokerOffset); offsetWrapper.setConsumerOffset(consumerOffset); long timeOffset = consumerOffset - 1; if (timeOffset >= 0) { - long lastTimestamp = this.brokerController.getMessageStore() - .getMessageStoreTimeStamp(topic, i, timeOffset); + long lastTimestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, timeOffset); if (lastTimestamp > 0) { offsetWrapper.setLastTimestamp(lastTimestamp); } } consumeStats.getOffsetTable().put(mq, offsetWrapper); } - double consumeTps = this.brokerController.getBrokerStatsManager() - .tpsGroupGetNums(group, topic); + double consumeTps = this.brokerController.getBrokerStatsManager().tpsGroupGetNums(group, topic); consumeTps += consumeStats.getConsumeTps(); consumeStats.setConsumeTps(consumeTps); totalDiff += consumeStats.computeTotalDiff(); @@ -1484,114 +1352,82 @@ private RemotingCommand fetchAllConsumeStatsInBroker(ChannelHandlerContext ctx, } private HashMap prepareRuntimeInfo() { - HashMap runtimeInfo = this.brokerController.getMessageStore() - .getRuntimeInfo(); + HashMap runtimeInfo = this.brokerController.getMessageStore().getRuntimeInfo(); runtimeInfo.put("brokerVersionDesc", MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION)); runtimeInfo.put("brokerVersion", String.valueOf(MQVersion.CURRENT_VERSION)); runtimeInfo.put("msgPutTotalYesterdayMorning", - String.valueOf( - this.brokerController.getBrokerStats().getMsgPutTotalYesterdayMorning())); - runtimeInfo.put("msgPutTotalTodayMorning", String.valueOf( - this.brokerController.getBrokerStats().getMsgPutTotalTodayMorning())); - runtimeInfo.put("msgPutTotalTodayNow", - String.valueOf(this.brokerController.getBrokerStats().getMsgPutTotalTodayNow())); + String.valueOf(this.brokerController.getBrokerStats().getMsgPutTotalYesterdayMorning())); + runtimeInfo.put("msgPutTotalTodayMorning", String.valueOf(this.brokerController.getBrokerStats().getMsgPutTotalTodayMorning())); + runtimeInfo.put("msgPutTotalTodayNow", String.valueOf(this.brokerController.getBrokerStats().getMsgPutTotalTodayNow())); runtimeInfo.put("msgGetTotalYesterdayMorning", - String.valueOf( - this.brokerController.getBrokerStats().getMsgGetTotalYesterdayMorning())); - runtimeInfo.put("msgGetTotalTodayMorning", String.valueOf( - this.brokerController.getBrokerStats().getMsgGetTotalTodayMorning())); - runtimeInfo.put("msgGetTotalTodayNow", - String.valueOf(this.brokerController.getBrokerStats().getMsgGetTotalTodayNow())); + String.valueOf(this.brokerController.getBrokerStats().getMsgGetTotalYesterdayMorning())); + runtimeInfo.put("msgGetTotalTodayMorning", String.valueOf(this.brokerController.getBrokerStats().getMsgGetTotalTodayMorning())); + runtimeInfo.put("msgGetTotalTodayNow", String.valueOf(this.brokerController.getBrokerStats().getMsgGetTotalTodayNow())); - runtimeInfo.put("sendThreadPoolQueueSize", - String.valueOf(this.brokerController.getSendThreadPoolQueue().size())); + runtimeInfo.put("sendThreadPoolQueueSize", String.valueOf(this.brokerController.getSendThreadPoolQueue().size())); runtimeInfo.put("sendThreadPoolQueueCapacity", - String.valueOf( - this.brokerController.getBrokerConfig().getSendThreadPoolQueueCapacity())); + String.valueOf(this.brokerController.getBrokerConfig().getSendThreadPoolQueueCapacity())); - runtimeInfo.put("pullThreadPoolQueueSize", - String.valueOf(this.brokerController.getPullThreadPoolQueue().size())); + runtimeInfo.put("pullThreadPoolQueueSize", String.valueOf(this.brokerController.getPullThreadPoolQueue().size())); runtimeInfo.put("pullThreadPoolQueueCapacity", - String.valueOf( - this.brokerController.getBrokerConfig().getPullThreadPoolQueueCapacity())); + String.valueOf(this.brokerController.getBrokerConfig().getPullThreadPoolQueueCapacity())); - runtimeInfo.put("queryThreadPoolQueueSize", - String.valueOf(this.brokerController.getQueryThreadPoolQueue().size())); + runtimeInfo.put("queryThreadPoolQueueSize", String.valueOf(this.brokerController.getQueryThreadPoolQueue().size())); runtimeInfo.put("queryThreadPoolQueueCapacity", - String.valueOf( - this.brokerController.getBrokerConfig().getQueryThreadPoolQueueCapacity())); + String.valueOf(this.brokerController.getBrokerConfig().getQueryThreadPoolQueueCapacity())); - runtimeInfo.put("EndTransactionQueueSize", - String.valueOf(this.brokerController.getEndTransactionThreadPoolQueue().size())); + runtimeInfo.put("EndTransactionQueueSize", String.valueOf(this.brokerController.getEndTransactionThreadPoolQueue().size())); runtimeInfo.put("EndTransactionThreadPoolQueueCapacity", - String.valueOf(this.brokerController.getBrokerConfig() - .getEndTransactionPoolQueueCapacity())); - - runtimeInfo.put("dispatchBehindBytes", - String.valueOf(this.brokerController.getMessageStore().dispatchBehindBytes())); - runtimeInfo.put("pageCacheLockTimeMills", - String.valueOf(this.brokerController.getMessageStore().lockTimeMills())); - - runtimeInfo.put("sendThreadPoolQueueHeadWaitTimeMills", - String.valueOf(this.brokerController.headSlowTimeMills4SendThreadPoolQueue())); - runtimeInfo.put("pullThreadPoolQueueHeadWaitTimeMills", - String.valueOf(this.brokerController.headSlowTimeMills4PullThreadPoolQueue())); - runtimeInfo.put("queryThreadPoolQueueHeadWaitTimeMills", - String.valueOf(this.brokerController.headSlowTimeMills4QueryThreadPoolQueue())); - - runtimeInfo.put("earliestMessageTimeStamp", - String.valueOf(this.brokerController.getMessageStore().getEarliestMessageTime())); - runtimeInfo.put("startAcceptSendRequestTimeStamp", String.valueOf( - this.brokerController.getBrokerConfig().getStartAcceptSendRequestTimeStamp())); + String.valueOf(this.brokerController.getBrokerConfig().getEndTransactionPoolQueueCapacity())); + + runtimeInfo.put("dispatchBehindBytes", String.valueOf(this.brokerController.getMessageStore().dispatchBehindBytes())); + runtimeInfo.put("pageCacheLockTimeMills", String.valueOf(this.brokerController.getMessageStore().lockTimeMills())); + + runtimeInfo.put("sendThreadPoolQueueHeadWaitTimeMills", String.valueOf(this.brokerController.headSlowTimeMills4SendThreadPoolQueue())); + runtimeInfo.put("pullThreadPoolQueueHeadWaitTimeMills", String.valueOf(this.brokerController.headSlowTimeMills4PullThreadPoolQueue())); + runtimeInfo.put("queryThreadPoolQueueHeadWaitTimeMills", String.valueOf(this.brokerController.headSlowTimeMills4QueryThreadPoolQueue())); + + runtimeInfo.put("earliestMessageTimeStamp", String.valueOf(this.brokerController.getMessageStore().getEarliestMessageTime())); + runtimeInfo.put("startAcceptSendRequestTimeStamp", String.valueOf(this.brokerController.getBrokerConfig().getStartAcceptSendRequestTimeStamp())); if (this.brokerController.getMessageStore() instanceof DefaultMessageStore) { - DefaultMessageStore defaultMessageStore = (DefaultMessageStore) this.brokerController - .getMessageStore(); - runtimeInfo.put("remainTransientStoreBufferNumbs", - String.valueOf(defaultMessageStore.remainTransientStoreBufferNumbs())); + DefaultMessageStore defaultMessageStore = (DefaultMessageStore) this.brokerController.getMessageStore(); + runtimeInfo.put("remainTransientStoreBufferNumbs", String.valueOf(defaultMessageStore.remainTransientStoreBufferNumbs())); if (defaultMessageStore.getMessageStoreConfig().isTransientStorePoolEnable()) { - runtimeInfo.put("remainHowManyDataToCommit", MixAll.humanReadableByteCount( - defaultMessageStore.getCommitLog().remainHowManyDataToCommit(), false)); + runtimeInfo.put("remainHowManyDataToCommit", MixAll.humanReadableByteCount(defaultMessageStore.getCommitLog().remainHowManyDataToCommit(), false)); } - runtimeInfo.put("remainHowManyDataToFlush", MixAll.humanReadableByteCount( - defaultMessageStore.getCommitLog().remainHowManyDataToFlush(), false)); + runtimeInfo.put("remainHowManyDataToFlush", MixAll.humanReadableByteCount(defaultMessageStore.getCommitLog().remainHowManyDataToFlush(), false)); } - java.io.File commitLogDir = new java.io.File( - this.brokerController.getMessageStoreConfig().getStorePathRootDir()); + java.io.File commitLogDir = new java.io.File(this.brokerController.getMessageStoreConfig().getStorePathRootDir()); if (commitLogDir.exists()) { - runtimeInfo.put("commitLogDirCapacity", String.format("Total : %s, Free : %s.", - MixAll.humanReadableByteCount(commitLogDir.getTotalSpace(), false), - MixAll.humanReadableByteCount(commitLogDir.getFreeSpace(), false))); + runtimeInfo.put("commitLogDirCapacity", String.format("Total : %s, Free : %s.", MixAll.humanReadableByteCount(commitLogDir.getTotalSpace(), false), MixAll.humanReadableByteCount(commitLogDir.getFreeSpace(), false))); } return runtimeInfo; } private RemotingCommand callConsumer( - final int requestCode, - final RemotingCommand request, - final String consumerGroup, - final String clientId) throws RemotingCommandException { + final int requestCode, + final RemotingCommand request, + final String consumerGroup, + final String clientId) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); - ClientChannelInfo clientChannelInfo = this.brokerController.getConsumerManager() - .findChannel(consumerGroup, clientId); + ClientChannelInfo clientChannelInfo = this.brokerController.getConsumerManager().findChannel(consumerGroup, clientId); if (null == clientChannelInfo) { response.setCode(ResponseCode.SYSTEM_ERROR); - response.setRemark( - String.format("The Consumer <%s> <%s> not online", consumerGroup, clientId)); + response.setRemark(String.format("The Consumer <%s> <%s> not online", consumerGroup, clientId)); return response; } if (clientChannelInfo.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) { response.setCode(ResponseCode.SYSTEM_ERROR); - response.setRemark(String.format( - "The Consumer <%s> Version <%s> too low to finish, please upgrade it to V3_1_8_SNAPSHOT", - clientId, - MQVersion.getVersionDesc(clientChannelInfo.getVersion()))); + response.setRemark(String.format("The Consumer <%s> Version <%s> too low to finish, please upgrade it to V3_1_8_SNAPSHOT", + clientId, + MQVersion.getVersionDesc(clientChannelInfo.getVersion()))); return response; } @@ -1600,39 +1436,32 @@ private RemotingCommand callConsumer( newRequest.setExtFields(request.getExtFields()); newRequest.setBody(request.getBody()); - return this.brokerController.getBroker2Client() - .callClient(clientChannelInfo.getChannel(), newRequest); + return this.brokerController.getBroker2Client().callClient(clientChannelInfo.getChannel(), newRequest); } catch (RemotingTimeoutException e) { response.setCode(ResponseCode.CONSUME_MSG_TIMEOUT); response - .setRemark( - String.format("consumer <%s> <%s> Timeout: %s", consumerGroup, clientId, - RemotingHelper.exceptionSimpleDesc(e))); + .setRemark(String.format("consumer <%s> <%s> Timeout: %s", consumerGroup, clientId, RemotingHelper.exceptionSimpleDesc(e))); return response; } catch (Exception e) { response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark( - String.format("invoke consumer <%s> <%s> Exception: %s", consumerGroup, - clientId, RemotingHelper.exceptionSimpleDesc(e))); + String.format("invoke consumer <%s> <%s> Exception: %s", consumerGroup, clientId, RemotingHelper.exceptionSimpleDesc(e))); return response; } } private RemotingCommand queryConsumeQueue(ChannelHandlerContext ctx, - RemotingCommand request) throws RemotingCommandException { + RemotingCommand request) throws RemotingCommandException { QueryConsumeQueueRequestHeader requestHeader = - (QueryConsumeQueueRequestHeader) request - .decodeCommandCustomHeader(QueryConsumeQueueRequestHeader.class); + (QueryConsumeQueueRequestHeader) request.decodeCommandCustomHeader(QueryConsumeQueueRequestHeader.class); RemotingCommand response = RemotingCommand.createResponseCommand(null); - ConsumeQueue consumeQueue = this.brokerController.getMessageStore() - .getConsumeQueue(requestHeader.getTopic(), - requestHeader.getQueueId()); + ConsumeQueue consumeQueue = this.brokerController.getMessageStore().getConsumeQueue(requestHeader.getTopic(), + requestHeader.getQueueId()); if (consumeQueue == null) { response.setCode(ResponseCode.SYSTEM_ERROR); - response.setRemark(String.format("%d@%s is not exist!", requestHeader.getQueueId(), - requestHeader.getTopic())); + response.setRemark(String.format("%d@%s is not exist!", requestHeader.getQueueId(), requestHeader.getTopic())); return response; } @@ -1645,37 +1474,30 @@ private RemotingCommand queryConsumeQueue(ChannelHandlerContext ctx, MessageFilter messageFilter = null; if (requestHeader.getConsumerGroup() != null) { - SubscriptionData subscriptionData = this.brokerController.getConsumerManager() - .findSubscriptionData( - requestHeader.getConsumerGroup(), requestHeader.getTopic() - ); + SubscriptionData subscriptionData = this.brokerController.getConsumerManager().findSubscriptionData( + requestHeader.getConsumerGroup(), requestHeader.getTopic() + ); body.setSubscriptionData(subscriptionData); if (subscriptionData == null) { - body.setFilterData( - String.format("%s@%s is not online!", requestHeader.getConsumerGroup(), - requestHeader.getTopic())); + body.setFilterData(String.format("%s@%s is not online!", requestHeader.getConsumerGroup(), requestHeader.getTopic())); } else { ConsumerFilterData filterData = this.brokerController.getConsumerFilterManager() - .get(requestHeader.getTopic(), requestHeader.getConsumerGroup()); + .get(requestHeader.getTopic(), requestHeader.getConsumerGroup()); body.setFilterData(JSON.toJSONString(filterData, true)); messageFilter = new ExpressionMessageFilter(subscriptionData, filterData, - this.brokerController.getConsumerFilterManager()); + this.brokerController.getConsumerFilterManager()); } } SelectMappedBufferResult result = consumeQueue.getIndexBuffer(requestHeader.getIndex()); if (result == null) { - response.setRemark( - String.format("Index %d of %d@%s is not exist!", requestHeader.getIndex(), - requestHeader.getQueueId(), requestHeader.getTopic())); + response.setRemark(String.format("Index %d of %d@%s is not exist!", requestHeader.getIndex(), requestHeader.getQueueId(), requestHeader.getTopic())); return response; } try { List queues = new ArrayList<>(); - for (int i = 0; i < result.getSize() - && i < requestHeader.getCount() * ConsumeQueue.CQ_STORE_UNIT_SIZE; - i += ConsumeQueue.CQ_STORE_UNIT_SIZE) { + for (int i = 0; i < result.getSize() && i < requestHeader.getCount() * ConsumeQueue.CQ_STORE_UNIT_SIZE; i += ConsumeQueue.CQ_STORE_UNIT_SIZE) { ConsumeQueueData one = new ConsumeQueueData(); one.setPhysicOffset(result.getByteBuffer().getLong()); one.setPhysicSize(result.getByteBuffer().getInt()); @@ -1693,8 +1515,7 @@ private RemotingCommand queryConsumeQueue(ChannelHandlerContext ctx, one.setBitMap(BitsArray.create(cqExtUnit.getFilterBitMap()).toString()); } if (messageFilter != null) { - one.setEval(messageFilter - .isMatchedByConsumeQueue(cqExtUnit.getTagsCode(), cqExtUnit)); + one.setEval(messageFilter.isMatchedByConsumeQueue(cqExtUnit.getTagsCode(), cqExtUnit)); } } else { one.setMsg("Cq extend not exist!addr: " + one.getTagsCode()); @@ -1710,33 +1531,28 @@ private RemotingCommand queryConsumeQueue(ChannelHandlerContext ctx, return response; } - private RemotingCommand resumeCheckHalfMessage(ChannelHandlerContext ctx, - RemotingCommand request) - throws RemotingCommandException { + RemotingCommand request) + throws RemotingCommandException { final ResumeCheckHalfMessageRequestHeader requestHeader = (ResumeCheckHalfMessageRequestHeader) request - .decodeCommandCustomHeader(ResumeCheckHalfMessageRequestHeader.class); + .decodeCommandCustomHeader(ResumeCheckHalfMessageRequestHeader.class); final RemotingCommand response = RemotingCommand.createResponseCommand(null); - ResumeCheckHalfMessageResult resumeCheckHalfMessageResult = new ResumeCheckHalfMessageResult(); SelectMappedBufferResult selectMappedBufferResult = null; - Long beginTime = System.currentTimeMillis(); try { MessageId messageId = MessageDecoder.decodeMessageId(requestHeader.getMsgId()); selectMappedBufferResult = this.brokerController.getMessageStore() - .selectOneMessageByOffset(messageId.getOffset()); + .selectOneMessageByOffset(messageId.getOffset()); MessageExt msg = MessageDecoder.decode(selectMappedBufferResult.getByteBuffer()); msg.putUserProperty(MessageConst.PROPERTY_TRANSACTION_CHECK_TIMES, String.valueOf(0)); PutMessageResult putMessageResult = this.brokerController.getMessageStore() - .putMessage(toMessageExtBrokerInner(msg)); + .putMessage(toMessageExtBrokerInner(msg)); if (putMessageResult != null - && putMessageResult.getPutMessageStatus() == PutMessageStatus.PUT_OK) { + && putMessageResult.getPutMessageStatus() == PutMessageStatus.PUT_OK) { log.info( - "Put message back to RMQ_SYS_TRANS_HALF_TOPIC. real topic={}", - msg.getUserProperty(MessageConst.PROPERTY_REAL_TOPIC)); + "Put message back to RMQ_SYS_TRANS_HALF_TOPIC. real topic={}", + msg.getUserProperty(MessageConst.PROPERTY_REAL_TOPIC)); response.setCode(ResponseCode.SUCCESS); - resumeCheckHalfMessageResult.setResumeResult(ResumeResult.RESUME_SUCCESS); - resumeCheckHalfMessageResult.setSpentTimeMills(System.currentTimeMillis() - beginTime); - response.setBody(resumeCheckHalfMessageResult.encode()); + response.setRemark(null); } else { log.error("Put message back to RMQ_SYS_TRANS_HALF_TOPIC failed."); response.setCode(ResponseCode.SYSTEM_ERROR); @@ -1772,5 +1588,4 @@ private MessageExtBrokerInner toMessageExtBrokerInner(MessageExt msgExt) { inner.setWaitStoreMsgOK(false); return inner; } - } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java b/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java index 8652e0bb1b5..8f215cdcb9c 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java @@ -220,7 +220,7 @@ public TopicConfig createTopicInSendMessageMethod(final String topic, final Stri } if (createNew) { - this.brokerController.registerBrokerAll(false, true,true); + this.brokerController.registerBrokerAll(false, true, true); } return topicConfig; @@ -264,7 +264,7 @@ public TopicConfig createTopicInSendMessageBackMethod( } if (createNew) { - this.brokerController.registerBrokerAll(false, true,true); + this.brokerController.registerBrokerAll(false, true, true); } return topicConfig; @@ -304,7 +304,7 @@ public TopicConfig createTopicOfTranCheckMaxTime(final int clientDefaultTopicQue } if (createNew) { - this.brokerController.registerBrokerAll(false, true,true); + this.brokerController.registerBrokerAll(false, true, true); } return topicConfig; @@ -329,7 +329,7 @@ public void updateTopicUnitFlag(final String topic, final boolean unit) { this.dataVersion.nextVersion(); this.persist(); - this.brokerController.registerBrokerAll(false, true,true); + this.brokerController.registerBrokerAll(false, true, true); } } @@ -349,7 +349,7 @@ public void updateTopicUnitSubFlag(final String topic, final boolean hasUnitSub) this.dataVersion.nextVersion(); this.persist(); - this.brokerController.registerBrokerAll(false, true,true); + this.brokerController.registerBrokerAll(false, true, true); } } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListener.java b/broker/src/main/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListener.java index 80a0309a887..ee87bd37530 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListener.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListener.java @@ -30,12 +30,8 @@ import org.apache.rocketmq.store.PutMessageResult; import org.apache.rocketmq.store.PutMessageStatus; -public class DefaultTransactionalMessageCheckListener extends - AbstractTransactionalMessageCheckListener { - - private static final InternalLogger log = InternalLoggerFactory - .getLogger(LoggerName.TRANSACTION_LOGGER_NAME); - +public class DefaultTransactionalMessageCheckListener extends AbstractTransactionalMessageCheckListener { + private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.TRANSACTION_LOGGER_NAME); public DefaultTransactionalMessageCheckListener() { super(); @@ -43,26 +39,16 @@ public DefaultTransactionalMessageCheckListener() { @Override public void resolveDiscardMsg(MessageExt msgExt) { - log.error( - "MsgExt:{} has been checked too many times, so discard it by moving it to system topic TRANS_CHECK_MAXTIME_TOPIC", - msgExt); + log.error("MsgExt:{} has been checked too many times, so discard it by moving it to system topic TRANS_CHECK_MAXTIME_TOPIC", msgExt); try { MessageExtBrokerInner brokerInner = toMessageExtBrokerInner(msgExt); - PutMessageResult putMessageResult = this.getBrokerController().getMessageStore() - .putMessage(brokerInner); - if (putMessageResult != null - && putMessageResult.getPutMessageStatus() == PutMessageStatus.PUT_OK) { - log.info( - "Put checked-too-many-time half message to TRANS_CHECK_MAXTIME_TOPIC OK. Restored in queueOffset={}, " - + "commitLogOffset={}, real topic={}", - msgExt.getQueueOffset(), msgExt.getCommitLogOffset(), - msgExt.getUserProperty( - MessageConst.PROPERTY_REAL_TOPIC)); + PutMessageResult putMessageResult = this.getBrokerController().getMessageStore().putMessage(brokerInner); + if (putMessageResult != null && putMessageResult.getPutMessageStatus() == PutMessageStatus.PUT_OK) { + log.info("Put checked-too-many-time half message to TRANS_CHECK_MAXTIME_TOPIC OK. Restored in queueOffset={}, " + + "commitLogOffset={}, real topic={}", msgExt.getQueueOffset(), msgExt.getCommitLogOffset(), msgExt.getUserProperty(MessageConst.PROPERTY_REAL_TOPIC)); } else { - log.error( - "Put checked-too-many-time half message to TRANS_CHECK_MAXTIME_TOPIC failed, real topic={}, msgId={}", - msgExt.getTopic(), msgExt.getMsgId()); + log.error("Put checked-too-many-time half message to TRANS_CHECK_MAXTIME_TOPIC failed, real topic={}, msgId={}", msgExt.getTopic(), msgExt.getMsgId()); } } catch (Exception e) { log.warn("Put checked-too-many-time message to TRANS_CHECK_MAXTIME_TOPIC error. {}", e); @@ -71,9 +57,7 @@ public void resolveDiscardMsg(MessageExt msgExt) { } private MessageExtBrokerInner toMessageExtBrokerInner(MessageExt msgExt) { - TopicConfig topicConfig = this.getBrokerController().getTopicConfigManager() - .createTopicOfTranCheckMaxTime(TCMT_QUEUE_NUMS, - PermName.PERM_READ | PermName.PERM_WRITE); + TopicConfig topicConfig = this.getBrokerController().getTopicConfigManager().createTopicOfTranCheckMaxTime(TCMT_QUEUE_NUMS, PermName.PERM_READ | PermName.PERM_WRITE); int queueId = Math.abs(random.nextInt() % 99999999) % TCMT_QUEUE_NUMS; MessageExtBrokerInner inner = new MessageExtBrokerInner(); inner.setTopic(topicConfig.getTopicName()); diff --git a/broker/src/test/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessorTest.java b/broker/src/test/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessorTest.java index 90de9205226..501d2a2bc23 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessorTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessorTest.java @@ -16,10 +16,6 @@ */ package org.apache.rocketmq.broker.processor; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - import io.netty.channel.ChannelHandlerContext; import java.net.SocketAddress; import java.net.UnknownHostException; @@ -28,7 +24,6 @@ import org.apache.rocketmq.common.BrokerConfig; import org.apache.rocketmq.common.message.MessageAccessor; import org.apache.rocketmq.common.message.MessageConst; -import org.apache.rocketmq.common.message.MessageDecoder; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.message.MessageId; import org.apache.rocketmq.common.protocol.RequestCode; @@ -52,12 +47,13 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Spy; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.mockito.junit.MockitoJUnitRunner; -@RunWith(PowerMockRunner.class) -@PrepareForTest({MessageDecoder.class}) +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) public class AdminBrokerProcessorTest { private AdminBrokerProcessor adminBrokerProcessor; @@ -84,9 +80,9 @@ public void init() { public void testProcessRequest_success() throws RemotingCommandException, UnknownHostException { RemotingCommand request = createResumeCheckHalfMessageCommand(); when(messageStore.selectOneMessageByOffset(any(Long.class))).thenReturn(createSelectMappedBufferResult()); - PowerMockito.mockStatic(MessageDecoder.class); - PowerMockito.when(MessageDecoder.decode(any(ByteBuffer.class))).thenReturn(createDefaultMessageExt()); - PowerMockito.when(MessageDecoder.decodeMessageId(any(String.class))).thenReturn(createMessageId()); +// PowerMockito.mockStatic(MessageDecoder.class); +// PowerMockito.when(MessageDecoder.decode(any(ByteBuffer.class))).thenReturn(createDefaultMessageExt()); +// PowerMockito.when(MessageDecoder.decodeMessageId(any(String.class))).thenReturn(createMessageId()); when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK))); RemotingCommand response = adminBrokerProcessor.processRequest(handlerContext, request); @@ -97,28 +93,15 @@ public void testProcessRequest_success() throws RemotingCommandException, Unknow public void testProcessRequest_fail() throws RemotingCommandException, UnknownHostException { RemotingCommand request = createResumeCheckHalfMessageCommand(); when(messageStore.selectOneMessageByOffset(any(Long.class))).thenReturn(createSelectMappedBufferResult()); - PowerMockito.mockStatic(MessageDecoder.class); - PowerMockito.when(MessageDecoder.decode(any(ByteBuffer.class))).thenReturn(createDefaultMessageExt()); - PowerMockito.when(MessageDecoder.decodeMessageId(any(String.class))).thenReturn(createMessageId()); +// PowerMockito.mockStatic(MessageDecoder.class); +// PowerMockito.when(MessageDecoder.decode(any(ByteBuffer.class))).thenReturn(createDefaultMessageExt()); +// PowerMockito.when(MessageDecoder.decodeMessageId(any(String.class))).thenReturn(createMessageId()); when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult (PutMessageStatus.UNKNOWN_ERROR, new AppendMessageResult(AppendMessageStatus.UNKNOWN_ERROR))); RemotingCommand response = adminBrokerProcessor.processRequest(handlerContext, request); assertThat(response.getCode()).isEqualTo(ResponseCode.SYSTEM_ERROR); } - @Test - public void testProcessRequest_exception() throws RemotingCommandException, UnknownHostException { - RemotingCommand request = createResumeCheckHalfMessageCommand(); - when(messageStore.selectOneMessageByOffset(any(Long.class))).thenReturn(createSelectMappedBufferResult()); - PowerMockito.mockStatic(MessageDecoder.class); - PowerMockito.when(MessageDecoder.decode(any(ByteBuffer.class))).thenReturn(createDefaultMessageExt()); - PowerMockito.when(MessageDecoder.decodeMessageId(any(String.class))).thenThrow(new UnknownHostException()); - when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult - (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK))); - RemotingCommand response = adminBrokerProcessor.processRequest(handlerContext, request); - assertThat(response.getCode()).isEqualTo(ResponseCode.SYSTEM_ERROR); - } - private MessageExt createDefaultMessageExt() { MessageExt messageExt = new MessageExt(); messageExt.setMsgId("12345678"); @@ -142,7 +125,7 @@ private SelectMappedBufferResult createSelectMappedBufferResult(){ } private ResumeCheckHalfMessageRequestHeader createResumeCheckHalfMessageRequestHeader() { ResumeCheckHalfMessageRequestHeader header = new ResumeCheckHalfMessageRequestHeader(); - header.setMsgId("12345678"); + header.setMsgId("C0A803CA00002A9F0000000000031367"); return header; } diff --git a/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java b/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java index 3c5869e5fd7..2866de613c1 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java @@ -45,9 +45,8 @@ public class DefaultTransactionalMessageCheckListenerTest { @Spy private BrokerController brokerController = new BrokerController(new BrokerConfig(), - new NettyServerConfig(), - new NettyClientConfig(), new MessageStoreConfig()); - + new NettyServerConfig(), + new NettyClientConfig(), new MessageStoreConfig()); @Before public void init() throws Exception { @@ -61,6 +60,7 @@ public void init() throws Exception { public void destroy() { // brokerController.shutdown(); } + @Test public void testResolveHalfMsg() { listener.resolveHalfMsg(createMessageExt()); @@ -81,10 +81,10 @@ private MessageExtBrokerInner createMessageExt() { MessageExtBrokerInner inner = new MessageExtBrokerInner(); MessageAccessor.putProperty(inner, MessageConst.PROPERTY_REAL_QUEUE_ID, "1"); MessageAccessor - .putProperty(inner, MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX, "1234255"); + .putProperty(inner, MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX, "1234255"); MessageAccessor.putProperty(inner, MessageConst.PROPERTY_REAL_TOPIC, "realTopic"); inner.setTransactionId( - inner.getProperty(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX)); + inner.getProperty(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX)); inner.setBody("check".getBytes()); inner.setMsgId("12344567890"); inner.setQueueId(0); @@ -97,20 +97,15 @@ public void testResolveDiscardMsg() { messageExt.setTopic(MixAll.RMQ_SYS_TRANS_HALF_TOPIC); messageExt.setQueueId(0); messageExt.setBody("test resolve discard msg".getBytes()); - messageExt.setStoreHost(new InetSocketAddress("127.0.0.1",10911)); - messageExt.setBornHost(new InetSocketAddress("127.0.0.1",54270)); + messageExt.setStoreHost(new InetSocketAddress("127.0.0.1", 10911)); + messageExt.setBornHost(new InetSocketAddress("127.0.0.1", 54270)); MessageAccessor.putProperty(messageExt, MessageConst.PROPERTY_REAL_TOPIC, "test_topic"); - MessageAccessor.putProperty(messageExt, MessageConst.PROPERTY_PRODUCER_GROUP, - "PID_TEST_DISCARD_MSG"); + MessageAccessor.putProperty(messageExt, MessageConst.PROPERTY_PRODUCER_GROUP, "PID_TEST_DISCARD_MSG"); MessageAccessor.putProperty(messageExt, MessageConst.PROPERTY_TRANSACTION_PREPARED, "true"); - MessageAccessor - .putProperty(messageExt, MessageConst.PROPERTY_TRANSACTION_CHECK_TIMES, "15"); - MessageAccessor - .putProperty(messageExt, MessageConst.PROPERTY_REAL_QUEUE_ID, "2"); - MessageAccessor - .putProperty(messageExt, MessageConst.PROPERTY_TAGS, "test_discard_msg"); - MessageAccessor - .putProperty(messageExt, MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX, "AC14157E4F1C18B4AAC27EB1A0F30000"); + MessageAccessor.putProperty(messageExt, MessageConst.PROPERTY_TRANSACTION_CHECK_TIMES, "15"); + MessageAccessor.putProperty(messageExt, MessageConst.PROPERTY_REAL_QUEUE_ID, "2"); + MessageAccessor.putProperty(messageExt, MessageConst.PROPERTY_TAGS, "test_discard_msg"); + MessageAccessor.putProperty(messageExt, MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX, "AC14157E4F1C18B4AAC27EB1A0F30000"); listener.resolveDiscardMsg(messageExt); } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java index 708bfde09c6..b743af93d46 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java @@ -82,7 +82,6 @@ import org.apache.rocketmq.common.protocol.body.QueryCorrectionOffsetBody; import org.apache.rocketmq.common.protocol.body.QueueTimeSpan; import org.apache.rocketmq.common.protocol.body.ResetOffsetBody; -import org.apache.rocketmq.common.protocol.body.ResumeCheckHalfMessageResult; import org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper; import org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper; import org.apache.rocketmq.common.protocol.body.TopicList; @@ -2210,28 +2209,23 @@ public void checkClientInBroker(final String brokerAddr, final String consumerGr } } - public ResumeCheckHalfMessageResult resumeCheckHalfMessage(final String addr, String msgId, - final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { + public boolean resumeCheckHalfMessage(final String addr, String msgId, + final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { ResumeCheckHalfMessageRequestHeader requestHeader = new ResumeCheckHalfMessageRequestHeader(); requestHeader.setMsgId(msgId); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.RESUME_CHECK_HALF_MESSAGE, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), - request, timeoutMillis); + request, timeoutMillis); assert response != null; switch (response.getCode()) { case ResponseCode.SUCCESS: { - byte[] body = response.getBody(); - if (body != null) { - ResumeCheckHalfMessageResult info = ResumeCheckHalfMessageResult.decode(body, ResumeCheckHalfMessageResult.class); - return info; - } + return true; } default: - break; + log.error("Failed to resume half message check logic. Remark={}", response.getRemark()); + return false; } - - throw new MQClientException(response.getCode(), response.getRemark()); } } diff --git a/client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java b/client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java index 28555959ba9..84af6323557 100644 --- a/client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java +++ b/client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java @@ -26,17 +26,12 @@ import org.apache.rocketmq.client.producer.SendCallback; import org.apache.rocketmq.client.producer.SendResult; import org.apache.rocketmq.client.producer.SendStatus; -import org.apache.rocketmq.common.DataVersion; import org.apache.rocketmq.common.PlainAccessConfig; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.common.message.MessageConst; import org.apache.rocketmq.common.protocol.ResponseCode; -import org.apache.rocketmq.common.protocol.body.ClusterAclVersionInfo; -import org.apache.rocketmq.common.protocol.header.CreateAccessConfigRequestHeader; -import org.apache.rocketmq.common.protocol.header.GetBrokerAclConfigResponseHeader; import org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader; import org.apache.rocketmq.common.protocol.header.SendMessageResponseHeader; -import org.apache.rocketmq.common.protocol.header.UpdateConsumerOffsetRequestHeader; import org.apache.rocketmq.remoting.InvokeCallback; import org.apache.rocketmq.remoting.RemotingClient; import org.apache.rocketmq.remoting.exception.RemotingException; @@ -294,6 +289,45 @@ public Object answer(InvocationOnMock mock) throws Throwable { assertThat(ex.getErrorMessage()).isEqualTo("corresponding to accessConfig has been deleted failed"); } } + @Test + public void testResumeCheckHalfMessage_WithException() throws RemotingException, InterruptedException, MQBrokerException, MQClientException { + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock mock) throws Throwable { + RemotingCommand request = mock.getArgument(1); + RemotingCommand response = RemotingCommand.createResponseCommand(SendMessageResponseHeader.class); + response.setCode(ResponseCode.SYSTEM_ERROR); + response.setOpaque(request.getOpaque()); + response.setRemark("Put message back to RMQ_SYS_TRANS_HALF_TOPIC failed."); + return response; + } + }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong()); + + boolean result = mqClientAPI.resumeCheckHalfMessage(brokerAddr, "test", 3000); + assertThat(result).isEqualTo(false); + } + + @Test + public void testResumeCheckHalfMessage_Success() throws InterruptedException, RemotingException, MQBrokerException, MQClientException { + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock mock) throws Throwable { + RemotingCommand request = mock.getArgument(1); + return createResumeSuccessResponse(request); + } + }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong()); + + boolean result = mqClientAPI.resumeCheckHalfMessage(brokerAddr, "test", 3000); + + assertThat(result).isEqualTo(true); + } + + private RemotingCommand createResumeSuccessResponse(RemotingCommand request) { + RemotingCommand response = RemotingCommand.createResponseCommand(null); + response.setCode(ResponseCode.SUCCESS); + response.setOpaque(request.getOpaque()); + return response; + } private RemotingCommand createSuccessResponse(RemotingCommand request) { RemotingCommand response = RemotingCommand.createResponseCommand(SendMessageResponseHeader.class); @@ -329,7 +363,7 @@ private RemotingCommand createSuccessResponse4DeleteAclConfig(RemotingCommand re response.setOpaque(request.getOpaque()); response.markResponseType(); response.setRemark(null); - + return response; } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeCheckHalfMessageResult.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeCheckHalfMessageResult.java deleted file mode 100644 index 58dabf446a8..00000000000 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeCheckHalfMessageResult.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.common.protocol.body; - -import org.apache.rocketmq.remoting.protocol.RemotingSerializable; - -public class ResumeCheckHalfMessageResult extends RemotingSerializable { - - private ResumeResult resumeResult; - private String remark; - private long spentTimeMills; - - - public ResumeResult getResumeResult() { - return resumeResult; - } - - public void setResumeResult(ResumeResult resumeResult) { - this.resumeResult = resumeResult; - } - - public String getRemark() { - return remark; - } - - public void setRemark(String remark) { - this.remark = remark; - } - - - public long getSpentTimeMills() { - return spentTimeMills; - } - - public void setSpentTimeMills(long spentTimeMills) { - this.spentTimeMills = spentTimeMills; - } - - @Override - public String toString() { - return "ConsumeMessageDirectlyResult [consumeResult=" + resumeResult + ", remark=" + remark - + ", spentTimeMills=" - + spentTimeMills + "]"; - } -} diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeResult.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeResult.java deleted file mode 100644 index 583c737f3dd..00000000000 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ResumeResult.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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.common.protocol.body; - -public enum ResumeResult { - RESUME_SUCCESS, - RESUME_THROW_EXCEPTION -} diff --git a/pom.xml b/pom.xml index 175ff33434e..7d183e74884 100644 --- a/pom.xml +++ b/pom.xml @@ -458,18 +458,6 @@ 2.23.0 test - - org.powermock - powermock-api-mockito2 - 2.0.0 - test - - - org.powermock - powermock-module-junit4 - 2.0.0 - test - diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java index e564a62d122..92371f1e2c3 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java @@ -45,7 +45,6 @@ import org.apache.rocketmq.common.protocol.body.ProducerConnection; import org.apache.rocketmq.common.protocol.body.QueryConsumeQueueResponseBody; import org.apache.rocketmq.common.protocol.body.QueueTimeSpan; -import org.apache.rocketmq.common.protocol.body.ResumeCheckHalfMessageResult; import org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper; import org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper; import org.apache.rocketmq.common.protocol.body.TopicList; @@ -540,13 +539,13 @@ public QueryConsumeQueueResponseBody queryConsumeQueue(String brokerAddr, String } @Override - public ResumeCheckHalfMessageResult resumeCheckHalfMessage(String msgId) + public boolean resumeCheckHalfMessage(String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { return this.defaultMQAdminExtImpl.resumeCheckHalfMessage(msgId); } @Override - public ResumeCheckHalfMessageResult resumeCheckHalfMessage(String topic, + public boolean resumeCheckHalfMessage(String topic, String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { return this.defaultMQAdminExtImpl.resumeCheckHalfMessage(topic, msgId); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java index 1251aa2f284..210d5a997d4 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java @@ -49,7 +49,6 @@ import org.apache.rocketmq.common.admin.TopicStatsTable; import org.apache.rocketmq.common.help.FAQUrl; import org.apache.rocketmq.common.protocol.body.ClusterAclVersionInfo; -import org.apache.rocketmq.common.protocol.body.ResumeCheckHalfMessageResult; import org.apache.rocketmq.logging.InternalLogger; import org.apache.rocketmq.common.message.MessageClientExt; import org.apache.rocketmq.common.message.MessageConst; @@ -1028,7 +1027,7 @@ public QueryConsumeQueueResponseBody queryConsumeQueue(String brokerAddr, String } @Override - public ResumeCheckHalfMessageResult resumeCheckHalfMessage(String msgId) + public boolean resumeCheckHalfMessage(String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { MessageExt msg = this.viewMessage(msgId); @@ -1036,7 +1035,7 @@ public ResumeCheckHalfMessageResult resumeCheckHalfMessage(String msgId) } @Override - public ResumeCheckHalfMessageResult resumeCheckHalfMessage(final String topic, final String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { + public boolean resumeCheckHalfMessage(final String topic, final String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { MessageExt msg = this.viewMessage(topic, msgId); if (msg.getProperty(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX) == null) { return this.mqClientInstance.getMQClientAPIImpl().resumeCheckHalfMessage(RemotingUtil.socketAddress2String(msg.getStoreHost()), msgId, timeoutMillis); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java index 02c85941234..d5c75f0e82b 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java @@ -43,7 +43,6 @@ import org.apache.rocketmq.common.protocol.body.ProducerConnection; import org.apache.rocketmq.common.protocol.body.QueryConsumeQueueResponseBody; import org.apache.rocketmq.common.protocol.body.QueueTimeSpan; -import org.apache.rocketmq.common.protocol.body.ResumeCheckHalfMessageResult; import org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper; import org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper; import org.apache.rocketmq.common.protocol.body.TopicList; @@ -275,8 +274,8 @@ QueryConsumeQueueResponseBody queryConsumeQueue(final String brokerAddr, final long index, final int count, final String consumerGroup) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQClientException; - ResumeCheckHalfMessageResult resumeCheckHalfMessage(String msgId) + boolean resumeCheckHalfMessage(String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException; - ResumeCheckHalfMessageResult resumeCheckHalfMessage(final String topic, final String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException; + boolean resumeCheckHalfMessage(final String topic, final String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException; } diff --git a/tools/src/test/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommandTest.java b/tools/src/test/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommandTest.java index be6b6369de0..e757608280f 100644 --- a/tools/src/test/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommandTest.java +++ b/tools/src/test/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommandTest.java @@ -226,5 +226,20 @@ public void testExecuteWithConsumerGroupAndClientId() throws SubCommandException } + @Test + public void testExecute() throws SubCommandException { + + System.setProperty("rocketmq.namesrv.addr", "127.0.0.1:9876"); + QueryMsgByUniqueKeySubCommand cmd = new QueryMsgByUniqueKeySubCommand(); + String[] args = new String[]{"-t myTopicTest", "-i 0A3A54F7BF7D18B4AAC28A3FA2CF0000"}; + Options options = ServerUtil.buildCommandlineOptions(new Options()); + CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin ", args, cmd.buildCommandlineOptions(options), new PosixParser()); + cmd.execute(commandLine, options, null); + + args = new String[]{"-t myTopicTest", "-i 0A3A54F7BF7D18B4AAC28A3FA2CF0000", "-g producerGroupName", "-d clientId"}; + commandLine = ServerUtil.parseCmdLine("mqadmin ", args, cmd.buildCommandlineOptions(options), new PosixParser()); + cmd.execute(commandLine, options, null); + + } } From 8f973de5cf7cd7e52983b5e3717949d32eab4408 Mon Sep 17 00:00:00 2001 From: chengxiangwang Date: Tue, 12 Mar 2019 12:08:37 +0800 Subject: [PATCH 7/7] delete commented codes --- .../broker/processor/AdminBrokerProcessor.java | 2 -- .../broker/processor/AdminBrokerProcessorTest.java | 13 ------------- ...efaultTransactionalMessageCheckListenerTest.java | 6 ++---- 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java index 540d38373fb..76a051b924c 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java @@ -115,8 +115,6 @@ import org.apache.rocketmq.common.stats.StatsSnapshot; import org.apache.rocketmq.common.subscription.SubscriptionGroupConfig; import org.apache.rocketmq.filter.util.BitsArray; -import org.apache.rocketmq.logging.InternalLogger; -import org.apache.rocketmq.logging.InternalLoggerFactory; import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.exception.RemotingCommandException; import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; diff --git a/broker/src/test/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessorTest.java b/broker/src/test/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessorTest.java index 501d2a2bc23..ec0a879c209 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessorTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessorTest.java @@ -17,7 +17,6 @@ package org.apache.rocketmq.broker.processor; import io.netty.channel.ChannelHandlerContext; -import java.net.SocketAddress; import java.net.UnknownHostException; import java.nio.ByteBuffer; import org.apache.rocketmq.broker.BrokerController; @@ -25,7 +24,6 @@ import org.apache.rocketmq.common.message.MessageAccessor; import org.apache.rocketmq.common.message.MessageConst; import org.apache.rocketmq.common.message.MessageExt; -import org.apache.rocketmq.common.message.MessageId; import org.apache.rocketmq.common.protocol.RequestCode; import org.apache.rocketmq.common.protocol.ResponseCode; import org.apache.rocketmq.common.protocol.header.ResumeCheckHalfMessageRequestHeader; @@ -80,9 +78,6 @@ public void init() { public void testProcessRequest_success() throws RemotingCommandException, UnknownHostException { RemotingCommand request = createResumeCheckHalfMessageCommand(); when(messageStore.selectOneMessageByOffset(any(Long.class))).thenReturn(createSelectMappedBufferResult()); -// PowerMockito.mockStatic(MessageDecoder.class); -// PowerMockito.when(MessageDecoder.decode(any(ByteBuffer.class))).thenReturn(createDefaultMessageExt()); -// PowerMockito.when(MessageDecoder.decodeMessageId(any(String.class))).thenReturn(createMessageId()); when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult (PutMessageStatus.PUT_OK, new AppendMessageResult(AppendMessageStatus.PUT_OK))); RemotingCommand response = adminBrokerProcessor.processRequest(handlerContext, request); @@ -93,9 +88,6 @@ public void testProcessRequest_success() throws RemotingCommandException, Unknow public void testProcessRequest_fail() throws RemotingCommandException, UnknownHostException { RemotingCommand request = createResumeCheckHalfMessageCommand(); when(messageStore.selectOneMessageByOffset(any(Long.class))).thenReturn(createSelectMappedBufferResult()); -// PowerMockito.mockStatic(MessageDecoder.class); -// PowerMockito.when(MessageDecoder.decode(any(ByteBuffer.class))).thenReturn(createDefaultMessageExt()); -// PowerMockito.when(MessageDecoder.decodeMessageId(any(String.class))).thenReturn(createMessageId()); when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult (PutMessageStatus.UNKNOWN_ERROR, new AppendMessageResult(AppendMessageStatus.UNKNOWN_ERROR))); RemotingCommand response = adminBrokerProcessor.processRequest(handlerContext, request); @@ -114,11 +106,6 @@ private MessageExt createDefaultMessageExt() { return messageExt; } - private MessageId createMessageId() { - return new MessageId(new SocketAddress() { - }, 0); - } - private SelectMappedBufferResult createSelectMappedBufferResult(){ SelectMappedBufferResult result = new SelectMappedBufferResult(0, ByteBuffer.allocate(1024) ,0, new MappedFile()); return result; diff --git a/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java b/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java index 2866de613c1..653a96933ed 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/transaction/queue/DefaultTransactionalMessageCheckListenerTest.java @@ -80,11 +80,9 @@ public void sendCheckMessage() { private MessageExtBrokerInner createMessageExt() { MessageExtBrokerInner inner = new MessageExtBrokerInner(); MessageAccessor.putProperty(inner, MessageConst.PROPERTY_REAL_QUEUE_ID, "1"); - MessageAccessor - .putProperty(inner, MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX, "1234255"); + MessageAccessor.putProperty(inner, MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX, "1234255"); MessageAccessor.putProperty(inner, MessageConst.PROPERTY_REAL_TOPIC, "realTopic"); - inner.setTransactionId( - inner.getProperty(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX)); + inner.setTransactionId(inner.getProperty(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX)); inner.setBody("check".getBytes()); inner.setMsgId("12344567890"); inner.setQueueId(0);