Skip to content

Commit

Permalink
Revert "[ISSUE #7757] Use CompositeByteBuf to prevent memory copy. (#…
Browse files Browse the repository at this point in the history
…7694)" (#8209)

This reverts commit 7a36d4d.
  • Loading branch information
yuz10 committed May 30, 2024
1 parent 1520556 commit db163b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
package org.apache.rocketmq.remoting.netty;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.CompositeByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.FileRegion;
import io.netty.handler.codec.MessageToByteEncoder;
Expand Down Expand Up @@ -54,12 +51,9 @@ protected void encode(ChannelHandlerContext ctx, FileRegion msg, final ByteBuf o
WritableByteChannel writableByteChannel = new WritableByteChannel() {
@Override
public int write(ByteBuffer src) {
// To prevent mem_copy.
CompositeByteBuf b = (CompositeByteBuf) out;
// Have to increase writerIndex manually.
ByteBuf unpooled = Unpooled.wrappedBuffer(src);
b.addComponent(true, unpooled);
return unpooled.readableBytes();
int prev = out.writerIndex();
out.writeBytes(src);
return out.writerIndex() - prev;
}

@Override
Expand All @@ -82,10 +76,4 @@ public void close() throws IOException {
msg.transferTo(writableByteChannel, transferred);
}
}

@Override
protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, FileRegion msg, boolean preferDirect) throws Exception {
ByteBufAllocator allocator = ctx.alloc();
return preferDirect ? allocator.compositeDirectBuffer() : allocator.compositeHeapBuffer();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
import io.netty.channel.DefaultFileRegion;
import io.netty.channel.FileRegion;
import io.netty.channel.embedded.EmbeddedChannel;
import org.junit.Assert;
import org.junit.Test;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Random;
import java.util.UUID;
import org.junit.Assert;
import org.junit.Test;

public class FileRegionEncoderTest {

Expand Down

0 comments on commit db163b4

Please sign in to comment.