xxd763795151 commented on issue #2661: URL: https://github.com/apache/rocketmq/issues/2661#issuecomment-782006904
>  > This is expected。If you get the last position 5, it will happen BufferUnderflowException。Only when the second to last position is 4, then the last message is obtained @panzhi33 这个不是会不会出现BufferUnderflowException的问题。是消息偏移的获取问题。如果第1条消息的offset是1,那么第5条消息的offset是5,而不应当是4。 当然了,如果按我们编程习惯来说,索引应当是0开始。但不能套用到这里的offset上,因为如果第1条消息的offset是1的话,那第0条消息的offset就0了。 这个地方计算的问题,连带了很多的副作用了。比如根据时间戳重置消息偏移的时候,重置到当前时间的时候 ,重置的永远是当前最大偏移-1,而其它时间点都是正常的。同样在代码实现上根据2分查找获取偏移值的时候,除了最后一条消息,获取方式都是离时间戳最近的那个,结果预期,但是时间 大于等于当前时间的时候,就只能获取到倒数第2条。 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
