mirror of
https://github.com/apache/rocketmq.git
synced 2026-08-28 20:09:14 +08:00
[ISSUE #10015] Optimize writeWithoutMmap. add page alignment to avoid read-modify-write
Change-Id: I41ae3b71a4803295c2487cdf8f5e458764b64ebc Co-authored-by: guyinyou <guyinyou.gyy@alibaba-inc.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user