You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "kerneltime (via GitHub)" <gi...@apache.org> on 2023/01/21 09:00:34 UTC

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

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