You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2023/05/06 03:41:26 UTC

[GitHub] [rocketmq] yaowenbinqwq created a discussion: Why DefaultMappedFile::appendMessageInner() call ByteBuffer::position() after ByteBuffer::slice()

GitHub user yaowenbinqwq created a discussion: Why DefaultMappedFile::appendMessageInner() call ByteBuffer::position() after ByteBuffer::slice()

The code looks like this:
```java
    public AppendMessageResult appendMessagesInner(final MessageExt messageExt, final AppendMessageCallback cb,
        PutMessageContext putMessageContext) {
        int currentPos = WROTE_POSITION_UPDATER.get(this);

        if (currentPos < this.fileSize) {
            ByteBuffer byteBuffer = appendMessageBuffer().slice();
            byteBuffer.position(currentPos);
    ....
```

In my opinion, the slice() methods will return the new Rerecence of ByteBuffer with position is 0, and limit is remainning size.
And then The call to position() will resets current to the original ByteBuffer's position(which is currentPos) and starts writing, so isn't the space between the new ByteBuffer's 0 and currentPos wasted

GitHub link: https://github.com/apache/rocketmq/discussions/6698

----
This is an automatically sent email for dev@rocketmq.apache.org.
To unsubscribe, please send an email to: dev-unsubscribe@rocketmq.apache.org