You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/08/30 08:37:57 UTC

[GitHub] [ozone] szetszwo opened a new pull request, #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

szetszwo opened a new pull request, #3730:
URL: https://github.com/apache/ozone/pull/3730

   See https://issues.apache.org/jira/browse/HDDS-7188


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] kerneltime commented on a diff in pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on code in PR #3730:
URL: https://github.com/apache/ozone/pull/3730#discussion_r1083266732


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java:
##########
@@ -227,10 +248,40 @@ public static void readData(File file, ByteBuffer[] buffers,
         bytesRead, offset, file);
 
     validateReadSize(len, bytesRead);
+  }
 
-    for (ByteBuffer buf : buffers) {
-      buf.flip();
-    }
+  public static ChunkBufferToByteString readData(File file, long chunkSize,
+      long offset, long length, HddsVolume volume)
+      throws StorageContainerException {
+    final List<ByteBuf> buffers = ChunkUtils.readDataNettyChunkedNioFile(
+        file, Math.toIntExact(chunkSize), offset, length, volume);
+    return ChunkBufferToByteString.wrap(buffers);
+  }
+
+  /**
+   * Read data from the given file using {@link ChunkedNioFile}.
+   *
+   * @return a list of {@link ByteBuf} containing the data.
+   */
+  private static List<ByteBuf> readDataNettyChunkedNioFile(
+      File file, int chunkSize,
+      long offset, long length, HddsVolume volume)
+      throws StorageContainerException {
+
+    final List<ByteBuf> buffers = new ArrayList<>(
+        Math.toIntExact((length - 1) / chunkSize) + 1);
+    readData(file, offset, length, volume, channel -> {
+      final ChunkedNioFile f = new ChunkedNioFile(
+          channel, offset, length, chunkSize);
+      long readLen = 0;
+      while (readLen < length) {
+        final ByteBuf buf = f.readChunk(PooledByteBufAllocator.DEFAULT);

Review Comment:
   Actually since we are trying to read chunks here it might make sense to play with the allocator to select buffers that are the same as chunk size.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai commented on pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by GitBox <gi...@apache.org>.
adoroszlai commented on PR #3730:
URL: https://github.com/apache/ozone/pull/3730#issuecomment-1398489304

   @duongkame @jojochuang @kerneltime please review


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] kerneltime commented on a diff in pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on code in PR #3730:
URL: https://github.com/apache/ozone/pull/3730#discussion_r1083268263


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/ChunkBufferToByteStringByByteBufs.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.common;
+
+import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
+import org.apache.ratis.thirdparty.io.netty.buffer.ByteBuf;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * A {@link ChunkBufferToByteString} implementation
+ * using a list of {@link ByteBuf}s.
+ */
+class ChunkBufferToByteStringByByteBufs implements ChunkBufferToByteString {
+  private final List<ByteBuf> buffers;
+
+  private volatile List<ByteString> byteStrings;
+  private volatile ByteString byteString;
+
+  ChunkBufferToByteStringByByteBufs(List<ByteBuf> buffers) {
+    this.buffers = buffers == null || buffers.isEmpty() ?
+        Collections.emptyList() : Collections.unmodifiableList(buffers);
+  }
+
+  @Override
+  public ByteString toByteStringImpl(Function<ByteBuffer, ByteString> f) {
+    if (byteString != null) {
+      return byteString;
+    }
+    initByteStrings(f);
+    return Objects.requireNonNull(byteString, "byteString == null");
+  }
+
+  @Override
+  public List<ByteString> toByteStringListImpl(
+      Function<ByteBuffer, ByteString> f) {
+    if (byteStrings != null) {
+      return byteStrings;
+    }
+    return initByteStrings(f);
+  }
+
+  private synchronized List<ByteString> initByteStrings(
+      Function<ByteBuffer, ByteString> f) {
+    if (byteStrings != null) {
+      return byteStrings;
+    }
+
+    byteStrings = new ArrayList<>();
+    byteString = ByteString.EMPTY;
+    for (ByteBuf buf : buffers) {
+      final ByteString s = f.apply(buf.nioBuffer());
+      buf.release();

Review Comment:
   I don't understand why we need to release 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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] kerneltime commented on a diff in pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on code in PR #3730:
URL: https://github.com/apache/ozone/pull/3730#discussion_r1083267139


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java:
##########
@@ -227,10 +248,40 @@ public static void readData(File file, ByteBuffer[] buffers,
         bytesRead, offset, file);
 
     validateReadSize(len, bytesRead);
+  }
 
-    for (ByteBuffer buf : buffers) {
-      buf.flip();
-    }
+  public static ChunkBufferToByteString readData(File file, long chunkSize,
+      long offset, long length, HddsVolume volume)
+      throws StorageContainerException {
+    final List<ByteBuf> buffers = ChunkUtils.readDataNettyChunkedNioFile(
+        file, Math.toIntExact(chunkSize), offset, length, volume);
+    return ChunkBufferToByteString.wrap(buffers);
+  }
+
+  /**
+   * Read data from the given file using {@link ChunkedNioFile}.
+   *
+   * @return a list of {@link ByteBuf} containing the data.
+   */
+  private static List<ByteBuf> readDataNettyChunkedNioFile(
+      File file, int chunkSize,
+      long offset, long length, HddsVolume volume)
+      throws StorageContainerException {
+
+    final List<ByteBuf> buffers = new ArrayList<>(
+        Math.toIntExact((length - 1) / chunkSize) + 1);

Review Comment:
   Won't this depend on the allocator using buffers the same size as chunks?



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] szetszwo commented on a diff in pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on code in PR #3730:
URL: https://github.com/apache/ozone/pull/3730#discussion_r1100031100


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java:
##########
@@ -227,10 +248,40 @@ public static void readData(File file, ByteBuffer[] buffers,
         bytesRead, offset, file);
 
     validateReadSize(len, bytesRead);
+  }
 
-    for (ByteBuffer buf : buffers) {
-      buf.flip();
-    }
+  public static ChunkBufferToByteString readData(File file, long chunkSize,
+      long offset, long length, HddsVolume volume)
+      throws StorageContainerException {
+    final List<ByteBuf> buffers = ChunkUtils.readDataNettyChunkedNioFile(
+        file, Math.toIntExact(chunkSize), offset, length, volume);
+    return ChunkBufferToByteString.wrap(buffers);
+  }
+
+  /**
+   * Read data from the given file using {@link ChunkedNioFile}.
+   *
+   * @return a list of {@link ByteBuf} containing the data.
+   */
+  private static List<ByteBuf> readDataNettyChunkedNioFile(
+      File file, int chunkSize,
+      long offset, long length, HddsVolume volume)
+      throws StorageContainerException {
+
+    final List<ByteBuf> buffers = new ArrayList<>(
+        Math.toIntExact((length - 1) / chunkSize) + 1);

Review Comment:
   We pass `chunkSize` to initialize `ChunkedNioFile` below.  Then `readChunk(..)` will use it.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] kerneltime commented on a diff in pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on code in PR #3730:
URL: https://github.com/apache/ozone/pull/3730#discussion_r1083265017


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java:
##########
@@ -227,10 +248,40 @@ public static void readData(File file, ByteBuffer[] buffers,
         bytesRead, offset, file);
 
     validateReadSize(len, bytesRead);
+  }
 
-    for (ByteBuffer buf : buffers) {
-      buf.flip();
-    }
+  public static ChunkBufferToByteString readData(File file, long chunkSize,
+      long offset, long length, HddsVolume volume)
+      throws StorageContainerException {
+    final List<ByteBuf> buffers = ChunkUtils.readDataNettyChunkedNioFile(
+        file, Math.toIntExact(chunkSize), offset, length, volume);
+    return ChunkBufferToByteString.wrap(buffers);
+  }
+
+  /**
+   * Read data from the given file using {@link ChunkedNioFile}.
+   *
+   * @return a list of {@link ByteBuf} containing the data.
+   */
+  private static List<ByteBuf> readDataNettyChunkedNioFile(
+      File file, int chunkSize,
+      long offset, long length, HddsVolume volume)
+      throws StorageContainerException {
+
+    final List<ByteBuf> buffers = new ArrayList<>(
+        Math.toIntExact((length - 1) / chunkSize) + 1);
+    readData(file, offset, length, volume, channel -> {
+      final ChunkedNioFile f = new ChunkedNioFile(
+          channel, offset, length, chunkSize);
+      long readLen = 0;
+      while (readLen < length) {
+        final ByteBuf buf = f.readChunk(PooledByteBufAllocator.DEFAULT);

Review Comment:
   We should file a jira to allow for the allocator to be configured to play with the settings available.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] kerneltime commented on pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by GitBox <gi...@apache.org>.
kerneltime commented on PR #3730:
URL: https://github.com/apache/ozone/pull/3730#issuecomment-1251228859

   cc @duongkame 


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] szetszwo commented on pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on PR #3730:
URL: https://github.com/apache/ozone/pull/3730#issuecomment-1422504968

   @DaveTeng0 , yes, we should benchmarks.  Do you know if we have any existing tests to run?


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] szetszwo commented on a diff in pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on code in PR #3730:
URL: https://github.com/apache/ozone/pull/3730#discussion_r1100032302


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java:
##########
@@ -227,10 +248,40 @@ public static void readData(File file, ByteBuffer[] buffers,
         bytesRead, offset, file);
 
     validateReadSize(len, bytesRead);
+  }
 
-    for (ByteBuffer buf : buffers) {
-      buf.flip();
-    }
+  public static ChunkBufferToByteString readData(File file, long chunkSize,
+      long offset, long length, HddsVolume volume)
+      throws StorageContainerException {
+    final List<ByteBuf> buffers = ChunkUtils.readDataNettyChunkedNioFile(
+        file, Math.toIntExact(chunkSize), offset, length, volume);
+    return ChunkBufferToByteString.wrap(buffers);
+  }
+
+  /**
+   * Read data from the given file using {@link ChunkedNioFile}.
+   *
+   * @return a list of {@link ByteBuf} containing the data.
+   */
+  private static List<ByteBuf> readDataNettyChunkedNioFile(
+      File file, int chunkSize,
+      long offset, long length, HddsVolume volume)
+      throws StorageContainerException {
+
+    final List<ByteBuf> buffers = new ArrayList<>(
+        Math.toIntExact((length - 1) / chunkSize) + 1);
+    readData(file, offset, length, volume, channel -> {
+      final ChunkedNioFile f = new ChunkedNioFile(
+          channel, offset, length, chunkSize);
+      long readLen = 0;
+      while (readLen < length) {
+        final ByteBuf buf = f.readChunk(PooledByteBufAllocator.DEFAULT);

Review Comment:
   Currently, the allocator will use `chunkSize` as the buffer size.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] szetszwo commented on pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on PR #3730:
URL: https://github.com/apache/ozone/pull/3730#issuecomment-1422503506

   @kerneltime , just have replied to your comments.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] kerneltime commented on pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on PR #3730:
URL: https://github.com/apache/ozone/pull/3730#issuecomment-1418558284

   @szetszwo can you please address the review comments?


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] kerneltime commented on a diff in pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on code in PR #3730:
URL: https://github.com/apache/ozone/pull/3730#discussion_r1083265017


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java:
##########
@@ -227,10 +248,40 @@ public static void readData(File file, ByteBuffer[] buffers,
         bytesRead, offset, file);
 
     validateReadSize(len, bytesRead);
+  }
 
-    for (ByteBuffer buf : buffers) {
-      buf.flip();
-    }
+  public static ChunkBufferToByteString readData(File file, long chunkSize,
+      long offset, long length, HddsVolume volume)
+      throws StorageContainerException {
+    final List<ByteBuf> buffers = ChunkUtils.readDataNettyChunkedNioFile(
+        file, Math.toIntExact(chunkSize), offset, length, volume);
+    return ChunkBufferToByteString.wrap(buffers);
+  }
+
+  /**
+   * Read data from the given file using {@link ChunkedNioFile}.
+   *
+   * @return a list of {@link ByteBuf} containing the data.
+   */
+  private static List<ByteBuf> readDataNettyChunkedNioFile(
+      File file, int chunkSize,
+      long offset, long length, HddsVolume volume)
+      throws StorageContainerException {
+
+    final List<ByteBuf> buffers = new ArrayList<>(
+        Math.toIntExact((length - 1) / chunkSize) + 1);
+    readData(file, offset, length, volume, channel -> {
+      final ChunkedNioFile f = new ChunkedNioFile(
+          channel, offset, length, chunkSize);
+      long readLen = 0;
+      while (readLen < length) {
+        final ByteBuf buf = f.readChunk(PooledByteBufAllocator.DEFAULT);

Review Comment:
   ~~Not for this PR but we should file a jira to~~ allow for the allocator to be configured to play with the settings available.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] kerneltime commented on pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on PR #3730:
URL: https://github.com/apache/ozone/pull/3730#issuecomment-1399216746

   I need to do another round of going over the usage and memory model.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] kerneltime commented on a diff in pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by "kerneltime (via GitHub)" <gi...@apache.org>.
kerneltime commented on code in PR #3730:
URL: https://github.com/apache/ozone/pull/3730#discussion_r1083265017


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java:
##########
@@ -227,10 +248,40 @@ public static void readData(File file, ByteBuffer[] buffers,
         bytesRead, offset, file);
 
     validateReadSize(len, bytesRead);
+  }
 
-    for (ByteBuffer buf : buffers) {
-      buf.flip();
-    }
+  public static ChunkBufferToByteString readData(File file, long chunkSize,
+      long offset, long length, HddsVolume volume)
+      throws StorageContainerException {
+    final List<ByteBuf> buffers = ChunkUtils.readDataNettyChunkedNioFile(
+        file, Math.toIntExact(chunkSize), offset, length, volume);
+    return ChunkBufferToByteString.wrap(buffers);
+  }
+
+  /**
+   * Read data from the given file using {@link ChunkedNioFile}.
+   *
+   * @return a list of {@link ByteBuf} containing the data.
+   */
+  private static List<ByteBuf> readDataNettyChunkedNioFile(
+      File file, int chunkSize,
+      long offset, long length, HddsVolume volume)
+      throws StorageContainerException {
+
+    final List<ByteBuf> buffers = new ArrayList<>(
+        Math.toIntExact((length - 1) / chunkSize) + 1);
+    readData(file, offset, length, volume, channel -> {
+      final ChunkedNioFile f = new ChunkedNioFile(
+          channel, offset, length, chunkSize);
+      long readLen = 0;
+      while (readLen < length) {
+        final ByteBuf buf = f.readChunk(PooledByteBufAllocator.DEFAULT);

Review Comment:
   Not for this PR but we should file a jira to allow for the allocator to be configured to play with the settings available.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] DaveTeng0 commented on pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by "DaveTeng0 (via GitHub)" <gi...@apache.org>.
DaveTeng0 commented on PR #3730:
URL: https://github.com/apache/ozone/pull/3730#issuecomment-1408113772

   i saw this changes it's kind of an experiment with the ChunkBufferToByteString. Maybe we could run some tests and compare some metrics with using the original implementation of ChunkBuffer~?


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] szetszwo commented on a diff in pull request #3730: HDDS-7188. Read chunk files using netty ChunkedNioFile.

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on code in PR #3730:
URL: https://github.com/apache/ozone/pull/3730#discussion_r1100026441


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/ChunkBufferToByteStringByByteBufs.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.common;
+
+import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
+import org.apache.ratis.thirdparty.io.netty.buffer.ByteBuf;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * A {@link ChunkBufferToByteString} implementation
+ * using a list of {@link ByteBuf}s.
+ */
+class ChunkBufferToByteStringByByteBufs implements ChunkBufferToByteString {
+  private final List<ByteBuf> buffers;
+
+  private volatile List<ByteString> byteStrings;
+  private volatile ByteString byteString;
+
+  ChunkBufferToByteStringByByteBufs(List<ByteBuf> buffers) {
+    this.buffers = buffers == null || buffers.isEmpty() ?
+        Collections.emptyList() : Collections.unmodifiableList(buffers);
+  }
+
+  @Override
+  public ByteString toByteStringImpl(Function<ByteBuffer, ByteString> f) {
+    if (byteString != null) {
+      return byteString;
+    }
+    initByteStrings(f);
+    return Objects.requireNonNull(byteString, "byteString == null");
+  }
+
+  @Override
+  public List<ByteString> toByteStringListImpl(
+      Function<ByteBuffer, ByteString> f) {
+    if (byteStrings != null) {
+      return byteStrings;
+    }
+    return initByteStrings(f);
+  }
+
+  private synchronized List<ByteString> initByteStrings(
+      Function<ByteBuffer, ByteString> f) {
+    if (byteStrings != null) {
+      return byteStrings;
+    }
+
+    byteStrings = new ArrayList<>();
+    byteString = ByteString.EMPTY;
+    for (ByteBuf buf : buffers) {
+      final ByteString s = f.apply(buf.nioBuffer());
+      buf.release();

Review Comment:
   `buf` is initialized from a `ChunkedNioFile` which allocates it.  It must be released after finished reading it.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org