apache/rocketmq · error · RemotingCommandException

Failed to get max offset in queue

Error message

Failed to get max offset in queue

What it means

AdminBrokerProcessor's handler for the GetMaxOffset request (requestCode GET_MAX_OFFSET) reads the queue's max offset via getMaxOffsetInQueue; the checked ConsumeQueueException is rethrown as RemotingCommandException('Failed to get max offset in queue'). For static (statically-mapped) topics this runs after rewriteRequestForStaticTopic has resolved the local queue, so the failure is purely the local store lookup.

Source

Thrown at broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java:1362

    }

    private RemotingCommand getMaxOffset(ChannelHandlerContext ctx,
        RemotingCommand request) throws RemotingCommandException {
        final RemotingCommand response = RemotingCommand.createResponseCommand(GetMaxOffsetResponseHeader.class);
        final GetMaxOffsetResponseHeader responseHeader = (GetMaxOffsetResponseHeader) response.readCustomHeader();
        final GetMaxOffsetRequestHeader requestHeader = request.decodeCommandCustomHeader(GetMaxOffsetRequestHeader.class);

        TopicQueueMappingContext mappingContext = this.brokerController.getTopicQueueMappingManager().buildTopicQueueMappingContext(requestHeader);
        RemotingCommand rewriteResult = rewriteRequestForStaticTopic(requestHeader, mappingContext);
        if (rewriteResult != null) {
            return rewriteResult;
        }

        try {
            long offset = this.brokerController.getMessageStore().getMaxOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId());
            responseHeader.setOffset(offset);
        } catch (ConsumeQueueException e) {
            throw new RemotingCommandException("Failed to get max offset in queue", e);
        }
        response.setCode(ResponseCode.SUCCESS);
        response.setRemark(null);
        return response;
    }

    private CompletableFuture<RpcResponse> handleGetMinOffsetForStaticTopic(RpcRequest request,
        TopicQueueMappingContext mappingContext) {
        if (mappingContext.getMappingDetail() == null) {
            return null;
        }
        TopicQueueMappingDetail mappingDetail = mappingContext.getMappingDetail();
        if (!mappingContext.isLeader()) {
            //this may not
            return CompletableFuture.completedFuture(new RpcResponse(new RpcException(ResponseCode.NOT_LEADER_FOR_QUEUE,
                String.format("%s-%d is not leader in broker %s, request code %d", mappingContext.getTopic(), mappingContext.getGlobalId(), mappingDetail.getBname(), request.getCode()))));
        }
        GetMinOffsetRequestHeader requestHeader = (GetMinOffsetRequestHeader) request.getHeader();

View on GitHub (pinned to 293f588571)

Solutions

  1. Verify topic route and queue count (mqadmin topicRoute) and use a valid queueId
  2. Check broker logs for the ConsumeQueueException root cause
  3. If corruption is indicated, restart the broker to run store recovery for consume queues
  4. Retry the query after the broker is fully started
Defensive patterns

Strategy: validation

Validate before calling

// client-side: validate queueId against the route before querying
TopicRouteData route = mqAdminExt.examineTopicRouteInfo(topic);
int maxQueue = route.getQueueDatas().stream().mapToInt(QueueData::getReadQueueNums).max().orElse(0);
if (queueId < 0 || queueId >= maxQueue) throw new IllegalArgumentException("queueId out of range");

Try / catch

try {
    long max = mqAdminExt.maxOffset(new MessageQueue(topic, brokerName, queueId));
} catch (Exception e) {
    Throwable real = ExceptionUtils.getRealException(e);
    if (real instanceof RemotingCommandException) { /* store lookup failed: check broker logs, retry when healthy */ }
}

Prevention

When it happens

Trigger: Client/admin calling QueryMaxOffset (e.g. DefaultMQAdminExt / consumer client maxOffset) for a topic+queueId whose consume queue read fails: nonexistent queueId, deleted topic, corrupt consumeq, or store closing.

Common situations: Clients querying max offset on a queueId beyond the topic's queue count; querying during topic deletion or broker shutdown; consume queue corruption after crash.

Related errors


AI-assisted analysis of apache/rocketmq@293f588571 (2026-08-14). Data as JSON: /api/errors/b355513866900a3c. Report an issue: GitHub.