rickyma commented on code in PR #2253:
URL: 
https://github.com/apache/incubator-uniffle/pull/2253#discussion_r1855721679


##########
common/src/main/java/org/apache/uniffle/common/netty/protocol/CompositeFileRegion.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.uniffle.common.netty.protocol;
+
+import java.io.IOException;
+import java.nio.channels.WritableByteChannel;
+
+import io.netty.channel.FileRegion;
+
+public class CompositeFileRegion extends AbstractFileRegion {
+  private final FileRegion[] regions;
+  private long totalSize = 0;
+  private long transferred = 0;
+
+  public CompositeFileRegion(FileRegion... regions) {
+    this.regions = regions;
+    for (FileRegion region : regions) {
+      totalSize += region.count();
+    }
+  }
+
+  @Override
+  public long position() {
+    return transferred;
+  }
+
+  @Override
+  public long count() {
+    return totalSize;
+  }
+
+  @Override
+  public long transferTo(WritableByteChannel target, long position) throws 
IOException {
+    long totalTransferred = 0;
+
+    for (FileRegion region : regions) {
+      if (position >= region.count()) {
+        position -= region.count();
+      } else {
+        long transferredNow = region.transferTo(target, position);
+        totalTransferred += transferredNow;
+        transferred += transferredNow;
+
+        if (transferredNow < region.count() - position) {
+          break;
+        }
+        position = 0;
+      }
+    }
+
+    return totalTransferred;
+  }
+
+  @Override
+  public long transferred() {
+    return transferred;
+  }
+
+  @Override
+  public AbstractFileRegion retain() {
+    super.retain();
+    for (FileRegion region : regions) {
+      region.retain();
+    }
+    return this;
+  }
+
+  @Override
+  public AbstractFileRegion retain(int increment) {
+    super.retain(increment);
+    for (FileRegion region : regions) {
+      region.retain(increment);
+    }
+    return this;
+  }
+
+  @Override
+  public boolean release() {
+    super.release();

Review Comment:
   The return value of `super.release()` is never checked.
   
   Maybe use the return value to initialize `released`:
   ```
   boolean released = super.release();
   ```



##########
common/src/main/java/org/apache/uniffle/common/netty/protocol/CompositeFileRegion.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.uniffle.common.netty.protocol;
+
+import java.io.IOException;
+import java.nio.channels.WritableByteChannel;
+
+import io.netty.channel.FileRegion;
+
+public class CompositeFileRegion extends AbstractFileRegion {
+  private final FileRegion[] regions;
+  private long totalSize = 0;
+  private long transferred = 0;
+
+  public CompositeFileRegion(FileRegion... regions) {
+    this.regions = regions;
+    for (FileRegion region : regions) {
+      totalSize += region.count();
+    }
+  }
+
+  @Override
+  public long position() {
+    return transferred;
+  }
+
+  @Override
+  public long count() {
+    return totalSize;
+  }
+
+  @Override
+  public long transferTo(WritableByteChannel target, long position) throws 
IOException {
+    long totalTransferred = 0;
+
+    for (FileRegion region : regions) {
+      if (position >= region.count()) {
+        position -= region.count();
+      } else {
+        long transferredNow = region.transferTo(target, position);
+        totalTransferred += transferredNow;
+        transferred += transferredNow;
+
+        if (transferredNow < region.count() - position) {
+          break;
+        }
+        position = 0;
+      }
+    }
+
+    return totalTransferred;
+  }
+
+  @Override
+  public long transferred() {
+    return transferred;
+  }
+
+  @Override
+  public AbstractFileRegion retain() {
+    super.retain();
+    for (FileRegion region : regions) {
+      region.retain();
+    }
+    return this;
+  }
+
+  @Override
+  public AbstractFileRegion retain(int increment) {
+    super.retain(increment);
+    for (FileRegion region : regions) {
+      region.retain(increment);
+    }
+    return this;
+  }
+
+  @Override
+  public boolean release() {
+    super.release();
+    boolean released = true;
+    for (FileRegion region : regions) {
+      if (!region.release()) {
+        released = false;
+      }
+    }
+    return released;
+  }
+
+  @Override
+  public boolean release(int decrement) {
+    super.release(decrement);

Review Comment:
   ditto.
   
   The return value of `super.release(decrement)` is never checked.



##########
common/src/main/java/org/apache/uniffle/common/netty/protocol/CompositeFileRegion.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.uniffle.common.netty.protocol;
+
+import java.io.IOException;
+import java.nio.channels.WritableByteChannel;
+
+import io.netty.channel.FileRegion;
+
+public class CompositeFileRegion extends AbstractFileRegion {
+  private final FileRegion[] regions;
+  private long totalSize = 0;
+  private long transferred = 0;
+
+  public CompositeFileRegion(FileRegion... regions) {
+    this.regions = regions;
+    for (FileRegion region : regions) {
+      totalSize += region.count();
+    }
+  }
+
+  @Override
+  public long position() {
+    return transferred;
+  }
+
+  @Override
+  public long count() {
+    return totalSize;
+  }
+
+  @Override
+  public long transferTo(WritableByteChannel target, long position) throws 
IOException {
+    long totalTransferred = 0;
+
+    for (FileRegion region : regions) {
+      if (position >= region.count()) {
+        position -= region.count();
+      } else {
+        long transferredNow = region.transferTo(target, position);
+        totalTransferred += transferredNow;

Review Comment:
   `totalTranferred` -> `totalBytesTransferred`
   `transferredNow` -> `currentBytesTransferred`
   `transferred` -> `bytesTransferred`



##########
common/src/main/java/org/apache/uniffle/common/netty/protocol/CompositeFileRegion.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.uniffle.common.netty.protocol;
+
+import java.io.IOException;
+import java.nio.channels.WritableByteChannel;
+
+import io.netty.channel.FileRegion;
+
+public class CompositeFileRegion extends AbstractFileRegion {
+  private final FileRegion[] regions;
+  private long totalSize = 0;
+  private long transferred = 0;
+
+  public CompositeFileRegion(FileRegion... regions) {
+    this.regions = regions;
+    for (FileRegion region : regions) {
+      totalSize += region.count();
+    }
+  }
+
+  @Override
+  public long position() {
+    return transferred;
+  }
+
+  @Override
+  public long count() {
+    return totalSize;
+  }
+
+  @Override
+  public long transferTo(WritableByteChannel target, long position) throws 
IOException {
+    long totalTransferred = 0;
+
+    for (FileRegion region : regions) {
+      if (position >= region.count()) {
+        position -= region.count();
+      } else {
+        long transferredNow = region.transferTo(target, position);
+        totalTransferred += transferredNow;
+        transferred += transferredNow;
+
+        if (transferredNow < region.count() - position) {
+          break;
+        }
+        position = 0;
+      }
+    }
+
+    return totalTransferred;
+  }
+
+  @Override
+  public long transferred() {
+    return transferred;
+  }
+
+  @Override
+  public AbstractFileRegion retain() {
+    super.retain();
+    for (FileRegion region : regions) {
+      region.retain();
+    }
+    return this;
+  }
+
+  @Override
+  public AbstractFileRegion retain(int increment) {
+    super.retain(increment);
+    for (FileRegion region : regions) {
+      region.retain(increment);
+    }
+    return this;
+  }
+
+  @Override
+  public boolean release() {
+    super.release();
+    boolean released = true;
+    for (FileRegion region : regions) {
+      if (!region.release()) {
+        released = false;
+      }
+    }
+    return released;
+  }
+
+  @Override
+  public boolean release(int decrement) {
+    super.release(decrement);
+    boolean released = true;
+    for (FileRegion region : regions) {
+      if (!region.release(decrement)) {
+        released = false;
+      }
+    }
+    return released;
+  }
+
+  @Override
+  protected void deallocate() {}

Review Comment:
   This is empty. Do we need to release extra resources here?



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to