sijie closed pull request #206: Issue 205: Avoid copying bytebuf for 
constructing log record to write
URL: https://github.com/apache/distributedlog/pull/206
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/distributedlog-protocol/src/main/java/org/apache/distributedlog/LogRecord.java
 
b/distributedlog-protocol/src/main/java/org/apache/distributedlog/LogRecord.java
index 5d666a0a..63b694aa 100644
--- 
a/distributedlog-protocol/src/main/java/org/apache/distributedlog/LogRecord.java
+++ 
b/distributedlog-protocol/src/main/java/org/apache/distributedlog/LogRecord.java
@@ -172,15 +172,13 @@ public LogRecord(long txid, ByteBuffer buffer) {
 
     /**
      * Construct a log record with <i>txid</i> and ByteBuf <i>payload</i>.
+     *
      * @param txid transaction id
      * @param payload playload
      */
     public LogRecord(long txid, ByteBuf payload) {
         this.txid = txid;
-        // Need to make a copy since the passed payload is using a ref-count 
buffer that we don't know when could
-        // release, since the record is passed to the user. Also, the passed 
ByteBuf is coming from network and is
-        // backed by a direct buffer which we could not expose as a byte[]
-        this.payload = Unpooled.copiedBuffer(payload);
+        this.payload = payload;
         this.metadata = 0;
     }
 
diff --git 
a/distributedlog-protocol/src/main/java/org/apache/distributedlog/LogRecordWithDLSN.java
 
b/distributedlog-protocol/src/main/java/org/apache/distributedlog/LogRecordWithDLSN.java
index 096fc819..ac9c3a86 100644
--- 
a/distributedlog-protocol/src/main/java/org/apache/distributedlog/LogRecordWithDLSN.java
+++ 
b/distributedlog-protocol/src/main/java/org/apache/distributedlog/LogRecordWithDLSN.java
@@ -19,6 +19,7 @@
 
 import com.google.common.annotations.VisibleForTesting;
 import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
 
 /**
  * Log record with {@link DLSN} and <code>SequenceId</code>.
@@ -75,7 +76,10 @@ public LogRecordWithDLSN(DLSN dlsn, long txid, byte[] data, 
long startSequenceId
 
     @VisibleForTesting
     public LogRecordWithDLSN(DLSN dlsn, long txid, ByteBuf buffer, long 
startSequenceIdOfCurrentSegment) {
-        super(txid, buffer);
+        // Need to make a copy since the passed payload is using a ref-count 
buffer that we don't know when could
+        // release, since the record is passed to the user. Also, the passed 
ByteBuf is coming from network and is
+        // backed by a direct buffer which we could not expose as a byte[]
+        super(txid, Unpooled.copiedBuffer(buffer));
         this.dlsn = dlsn;
         this.startSequenceIdOfCurrentSegment = startSequenceIdOfCurrentSegment;
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to