Said ahead
Management Request GET_MIN_OFFSET Gets Minimum offset
Source code analysis
Enter the method org.apache.rocketmq.broker.processor.AdminBrokerProcessor#getMinOffset to get the smallest offset
private RemotingCommand getMinOffset(ChannelHandlerContext ctx, 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); // Find the smallest offset = based on topic and queueId long offset = this.brokerController.getMessageStore().getMinOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId()); responseHeader.setOffset(offset); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; }
Enter the method org.apache.rocketmq.store.DefaultMessageStore#getMinOffsetInQueue to query the smallest offset based on topic and queueId
public long getMinOffsetInQueue(String topic, int queueId) { // Query the consumer queue= based on topic and queueId ConsumeQueue logic = this.findConsumeQueue(topic, queueId); if (logic != null) { // Get the minimum offset in the queue return logic.getMinOffsetInQueue(); } return -1; }
Enter the method org.apache.rocketmq.store.DefaultMessageStore#findConsumeQueue to query the consumption queue by topic and queueId, as described earlier.
public ConsumeQueue findConsumeQueue(String topic, int queueId) { ConcurrentMap<Integer, ConsumeQueue> map = consumeQueueTable.get(topic); if (null == map) { ConcurrentMap<Integer, ConsumeQueue> newMap = new ConcurrentHashMap<Integer, ConsumeQueue>(128); ConcurrentMap<Integer, ConsumeQueue> oldMap = consumeQueueTable.putIfAbsent(topic, newMap); if (oldMap != null) { map = oldMap; } else { map = newMap; } } // Find the consumer queue by queue id ConsumeQueue logic = map.get(queueId); if (null == logic) { ConsumeQueue newLogic = new ConsumeQueue( topic, queueId, // Consumer queue storage address user.home/store/consumequeue StorePathConfigHelper.getStorePathConsumeQueue(this.messageStoreConfig.getStorePathRootDir()), // Default 30W per file store this.getMessageStoreConfig().getMapedFileSizeConsumeQueue(), this); ConsumeQueue oldLogic = map.putIfAbsent(queueId, newLogic); if (oldLogic != null) { logic = oldLogic; } else { logic = newLogic; } } return logic; }
Go back up to the end of the method org.apache.rocketmq.broker.processor.AdminBrokerProcessor#getMinOffset
Said at the end
This analysis only represents personal views, for reference only.
Joining WeChat Technology Group
Nail Technology Group