You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "peterxcli (via GitHub)" <gi...@apache.org> on 2026/10/13 21:47:14 UTC

[PR] HDDS-16983. Reuse chunk streams for positioned reads in BlockInputStream [ozone]

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

   ## What changes were proposed in this pull request?
   
   Positioned reads in `BlockInputStream` now reuse the block's existing chunk streams. Before this change, every positioned read created and closed a temporary `ChunkInputStream` for each chunk it touched. This builds on the merged #11348.
   
   The checksum alignment and range copy move from `ChunkInputStream` into a new `ChunkReader`, which keeps no position and no data buffers. Concurrent positioned reads can therefore share a chunk stream without touching its sequential-read state. Each positioned read still acquires its own datanode client and releases it afterwards. Short-circuit reads still read the local block file.
   
   To make sharing safe, a positioned read builds its `DatanodeBlockID` as a local value. It no longer writes the stream's `datanodeBlockID` field.
   
   When a positioned read fails, it now only refreshes the pipeline. It no longer releases the clients held by the sequential chunk streams. A sequential read still has its own retry handling: if its client points at the old pipeline, its next failure triggers its own refresh.
   
   `LocalChunkInputStream` now takes the block's `FileChannel` instead of the `FileInputStream`, because test code is not allowed to import `FileInputStream`.
   
   some context:
   - [HDDS-16325](https://issues.apache.org/jira/browse/HDDS-16325) tracks the larger refactor of the `BlockInputStream` state. This PR does not cover it.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-16983
   
   ## How was this patch tested?
   
   Added two unit tests:
   - Concurrent positioned reads from a local block file. The test checks that the file position and the stream position do not change.
   - Two overlapping `ChunkReader` reads. The test checks that they do not block each other and do not change the source buffers.
   
   The existing positioned-read tests in `TestBlockInputStream`, `TestChunkInputStream`, `TestStreamBlockInputStream`, `TestMultipartInputStream` and the EC stream tests pass, and so does checkstyle.
   


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


Re: [PR] HDDS-16983. Reuse chunk streams for positioned reads in BlockInputStream [ozone]

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

   > @peterxcli does this change improve latency/throughput in a single thread/multithreaded use scenario?
   
   @yandrey321 I didnt run the benchmark actually, this is just a low hanging fruit that get rid of duplicate chunk streams allocation.


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


Re: [PR] HDDS-16983. Reuse chunk streams for positioned reads in BlockInputStream [ozone]

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


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/ChunkReader.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.hadoop.hdds.scm.storage;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ChunkInfo;
+import org.apache.ratis.util.function.CheckedFunction;
+
+/**
+ * Reads checksum-aligned ranges without retaining a cursor or data buffers.
+ */
+final class ChunkReader {
+  private final ChunkInfo chunkInfo;
+  private final long length;

Review Comment:
   Remove length field and use  chunkInfo.getLen()  (similar to chunkInfo.getOffset())



##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/ChunkReader.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.hadoop.hdds.scm.storage;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ChunkInfo;
+import org.apache.ratis.util.function.CheckedFunction;
+
+/**
+ * Reads checksum-aligned ranges without retaining a cursor or data buffers.
+ */
+final class ChunkReader {
+  private final ChunkInfo chunkInfo;
+  private final long length;
+  private final boolean verifyChecksum;
+  private final CheckedFunction<ChunkInfo, ByteBuffer[], IOException> readChunk;

Review Comment:
   Rename it to readChunkPositioned



##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/ChunkInputStream.java:
##########
@@ -399,21 +393,7 @@ private synchronized void readChunkFromContainer(int len) throws IOException {
   }
 
   ChunkInfo getChunkInfo(long chunkRelativePosition, int toRead) {

Review Comment:
   Remove this method and call  reader.getChunkInfo(..) directly
   ```java
   //readChunkFromContainer
       final ChunkInfo adjustedChunkInfo = reader.getChunkInfo(startByteIndex, len);
   ```



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


Re: [PR] HDDS-16983. Reuse chunk streams for positioned reads in BlockInputStream [ozone]

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

   Converted to draft to avoid accidental merge, because only pull-request workflow had run for some reason.
   
   @peterxcli can you please re-enable workflows in your fork?  GitHub says:
   
   > Workflows are not currently being run on this fork due to the scale of GitHub Actions usage. A repository maintainer can choose to re-enable these.


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


Re: [PR] HDDS-16983. Reuse chunk streams for positioned reads in BlockInputStream [ozone]

Posted by "peterxcli (via GitHub)" <gi...@apache.org>.
peterxcli merged PR #11518:
URL: https://github.com/apache/ozone/pull/11518


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


Re: [PR] HDDS-16983. Reuse chunk streams for positioned reads in BlockInputStream [ozone]

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

   @yandrey321 @adoroszlai @szetszwo @chihsuan thanks for the 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


Re: [PR] HDDS-16983. Reuse chunk streams for positioned reads in BlockInputStream [ozone]

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

   @peterxcli does this change improve latency/throughput in a single thread/multithreaded use scenario?


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


Re: [PR] HDDS-16983. Reuse chunk streams for positioned reads in BlockInputStream [ozone]

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

   @szetszwo thanks for the review, address them all. please take another look.


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