Caideyipi commented on code in PR #17665:
URL: https://github.com/apache/iotdb/pull/17665#discussion_r3489060632


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/payload/evolvable/request/PipeTransferPlanNodeReq.java:
##########
@@ -73,15 +79,27 @@ public static PipeTransferPlanNodeReq 
fromTPipeTransferReq(final TPipeTransferRe
   /////////////////////////////// Air Gap ///////////////////////////////
 
   public static byte[] toTPipeTransferBytes(final PlanNode planNode) throws 
IOException {
+    return toTPipeTransferBytes(planNode.serializeToByteBuffer());
+  }
+
+  public static byte[] toTPipeTransferBytes(final ByteBuffer 
serializedPlanNode)
+      throws IOException {
     try (final PublicBAOS byteArrayOutputStream = new PublicBAOS();
         final DataOutputStream outputStream = new 
DataOutputStream(byteArrayOutputStream)) {
       ReadWriteIOUtils.write(IoTDBSinkRequestVersion.VERSION_1.getVersion(), 
outputStream);
       ReadWriteIOUtils.write(PipeRequestType.TRANSFER_PLAN_NODE.getType(), 
outputStream);
       return BytesUtils.concatByteArray(
-          byteArrayOutputStream.toByteArray(), 
planNode.serializeToByteBuffer().array());
+          byteArrayOutputStream.toByteArray(), getBytes(serializedPlanNode));
     }
   }
 
+  private static byte[] getBytes(final ByteBuffer byteBuffer) {
+    final ByteBuffer duplicateBuffer = byteBuffer.duplicate();
+    final byte[] bytes = new byte[duplicateBuffer.remaining()];
+    duplicateBuffer.get(bytes);
+    return bytes;
+  }

Review Comment:
   Good point. I avoided the extra intermediate copy on the IoTDB side by 
filling the final byte[] directly from the PublicBAOS backing buffer and the 
duplicated ByteBuffer's remaining bytes. Extending BytesUtils itself would 
require a tsfile-side API change, so I kept the change local to this PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to