Search in sources :

Example 46 with QueueData

use of org.apache.rocketmq.common.protocol.route.QueueData in project rocketmq by apache.

the class BrokerLiveInfo method wipeWritePermOfBroker.

private int wipeWritePermOfBroker(final String brokerName) {
    int wipeTopicCnt = 0;
    Iterator<Entry<String, List<QueueData>>> itTopic = this.topicQueueTable.entrySet().iterator();
    while (itTopic.hasNext()) {
        Entry<String, List<QueueData>> entry = itTopic.next();
        List<QueueData> qdList = entry.getValue();
        Iterator<QueueData> it = qdList.iterator();
        while (it.hasNext()) {
            QueueData qd = it.next();
            if (qd.getBrokerName().equals(brokerName)) {
                int perm = qd.getPerm();
                perm &= ~PermName.PERM_WRITE;
                qd.setPerm(perm);
                wipeTopicCnt++;
            }
        }
    }
    return wipeTopicCnt;
}
Also used : Entry(java.util.Map.Entry) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 47 with QueueData

use of org.apache.rocketmq.common.protocol.route.QueueData 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

QueueData (org.apache.rocketmq.common.protocol.route.QueueData)47 List (java.util.List)30 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)29 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)25 TopicList (org.apache.rocketmq.common.protocol.body.TopicList)21 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)17 HashSet (java.util.HashSet)17 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)17 LinkedList (java.util.LinkedList)16 Entry (java.util.Map.Entry)16 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 Field (java.lang.reflect.Field)10 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)10 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)10 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)10 BeforeClass (org.junit.BeforeClass)10 Set (java.util.Set)8 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)8