{"record":{"id":"928887c88b1ed752","repo":"apache/rocketmq","slug":"failed-to-get-max-offset-in-queue","errorCode":null,"errorMessage":"Failed to get max offset in queue","messagePattern":"Failed to get max offset in queue","errorType":"exception","errorClass":"RemotingCommandException","httpStatus":null,"severity":"error","filePath":"broker/src/main/java/org/apache/rocketmq/broker/client/net/Broker2Client.java","lineNumber":153,"sourceCode":"            MessageQueue mq = new MessageQueue();\n            mq.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName());\n            mq.setTopic(topic);\n            mq.setQueueId(i);\n\n            long consumerOffset =\n                this.brokerController.getConsumerOffsetManager().queryOffset(group, topic, i);\n            if (-1 == consumerOffset) {\n                response.setCode(ResponseCode.SYSTEM_ERROR);\n                response.setRemark(String.format(\"THe consumer group <%s> not exist\", group));\n                return response;\n            }\n\n            long timeStampOffset;\n            if (timeStamp == -1) {\n                try {\n                    timeStampOffset = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i);\n                } catch (ConsumeQueueException e) {\n                    throw new RemotingCommandException(\"Failed to get max offset in queue\", e);\n                }\n            } else {\n                timeStampOffset = this.brokerController.getMessageStore().getOffsetInQueueByTime(topic, i, timeStamp);\n            }\n\n            if (timeStampOffset < 0) {\n                log.warn(\"reset offset is invalid. topic={}, queueId={}, timeStampOffset={}\", topic, i, timeStampOffset);\n                timeStampOffset = 0;\n            }\n\n            if (isForce || timeStampOffset < consumerOffset) {\n                offsetTable.put(mq, timeStampOffset);\n            } else {\n                offsetTable.put(mq, consumerOffset);\n            }\n        }\n\n        ResetOffsetRequestHeader requestHeader = new ResetOffsetRequestHeader();","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/broker/src/main/java/org/apache/rocketmq/broker/client/net/Broker2Client.java#L135-L171","documentation":"In Broker2Client's reset-offset flow, when the caller passes timeStamp == -1 (meaning 'reset to latest'), the broker resolves the latest offset via messageStore.getMaxOffsetInQueue(). Since getMaxOffsetInQueue declares ConsumeQueueException (a checked store-level failure), the processor wraps it in RemotingCommandException('Failed to get max offset in queue'). The resetOffset request therefore aborts before any offset table is pushed to consumers.","triggerScenarios":"mqadmin resetOffsetByTime with no timestamp (latest) or the admin ResetOffset request with timeStamp=-1 against a topic/queue whose consume queue read fails in the store — e.g. queue files missing/corrupt or store in a failed state.","commonSituations":"Resetting offsets on a topic whose consume queue was manually deleted or corrupted; store shutdown in progress during the admin call; deleting a topic concurrently with resetOffset.","solutions":["Check broker logs for the underlying ConsumeQueueException and the affected topic/queue","Verify the topic and queue exist on this broker (topicRoute/queryTopic) before resetting offsets","If consume queue files are damaged, recover or rebuild them (store recovery on restart) before retrying the reset","Retry the admin operation when the broker store is fully healthy"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before issuing resetOffset with latest semantics, confirm the queue is readable\nlong probe = brokerController.getMessageStore().getMinOffsetInQueue(topic, queueId);\nif (probe < 0) throw new IllegalStateException(\"queue not available: \" + topic + \"-\" + queueId);","typeGuard":null,"tryCatchPattern":"try {\n    adminExt.resetOffsetByTime(topic, group, timestamp);\n} catch (Exception e) {\n    Throwable real = ExceptionUtils.getRealException(e);\n    if (real instanceof RemotingCommandException) { /* store-level failure: check broker logs, retry later */ }\n}","preventionTips":["Do not reset offsets while deleting or migrating the topic","Run admin offset resets only against a fully started, healthy broker"],"tags":["broker","admin","reset-offset","consume-queue","rocketmq"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}