Search in sources :

Example 21 with OffsetWrapper

use of org.apache.rocketmq.common.admin.OffsetWrapper in project rocketmq by apache.

the class DefaultMQAdminExtImpl method consumed.

public boolean consumed(final MessageExt msg, final String group) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    ConsumeStats cstats = this.examineConsumeStats(group);
    ClusterInfo ci = this.examineBrokerClusterInfo();
    Iterator<Entry<MessageQueue, OffsetWrapper>> it = cstats.getOffsetTable().entrySet().iterator();
    while (it.hasNext()) {
        Entry<MessageQueue, OffsetWrapper> next = it.next();
        MessageQueue mq = next.getKey();
        if (mq.getTopic().equals(msg.getTopic()) && mq.getQueueId() == msg.getQueueId()) {
            BrokerData brokerData = ci.getBrokerAddrTable().get(mq.getBrokerName());
            if (brokerData != null) {
                String addr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
                if (addr.equals(RemotingUtil.socketAddress2String(msg.getStoreHost()))) {
                    if (next.getValue().getConsumerOffset() > msg.getQueueOffset()) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) Entry(java.util.Map.Entry) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) OffsetWrapper(org.apache.rocketmq.common.admin.OffsetWrapper)

Example 22 with OffsetWrapper

use of org.apache.rocketmq.common.admin.OffsetWrapper in project rocketmq by apache.

the class DefaultMQAdminExtImpl method resetOffsetByTimestampOld.

@Override
public List<RollbackStats> resetOffsetByTimestampOld(String consumerGroup, String topic, long timestamp, boolean force) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    List<RollbackStats> rollbackStatsList = new ArrayList<RollbackStats>();
    Map<String, Integer> topicRouteMap = new HashMap<String, Integer>();
    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
        for (QueueData queueData : topicRouteData.getQueueDatas()) {
            topicRouteMap.put(bd.selectBrokerAddr(), queueData.getReadQueueNums());
        }
    }
    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
        String addr = bd.selectBrokerAddr();
        if (addr != null) {
            ConsumeStats consumeStats = this.mqClientInstance.getMQClientAPIImpl().getConsumeStats(addr, consumerGroup, timeoutMillis);
            boolean hasConsumed = false;
            for (Map.Entry<MessageQueue, OffsetWrapper> entry : consumeStats.getOffsetTable().entrySet()) {
                MessageQueue queue = entry.getKey();
                OffsetWrapper offsetWrapper = entry.getValue();
                if (topic.equals(queue.getTopic())) {
                    hasConsumed = true;
                    RollbackStats rollbackStats = resetOffsetConsumeOffset(addr, consumerGroup, queue, offsetWrapper, timestamp, force);
                    rollbackStatsList.add(rollbackStats);
                }
            }
            if (!hasConsumed) {
                HashMap<MessageQueue, TopicOffset> topicStatus = this.mqClientInstance.getMQClientAPIImpl().getTopicStatsInfo(addr, topic, timeoutMillis).getOffsetTable();
                for (int i = 0; i < topicRouteMap.get(addr); i++) {
                    MessageQueue queue = new MessageQueue(topic, bd.getBrokerName(), i);
                    OffsetWrapper offsetWrapper = new OffsetWrapper();
                    offsetWrapper.setBrokerOffset(topicStatus.get(queue).getMaxOffset());
                    offsetWrapper.setConsumerOffset(topicStatus.get(queue).getMinOffset());
                    RollbackStats rollbackStats = resetOffsetConsumeOffset(addr, consumerGroup, queue, offsetWrapper, timestamp, force);
                    rollbackStatsList.add(rollbackStats);
                }
            }
        }
    }
    return rollbackStatsList;
}
Also used : HashMap(java.util.HashMap) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) ArrayList(java.util.ArrayList) OffsetWrapper(org.apache.rocketmq.common.admin.OffsetWrapper) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) TopicOffset(org.apache.rocketmq.common.admin.TopicOffset) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) RollbackStats(org.apache.rocketmq.common.admin.RollbackStats) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

OffsetWrapper (org.apache.rocketmq.common.admin.OffsetWrapper)22 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)22 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)20 HashMap (java.util.HashMap)12 ArrayList (java.util.ArrayList)10 List (java.util.List)10 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)10 Map (java.util.Map)8 ConsumerConnection (org.apache.rocketmq.common.protocol.body.ConsumerConnection)8 TopicList (org.apache.rocketmq.common.protocol.body.TopicList)8 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)8 QueueData (org.apache.rocketmq.common.protocol.route.QueueData)8 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)8 Field (java.lang.reflect.Field)6 HashSet (java.util.HashSet)6 Entry (java.util.Map.Entry)6 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)6 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)6 ConsumeStatsList (org.apache.rocketmq.common.protocol.body.ConsumeStatsList)6 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)6