This is an automated email from the ASF dual-hosted git repository.

jinrongtong pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new ee104114ac [ISSUE #10015] Optimize writeWithoutMmap. add page 
alignment to avoid read-modify-write
ee104114ac is described below

commit ee104114ac822e02aabd55f3a14d3609bee3e6b3
Author: guyinyou <[email protected]>
AuthorDate: Fri Jan 16 17:59:02 2026 +0800

    [ISSUE #10015] Optimize writeWithoutMmap. add page alignment to avoid 
read-modify-write
    
    Change-Id: I41ae3b71a4803295c2487cdf8f5e458764b64ebc
    
    Co-authored-by: guyinyou <[email protected]>
---
 .../apache/rocketmq/store/logfile/DefaultMappedFile.java    | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git 
a/store/src/main/java/org/apache/rocketmq/store/logfile/DefaultMappedFile.java 
b/store/src/main/java/org/apache/rocketmq/store/logfile/DefaultMappedFile.java
index fbfffef3bc..7c4e5e025a 100644
--- 
a/store/src/main/java/org/apache/rocketmq/store/logfile/DefaultMappedFile.java
+++ 
b/store/src/main/java/org/apache/rocketmq/store/logfile/DefaultMappedFile.java
@@ -385,8 +385,19 @@ public class DefaultMappedFile extends AbstractMappedFile {
 
                 if (sharedByteBuffer != null) {
                     try {
+                        int msgLen = result.getWroteBytes();
+                        int endpos = currentPos + msgLen;
+                        // alignment end position
+                        int extraAppendSize = UNSAFE_PAGE_SIZE - endpos % 
UNSAFE_PAGE_SIZE;
+                        int actualAppendSize = msgLen + extraAppendSize;
+
                         this.fileChannel.position(currentPos);
-                        byteBuffer.position(0).limit(result.getWroteBytes());
+                        // commitlog can contain dirty data at the end.
+                        if (byteBuffer.capacity() >= actualAppendSize) {
+                            byteBuffer.position(0).limit(actualAppendSize);
+                        } else {
+                            byteBuffer.position(0).limit(msgLen);
+                        }
                         this.fileChannel.write(byteBuffer);
                     } catch (Throwable t) {
                         log.error("Failed to write to mappedFile {}", 
this.fileName, t);

Reply via email to