You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by "anmolanmol1234 (via GitHub)" <gi...@apache.org> on 2026/04/02 17:41:59 UTC

[PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

anmolanmol1234 opened a new pull request, #8400:
URL: https://github.com/apache/hadoop/pull/8400

   This PR introduces vectored read support in the Azure Blob File System (ABFS) driver to improve read performance for workloads that issue multiple small, non-contiguous read requests.
   
   Vectored reads enable batching of multiple read ranges into fewer network calls, reducing request overhead and improving throughput—especially beneficial for analytics engines like Spark.
   
   Current ABFS read implementation performs sequential, independent read operations for each requested range. This leads to:
   Increased number of network calls
   Higher latency for small/random reads
   Inefficient utilization of bandwidth
   
   Vectored I/O addresses these issues by coalescing multiple read requests into a single or fewer backend calls.


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "steveloughran (via GitHub)" <gi...@apache.org>.
steveloughran commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3080384818


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStream.java:
##########
@@ -1184,7 +1209,7 @@ ReadBufferManager getReadBufferManager() {
    */
   @Override
   public int minSeekForVectorReads() {

Review Comment:
   I'm actually going to recommend *not* coalescing vectors unless you have a good strategy to deal with partial failures, memory releases, retries etc.
   
   I did try to do that in s3a and gave up, even after extending the api to allow a "release" operation to be passed (which parquet passes down FWIW).
   
   We've never seen failures with s3 in production and coalesced ranges as parquet/orc rowgroups are too far apart. So it's better to focus on retry and recovery there than range coalescing



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "hadoop-yetus (via GitHub)" <gi...@apache.org>.
hadoop-yetus commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4243105139

   :confetti_ball: **+1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime |  Logfile | Comment |
   |:----:|----------:|--------:|:--------:|:-------:|
   | +0 :ok: |  reexec  |   0m 52s |  |  Docker mode activated.  |
   |||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  0s |  |  No case conflicting files found.  |
   | +0 :ok: |  codespell  |   0m  1s |  |  codespell was not available.  |
   | +0 :ok: |  detsecrets  |   0m  1s |  |  detect-secrets was not available.  |
   | +0 :ok: |  xmllint  |   0m  1s |  |  xmllint was not available.  |
   | +1 :green_heart: |  @author  |   0m  0s |  |  The patch does not contain any @author tags.  |
   | +1 :green_heart: |  test4tests  |   0m  0s |  |  The patch appears to include 2 new or modified test files.  |
   |||| _ trunk Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  46m 32s |  |  trunk passed  |
   | +1 :green_heart: |  compile  |   1m  1s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  compile  |   1m  2s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  checkstyle  |   0m 54s |  |  trunk passed  |
   | +1 :green_heart: |  mvnsite  |   1m  4s |  |  trunk passed  |
   | +1 :green_heart: |  javadoc  |   0m 57s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 52s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 37s |  |  trunk passed  |
   | +1 :green_heart: |  shadedclient  |  34m 14s |  |  branch has no errors when building and testing our client artifacts.  |
   | -0 :warning: |  patch  |  34m 47s |  |  Used diff version of patch file. Binary files and potentially other changes not applied. Please rebase and squash commits if necessary.  |
   |||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   0m 36s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 32s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javac  |   0m 32s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 35s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  javac  |   0m 35s |  |  the patch passed  |
   | +1 :green_heart: |  blanks  |   0m  0s |  |  The patch has no blanks issues.  |
   | +1 :green_heart: |  checkstyle  |   0m 26s |  |  the patch passed  |
   | +1 :green_heart: |  mvnsite  |   0m 38s |  |  the patch passed  |
   | +1 :green_heart: |  javadoc  |   0m 29s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 28s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 15s |  |  the patch passed  |
   | +1 :green_heart: |  shadedclient  |  33m 26s |  |  patch has no errors when building and testing our client artifacts.  |
   |||| _ Other Tests _ |
   | +1 :green_heart: |  unit  |   2m 11s |  |  hadoop-azure in the patch passed.  |
   | +1 :green_heart: |  asflicense  |   0m 35s |  |  The patch does not generate ASF License warnings.  |
   |  |   | 132m 31s |  |  |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/10/artifact/out/Dockerfile |
   | GITHUB PR | https://github.com/apache/hadoop/pull/8400 |
   | Optional Tests | dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient codespell detsecrets xmllint spotbugs checkstyle |
   | uname | Linux 3b91f8c5a9ca 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | dev-support/bin/hadoop.sh |
   | git revision | trunk / 339d7e3cc6852254c07ecf5e9e58fa17261b652e |
   | Default Java | Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   | Multi-JDK versions | /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   |  Test Results | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/10/testReport/ |
   | Max. process+thread count | 577 (vs. ulimit of 10000) |
   | modules | C: hadoop-tools/hadoop-azure U: hadoop-tools/hadoop-azure |
   | Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/10/console |
   | versions | git=2.43.0 maven=3.9.11 spotbugs=4.9.7 |
   | Powered by | Apache Yetus 0.14.1 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "bhattmanish98 (via GitHub)" <gi...@apache.org>.
bhattmanish98 commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4191891012

   @copilot Review 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: common-issues-unsubscribe@hadoop.apache.org

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3115806077


##########
hadoop-tools/hadoop-azure/pom.xml:
##########
@@ -497,6 +498,7 @@
                     <include>**/azurebfs/ITestSmallWriteOptimization.java</include>
                     <include>**/azurebfs/services/ITestReadBufferManager.java</include>
                     <include>**/azurebfs/ITestAbfsStreamStatistics*.java</include>
+                    <include>**/azurebfs/services/ITestVectoredRead.java</include>

Review Comment:
   So, we are taking dependency on buffer states, running in parallel leads to buffer moving out of queues and hence moved it to sequential runs



##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -749,7 +937,7 @@ private ReadBuffer getBufferFromCompletedQueue(final String eTag,
     for (ReadBuffer buffer : getCompletedReadList()) {
       // Buffer is returned if the requestedOffset is at or above buffer's
       // offset but less than buffer's length or the actual requestedLength
-      if (eTag.equals(buffer.getETag())
+      if (eTag != null && eTag.equals(buffer.getETag())

Review Comment:
   taken



##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -506,7 +694,7 @@ private ReadBuffer getFromList(final Collection<ReadBuffer> list,
       final String eTag,
       final long requestedOffset) {
     for (ReadBuffer buffer : list) {
-      if (eTag.equals(buffer.getETag())) {
+      if (eTag != null && eTag.equals(buffer.getETag())) {

Review Comment:
   taken



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3071406691


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -338,6 +356,117 @@ public void queueReadAhead(final AbfsInputStream stream,
     }
   }
 
+  /**
+   * Queue a vectored read for a buffer-sized physical read unit.
+   *
+   * <p>The method first attempts to attach the logical unit to an already
+   * in-progress physical read for the same file and offset. If that is not
+   * possible, a free read buffer is acquired and a new backend read is
+   * queued.</p>
+   *
+   * @param stream         input stream for the file being read
+   * @param unit           buffer-sized combined file range to be read
+   * @param tracingContext tracing context used for the backend read request
+   * @param allocator      allocator used to create buffers for vectored fan-out
+   * @return {@code true} if the read was queued or attached to an existing
+   *         in-progress buffer; {@code false} if no buffer was available
+   */
+  boolean queueVectoredRead(AbfsInputStream stream,
+      CombinedFileRange unit,
+      TracingContext tracingContext,
+      IntFunction<ByteBuffer> allocator) {
+    /* Create a child tracing context for vectored read-ahead requests */
+    TracingContext readAheadTracingContext =
+        new TracingContext(tracingContext);
+    readAheadTracingContext.setPrimaryRequestID();
+    readAheadTracingContext.setReadType(ReadType.VECTORED_READ);
+    synchronized (this) {
+      /*
+       * Attempt to hitchhike on an existing in-progress physical read if it
+       * covers the requested logical range completely.
+       */
+      if (isAlreadyQueued(stream.getETag(), unit.getOffset())) {
+        ReadBuffer existing = findQueuedBuffer(stream, unit.getOffset());
+        if (existing != null && existing.getStream().getETag() != null  && stream.getETag()

Review Comment:
   yes addressed above



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3193773827


##########
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestVectoredRead.java:
##########
@@ -0,0 +1,703 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.FilterInputStream;
+import java.lang.reflect.Field;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.IntFunction;
+
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mockito;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileRange;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.azurebfs.AbstractAbfsIntegrationTest;
+import org.apache.hadoop.fs.azurebfs.AzureBlobFileSystem;
+import org.apache.hadoop.fs.azurebfs.enums.VectoredReadStrategy;
+import org.apache.hadoop.fs.impl.CombinedFileRange;
+
+import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_VECTORED_READ_STRATEGY;
+import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.ONE_KB;
+import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.ONE_MB;
+import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.ZERO;
+import static org.apache.hadoop.fs.contract.ContractTestUtils.validateVectoredReadResult;
+
+public class ITestVectoredRead extends AbstractAbfsIntegrationTest {

Review Comment:
   yes all tests are passing 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: common-issues-unsubscribe@hadoop.apache.org

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "mukund-thakur (via GitHub)" <gi...@apache.org>.
mukund-thakur commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3150155976


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStream.java:
##########
@@ -1193,7 +1218,7 @@ public int minSeekForVectorReads() {
    */
   @Override
   public int maxReadSizeForVectorReads() {
-    return S_2M;
+    return client.getAbfsConfiguration().getMaxSeekForVectoredReads();

Review Comment:
   It should be in lines of maxReadSizeForVectorReads



##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/constants/ConfigurationKeys.java:
##########
@@ -627,6 +627,32 @@ public static String containerProperty(String property, String fsName, String ac
    */
   public static final String FS_AZURE_TAIL_LATENCY_MAX_RETRY_COUNT = "fs.azure.tail.latency.max.retry.count";
 
+  /**
+   * Configuration key to control the vectored read strategy used by ABFS: {@value}
+   */
+  public static final String FS_AZURE_VECTORED_READ_STRATEGY = "fs.azure.vectored.read.strategy";
+
+  /**
+   * Configuration key that defines the minimum gap between adjacent read ranges
+   * for merging ranges during vectored reads in ABFS: {@value}.
+   */
+  public static final String FS_AZURE_MIN_SEEK_FOR_VECTORED_READS =
+      "fs.azure.min.seek.for.vectored.reads";
+
+  /**
+   * Configuration key that defines the maximum gap between adjacent read ranges
+   * for merging ranges during vectored reads in ABFS: {@value}.
+   */
+  public static final String FS_AZURE_MAX_SEEK_FOR_VECTORED_READS =

Review Comment:
   It would be good if you use consistent parameter names. 
   fs.s3a.vectored.read.max.merged.size  is the name in S3A. 



##########
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestVectoredRead.java:
##########
@@ -0,0 +1,703 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.FilterInputStream;
+import java.lang.reflect.Field;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.IntFunction;
+
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mockito;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileRange;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.azurebfs.AbstractAbfsIntegrationTest;
+import org.apache.hadoop.fs.azurebfs.AzureBlobFileSystem;
+import org.apache.hadoop.fs.azurebfs.enums.VectoredReadStrategy;
+import org.apache.hadoop.fs.impl.CombinedFileRange;
+
+import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_VECTORED_READ_STRATEGY;
+import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.ONE_KB;
+import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.ONE_MB;
+import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.ZERO;
+import static org.apache.hadoop.fs.contract.ContractTestUtils.validateVectoredReadResult;
+
+public class ITestVectoredRead extends AbstractAbfsIntegrationTest {

Review Comment:
   Please make sure to run ABFS contract tests ITestAbfsFileSystemContractVectoredRead



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "bhattmanish98 (via GitHub)" <gi...@apache.org>.
bhattmanish98 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3073562184


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBuffer.java:
##########
@@ -48,6 +54,13 @@ class ReadBuffer {
   private boolean isLastByteConsumed = false;
   private boolean isAnyByteConsumed = false;
   private AtomicInteger refCount = new AtomicInteger(0);
+  private BufferType bufferType = BufferType.NORMAL;
+  // list of combined file ranges for vectored read.
+  private List<CombinedFileRange> vectoredUnits = new ArrayList<>();
+  // Allocator used for vectored fan-out; captured at queue time */
+  private IntFunction<ByteBuffer> allocator;
+  // Tracks whether fanOut has already been executed
+  private final AtomicInteger fanOutDone = new AtomicInteger(0);

Review Comment:
   Would it be better to keep fanOutDone as AtomicBoolean instead of AtomicInteger? We don't have to compare the value in isFanOutDone() in that case.



##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBuffer.java:
##########
@@ -199,4 +212,67 @@ public void setAnyByteConsumed(boolean isAnyByteConsumed) {
   public boolean isFullyConsumed() {
     return isFirstByteConsumed() && isLastByteConsumed();
   }
+
+  void addVectoredUnit(CombinedFileRange u) {

Review Comment:
   Java doc for all the newly created methods



##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManager.java:
##########
@@ -285,5 +310,94 @@ protected void testMimicFullUseAndAddFailedBuffer(ReadBuffer buf) {
     completedReadList.add(buf);
   }
 
+  /**
+   * Finds an existing {@link ReadBuffer} for the given stream whose buffered
+   * range covers the specified logical offset.
+   *
+   * <p>The search is performed in the read-ahead queue, in-progress list,
+   * and completed-read list, in that order.
+   *
+   * @param stream the {@link AbfsInputStream} associated with the read request
+   *
+   * @return a matching {@link ReadBuffer} if one exists, or {@code null} otherwise
+   */
+  ReadBuffer findQueuedBuffer(final AbfsInputStream stream,
+      long requestedOffset) {
+    ReadBuffer buffer;
+    buffer = findInList(getReadAheadQueue(), stream, requestedOffset);
+    if (buffer != null) {
+      return buffer;
+    }
+    buffer = findInList(getInProgressList(), stream, requestedOffset);
+    if (buffer != null) {
+      return buffer;
+    }
+    return findInList(getCompletedReadList(), stream, requestedOffset);
+  }
+
+  /**
+   * Searches the given collection of {@link ReadBuffer}s for one that belongs
+   * to the specified stream and whose buffered range covers the given offset.
+   *
+   * @param buffers the collection of {@link ReadBuffer}s to search
+   * @param stream the {@link AbfsInputStream} associated with the read request
+   *
+   * @return the matching {@link ReadBuffer}, or {@code null} if none is found
+   */
+  ReadBuffer findInList(final Collection<ReadBuffer> buffers,
+      final AbfsInputStream stream, long requestedOffset) {
+    for (ReadBuffer buffer : buffers) {
+      if (buffer.getStream() == stream

Review Comment:
   can buffer be null, if yes it will result into null pointer exception 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: common-issues-unsubscribe@hadoop.apache.org

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3077930601


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBuffer.java:
##########
@@ -48,6 +54,13 @@ class ReadBuffer {
   private boolean isLastByteConsumed = false;
   private boolean isAnyByteConsumed = false;
   private AtomicInteger refCount = new AtomicInteger(0);
+  private BufferType bufferType = BufferType.NORMAL;
+  // list of combined file ranges for vectored read.
+  private List<CombinedFileRange> vectoredUnits = new ArrayList<>();
+  // Allocator used for vectored fan-out; captured at queue time */
+  private IntFunction<ByteBuffer> allocator;
+  // Tracks whether fanOut has already been executed
+  private final AtomicInteger fanOutDone = new AtomicInteger(0);

Review Comment:
   Taken



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "hadoop-yetus (via GitHub)" <gi...@apache.org>.
hadoop-yetus commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4192113341

   :broken_heart: **-1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime |  Logfile | Comment |
   |:----:|----------:|--------:|:--------:|:-------:|
   | +0 :ok: |  reexec  |   0m  0s |  |  Docker mode activated.  |
   | -1 :x: |  patch  |   0m 17s |  |  https://github.com/apache/hadoop/pull/8400 does not apply to trunk. Rebase required? Wrong Branch? See https://cwiki.apache.org/confluence/display/HADOOP/How+To+Contribute for help.  |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/6/console |
   | versions | git=2.34.1 |
   | Powered by | Apache Yetus 0.14.1 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "manika137 (via GitHub)" <gi...@apache.org>.
manika137 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3067693036


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/VectoredReadHandler.java:
##########
@@ -0,0 +1,696 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.IntFunction;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.classification.VisibleForTesting;
+import org.apache.hadoop.fs.FileRange;
+import org.apache.hadoop.fs.VectoredReadUtils;
+import org.apache.hadoop.fs.azurebfs.constants.ReadType;
+import org.apache.hadoop.fs.azurebfs.enums.VectoredReadStrategy;
+import org.apache.hadoop.fs.azurebfs.utils.TracingContext;
+import org.apache.hadoop.fs.impl.CombinedFileRange;
+
+/**
+ * Handles vectored read operations by coordinating with a ReadBufferManager
+ * and applying the configured VectoredReadStrategy.
+ * This class acts as the orchestration layer that decides how vectored reads
+ * are executed, while delegating buffer management and read behavior to
+ * dedicated components.
+ */
+class VectoredReadHandler {
+
+  private static final Logger LOG = LoggerFactory.getLogger(VectoredReadHandler.class);
+
+  /**
+   * Manages allocation, lifecycle, and reuse of read buffers
+   * used during vectored read operations.
+   */
+  private final ReadBufferManager readBufferManager;
+
+  /**
+   * Strategy defining how vectored reads should be performed.
+   */
+  private final VectoredReadStrategy strategy;
+
+  /**
+   * Shared reconstruction buffers for ranges that span multiple chunks.
+   * Keyed by the original FileRange instance.
+   */
+  private final ConcurrentHashMap<RangeKey, ByteBuffer> partialBuffers =
+      new ConcurrentHashMap<>();
+
+  /**
+   * Tracks remaining bytes to be received for each logical range.
+   * Keyed by the original FileRange instance.
+   */
+  private final ConcurrentHashMap<RangeKey, AtomicInteger> pendingBytes =
+      new ConcurrentHashMap<>();
+
+  /**
+   * Creates a VectoredReadHandler using the provided ReadBufferManager.
+   * The vectored read strategy is obtained from the manager to ensure
+   * consistent configuration across the read pipeline.
+   *
+   * @param readBufferManager manager responsible for buffer handling
+   *                          and providing the vectored read strategy
+   */
+  VectoredReadHandler(ReadBufferManager readBufferManager) {
+    this.readBufferManager = readBufferManager;
+    this.strategy = readBufferManager.getVectoredReadStrategy();
+    LOG.debug("VectoredReadHandler initialized with strategy={}", strategy);
+  }
+
+  /**
+   * Perform a vectored read over multiple logical file ranges.
+   *
+   * <p>Logical ranges are first merged using a span-first strategy determined
+   * by the configured {@link VectoredReadStrategy}. The merged ranges are then
+   * split into buffer-sized physical read units and queued for asynchronous
+   * execution. If a pooled buffer is unavailable, the read falls back to a
+   * direct read path.</p>
+   *
+   * @param stream    input stream for the file being read
+   * @param ranges    logical file ranges to read; each range will be completed
+   *                  with data or failure via its associated future
+   * @param allocator allocator used to create buffers for direct reads and
+   *                  vectored fan-out
+   */
+  public void readVectored(
+      AbfsInputStream stream,
+      List<? extends FileRange> ranges,
+      IntFunction<ByteBuffer> allocator) throws EOFException {
+    LOG.debug("readVectored invoked: path={}, rangeCount={}",
+        stream.getPath(), ranges.size());
+
+    /* Initialize a future for each logical file range */
+    long fileLength = stream.getContentLength();
+    List<FileRange> validRanges = validateAndPrepareRanges(ranges, fileLength);
+
+    /* Select the maximum allowed merge span based on the configured strategy */
+    int maxSpan =
+        (strategy == VectoredReadStrategy.TPS_OPTIMIZED)
+            ? readBufferManager.getMaxSeekForVectoredReads()
+            : readBufferManager.getMaxSeekForVectoredReadsThroughput();
+
+    LOG.debug("readVectored: path={}, strategy={}, maxSpan={}",
+        stream.getPath(), strategy, maxSpan);
+
+    /* Merge logical ranges using a span-first coalescing strategy */
+    List<CombinedFileRange> merged = mergeBySpanAndGap(validRanges, maxSpan, fileLength);
+
+    LOG.debug("readVectored: path={}, mergedRangeCount={}",
+        stream.getPath(), merged.size());
+
+    /* Read buffer size acts as a hard upper bound for physical reads */
+    int readBufferSize = ReadBufferManager.getReadAheadBlockSize();
+
+    /* Split merged ranges into buffer-sized chunks and queue each for read */
+    for (CombinedFileRange unit : merged) {
+      List<CombinedFileRange> chunks = splitByBufferSize(unit, readBufferSize);
+
+      LOG.debug("readVectored: path={}, mergedOffset={}, mergedLength={}, chunkCount={}",
+          stream.getPath(), unit.getOffset(), unit.getLength(), chunks.size());
+
+      for (CombinedFileRange chunk : chunks) {
+        try {
+          VectoredReadUtils.validateRangeRequest(chunk);
+          boolean queued = queueVectoredRead(stream, chunk, allocator);
+          if (!queued) {
+            LOG.debug("readVectored: buffer pool exhausted, falling back to directRead: path={}, offset={}, length={}",
+                stream.getPath(), chunk.getOffset(), chunk.getLength());
+            directRead(stream, chunk, allocator);
+          }
+        } catch (Exception e) {
+          LOG.warn("readVectored: chunk read failed, failing underlying ranges:"
+                  + " path={}, offset={}, length={}",
+              stream.getPath(), chunk.getOffset(), chunk.getLength(), e);
+          failUnit(chunk, e);
+        }
+      }
+    }
+  }
+
+  /**
+   * Queues a vectored read request with the buffer manager.
+   *
+   * @return true if successfully queued, false if the queue is full and fallback is required.
+   */
+  @VisibleForTesting
+  boolean queueVectoredRead(AbfsInputStream stream, CombinedFileRange unit,
+      IntFunction<ByteBuffer> allocator) {
+    LOG.debug("queueVectoredRead: path={}, offset={}, length={}",
+        stream.getPath(), unit.getOffset(), unit.getLength());
+    TracingContext tracingContext = stream.getTracingContext();
+    tracingContext.setReadType(ReadType.VECTORED_READ);
+    return getReadBufferManager().queueVectoredRead(stream, unit, tracingContext, allocator);
+  }
+
+  /**
+   * Accesses the shared manager responsible for coordinating asynchronous read buffers.
+   *
+   * @return the {@link ReadBufferManager} instance.
+   */
+  public ReadBufferManager getReadBufferManager() {
+    return readBufferManager;
+  }
+
+  /**
+   * Validates and prepares a list of {@link FileRange} instances for vectored reads.
+   *
+   * <p>This method performs the following steps for each input range:
+   * <ul>
+   *   <li>Validates the range using {@link VectoredReadUtils#validateRangeRequest(FileRange)}</li>
+   *   <li>Initializes a {@link CompletableFuture} to hold the read result</li>
+   *   <li>Checks that the range falls within the bounds of the file</li>
+   * </ul>
+   *
+   * <p>Ranges that are invalid (e.g., negative offset/length or exceeding file bounds)
+   * are not included in the returned list. Instead, their associated future is
+   * completed exceptionally with an {@link EOFException}.
+   *
+   * @param ranges     the input list of logical file ranges to validate and prepare
+   * @param fileLength the total length of the file, used for bounds checking
+   * @return a list of valid {@link FileRange} instances ready for vectored read processing
+   */
+  private List<FileRange> validateAndPrepareRanges(
+      List<? extends FileRange> ranges, long fileLength) throws EOFException {
+
+    List<FileRange> validRanges = new ArrayList<>();
+
+    for (FileRange r : ranges) {
+      VectoredReadUtils.validateRangeRequest(r);
+      r.setData(new CompletableFuture<>());
+
+      long offset = r.getOffset();
+      long length = r.getLength();
+
+      if (offset < 0 || length < 0 || offset > fileLength || length > fileLength - offset) {
+        r.getData().completeExceptionally(new EOFException(
+            "Invalid range: offset=" + offset + ", length=" + length + ", fileLength=" + fileLength));
+        continue;
+      }
+      validRanges.add(r);
+    }
+    return validRanges;
+  }
+
+  /**
+   * Splits a merged logical {@link CombinedFileRange} into smaller
+   * buffer-sized physical read units.
+   *
+   * <p>Each resulting unit will have a maximum size equal to the provided
+   * {@code bufferSize}. Any handling of multi-chunk ranges or reassembly
+   * of underlying {@link FileRange} data is delegated to the fan-out logic.</p>
+   *
+   * @param unit       the combined logical range to be split
+   * @param bufferSize the maximum size (in bytes) of each physical read unit
+   * @return a list of buffer-sized {@link CombinedFileRange} instances
+   */
+  private List<CombinedFileRange> splitByBufferSize(
+      CombinedFileRange unit,
+      int bufferSize) {
+    LOG.debug("splitByBufferSize: offset={}, length={}, bufferSize={}",
+        unit.getOffset(), unit.getLength(), bufferSize);
+
+    List<CombinedFileRange> parts = new ArrayList<>();
+    long unitStart = unit.getOffset();
+    long unitEnd = unitStart + unit.getLength();
+    long start = unitStart;
+
+    while (start < unitEnd) {
+      long partEnd = Math.min(start + bufferSize, unitEnd);
+
+      CombinedFileRange part =
+          new CombinedFileRange(start, partEnd, unit.getUnderlying().get(0));
+      part.getUnderlying().clear();
+
+      for (FileRange r : unit.getUnderlying()) {
+        long rStart = r.getOffset();
+        long rEnd = rStart + r.getLength();
+        if (rEnd > start && rStart < partEnd) {
+          part.getUnderlying().add(r);
+        }
+      }
+      parts.add(part);
+      start = partEnd;
+    }
+
+    LOG.debug("splitByBufferSize: offset={}, produced {} parts",
+        unit.getOffset(), parts.size());
+    return parts;
+  }
+
+  /**
+   * Merge logical {@link FileRange}s into {@link CombinedFileRange}s using a
+   * span-first coalescing strategy.
+   *
+   * <p>Ranges are merged as long as the total span from the first offset to the
+   * end of the last range does not exceed {@code maxSpan}. Gaps between ranges
+   * are ignored.</p>
+   *
+   * @param ranges  logical file ranges to merge
+   * @param maxSpan maximum allowed span (in bytes) for a combined read
+   * @return merged {@link CombinedFileRange}s covering the input ranges
+   */
+  private List<CombinedFileRange> mergeBySpanAndGap(
+      List<? extends FileRange> ranges,
+      int maxSpan, long  fileLength) throws EOFException {
+
+    LOG.debug("mergeBySpanAndGap: rangeCount={}, maxSpan={}", ranges.size(), maxSpan);
+    List<? extends FileRange> sortedRanges = VectoredReadUtils.validateAndSortRanges(
+        ranges, Optional.of(fileLength));
+
+    List<CombinedFileRange> out = new ArrayList<>();
+    CombinedFileRange current = null;
+
+    for (FileRange r : sortedRanges) {
+      long rOffset = r.getOffset();
+      long rEnd = rOffset + r.getLength();
+
+      /* Initialize the first combined range */
+      if (current == null) {
+        current = new CombinedFileRange(rOffset, rEnd, r);
+        continue;
+      }
+
+      /* Check whether adding this range keeps the total span within the limit */
+      long newSpan = rEnd - current.getOffset();
+
+      if (newSpan <= maxSpan) {
+        current.setLength((int) newSpan);
+        current.getUnderlying().add(r);
+      } else {
+        /* Span exceeded; finalize current range and start a new one */
+        out.add(current);
+        current = new CombinedFileRange(rOffset, rEnd, r);
+      }
+    }
+
+    /* Add the final combined range, if any */
+    if (current != null) {
+      out.add(current);
+    }
+
+    LOG.debug("mergeBySpanAndGap: produced {} combined ranges", out.size());
+    return out;
+  }
+
+  /**
+   * Distributes data from a physical read buffer into the corresponding
+   * logical {@link FileRange}s.
+   *
+   * <p>This method performs a "fan-out" operation where a single physical
+   * read (represented by {@link ReadBuffer}) may contain data for multiple
+   * logical ranges. The relevant portions are copied into per-range buffers
+   * and completed once fully populated.</p>
+   *
+   * <p>Partial reads are accumulated using {@code partialBuffers} and
+   * {@code pendingBytes}. A range is only completed when all expected
+   * bytes have been received.</p>
+   *
+   * <p>Thread safety:
+   * <ul>
+   *   <li>Each logical range buffer is synchronized independently</li>
+   *   <li>Writes use {@code System.arraycopy} directly into the backing array
+   *       to avoid shared {@link ByteBuffer} position mutation</li>
+   * </ul>
+   * </p>
+   *
+   * @param buffer    the physical read buffer containing merged data
+   * @param bytesRead number of valid bytes in the buffer
+   */
+  void fanOut(ReadBuffer buffer, int bytesRead) {
+    LOG.debug("fanOut: path={}, bufferOffset={}, bytesRead={}",
+        buffer.getPath(), buffer.getOffset(), bytesRead);
+
+    List<CombinedFileRange> units = buffer.getVectoredUnits();
+    if (units == null) {
+      LOG.warn("fanOut: no vectored units found for path={}, offset={}",
+          buffer.getPath(), buffer.getOffset());
+      return;
+    }
+
+    long bufferStart = buffer.getOffset();
+    long bufferEnd = bufferStart + bytesRead;
+
+    /* Iterate over all combined logical units mapped to this buffer */
+    for (CombinedFileRange unit : units) {
+      /* Each unit may contain multiple logical FileRanges */
+      for (FileRange r : unit.getUnderlying()) {
+        CompletableFuture<ByteBuffer> future = r.getData();
+        RangeKey key = new RangeKey(r);
+
+        /* Skip already completed or cancelled ranges */
+        if (future.isCancelled()) {
+          LOG.debug("fanOut: range cancelled, cleaning up: path={}, rangeOffset={}",
+              buffer.getPath(), r.getOffset());
+          partialBuffers.remove(key);
+          pendingBytes.remove(key);
+          continue;
+        }
+        if (future.isDone()) {
+          continue;
+        }
+
+        try {
+          long rangeStart = r.getOffset();
+          long rangeEnd = rangeStart + r.getLength();
+
+          /* Compute overlap between buffer and logical range */
+          long overlapStart = Math.max(rangeStart, bufferStart);
+          long overlapEnd = Math.min(rangeEnd, bufferEnd);
+
+          /* No overlap nothing to copy */
+          if (overlapStart >= overlapEnd) {
+            LOG.debug("fanOut: no overlap for path={}, rangeOffset={}, bufferOffset={}",
+                buffer.getPath(), r.getOffset(), bufferStart);
+            continue;
+          }
+
+          int srcOffset = (int) (overlapStart - bufferStart);
+          int destOffset = (int) (overlapStart - rangeStart);
+          int length = (int) (overlapEnd - overlapStart);
+
+          LOG.debug("fanOut: copying path={}, rangeOffset={}, rangeLength={},"
+                  + " bufferOffset={}, srcOffset={}, destOffset={}, length={}",
+              buffer.getPath(), r.getOffset(), r.getLength(),
+              bufferStart, srcOffset, destOffset, length);
+
+          /* Allocate or reuse the full buffer for this logical range */
+          ByteBuffer fullBuf = partialBuffers.computeIfAbsent(
+              key, k -> buffer.getAllocator().apply(r.getLength()));
+
+          /* Track remaining bytes required to complete this range */
+          AtomicInteger pending = pendingBytes.computeIfAbsent(
+              key, k -> new AtomicInteger(r.getLength()));
+
+          synchronized (fullBuf) {
+            /* Double-check completion inside lock */
+            if (future.isDone()) {
+              continue;
+            }
+
+            ByteBuffer dst = fullBuf.duplicate();
+            dst.position(destOffset);
+            dst.put(buffer.getBuffer(), srcOffset, length);
+
+            int left = pending.addAndGet(-length);
+
+            LOG.debug("fanOut: wrote chunk: path={}, rangeOffset={}, destOffset={},"
+                    + " length={}, pendingBytes={}",
+                buffer.getPath(), r.getOffset(), destOffset, length, left);
+
+            if (left < 0) {
+              LOG.error("fanOut: pending bytes went negative  possible duplicate write:"

Review Comment:
   nit: non-printable character



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "manika137 (via GitHub)" <gi...@apache.org>.
manika137 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3067912692


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -338,6 +356,117 @@ public void queueReadAhead(final AbfsInputStream stream,
     }
   }
 
+  /**
+   * Queue a vectored read for a buffer-sized physical read unit.
+   *
+   * <p>The method first attempts to attach the logical unit to an already
+   * in-progress physical read for the same file and offset. If that is not
+   * possible, a free read buffer is acquired and a new backend read is
+   * queued.</p>
+   *
+   * @param stream         input stream for the file being read
+   * @param unit           buffer-sized combined file range to be read
+   * @param tracingContext tracing context used for the backend read request
+   * @param allocator      allocator used to create buffers for vectored fan-out
+   * @return {@code true} if the read was queued or attached to an existing
+   *         in-progress buffer; {@code false} if no buffer was available
+   */
+  boolean queueVectoredRead(AbfsInputStream stream,
+      CombinedFileRange unit,
+      TracingContext tracingContext,
+      IntFunction<ByteBuffer> allocator) {
+    /* Create a child tracing context for vectored read-ahead requests */
+    TracingContext readAheadTracingContext =
+        new TracingContext(tracingContext);
+    readAheadTracingContext.setPrimaryRequestID();
+    readAheadTracingContext.setReadType(ReadType.VECTORED_READ);
+    synchronized (this) {
+      /*
+       * Attempt to hitchhike on an existing in-progress physical read if it
+       * covers the requested logical range completely.
+       */
+      if (isAlreadyQueued(stream.getETag(), unit.getOffset())) {
+        ReadBuffer existing = findQueuedBuffer(stream, unit.getOffset());
+        if (existing != null && existing.getStream().getETag() != null  && stream.getETag()

Review Comment:
   same doubt as RBMV1, do we wait for UNAVAILABLE state readbuffers too?



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "manika137 (via GitHub)" <gi...@apache.org>.
manika137 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3067915908


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -160,12 +171,16 @@ static ReadBufferManagerV2 getBufferManager(AbfsCounters abfsCounters) {
     return bufferManager;
   }
 
+VectoredReadHandler getVectoredReadHandler() {
+    return vectoredReadHandler;
+  }
+
   /**
    * Set the ReadBufferManagerV2 configurations based on the provided before singleton initialization.
    * @param readAheadBlockSize the read-ahead block size to set for the ReadBufferManagerV2.
    * @param abfsConfiguration the configuration to set for the ReadBufferManagerV2.
    */
-  public static void setReadBufferManagerConfigs(final int readAheadBlockSize,
+  public static void setReadBufferManagerConfigs(int readAheadBlockSize,

Review Comment:
   why this change?



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3071399676


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV1.java:
##########
@@ -146,6 +168,124 @@ public void queueReadAhead(final AbfsInputStream stream, final long requestedOff
     }
   }
 
+  /**
+   * Queue a vectored read for a buffer-sized physical read unit.
+   *
+   * <p>The method first attempts to attach the logical unit to an already
+   * in-progress physical read for the same file and offset. If that is not
+   * possible, a free read buffer is acquired and a new backend read is
+   * queued.</p>
+   *
+   * @param stream         input stream for the file being read
+   * @param unit           buffer-sized combined file range to be read
+   * @param tracingContext tracing context used for the backend read request
+   * @param allocator      allocator used to create buffers for vectored fan-out
+   * @return {@code true} if the read was queued or attached to an existing
+   *         in-progress buffer; {@code false} if no buffer was available
+   */
+  boolean queueVectoredRead(AbfsInputStream stream,
+      CombinedFileRange unit,
+      TracingContext tracingContext,
+      IntFunction<ByteBuffer> allocator) {
+    /* Create a child tracing context for vectored read-ahead requests */
+    TracingContext readAheadTracingContext =
+        new TracingContext(tracingContext);
+    readAheadTracingContext.setPrimaryRequestID();
+    readAheadTracingContext.setReadType(ReadType.VECTORED_READ);
+
+    synchronized (this) {
+      if (isAlreadyQueued(stream, unit.getOffset())) {
+        ReadBuffer existing = findQueuedBuffer(stream, unit.getOffset());
+        if (existing != null && existing.getStream().getETag() != null
+            && stream.getETag().equals(existing.getStream().getETag())) {
+          /*
+           * For AVAILABLE buffers use actual bytes read (getLength()) for
+           * coverage check. For READING_IN_PROGRESS buffers use
+           * requestedLength as an estimate — the short-read guard will be
+           * applied later in doneReading before dispatching completion.
+           */
+          long end = existing.getOffset() + (
+              existing.getStatus() == ReadBufferStatus.AVAILABLE
+                  ? existing.getLength()
+                  : existing.getRequestedLength());
+          if (end >= unit.getOffset() + unit.getLength()) {
+            existing.setBufferType(BufferType.VECTORED);
+            existing.addVectoredUnit(unit);
+            existing.setAllocator(allocator);
+            if (existing.getStatus() == ReadBufferStatus.AVAILABLE) {
+              /*
+               * Buffer is already AVAILABLE. Trigger completion immediately.
+               * Use getLength() (actual bytes) for coverage — redundant here
+               * since the outer check already used getLength() for AVAILABLE,
+               * but kept explicit for clarity.
+               */
+              LOGGER.debug("Hitchhiking onto AVAILABLE buffer {}, length {}",
+                  existing, existing.getLength());
+              handleVectoredCompletion(existing,
+                  existing.getStatus(),
+                  existing.getLength());
+            }
+            /*
+             * For READING_IN_PROGRESS: unit is attached and will be
+             * completed in doneReading once actual bytes are known.
+             * Short-read safety is enforced there via per-unit coverage check.
+             */
+            return true;

Review Comment:
   yes, that will also land here, will update the comments. In case of doneReading we validate that it has read the needed data for the vectored case.



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4251403274

   > have a look at #7105 / [HADOOP-19105](https://issues.apache.org/jira/browse/HADOOP-19105). Improve resilience in vector reads. https://issues.apache.org/jira/browse/HADOOP-19105
   > 
   > to see why I now think trying to merge ranges is a PITA.
   > 
   > do make sure that your error handling explicitly releases any allocated buffers before raising exceptions; the PositionedReadable interface was extended to support this
   
   Have tried to take care of this in the VectoredReadHandler fanOut and directRead methods, can you please check if you see any concerns with the code there.


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "hadoop-yetus (via GitHub)" <gi...@apache.org>.
hadoop-yetus commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4180160622

   :confetti_ball: **+1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime |  Logfile | Comment |
   |:----:|----------:|--------:|:--------:|:-------:|
   | +0 :ok: |  reexec  |   0m 53s |  |  Docker mode activated.  |
   |||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  0s |  |  No case conflicting files found.  |
   | +0 :ok: |  codespell  |   0m  1s |  |  codespell was not available.  |
   | +0 :ok: |  detsecrets  |   0m  1s |  |  detect-secrets was not available.  |
   | +1 :green_heart: |  @author  |   0m  0s |  |  The patch does not contain any @author tags.  |
   | +1 :green_heart: |  test4tests  |   0m  0s |  |  The patch appears to include 2 new or modified test files.  |
   |||| _ trunk Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  48m 13s |  |  trunk passed  |
   | +1 :green_heart: |  compile  |   1m  1s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  compile  |   1m  4s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  checkstyle  |   0m 58s |  |  trunk passed  |
   | +1 :green_heart: |  mvnsite  |   1m  7s |  |  trunk passed  |
   | +1 :green_heart: |  javadoc  |   0m 59s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 58s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 35s |  |  trunk passed  |
   | +1 :green_heart: |  shadedclient  |  34m 39s |  |  branch has no errors when building and testing our client artifacts.  |
   | -0 :warning: |  patch  |  35m 11s |  |  Used diff version of patch file. Binary files and potentially other changes not applied. Please rebase and squash commits if necessary.  |
   |||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   0m 37s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 32s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javac  |   0m 32s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 35s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  javac  |   0m 35s |  |  the patch passed  |
   | +1 :green_heart: |  blanks  |   0m  0s |  |  The patch has no blanks issues.  |
   | -0 :warning: |  checkstyle  |   0m 25s | [/results-checkstyle-hadoop-tools_hadoop-azure.txt](https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/1/artifact/out/results-checkstyle-hadoop-tools_hadoop-azure.txt) |  hadoop-tools/hadoop-azure: The patch generated 10 new + 5 unchanged - 0 fixed = 15 total (was 5)  |
   | +1 :green_heart: |  mvnsite  |   0m 39s |  |  the patch passed  |
   | +1 :green_heart: |  javadoc  |   0m 29s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 29s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 17s |  |  the patch passed  |
   | +1 :green_heart: |  shadedclient  |  32m 56s |  |  patch has no errors when building and testing our client artifacts.  |
   |||| _ Other Tests _ |
   | +1 :green_heart: |  unit  |   2m 10s |  |  hadoop-azure in the patch passed.  |
   | +1 :green_heart: |  asflicense  |   0m 35s |  |  The patch does not generate ASF License warnings.  |
   |  |   | 134m 18s |  |  |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/1/artifact/out/Dockerfile |
   | GITHUB PR | https://github.com/apache/hadoop/pull/8400 |
   | Optional Tests | dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets |
   | uname | Linux bec554755465 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | dev-support/bin/hadoop.sh |
   | git revision | trunk / 437ffc8e00e2dc1f16aad75cb8f02ecc741de8be |
   | Default Java | Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   | Multi-JDK versions | /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   |  Test Results | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/1/testReport/ |
   | Max. process+thread count | 574 (vs. ulimit of 10000) |
   | modules | C: hadoop-tools/hadoop-azure U: hadoop-tools/hadoop-azure |
   | Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/1/console |
   | versions | git=2.43.0 maven=3.9.11 spotbugs=4.9.7 |
   | Powered by | Apache Yetus 0.14.1 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3071276942


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -160,12 +171,16 @@ static ReadBufferManagerV2 getBufferManager(AbfsCounters abfsCounters) {
     return bufferManager;
   }
 
+VectoredReadHandler getVectoredReadHandler() {

Review Comment:
   taken



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3071405572


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV1.java:
##########
@@ -146,6 +168,124 @@ public void queueReadAhead(final AbfsInputStream stream, final long requestedOff
     }
   }
 
+  /**
+   * Queue a vectored read for a buffer-sized physical read unit.
+   *
+   * <p>The method first attempts to attach the logical unit to an already
+   * in-progress physical read for the same file and offset. If that is not
+   * possible, a free read buffer is acquired and a new backend read is
+   * queued.</p>
+   *
+   * @param stream         input stream for the file being read
+   * @param unit           buffer-sized combined file range to be read
+   * @param tracingContext tracing context used for the backend read request
+   * @param allocator      allocator used to create buffers for vectored fan-out
+   * @return {@code true} if the read was queued or attached to an existing
+   *         in-progress buffer; {@code false} if no buffer was available
+   */
+  boolean queueVectoredRead(AbfsInputStream stream,
+      CombinedFileRange unit,
+      TracingContext tracingContext,
+      IntFunction<ByteBuffer> allocator) {
+    /* Create a child tracing context for vectored read-ahead requests */
+    TracingContext readAheadTracingContext =
+        new TracingContext(tracingContext);
+    readAheadTracingContext.setPrimaryRequestID();
+    readAheadTracingContext.setReadType(ReadType.VECTORED_READ);
+
+    synchronized (this) {
+      if (isAlreadyQueued(stream, unit.getOffset())) {
+        ReadBuffer existing = findQueuedBuffer(stream, unit.getOffset());
+        if (existing != null && existing.getStream().getETag() != null
+            && stream.getETag().equals(existing.getStream().getETag())) {
+          /*
+           * For AVAILABLE buffers use actual bytes read (getLength()) for
+           * coverage check. For READING_IN_PROGRESS buffers use
+           * requestedLength as an estimate — the short-read guard will be
+           * applied later in doneReading before dispatching completion.
+           */
+          long end = existing.getOffset() + (
+              existing.getStatus() == ReadBufferStatus.AVAILABLE

Review Comment:
   doneReading is where the actual handling of vectored reads happens, so if the buffer is already queued it is safe to attach the buffer here and later do the handling in doneReading.



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "manika137 (via GitHub)" <gi...@apache.org>.
manika137 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3067605283


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV1.java:
##########
@@ -146,6 +168,124 @@ public void queueReadAhead(final AbfsInputStream stream, final long requestedOff
     }
   }
 
+  /**
+   * Queue a vectored read for a buffer-sized physical read unit.
+   *
+   * <p>The method first attempts to attach the logical unit to an already
+   * in-progress physical read for the same file and offset. If that is not
+   * possible, a free read buffer is acquired and a new backend read is
+   * queued.</p>
+   *
+   * @param stream         input stream for the file being read
+   * @param unit           buffer-sized combined file range to be read
+   * @param tracingContext tracing context used for the backend read request
+   * @param allocator      allocator used to create buffers for vectored fan-out
+   * @return {@code true} if the read was queued or attached to an existing
+   *         in-progress buffer; {@code false} if no buffer was available
+   */
+  boolean queueVectoredRead(AbfsInputStream stream,
+      CombinedFileRange unit,
+      TracingContext tracingContext,
+      IntFunction<ByteBuffer> allocator) {
+    /* Create a child tracing context for vectored read-ahead requests */
+    TracingContext readAheadTracingContext =
+        new TracingContext(tracingContext);
+    readAheadTracingContext.setPrimaryRequestID();
+    readAheadTracingContext.setReadType(ReadType.VECTORED_READ);
+
+    synchronized (this) {
+      if (isAlreadyQueued(stream, unit.getOffset())) {
+        ReadBuffer existing = findQueuedBuffer(stream, unit.getOffset());
+        if (existing != null && existing.getStream().getETag() != null
+            && stream.getETag().equals(existing.getStream().getETag())) {
+          /*
+           * For AVAILABLE buffers use actual bytes read (getLength()) for
+           * coverage check. For READING_IN_PROGRESS buffers use
+           * requestedLength as an estimate — the short-read guard will be
+           * applied later in doneReading before dispatching completion.
+           */
+          long end = existing.getOffset() + (
+              existing.getStatus() == ReadBufferStatus.AVAILABLE

Review Comment:
   So we would wait and attach the buffer even if its not yet picked up by thread yet (unavailable state)?



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "manika137 (via GitHub)" <gi...@apache.org>.
manika137 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3067814168


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -160,12 +171,16 @@ static ReadBufferManagerV2 getBufferManager(AbfsCounters abfsCounters) {
     return bufferManager;
   }
 
+VectoredReadHandler getVectoredReadHandler() {

Review Comment:
   nit: format



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3085893951


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/constants/ReadType.java:
##########
@@ -48,6 +48,16 @@ public enum ReadType {
    * Only triggered when small file read optimization kicks in.
    */
   SMALLFILE_READ("SR"),
+  /**
+   * Read multiple disjoint ranges from the storage service using vectored reads.
+   * Used to coalesce and execute non-contiguous reads efficiently.
+   */
+  VECTORED_READ("VR"),
+  /**
+   * Performs a vectored direct read by fetching multiple non-contiguous
+   * ranges in a single operation.
+   */
+  VECTORED_DIRECT_READ("VDR"),

Review Comment:
   Here this direct read is when we are not able to queue a vectored read in the read ahead queue due to read ahead buffers not being available, we do a direct readRemote call



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4324707955

   Hi @mukund-thakur gentle reminder for reviewing the 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: common-issues-unsubscribe@hadoop.apache.org

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "manika137 (via GitHub)" <gi...@apache.org>.
manika137 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3067642442


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/VectoredReadHandler.java:
##########
@@ -0,0 +1,696 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.IntFunction;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.classification.VisibleForTesting;
+import org.apache.hadoop.fs.FileRange;
+import org.apache.hadoop.fs.VectoredReadUtils;
+import org.apache.hadoop.fs.azurebfs.constants.ReadType;
+import org.apache.hadoop.fs.azurebfs.enums.VectoredReadStrategy;
+import org.apache.hadoop.fs.azurebfs.utils.TracingContext;
+import org.apache.hadoop.fs.impl.CombinedFileRange;
+
+/**
+ * Handles vectored read operations by coordinating with a ReadBufferManager
+ * and applying the configured VectoredReadStrategy.
+ * This class acts as the orchestration layer that decides how vectored reads
+ * are executed, while delegating buffer management and read behavior to
+ * dedicated components.
+ */
+class VectoredReadHandler {
+
+  private static final Logger LOG = LoggerFactory.getLogger(VectoredReadHandler.class);
+
+  /**
+   * Manages allocation, lifecycle, and reuse of read buffers
+   * used during vectored read operations.
+   */
+  private final ReadBufferManager readBufferManager;
+
+  /**
+   * Strategy defining how vectored reads should be performed.
+   */
+  private final VectoredReadStrategy strategy;
+
+  /**
+   * Shared reconstruction buffers for ranges that span multiple chunks.
+   * Keyed by the original FileRange instance.
+   */
+  private final ConcurrentHashMap<RangeKey, ByteBuffer> partialBuffers =
+      new ConcurrentHashMap<>();
+
+  /**
+   * Tracks remaining bytes to be received for each logical range.
+   * Keyed by the original FileRange instance.
+   */
+  private final ConcurrentHashMap<RangeKey, AtomicInteger> pendingBytes =
+      new ConcurrentHashMap<>();
+
+  /**
+   * Creates a VectoredReadHandler using the provided ReadBufferManager.
+   * The vectored read strategy is obtained from the manager to ensure
+   * consistent configuration across the read pipeline.
+   *
+   * @param readBufferManager manager responsible for buffer handling
+   *                          and providing the vectored read strategy
+   */
+  VectoredReadHandler(ReadBufferManager readBufferManager) {
+    this.readBufferManager = readBufferManager;
+    this.strategy = readBufferManager.getVectoredReadStrategy();
+    LOG.debug("VectoredReadHandler initialized with strategy={}", strategy);
+  }
+
+  /**
+   * Perform a vectored read over multiple logical file ranges.
+   *
+   * <p>Logical ranges are first merged using a span-first strategy determined
+   * by the configured {@link VectoredReadStrategy}. The merged ranges are then
+   * split into buffer-sized physical read units and queued for asynchronous
+   * execution. If a pooled buffer is unavailable, the read falls back to a
+   * direct read path.</p>
+   *
+   * @param stream    input stream for the file being read
+   * @param ranges    logical file ranges to read; each range will be completed
+   *                  with data or failure via its associated future
+   * @param allocator allocator used to create buffers for direct reads and
+   *                  vectored fan-out
+   */
+  public void readVectored(
+      AbfsInputStream stream,
+      List<? extends FileRange> ranges,
+      IntFunction<ByteBuffer> allocator) throws EOFException {
+    LOG.debug("readVectored invoked: path={}, rangeCount={}",
+        stream.getPath(), ranges.size());
+
+    /* Initialize a future for each logical file range */
+    long fileLength = stream.getContentLength();
+    List<FileRange> validRanges = validateAndPrepareRanges(ranges, fileLength);
+
+    /* Select the maximum allowed merge span based on the configured strategy */
+    int maxSpan =
+        (strategy == VectoredReadStrategy.TPS_OPTIMIZED)
+            ? readBufferManager.getMaxSeekForVectoredReads()
+            : readBufferManager.getMaxSeekForVectoredReadsThroughput();
+
+    LOG.debug("readVectored: path={}, strategy={}, maxSpan={}",
+        stream.getPath(), strategy, maxSpan);
+
+    /* Merge logical ranges using a span-first coalescing strategy */
+    List<CombinedFileRange> merged = mergeBySpanAndGap(validRanges, maxSpan, fileLength);
+
+    LOG.debug("readVectored: path={}, mergedRangeCount={}",
+        stream.getPath(), merged.size());
+
+    /* Read buffer size acts as a hard upper bound for physical reads */
+    int readBufferSize = ReadBufferManager.getReadAheadBlockSize();
+
+    /* Split merged ranges into buffer-sized chunks and queue each for read */
+    for (CombinedFileRange unit : merged) {
+      List<CombinedFileRange> chunks = splitByBufferSize(unit, readBufferSize);
+
+      LOG.debug("readVectored: path={}, mergedOffset={}, mergedLength={}, chunkCount={}",
+          stream.getPath(), unit.getOffset(), unit.getLength(), chunks.size());
+
+      for (CombinedFileRange chunk : chunks) {
+        try {
+          VectoredReadUtils.validateRangeRequest(chunk);
+          boolean queued = queueVectoredRead(stream, chunk, allocator);
+          if (!queued) {
+            LOG.debug("readVectored: buffer pool exhausted, falling back to directRead: path={}, offset={}, length={}",
+                stream.getPath(), chunk.getOffset(), chunk.getLength());
+            directRead(stream, chunk, allocator);
+          }
+        } catch (Exception e) {
+          LOG.warn("readVectored: chunk read failed, failing underlying ranges:"
+                  + " path={}, offset={}, length={}",
+              stream.getPath(), chunk.getOffset(), chunk.getLength(), e);
+          failUnit(chunk, e);
+        }
+      }
+    }
+  }
+
+  /**
+   * Queues a vectored read request with the buffer manager.
+   *
+   * @return true if successfully queued, false if the queue is full and fallback is required.
+   */
+  @VisibleForTesting
+  boolean queueVectoredRead(AbfsInputStream stream, CombinedFileRange unit,
+      IntFunction<ByteBuffer> allocator) {
+    LOG.debug("queueVectoredRead: path={}, offset={}, length={}",
+        stream.getPath(), unit.getOffset(), unit.getLength());
+    TracingContext tracingContext = stream.getTracingContext();
+    tracingContext.setReadType(ReadType.VECTORED_READ);
+    return getReadBufferManager().queueVectoredRead(stream, unit, tracingContext, allocator);
+  }
+
+  /**
+   * Accesses the shared manager responsible for coordinating asynchronous read buffers.
+   *
+   * @return the {@link ReadBufferManager} instance.
+   */
+  public ReadBufferManager getReadBufferManager() {
+    return readBufferManager;
+  }
+
+  /**
+   * Validates and prepares a list of {@link FileRange} instances for vectored reads.
+   *
+   * <p>This method performs the following steps for each input range:
+   * <ul>
+   *   <li>Validates the range using {@link VectoredReadUtils#validateRangeRequest(FileRange)}</li>
+   *   <li>Initializes a {@link CompletableFuture} to hold the read result</li>
+   *   <li>Checks that the range falls within the bounds of the file</li>
+   * </ul>
+   *
+   * <p>Ranges that are invalid (e.g., negative offset/length or exceeding file bounds)
+   * are not included in the returned list. Instead, their associated future is
+   * completed exceptionally with an {@link EOFException}.
+   *
+   * @param ranges     the input list of logical file ranges to validate and prepare
+   * @param fileLength the total length of the file, used for bounds checking
+   * @return a list of valid {@link FileRange} instances ready for vectored read processing
+   */
+  private List<FileRange> validateAndPrepareRanges(
+      List<? extends FileRange> ranges, long fileLength) throws EOFException {
+
+    List<FileRange> validRanges = new ArrayList<>();
+
+    for (FileRange r : ranges) {
+      VectoredReadUtils.validateRangeRequest(r);
+      r.setData(new CompletableFuture<>());
+
+      long offset = r.getOffset();
+      long length = r.getLength();
+
+      if (offset < 0 || length < 0 || offset > fileLength || length > fileLength - offset) {
+        r.getData().completeExceptionally(new EOFException(
+            "Invalid range: offset=" + offset + ", length=" + length + ", fileLength=" + fileLength));
+        continue;
+      }
+      validRanges.add(r);
+    }
+    return validRanges;
+  }
+
+  /**
+   * Splits a merged logical {@link CombinedFileRange} into smaller
+   * buffer-sized physical read units.
+   *
+   * <p>Each resulting unit will have a maximum size equal to the provided
+   * {@code bufferSize}. Any handling of multi-chunk ranges or reassembly
+   * of underlying {@link FileRange} data is delegated to the fan-out logic.</p>
+   *
+   * @param unit       the combined logical range to be split
+   * @param bufferSize the maximum size (in bytes) of each physical read unit
+   * @return a list of buffer-sized {@link CombinedFileRange} instances
+   */
+  private List<CombinedFileRange> splitByBufferSize(
+      CombinedFileRange unit,
+      int bufferSize) {
+    LOG.debug("splitByBufferSize: offset={}, length={}, bufferSize={}",
+        unit.getOffset(), unit.getLength(), bufferSize);
+
+    List<CombinedFileRange> parts = new ArrayList<>();
+    long unitStart = unit.getOffset();
+    long unitEnd = unitStart + unit.getLength();
+    long start = unitStart;
+
+    while (start < unitEnd) {
+      long partEnd = Math.min(start + bufferSize, unitEnd);
+
+      CombinedFileRange part =
+          new CombinedFileRange(start, partEnd, unit.getUnderlying().get(0));
+      part.getUnderlying().clear();
+
+      for (FileRange r : unit.getUnderlying()) {
+        long rStart = r.getOffset();
+        long rEnd = rStart + r.getLength();
+        if (rEnd > start && rStart < partEnd) {
+          part.getUnderlying().add(r);
+        }
+      }
+      parts.add(part);
+      start = partEnd;
+    }
+
+    LOG.debug("splitByBufferSize: offset={}, produced {} parts",
+        unit.getOffset(), parts.size());
+    return parts;
+  }
+
+  /**
+   * Merge logical {@link FileRange}s into {@link CombinedFileRange}s using a
+   * span-first coalescing strategy.
+   *
+   * <p>Ranges are merged as long as the total span from the first offset to the
+   * end of the last range does not exceed {@code maxSpan}. Gaps between ranges
+   * are ignored.</p>
+   *
+   * @param ranges  logical file ranges to merge
+   * @param maxSpan maximum allowed span (in bytes) for a combined read
+   * @return merged {@link CombinedFileRange}s covering the input ranges
+   */
+  private List<CombinedFileRange> mergeBySpanAndGap(
+      List<? extends FileRange> ranges,
+      int maxSpan, long  fileLength) throws EOFException {
+
+    LOG.debug("mergeBySpanAndGap: rangeCount={}, maxSpan={}", ranges.size(), maxSpan);
+    List<? extends FileRange> sortedRanges = VectoredReadUtils.validateAndSortRanges(
+        ranges, Optional.of(fileLength));
+
+    List<CombinedFileRange> out = new ArrayList<>();
+    CombinedFileRange current = null;
+
+    for (FileRange r : sortedRanges) {
+      long rOffset = r.getOffset();
+      long rEnd = rOffset + r.getLength();
+
+      /* Initialize the first combined range */
+      if (current == null) {
+        current = new CombinedFileRange(rOffset, rEnd, r);
+        continue;
+      }
+
+      /* Check whether adding this range keeps the total span within the limit */
+      long newSpan = rEnd - current.getOffset();
+
+      if (newSpan <= maxSpan) {
+        current.setLength((int) newSpan);
+        current.getUnderlying().add(r);
+      } else {
+        /* Span exceeded; finalize current range and start a new one */
+        out.add(current);
+        current = new CombinedFileRange(rOffset, rEnd, r);
+      }
+    }
+
+    /* Add the final combined range, if any */
+    if (current != null) {
+      out.add(current);
+    }
+
+    LOG.debug("mergeBySpanAndGap: produced {} combined ranges", out.size());
+    return out;
+  }
+
+  /**
+   * Distributes data from a physical read buffer into the corresponding
+   * logical {@link FileRange}s.
+   *
+   * <p>This method performs a "fan-out" operation where a single physical
+   * read (represented by {@link ReadBuffer}) may contain data for multiple
+   * logical ranges. The relevant portions are copied into per-range buffers
+   * and completed once fully populated.</p>
+   *
+   * <p>Partial reads are accumulated using {@code partialBuffers} and
+   * {@code pendingBytes}. A range is only completed when all expected
+   * bytes have been received.</p>
+   *
+   * <p>Thread safety:
+   * <ul>
+   *   <li>Each logical range buffer is synchronized independently</li>
+   *   <li>Writes use {@code System.arraycopy} directly into the backing array
+   *       to avoid shared {@link ByteBuffer} position mutation</li>
+   * </ul>
+   * </p>
+   *
+   * @param buffer    the physical read buffer containing merged data
+   * @param bytesRead number of valid bytes in the buffer
+   */
+  void fanOut(ReadBuffer buffer, int bytesRead) {
+    LOG.debug("fanOut: path={}, bufferOffset={}, bytesRead={}",
+        buffer.getPath(), buffer.getOffset(), bytesRead);
+
+    List<CombinedFileRange> units = buffer.getVectoredUnits();
+    if (units == null) {
+      LOG.warn("fanOut: no vectored units found for path={}, offset={}",
+          buffer.getPath(), buffer.getOffset());
+      return;
+    }
+
+    long bufferStart = buffer.getOffset();
+    long bufferEnd = bufferStart + bytesRead;
+
+    /* Iterate over all combined logical units mapped to this buffer */
+    for (CombinedFileRange unit : units) {
+      /* Each unit may contain multiple logical FileRanges */
+      for (FileRange r : unit.getUnderlying()) {
+        CompletableFuture<ByteBuffer> future = r.getData();
+        RangeKey key = new RangeKey(r);
+
+        /* Skip already completed or cancelled ranges */
+        if (future.isCancelled()) {
+          LOG.debug("fanOut: range cancelled, cleaning up: path={}, rangeOffset={}",
+              buffer.getPath(), r.getOffset());
+          partialBuffers.remove(key);
+          pendingBytes.remove(key);
+          continue;
+        }
+        if (future.isDone()) {
+          continue;
+        }
+
+        try {
+          long rangeStart = r.getOffset();
+          long rangeEnd = rangeStart + r.getLength();
+
+          /* Compute overlap between buffer and logical range */
+          long overlapStart = Math.max(rangeStart, bufferStart);
+          long overlapEnd = Math.min(rangeEnd, bufferEnd);
+
+          /* No overlap nothing to copy */
+          if (overlapStart >= overlapEnd) {
+            LOG.debug("fanOut: no overlap for path={}, rangeOffset={}, bufferOffset={}",
+                buffer.getPath(), r.getOffset(), bufferStart);
+            continue;
+          }
+
+          int srcOffset = (int) (overlapStart - bufferStart);
+          int destOffset = (int) (overlapStart - rangeStart);
+          int length = (int) (overlapEnd - overlapStart);
+
+          LOG.debug("fanOut: copying path={}, rangeOffset={}, rangeLength={},"
+                  + " bufferOffset={}, srcOffset={}, destOffset={}, length={}",
+              buffer.getPath(), r.getOffset(), r.getLength(),
+              bufferStart, srcOffset, destOffset, length);
+
+          /* Allocate or reuse the full buffer for this logical range */
+          ByteBuffer fullBuf = partialBuffers.computeIfAbsent(
+              key, k -> buffer.getAllocator().apply(r.getLength()));
+
+          /* Track remaining bytes required to complete this range */
+          AtomicInteger pending = pendingBytes.computeIfAbsent(
+              key, k -> new AtomicInteger(r.getLength()));
+
+          synchronized (fullBuf) {
+            /* Double-check completion inside lock */
+            if (future.isDone()) {
+              continue;
+            }
+
+            ByteBuffer dst = fullBuf.duplicate();
+            dst.position(destOffset);
+            dst.put(buffer.getBuffer(), srcOffset, length);
+
+            int left = pending.addAndGet(-length);
+
+            LOG.debug("fanOut: wrote chunk: path={}, rangeOffset={}, destOffset={},"
+                    + " length={}, pendingBytes={}",
+                buffer.getPath(), r.getOffset(), destOffset, length, left);
+
+            if (left < 0) {
+              LOG.error("fanOut: pending bytes went negative  possible duplicate write:"
+                      + " path={}, rangeOffset={}, pending={}",
+                  buffer.getPath(), r.getOffset(), left);
+              future.completeExceptionally(new IllegalStateException(
+                  "Pending bytes negative for offset=" + r.getOffset()));
+              partialBuffers.remove(key);
+              pendingBytes.remove(key);
+              continue;
+            }
+
+            /* Complete future once all bytes are received */
+            if (left == 0 && !future.isDone()) {
+              /*
+               * Prepare buffer for reading.
+               * DO NOT use flip() because writes may arrive out-of-order.
+               * Instead, explicitly expose the full buffer.
+               */
+              fullBuf.position(0);
+              fullBuf.limit(fullBuf.capacity());
+
+              if (fullBuf.limit() != r.getLength()) {
+                LOG.warn("fanOut: buffer size mismatch: path={}, rangeOffset={},"
+                        + " expected={}, actual={}",
+                    buffer.getPath(), r.getOffset(), r.getLength(), fullBuf.limit());
+              }
+
+              future.complete(fullBuf);
+              partialBuffers.remove(key);
+              pendingBytes.remove(key);
+
+              LOG.debug("fanOut: completed range: path={}, rangeOffset={}, rangeLength={}",
+                  buffer.getPath(), r.getOffset(), r.getLength());
+            }
+          }
+        } catch (Exception e) {
+          LOG.warn("fanOut: exception processing range: path={}, rangeOffset={}",
+              buffer.getPath(), r.getOffset(), e);
+          partialBuffers.remove(key);
+          pendingBytes.remove(key);
+          if (!future.isDone()) {
+            future.completeExceptionally(e);
+          }
+        }
+      }
+    }
+  }
+
+  /**
+   * Fails all logical {@link FileRange}s associated with a given
+   * {@link CombinedFileRange}.
+   *
+   * <p>This method is invoked when a vectored read for the combined unit
+   * fails. It ensures that:
+   * <ul>
+   *   <li>Any partially accumulated buffers are cleaned up</li>
+   *   <li>Pending byte tracking state is removed</li>
+   *   <li>All corresponding {@link CompletableFuture}s are completed exceptionally</li>
+   * </ul>
+   * </p>
+   *
+   * @param unit the combined vectored read unit whose underlying ranges must be failed
+   * @param t    the exception that caused the failure
+   */
+  private void failUnit(CombinedFileRange unit, Throwable t) {
+    for (FileRange r : unit.getUnderlying()) {
+      RangeKey key = new RangeKey(r);
+      partialBuffers.remove(key);
+      pendingBytes.remove(key);
+      CompletableFuture<ByteBuffer> future = r.getData();
+      if (future != null && !future.isDone()) {
+        future.completeExceptionally(t);
+      }
+    }
+  }
+
+  /**
+   * Fails all {@link FileRange} futures associated with the given
+   * {@link ReadBuffer} and clears any partial state.
+   *
+   * @param buffer the read buffer whose ranges should be failed
+   * @param t      the exception causing the failure
+   */
+  void failBufferFutures(ReadBuffer buffer, Throwable t) {
+    List<CombinedFileRange> units = buffer.getVectoredUnits();
+    if (units == null) {
+      LOG.warn("fanOut: no vectored units found for path={}, offset={}",
+          buffer.getPath(), buffer.getOffset());
+      return;
+    }
+
+    for (CombinedFileRange unit : units) {
+      for (FileRange r : unit.getUnderlying()) {
+        RangeKey key = new RangeKey(r);
+        partialBuffers.remove(key);
+        pendingBytes.remove(key);
+        CompletableFuture<ByteBuffer> future = r.getData();
+        if (future != null && !future.isDone()) {
+          future.completeExceptionally(t);
+        }
+      }
+    }
+  }
+
+  /**
+   * Performs a synchronous direct read for a {@link CombinedFileRange}
+   * when pooled buffering is not available.
+   *
+   * <p>Data is accumulated into per-range partial buffers shared with
+   * {@link #fanOut}, ensuring that ranges spanning multiple chunks are
+   * correctly reassembled regardless of whether individual chunks were
+   * served via the async queue or this direct fallback path.</p>
+   *
+   * @param stream    input stream to read from
+   * @param unit      combined range to read
+   * @param allocator buffer allocator for logical ranges
+   * @throws IOException if the read fails
+   */
+  void directRead(
+      AbfsInputStream stream,
+      CombinedFileRange unit,
+      IntFunction<ByteBuffer> allocator) throws IOException {
+
+    LOG.debug("directRead: path={}, offset={}, length={}",
+        stream.getPath(), unit.getOffset(), unit.getLength());
+
+    /* Read entire combined range into a temporary buffer */
+    byte[] tmp = new byte[unit.getLength()];
+    TracingContext tracingContext = new TracingContext(stream.getTracingContext());
+    tracingContext.setReadType(ReadType.VECTORED_DIRECT_READ);
+
+    int total = 0;
+    int requested = unit.getLength();
+    while (total < requested) {
+      int n = stream.readRemote(unit.getOffset() + total, tmp, total,
+          requested - total, tracingContext);
+      if (n <= 0) {
+        throw new IOException(
+            "Unexpected end of stream during direct read: path=" + stream.getPath()
+                + ", offset=" + (unit.getOffset() + total)
+                + ", requested=" + requested);
+      }
+      total += n;
+    }
+
+    LOG.debug("directRead: read complete: path={}, offset={}, bytesRead={}",
+        stream.getPath(), unit.getOffset(), total);
+
+    long unitStart = unit.getOffset();
+    long unitEnd = unitStart + unit.getLength();
+
+    /* Distribute data to each logical FileRange */
+    for (FileRange r : unit.getUnderlying()) {
+      CompletableFuture<ByteBuffer> future = r.getData();
+      if (future == null || future.isDone()) {
+        continue;
+      }
+
+      long rangeStart = r.getOffset();
+      long rangeEnd = rangeStart + r.getLength();
+
+      /* Compute overlap between unit and logical range */
+      long overlapStart = Math.max(rangeStart, unitStart);
+      long overlapEnd = Math.min(rangeEnd, unitEnd);
+      if (overlapStart >= overlapEnd) {
+        continue;
+      }
+
+      int srcOffset = (int) (overlapStart - unitStart);
+      int destOffset = (int) (overlapStart - rangeStart);
+      int length = (int) (overlapEnd - overlapStart);
+
+      LOG.debug("directRead: copying: path={}, rangeOffset={}, rangeLength={},"
+              + " srcOffset={}, destOffset={}, length={}",
+          stream.getPath(), r.getOffset(), r.getLength(),
+          srcOffset, destOffset, length);
+
+      RangeKey key = new RangeKey(r);
+
+      /*
+       * Use the shared partialBuffers/pendingBytes maps so that ranges
+       * spanning multiple chunks are correctly reassembled even when some
+       * chunks are served via directRead and others via the async fanOut path.
+       */
+      ByteBuffer fullBuf = partialBuffers.computeIfAbsent(
+          key, k -> allocator.apply(r.getLength()));
+      AtomicInteger pending = pendingBytes.computeIfAbsent(
+          key, k -> new AtomicInteger(r.getLength()));
+
+      synchronized (fullBuf) {
+        /* Re-check inside lock in case another chunk already completed this range */
+        if (future.isDone()) {
+          continue;
+        }
+
+        if (fullBuf.hasArray()) {
+          System.arraycopy(tmp, srcOffset,
+              fullBuf.array(), fullBuf.arrayOffset() + destOffset,
+              length);
+        } else {
+          ByteBuffer dst = fullBuf.duplicate();
+          dst.position(destOffset);
+          dst.put(tmp, srcOffset, length);
+        }
+
+        int left = pending.addAndGet(-length);
+
+        LOG.debug("directRead: wrote chunk: path={}, rangeOffset={}, destOffset={},"
+                + " length={}, pendingBytes={}",
+            stream.getPath(), r.getOffset(), destOffset, length, left);
+
+        if (left < 0) {
+          LOG.error("directRead: pending bytes went negative  possible duplicate write:"
+                  + " path={}, rangeOffset={}, pending={}",
+              stream.getPath(), r.getOffset(), left);
+          future.completeExceptionally(new IllegalStateException(
+              "Pending bytes negative in directRead for offset=" + r.getOffset()));
+          partialBuffers.remove(key);
+          pendingBytes.remove(key);
+          continue;
+        }
+
+        if (left == 0) {
+          fullBuf.position(0);
+          fullBuf.limit(r.getLength());
+          future.complete(fullBuf);
+          partialBuffers.remove(key);
+          pendingBytes.remove(key);
+          LOG.debug("directRead: completed range: path={}, rangeOffset={}, rangeLength={}",
+              stream.getPath(), r.getOffset(), r.getLength());
+        }
+      }
+    }
+  }
+
+  /**
+   * Identity-based key wrapper for {@link FileRange}.
+   *
+   * <p>This class ensures that {@link FileRange} instances are compared
+   * using reference equality rather than logical equality. It is used as
+   * a key in maps where multiple ranges may have identical offsets and
+   * lengths but must be treated as distinct objects.</p>
+   *
+   * <p>Equality and hash code are based on object identity
+   * ({@code ==}) via {@link System#identityHashCode(Object)}.</p>
+   */
+  static final class RangeKey {
+    private final FileRange range;
+
+    RangeKey(FileRange range) {
+      this.range = range;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      return this == o || (o instanceof RangeKey && this.range == ((RangeKey) o).range);
+    }
+
+    @Override
+    public int hashCode() {
+      return System.identityHashCode(range);
+    }
+  }
+}

Review Comment:
   nit: EOF



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "manika137 (via GitHub)" <gi...@apache.org>.
manika137 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3067898915


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/VectoredReadHandler.java:
##########
@@ -0,0 +1,696 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.IntFunction;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.classification.VisibleForTesting;
+import org.apache.hadoop.fs.FileRange;
+import org.apache.hadoop.fs.VectoredReadUtils;
+import org.apache.hadoop.fs.azurebfs.constants.ReadType;
+import org.apache.hadoop.fs.azurebfs.enums.VectoredReadStrategy;
+import org.apache.hadoop.fs.azurebfs.utils.TracingContext;
+import org.apache.hadoop.fs.impl.CombinedFileRange;
+
+/**
+ * Handles vectored read operations by coordinating with a ReadBufferManager
+ * and applying the configured VectoredReadStrategy.
+ * This class acts as the orchestration layer that decides how vectored reads
+ * are executed, while delegating buffer management and read behavior to
+ * dedicated components.
+ */
+class VectoredReadHandler {
+
+  private static final Logger LOG = LoggerFactory.getLogger(VectoredReadHandler.class);
+
+  /**
+   * Manages allocation, lifecycle, and reuse of read buffers
+   * used during vectored read operations.
+   */
+  private final ReadBufferManager readBufferManager;
+
+  /**
+   * Strategy defining how vectored reads should be performed.
+   */
+  private final VectoredReadStrategy strategy;
+
+  /**
+   * Shared reconstruction buffers for ranges that span multiple chunks.
+   * Keyed by the original FileRange instance.
+   */
+  private final ConcurrentHashMap<RangeKey, ByteBuffer> partialBuffers =
+      new ConcurrentHashMap<>();
+
+  /**
+   * Tracks remaining bytes to be received for each logical range.
+   * Keyed by the original FileRange instance.
+   */
+  private final ConcurrentHashMap<RangeKey, AtomicInteger> pendingBytes =
+      new ConcurrentHashMap<>();
+
+  /**
+   * Creates a VectoredReadHandler using the provided ReadBufferManager.
+   * The vectored read strategy is obtained from the manager to ensure
+   * consistent configuration across the read pipeline.
+   *
+   * @param readBufferManager manager responsible for buffer handling
+   *                          and providing the vectored read strategy
+   */
+  VectoredReadHandler(ReadBufferManager readBufferManager) {
+    this.readBufferManager = readBufferManager;
+    this.strategy = readBufferManager.getVectoredReadStrategy();
+    LOG.debug("VectoredReadHandler initialized with strategy={}", strategy);
+  }
+
+  /**
+   * Perform a vectored read over multiple logical file ranges.
+   *
+   * <p>Logical ranges are first merged using a span-first strategy determined
+   * by the configured {@link VectoredReadStrategy}. The merged ranges are then
+   * split into buffer-sized physical read units and queued for asynchronous
+   * execution. If a pooled buffer is unavailable, the read falls back to a
+   * direct read path.</p>
+   *
+   * @param stream    input stream for the file being read
+   * @param ranges    logical file ranges to read; each range will be completed
+   *                  with data or failure via its associated future
+   * @param allocator allocator used to create buffers for direct reads and
+   *                  vectored fan-out
+   */
+  public void readVectored(
+      AbfsInputStream stream,
+      List<? extends FileRange> ranges,
+      IntFunction<ByteBuffer> allocator) throws EOFException {
+    LOG.debug("readVectored invoked: path={}, rangeCount={}",
+        stream.getPath(), ranges.size());
+
+    /* Initialize a future for each logical file range */
+    long fileLength = stream.getContentLength();
+    List<FileRange> validRanges = validateAndPrepareRanges(ranges, fileLength);
+
+    /* Select the maximum allowed merge span based on the configured strategy */
+    int maxSpan =
+        (strategy == VectoredReadStrategy.TPS_OPTIMIZED)
+            ? readBufferManager.getMaxSeekForVectoredReads()
+            : readBufferManager.getMaxSeekForVectoredReadsThroughput();
+
+    LOG.debug("readVectored: path={}, strategy={}, maxSpan={}",
+        stream.getPath(), strategy, maxSpan);
+
+    /* Merge logical ranges using a span-first coalescing strategy */
+    List<CombinedFileRange> merged = mergeBySpanAndGap(validRanges, maxSpan, fileLength);
+
+    LOG.debug("readVectored: path={}, mergedRangeCount={}",
+        stream.getPath(), merged.size());
+
+    /* Read buffer size acts as a hard upper bound for physical reads */
+    int readBufferSize = ReadBufferManager.getReadAheadBlockSize();
+
+    /* Split merged ranges into buffer-sized chunks and queue each for read */
+    for (CombinedFileRange unit : merged) {
+      List<CombinedFileRange> chunks = splitByBufferSize(unit, readBufferSize);
+
+      LOG.debug("readVectored: path={}, mergedOffset={}, mergedLength={}, chunkCount={}",
+          stream.getPath(), unit.getOffset(), unit.getLength(), chunks.size());
+
+      for (CombinedFileRange chunk : chunks) {
+        try {
+          VectoredReadUtils.validateRangeRequest(chunk);
+          boolean queued = queueVectoredRead(stream, chunk, allocator);
+          if (!queued) {
+            LOG.debug("readVectored: buffer pool exhausted, falling back to directRead: path={}, offset={}, length={}",
+                stream.getPath(), chunk.getOffset(), chunk.getLength());
+            directRead(stream, chunk, allocator);
+          }
+        } catch (Exception e) {
+          LOG.warn("readVectored: chunk read failed, failing underlying ranges:"
+                  + " path={}, offset={}, length={}",
+              stream.getPath(), chunk.getOffset(), chunk.getLength(), e);
+          failUnit(chunk, e);
+        }
+      }
+    }
+  }
+
+  /**
+   * Queues a vectored read request with the buffer manager.
+   *
+   * @return true if successfully queued, false if the queue is full and fallback is required.
+   */
+  @VisibleForTesting
+  boolean queueVectoredRead(AbfsInputStream stream, CombinedFileRange unit,
+      IntFunction<ByteBuffer> allocator) {
+    LOG.debug("queueVectoredRead: path={}, offset={}, length={}",
+        stream.getPath(), unit.getOffset(), unit.getLength());
+    TracingContext tracingContext = stream.getTracingContext();
+    tracingContext.setReadType(ReadType.VECTORED_READ);
+    return getReadBufferManager().queueVectoredRead(stream, unit, tracingContext, allocator);
+  }
+
+  /**
+   * Accesses the shared manager responsible for coordinating asynchronous read buffers.
+   *
+   * @return the {@link ReadBufferManager} instance.
+   */
+  public ReadBufferManager getReadBufferManager() {
+    return readBufferManager;
+  }
+
+  /**
+   * Validates and prepares a list of {@link FileRange} instances for vectored reads.
+   *
+   * <p>This method performs the following steps for each input range:
+   * <ul>
+   *   <li>Validates the range using {@link VectoredReadUtils#validateRangeRequest(FileRange)}</li>
+   *   <li>Initializes a {@link CompletableFuture} to hold the read result</li>
+   *   <li>Checks that the range falls within the bounds of the file</li>
+   * </ul>
+   *
+   * <p>Ranges that are invalid (e.g., negative offset/length or exceeding file bounds)
+   * are not included in the returned list. Instead, their associated future is
+   * completed exceptionally with an {@link EOFException}.
+   *
+   * @param ranges     the input list of logical file ranges to validate and prepare
+   * @param fileLength the total length of the file, used for bounds checking
+   * @return a list of valid {@link FileRange} instances ready for vectored read processing
+   */
+  private List<FileRange> validateAndPrepareRanges(
+      List<? extends FileRange> ranges, long fileLength) throws EOFException {
+
+    List<FileRange> validRanges = new ArrayList<>();
+
+    for (FileRange r : ranges) {
+      VectoredReadUtils.validateRangeRequest(r);
+      r.setData(new CompletableFuture<>());
+
+      long offset = r.getOffset();
+      long length = r.getLength();
+
+      if (offset < 0 || length < 0 || offset > fileLength || length > fileLength - offset) {
+        r.getData().completeExceptionally(new EOFException(
+            "Invalid range: offset=" + offset + ", length=" + length + ", fileLength=" + fileLength));
+        continue;
+      }
+      validRanges.add(r);
+    }
+    return validRanges;
+  }
+
+  /**
+   * Splits a merged logical {@link CombinedFileRange} into smaller
+   * buffer-sized physical read units.
+   *
+   * <p>Each resulting unit will have a maximum size equal to the provided
+   * {@code bufferSize}. Any handling of multi-chunk ranges or reassembly
+   * of underlying {@link FileRange} data is delegated to the fan-out logic.</p>
+   *
+   * @param unit       the combined logical range to be split
+   * @param bufferSize the maximum size (in bytes) of each physical read unit
+   * @return a list of buffer-sized {@link CombinedFileRange} instances
+   */
+  private List<CombinedFileRange> splitByBufferSize(
+      CombinedFileRange unit,
+      int bufferSize) {
+    LOG.debug("splitByBufferSize: offset={}, length={}, bufferSize={}",
+        unit.getOffset(), unit.getLength(), bufferSize);
+
+    List<CombinedFileRange> parts = new ArrayList<>();
+    long unitStart = unit.getOffset();
+    long unitEnd = unitStart + unit.getLength();
+    long start = unitStart;
+
+    while (start < unitEnd) {
+      long partEnd = Math.min(start + bufferSize, unitEnd);
+
+      CombinedFileRange part =
+          new CombinedFileRange(start, partEnd, unit.getUnderlying().get(0));
+      part.getUnderlying().clear();
+
+      for (FileRange r : unit.getUnderlying()) {
+        long rStart = r.getOffset();
+        long rEnd = rStart + r.getLength();
+        if (rEnd > start && rStart < partEnd) {
+          part.getUnderlying().add(r);
+        }
+      }
+      parts.add(part);
+      start = partEnd;
+    }
+
+    LOG.debug("splitByBufferSize: offset={}, produced {} parts",
+        unit.getOffset(), parts.size());
+    return parts;
+  }
+
+  /**
+   * Merge logical {@link FileRange}s into {@link CombinedFileRange}s using a
+   * span-first coalescing strategy.
+   *
+   * <p>Ranges are merged as long as the total span from the first offset to the
+   * end of the last range does not exceed {@code maxSpan}. Gaps between ranges
+   * are ignored.</p>
+   *
+   * @param ranges  logical file ranges to merge
+   * @param maxSpan maximum allowed span (in bytes) for a combined read
+   * @return merged {@link CombinedFileRange}s covering the input ranges
+   */
+  private List<CombinedFileRange> mergeBySpanAndGap(
+      List<? extends FileRange> ranges,
+      int maxSpan, long  fileLength) throws EOFException {
+
+    LOG.debug("mergeBySpanAndGap: rangeCount={}, maxSpan={}", ranges.size(), maxSpan);
+    List<? extends FileRange> sortedRanges = VectoredReadUtils.validateAndSortRanges(
+        ranges, Optional.of(fileLength));
+
+    List<CombinedFileRange> out = new ArrayList<>();
+    CombinedFileRange current = null;
+
+    for (FileRange r : sortedRanges) {
+      long rOffset = r.getOffset();
+      long rEnd = rOffset + r.getLength();
+
+      /* Initialize the first combined range */
+      if (current == null) {
+        current = new CombinedFileRange(rOffset, rEnd, r);
+        continue;
+      }
+
+      /* Check whether adding this range keeps the total span within the limit */
+      long newSpan = rEnd - current.getOffset();
+
+      if (newSpan <= maxSpan) {
+        current.setLength((int) newSpan);
+        current.getUnderlying().add(r);
+      } else {
+        /* Span exceeded; finalize current range and start a new one */
+        out.add(current);
+        current = new CombinedFileRange(rOffset, rEnd, r);
+      }
+    }
+
+    /* Add the final combined range, if any */
+    if (current != null) {
+      out.add(current);
+    }
+
+    LOG.debug("mergeBySpanAndGap: produced {} combined ranges", out.size());
+    return out;
+  }
+
+  /**
+   * Distributes data from a physical read buffer into the corresponding
+   * logical {@link FileRange}s.
+   *
+   * <p>This method performs a "fan-out" operation where a single physical
+   * read (represented by {@link ReadBuffer}) may contain data for multiple
+   * logical ranges. The relevant portions are copied into per-range buffers
+   * and completed once fully populated.</p>
+   *
+   * <p>Partial reads are accumulated using {@code partialBuffers} and
+   * {@code pendingBytes}. A range is only completed when all expected
+   * bytes have been received.</p>
+   *
+   * <p>Thread safety:
+   * <ul>
+   *   <li>Each logical range buffer is synchronized independently</li>
+   *   <li>Writes use {@code System.arraycopy} directly into the backing array
+   *       to avoid shared {@link ByteBuffer} position mutation</li>
+   * </ul>
+   * </p>
+   *
+   * @param buffer    the physical read buffer containing merged data
+   * @param bytesRead number of valid bytes in the buffer
+   */
+  void fanOut(ReadBuffer buffer, int bytesRead) {
+    LOG.debug("fanOut: path={}, bufferOffset={}, bytesRead={}",
+        buffer.getPath(), buffer.getOffset(), bytesRead);
+
+    List<CombinedFileRange> units = buffer.getVectoredUnits();
+    if (units == null) {
+      LOG.warn("fanOut: no vectored units found for path={}, offset={}",
+          buffer.getPath(), buffer.getOffset());
+      return;
+    }
+
+    long bufferStart = buffer.getOffset();
+    long bufferEnd = bufferStart + bytesRead;
+
+    /* Iterate over all combined logical units mapped to this buffer */
+    for (CombinedFileRange unit : units) {

Review Comment:
   could the following scenario be possible: while we fan-out here, we have another vectorRead call come in overlapping the ranges shared by this buffer and getting attached to the same buffer as a unit



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3077908179


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBuffer.java:
##########
@@ -199,4 +212,67 @@ public void setAnyByteConsumed(boolean isAnyByteConsumed) {
   public boolean isFullyConsumed() {
     return isFirstByteConsumed() && isLastByteConsumed();
   }
+
+  void addVectoredUnit(CombinedFileRange u) {

Review Comment:
   Added



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "hadoop-yetus (via GitHub)" <gi...@apache.org>.
hadoop-yetus commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4180829904

   :confetti_ball: **+1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime |  Logfile | Comment |
   |:----:|----------:|--------:|:--------:|:-------:|
   | +0 :ok: |  reexec  |   0m 52s |  |  Docker mode activated.  |
   |||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  1s |  |  No case conflicting files found.  |
   | +0 :ok: |  codespell  |   0m  0s |  |  codespell was not available.  |
   | +0 :ok: |  detsecrets  |   0m  0s |  |  detect-secrets was not available.  |
   | +1 :green_heart: |  @author  |   0m  0s |  |  The patch does not contain any @author tags.  |
   | +1 :green_heart: |  test4tests  |   0m  0s |  |  The patch appears to include 2 new or modified test files.  |
   |||| _ trunk Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  47m 14s |  |  trunk passed  |
   | +1 :green_heart: |  compile  |   1m  1s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  compile  |   1m  3s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  checkstyle  |   0m 56s |  |  trunk passed  |
   | +1 :green_heart: |  mvnsite  |   1m  7s |  |  trunk passed  |
   | +1 :green_heart: |  javadoc  |   0m 59s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 57s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 36s |  |  trunk passed  |
   | +1 :green_heart: |  shadedclient  |  34m  1s |  |  branch has no errors when building and testing our client artifacts.  |
   | -0 :warning: |  patch  |  34m 33s |  |  Used diff version of patch file. Binary files and potentially other changes not applied. Please rebase and squash commits if necessary.  |
   |||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   0m 37s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 32s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javac  |   0m 32s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 34s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  javac  |   0m 34s |  |  the patch passed  |
   | +1 :green_heart: |  blanks  |   0m  0s |  |  The patch has no blanks issues.  |
   | -0 :warning: |  checkstyle  |   0m 25s | [/results-checkstyle-hadoop-tools_hadoop-azure.txt](https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/2/artifact/out/results-checkstyle-hadoop-tools_hadoop-azure.txt) |  hadoop-tools/hadoop-azure: The patch generated 1 new + 5 unchanged - 0 fixed = 6 total (was 5)  |
   | +1 :green_heart: |  mvnsite  |   0m 39s |  |  the patch passed  |
   | +1 :green_heart: |  javadoc  |   0m 28s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 29s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 16s |  |  the patch passed  |
   | +1 :green_heart: |  shadedclient  |  33m 33s |  |  patch has no errors when building and testing our client artifacts.  |
   |||| _ Other Tests _ |
   | +1 :green_heart: |  unit  |   2m  8s |  |  hadoop-azure in the patch passed.  |
   | +1 :green_heart: |  asflicense  |   0m 35s |  |  The patch does not generate ASF License warnings.  |
   |  |   | 133m 20s |  |  |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/2/artifact/out/Dockerfile |
   | GITHUB PR | https://github.com/apache/hadoop/pull/8400 |
   | Optional Tests | dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets |
   | uname | Linux ad47bd66149a 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | dev-support/bin/hadoop.sh |
   | git revision | trunk / 975bf739d2d8bc1f1f7acd86f0a3d14d9dae5341 |
   | Default Java | Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   | Multi-JDK versions | /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   |  Test Results | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/2/testReport/ |
   | Max. process+thread count | 586 (vs. ulimit of 10000) |
   | modules | C: hadoop-tools/hadoop-azure U: hadoop-tools/hadoop-azure |
   | Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/2/console |
   | versions | git=2.43.0 maven=3.9.11 spotbugs=4.9.7 |
   | Powered by | Apache Yetus 0.14.1 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3071281885


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -160,12 +171,16 @@ static ReadBufferManagerV2 getBufferManager(AbfsCounters abfsCounters) {
     return bufferManager;
   }
 
+VectoredReadHandler getVectoredReadHandler() {
+    return vectoredReadHandler;
+  }
+
   /**
    * Set the ReadBufferManagerV2 configurations based on the provided before singleton initialization.
    * @param readAheadBlockSize the read-ahead block size to set for the ReadBufferManagerV2.
    * @param abfsConfiguration the configuration to set for the ReadBufferManagerV2.
    */
-  public static void setReadBufferManagerConfigs(final int readAheadBlockSize,
+  public static void setReadBufferManagerConfigs(int readAheadBlockSize,

Review Comment:
   reverted



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "hadoop-yetus (via GitHub)" <gi...@apache.org>.
hadoop-yetus commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4192669655

   :confetti_ball: **+1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime |  Logfile | Comment |
   |:----:|----------:|--------:|:--------:|:-------:|
   | +0 :ok: |  reexec  |  19m 11s |  |  Docker mode activated.  |
   |||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  0s |  |  No case conflicting files found.  |
   | +0 :ok: |  codespell  |   0m  1s |  |  codespell was not available.  |
   | +0 :ok: |  detsecrets  |   0m  1s |  |  detect-secrets was not available.  |
   | +0 :ok: |  xmllint  |   0m  1s |  |  xmllint was not available.  |
   | +1 :green_heart: |  @author  |   0m  0s |  |  The patch does not contain any @author tags.  |
   | +1 :green_heart: |  test4tests  |   0m  0s |  |  The patch appears to include 2 new or modified test files.  |
   |||| _ trunk Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  47m  1s |  |  trunk passed  |
   | +1 :green_heart: |  compile  |   1m  0s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  compile  |   1m  2s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  checkstyle  |   0m 55s |  |  trunk passed  |
   | +1 :green_heart: |  mvnsite  |   1m  5s |  |  trunk passed  |
   | +1 :green_heart: |  javadoc  |   0m 59s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 55s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 33s |  |  trunk passed  |
   | +1 :green_heart: |  shadedclient  |  33m 26s |  |  branch has no errors when building and testing our client artifacts.  |
   | -0 :warning: |  patch  |  33m 57s |  |  Used diff version of patch file. Binary files and potentially other changes not applied. Please rebase and squash commits if necessary.  |
   |||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   0m 36s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 32s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javac  |   0m 32s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 35s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  javac  |   0m 35s |  |  the patch passed  |
   | +1 :green_heart: |  blanks  |   0m  0s |  |  The patch has no blanks issues.  |
   | +1 :green_heart: |  checkstyle  |   0m 25s |  |  the patch passed  |
   | +1 :green_heart: |  mvnsite  |   0m 38s |  |  the patch passed  |
   | +1 :green_heart: |  javadoc  |   0m 28s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 28s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 18s |  |  the patch passed  |
   | +1 :green_heart: |  shadedclient  |  32m 49s |  |  patch has no errors when building and testing our client artifacts.  |
   |||| _ Other Tests _ |
   | +1 :green_heart: |  unit  |   2m  9s |  |  hadoop-azure in the patch passed.  |
   | +1 :green_heart: |  asflicense  |   0m 35s |  |  The patch does not generate ASF License warnings.  |
   |  |   | 149m 33s |  |  |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/5/artifact/out/Dockerfile |
   | GITHUB PR | https://github.com/apache/hadoop/pull/8400 |
   | Optional Tests | dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient codespell detsecrets xmllint spotbugs checkstyle |
   | uname | Linux bcec24f39c71 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | dev-support/bin/hadoop.sh |
   | git revision | trunk / 4f8f7554f68a618c6a6c6d026b87cc143bbf24a8 |
   | Default Java | Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   | Multi-JDK versions | /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   |  Test Results | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/5/testReport/ |
   | Max. process+thread count | 570 (vs. ulimit of 10000) |
   | modules | C: hadoop-tools/hadoop-azure U: hadoop-tools/hadoop-azure |
   | Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/5/console |
   | versions | git=2.43.0 maven=3.9.11 spotbugs=4.9.7 |
   | Powered by | Apache Yetus 0.14.1 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "hadoop-yetus (via GitHub)" <gi...@apache.org>.
hadoop-yetus commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4183054787

   :confetti_ball: **+1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime |  Logfile | Comment |
   |:----:|----------:|--------:|:--------:|:-------:|
   | +0 :ok: |  reexec  |   0m 52s |  |  Docker mode activated.  |
   |||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  1s |  |  No case conflicting files found.  |
   | +0 :ok: |  codespell  |   0m  0s |  |  codespell was not available.  |
   | +0 :ok: |  detsecrets  |   0m  0s |  |  detect-secrets was not available.  |
   | +0 :ok: |  xmllint  |   0m  0s |  |  xmllint was not available.  |
   | +1 :green_heart: |  @author  |   0m  0s |  |  The patch does not contain any @author tags.  |
   | +1 :green_heart: |  test4tests  |   0m  0s |  |  The patch appears to include 2 new or modified test files.  |
   |||| _ trunk Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  46m 40s |  |  trunk passed  |
   | +1 :green_heart: |  compile  |   1m  2s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  compile  |   1m  3s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  checkstyle  |   0m 56s |  |  trunk passed  |
   | +1 :green_heart: |  mvnsite  |   1m  7s |  |  trunk passed  |
   | +1 :green_heart: |  javadoc  |   0m 58s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 54s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 31s |  |  trunk passed  |
   | +1 :green_heart: |  shadedclient  |  34m 49s |  |  branch has no errors when building and testing our client artifacts.  |
   | -0 :warning: |  patch  |  35m 23s |  |  Used diff version of patch file. Binary files and potentially other changes not applied. Please rebase and squash commits if necessary.  |
   |||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   0m 36s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 33s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javac  |   0m 33s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 34s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  javac  |   0m 34s |  |  the patch passed  |
   | +1 :green_heart: |  blanks  |   0m  0s |  |  The patch has no blanks issues.  |
   | +1 :green_heart: |  checkstyle  |   0m 26s |  |  the patch passed  |
   | +1 :green_heart: |  mvnsite  |   0m 39s |  |  the patch passed  |
   | +1 :green_heart: |  javadoc  |   0m 29s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 29s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 16s |  |  the patch passed  |
   | +1 :green_heart: |  shadedclient  |  32m 54s |  |  patch has no errors when building and testing our client artifacts.  |
   |||| _ Other Tests _ |
   | +1 :green_heart: |  unit  |   2m  9s |  |  hadoop-azure in the patch passed.  |
   | +1 :green_heart: |  asflicense  |   0m 35s |  |  The patch does not generate ASF License warnings.  |
   |  |   | 132m 41s |  |  |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/3/artifact/out/Dockerfile |
   | GITHUB PR | https://github.com/apache/hadoop/pull/8400 |
   | Optional Tests | dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient codespell detsecrets xmllint spotbugs checkstyle |
   | uname | Linux 66df0e5ca7be 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | dev-support/bin/hadoop.sh |
   | git revision | trunk / ba7c9ff404bf445cf1841c36f084e2e9da2a4ac2 |
   | Default Java | Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   | Multi-JDK versions | /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   |  Test Results | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/3/testReport/ |
   | Max. process+thread count | 638 (vs. ulimit of 10000) |
   | modules | C: hadoop-tools/hadoop-azure U: hadoop-tools/hadoop-azure |
   | Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/3/console |
   | versions | git=2.43.0 maven=3.9.11 spotbugs=4.9.7 |
   | Powered by | Apache Yetus 0.14.1 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3085889232


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStream.java:
##########
@@ -1184,7 +1209,7 @@ ReadBufferManager getReadBufferManager() {
    */
   @Override
   public int minSeekForVectorReads() {

Review Comment:
   In case of Azure, we do 4 MB buffer reads, so if don't do coalescing, we are wasting a lot of read data per range and hence we found that merging ranges which fall in one buffer i.e. 4 MB is giving better results



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3115829412


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -427,27 +558,84 @@ public ReadBuffer getNextBlockToRead() throws InterruptedException {
   public void doneReading(final ReadBuffer buffer,
       final ReadBufferStatus result,
       final int bytesActuallyRead) {
-    printTraceLog(
-        "ReadBufferWorker completed prefetch for file: {} with eTag: {}, for offset: {}, queued by stream: {}, with status: {} and bytes read: {}",
-        buffer.getPath(), buffer.getETag(), buffer.getOffset(),
-        buffer.getStream().hashCode(), result, bytesActuallyRead);
+    if (LOGGER.isTraceEnabled()) {

Review Comment:
   taken



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3071254102


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/VectoredReadHandler.java:
##########
@@ -0,0 +1,696 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.IntFunction;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.classification.VisibleForTesting;
+import org.apache.hadoop.fs.FileRange;
+import org.apache.hadoop.fs.VectoredReadUtils;
+import org.apache.hadoop.fs.azurebfs.constants.ReadType;
+import org.apache.hadoop.fs.azurebfs.enums.VectoredReadStrategy;
+import org.apache.hadoop.fs.azurebfs.utils.TracingContext;
+import org.apache.hadoop.fs.impl.CombinedFileRange;
+
+/**
+ * Handles vectored read operations by coordinating with a ReadBufferManager
+ * and applying the configured VectoredReadStrategy.
+ * This class acts as the orchestration layer that decides how vectored reads
+ * are executed, while delegating buffer management and read behavior to
+ * dedicated components.
+ */
+class VectoredReadHandler {
+
+  private static final Logger LOG = LoggerFactory.getLogger(VectoredReadHandler.class);
+
+  /**
+   * Manages allocation, lifecycle, and reuse of read buffers
+   * used during vectored read operations.
+   */
+  private final ReadBufferManager readBufferManager;
+
+  /**
+   * Strategy defining how vectored reads should be performed.
+   */
+  private final VectoredReadStrategy strategy;
+
+  /**
+   * Shared reconstruction buffers for ranges that span multiple chunks.
+   * Keyed by the original FileRange instance.
+   */
+  private final ConcurrentHashMap<RangeKey, ByteBuffer> partialBuffers =
+      new ConcurrentHashMap<>();
+
+  /**
+   * Tracks remaining bytes to be received for each logical range.
+   * Keyed by the original FileRange instance.
+   */
+  private final ConcurrentHashMap<RangeKey, AtomicInteger> pendingBytes =
+      new ConcurrentHashMap<>();
+
+  /**
+   * Creates a VectoredReadHandler using the provided ReadBufferManager.
+   * The vectored read strategy is obtained from the manager to ensure
+   * consistent configuration across the read pipeline.
+   *
+   * @param readBufferManager manager responsible for buffer handling
+   *                          and providing the vectored read strategy
+   */
+  VectoredReadHandler(ReadBufferManager readBufferManager) {
+    this.readBufferManager = readBufferManager;
+    this.strategy = readBufferManager.getVectoredReadStrategy();
+    LOG.debug("VectoredReadHandler initialized with strategy={}", strategy);
+  }
+
+  /**
+   * Perform a vectored read over multiple logical file ranges.
+   *
+   * <p>Logical ranges are first merged using a span-first strategy determined
+   * by the configured {@link VectoredReadStrategy}. The merged ranges are then
+   * split into buffer-sized physical read units and queued for asynchronous
+   * execution. If a pooled buffer is unavailable, the read falls back to a
+   * direct read path.</p>
+   *
+   * @param stream    input stream for the file being read
+   * @param ranges    logical file ranges to read; each range will be completed
+   *                  with data or failure via its associated future
+   * @param allocator allocator used to create buffers for direct reads and
+   *                  vectored fan-out
+   */
+  public void readVectored(
+      AbfsInputStream stream,
+      List<? extends FileRange> ranges,
+      IntFunction<ByteBuffer> allocator) throws EOFException {
+    LOG.debug("readVectored invoked: path={}, rangeCount={}",
+        stream.getPath(), ranges.size());
+
+    /* Initialize a future for each logical file range */
+    long fileLength = stream.getContentLength();
+    List<FileRange> validRanges = validateAndPrepareRanges(ranges, fileLength);
+
+    /* Select the maximum allowed merge span based on the configured strategy */
+    int maxSpan =
+        (strategy == VectoredReadStrategy.TPS_OPTIMIZED)
+            ? readBufferManager.getMaxSeekForVectoredReads()
+            : readBufferManager.getMaxSeekForVectoredReadsThroughput();
+
+    LOG.debug("readVectored: path={}, strategy={}, maxSpan={}",
+        stream.getPath(), strategy, maxSpan);
+
+    /* Merge logical ranges using a span-first coalescing strategy */
+    List<CombinedFileRange> merged = mergeBySpanAndGap(validRanges, maxSpan, fileLength);
+
+    LOG.debug("readVectored: path={}, mergedRangeCount={}",
+        stream.getPath(), merged.size());
+
+    /* Read buffer size acts as a hard upper bound for physical reads */
+    int readBufferSize = ReadBufferManager.getReadAheadBlockSize();
+
+    /* Split merged ranges into buffer-sized chunks and queue each for read */
+    for (CombinedFileRange unit : merged) {
+      List<CombinedFileRange> chunks = splitByBufferSize(unit, readBufferSize);
+
+      LOG.debug("readVectored: path={}, mergedOffset={}, mergedLength={}, chunkCount={}",
+          stream.getPath(), unit.getOffset(), unit.getLength(), chunks.size());
+
+      for (CombinedFileRange chunk : chunks) {
+        try {
+          VectoredReadUtils.validateRangeRequest(chunk);
+          boolean queued = queueVectoredRead(stream, chunk, allocator);
+          if (!queued) {
+            LOG.debug("readVectored: buffer pool exhausted, falling back to directRead: path={}, offset={}, length={}",
+                stream.getPath(), chunk.getOffset(), chunk.getLength());
+            directRead(stream, chunk, allocator);
+          }
+        } catch (Exception e) {
+          LOG.warn("readVectored: chunk read failed, failing underlying ranges:"
+                  + " path={}, offset={}, length={}",
+              stream.getPath(), chunk.getOffset(), chunk.getLength(), e);
+          failUnit(chunk, e);
+        }
+      }
+    }
+  }
+
+  /**
+   * Queues a vectored read request with the buffer manager.
+   *
+   * @return true if successfully queued, false if the queue is full and fallback is required.
+   */
+  @VisibleForTesting
+  boolean queueVectoredRead(AbfsInputStream stream, CombinedFileRange unit,
+      IntFunction<ByteBuffer> allocator) {
+    LOG.debug("queueVectoredRead: path={}, offset={}, length={}",
+        stream.getPath(), unit.getOffset(), unit.getLength());
+    TracingContext tracingContext = stream.getTracingContext();
+    tracingContext.setReadType(ReadType.VECTORED_READ);
+    return getReadBufferManager().queueVectoredRead(stream, unit, tracingContext, allocator);
+  }
+
+  /**
+   * Accesses the shared manager responsible for coordinating asynchronous read buffers.
+   *
+   * @return the {@link ReadBufferManager} instance.
+   */
+  public ReadBufferManager getReadBufferManager() {
+    return readBufferManager;
+  }
+
+  /**
+   * Validates and prepares a list of {@link FileRange} instances for vectored reads.
+   *
+   * <p>This method performs the following steps for each input range:
+   * <ul>
+   *   <li>Validates the range using {@link VectoredReadUtils#validateRangeRequest(FileRange)}</li>
+   *   <li>Initializes a {@link CompletableFuture} to hold the read result</li>
+   *   <li>Checks that the range falls within the bounds of the file</li>
+   * </ul>
+   *
+   * <p>Ranges that are invalid (e.g., negative offset/length or exceeding file bounds)
+   * are not included in the returned list. Instead, their associated future is
+   * completed exceptionally with an {@link EOFException}.
+   *
+   * @param ranges     the input list of logical file ranges to validate and prepare
+   * @param fileLength the total length of the file, used for bounds checking
+   * @return a list of valid {@link FileRange} instances ready for vectored read processing
+   */
+  private List<FileRange> validateAndPrepareRanges(
+      List<? extends FileRange> ranges, long fileLength) throws EOFException {
+
+    List<FileRange> validRanges = new ArrayList<>();
+
+    for (FileRange r : ranges) {
+      VectoredReadUtils.validateRangeRequest(r);
+      r.setData(new CompletableFuture<>());
+
+      long offset = r.getOffset();
+      long length = r.getLength();
+
+      if (offset < 0 || length < 0 || offset > fileLength || length > fileLength - offset) {
+        r.getData().completeExceptionally(new EOFException(
+            "Invalid range: offset=" + offset + ", length=" + length + ", fileLength=" + fileLength));
+        continue;
+      }
+      validRanges.add(r);
+    }
+    return validRanges;
+  }
+
+  /**
+   * Splits a merged logical {@link CombinedFileRange} into smaller
+   * buffer-sized physical read units.
+   *
+   * <p>Each resulting unit will have a maximum size equal to the provided
+   * {@code bufferSize}. Any handling of multi-chunk ranges or reassembly
+   * of underlying {@link FileRange} data is delegated to the fan-out logic.</p>
+   *
+   * @param unit       the combined logical range to be split
+   * @param bufferSize the maximum size (in bytes) of each physical read unit
+   * @return a list of buffer-sized {@link CombinedFileRange} instances
+   */
+  private List<CombinedFileRange> splitByBufferSize(
+      CombinedFileRange unit,
+      int bufferSize) {
+    LOG.debug("splitByBufferSize: offset={}, length={}, bufferSize={}",
+        unit.getOffset(), unit.getLength(), bufferSize);
+
+    List<CombinedFileRange> parts = new ArrayList<>();
+    long unitStart = unit.getOffset();
+    long unitEnd = unitStart + unit.getLength();
+    long start = unitStart;
+
+    while (start < unitEnd) {
+      long partEnd = Math.min(start + bufferSize, unitEnd);
+
+      CombinedFileRange part =
+          new CombinedFileRange(start, partEnd, unit.getUnderlying().get(0));
+      part.getUnderlying().clear();
+
+      for (FileRange r : unit.getUnderlying()) {
+        long rStart = r.getOffset();
+        long rEnd = rStart + r.getLength();
+        if (rEnd > start && rStart < partEnd) {
+          part.getUnderlying().add(r);
+        }
+      }
+      parts.add(part);
+      start = partEnd;
+    }
+
+    LOG.debug("splitByBufferSize: offset={}, produced {} parts",
+        unit.getOffset(), parts.size());
+    return parts;
+  }
+
+  /**
+   * Merge logical {@link FileRange}s into {@link CombinedFileRange}s using a
+   * span-first coalescing strategy.
+   *
+   * <p>Ranges are merged as long as the total span from the first offset to the
+   * end of the last range does not exceed {@code maxSpan}. Gaps between ranges
+   * are ignored.</p>
+   *
+   * @param ranges  logical file ranges to merge
+   * @param maxSpan maximum allowed span (in bytes) for a combined read
+   * @return merged {@link CombinedFileRange}s covering the input ranges
+   */
+  private List<CombinedFileRange> mergeBySpanAndGap(
+      List<? extends FileRange> ranges,
+      int maxSpan, long  fileLength) throws EOFException {
+
+    LOG.debug("mergeBySpanAndGap: rangeCount={}, maxSpan={}", ranges.size(), maxSpan);
+    List<? extends FileRange> sortedRanges = VectoredReadUtils.validateAndSortRanges(
+        ranges, Optional.of(fileLength));
+
+    List<CombinedFileRange> out = new ArrayList<>();
+    CombinedFileRange current = null;
+
+    for (FileRange r : sortedRanges) {
+      long rOffset = r.getOffset();
+      long rEnd = rOffset + r.getLength();
+
+      /* Initialize the first combined range */
+      if (current == null) {
+        current = new CombinedFileRange(rOffset, rEnd, r);
+        continue;
+      }
+
+      /* Check whether adding this range keeps the total span within the limit */
+      long newSpan = rEnd - current.getOffset();
+
+      if (newSpan <= maxSpan) {
+        current.setLength((int) newSpan);
+        current.getUnderlying().add(r);
+      } else {
+        /* Span exceeded; finalize current range and start a new one */
+        out.add(current);
+        current = new CombinedFileRange(rOffset, rEnd, r);
+      }
+    }
+
+    /* Add the final combined range, if any */
+    if (current != null) {
+      out.add(current);
+    }
+
+    LOG.debug("mergeBySpanAndGap: produced {} combined ranges", out.size());
+    return out;
+  }
+
+  /**
+   * Distributes data from a physical read buffer into the corresponding
+   * logical {@link FileRange}s.
+   *
+   * <p>This method performs a "fan-out" operation where a single physical
+   * read (represented by {@link ReadBuffer}) may contain data for multiple
+   * logical ranges. The relevant portions are copied into per-range buffers
+   * and completed once fully populated.</p>
+   *
+   * <p>Partial reads are accumulated using {@code partialBuffers} and
+   * {@code pendingBytes}. A range is only completed when all expected
+   * bytes have been received.</p>
+   *
+   * <p>Thread safety:
+   * <ul>
+   *   <li>Each logical range buffer is synchronized independently</li>
+   *   <li>Writes use {@code System.arraycopy} directly into the backing array
+   *       to avoid shared {@link ByteBuffer} position mutation</li>
+   * </ul>
+   * </p>
+   *
+   * @param buffer    the physical read buffer containing merged data
+   * @param bytesRead number of valid bytes in the buffer
+   */
+  void fanOut(ReadBuffer buffer, int bytesRead) {
+    LOG.debug("fanOut: path={}, bufferOffset={}, bytesRead={}",
+        buffer.getPath(), buffer.getOffset(), bytesRead);
+
+    List<CombinedFileRange> units = buffer.getVectoredUnits();
+    if (units == null) {
+      LOG.warn("fanOut: no vectored units found for path={}, offset={}",
+          buffer.getPath(), buffer.getOffset());
+      return;
+    }
+
+    long bufferStart = buffer.getOffset();
+    long bufferEnd = bufferStart + bytesRead;
+
+    /* Iterate over all combined logical units mapped to this buffer */
+    for (CombinedFileRange unit : units) {
+      /* Each unit may contain multiple logical FileRanges */
+      for (FileRange r : unit.getUnderlying()) {
+        CompletableFuture<ByteBuffer> future = r.getData();
+        RangeKey key = new RangeKey(r);
+
+        /* Skip already completed or cancelled ranges */
+        if (future.isCancelled()) {
+          LOG.debug("fanOut: range cancelled, cleaning up: path={}, rangeOffset={}",
+              buffer.getPath(), r.getOffset());
+          partialBuffers.remove(key);
+          pendingBytes.remove(key);
+          continue;
+        }
+        if (future.isDone()) {
+          continue;
+        }
+
+        try {
+          long rangeStart = r.getOffset();
+          long rangeEnd = rangeStart + r.getLength();
+
+          /* Compute overlap between buffer and logical range */
+          long overlapStart = Math.max(rangeStart, bufferStart);
+          long overlapEnd = Math.min(rangeEnd, bufferEnd);
+
+          /* No overlap nothing to copy */
+          if (overlapStart >= overlapEnd) {
+            LOG.debug("fanOut: no overlap for path={}, rangeOffset={}, bufferOffset={}",
+                buffer.getPath(), r.getOffset(), bufferStart);
+            continue;
+          }
+
+          int srcOffset = (int) (overlapStart - bufferStart);
+          int destOffset = (int) (overlapStart - rangeStart);
+          int length = (int) (overlapEnd - overlapStart);
+
+          LOG.debug("fanOut: copying path={}, rangeOffset={}, rangeLength={},"
+                  + " bufferOffset={}, srcOffset={}, destOffset={}, length={}",
+              buffer.getPath(), r.getOffset(), r.getLength(),
+              bufferStart, srcOffset, destOffset, length);
+
+          /* Allocate or reuse the full buffer for this logical range */
+          ByteBuffer fullBuf = partialBuffers.computeIfAbsent(
+              key, k -> buffer.getAllocator().apply(r.getLength()));
+
+          /* Track remaining bytes required to complete this range */
+          AtomicInteger pending = pendingBytes.computeIfAbsent(
+              key, k -> new AtomicInteger(r.getLength()));
+
+          synchronized (fullBuf) {
+            /* Double-check completion inside lock */
+            if (future.isDone()) {
+              continue;
+            }
+
+            ByteBuffer dst = fullBuf.duplicate();
+            dst.position(destOffset);
+            dst.put(buffer.getBuffer(), srcOffset, length);
+
+            int left = pending.addAndGet(-length);
+
+            LOG.debug("fanOut: wrote chunk: path={}, rangeOffset={}, destOffset={},"
+                    + " length={}, pendingBytes={}",
+                buffer.getPath(), r.getOffset(), destOffset, length, left);
+
+            if (left < 0) {
+              LOG.error("fanOut: pending bytes went negative  possible duplicate write:"

Review Comment:
   taken



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3071268572


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV1.java:
##########
@@ -146,6 +168,124 @@ public void queueReadAhead(final AbfsInputStream stream, final long requestedOff
     }
   }
 
+  /**
+   * Queue a vectored read for a buffer-sized physical read unit.
+   *
+   * <p>The method first attempts to attach the logical unit to an already
+   * in-progress physical read for the same file and offset. If that is not
+   * possible, a free read buffer is acquired and a new backend read is
+   * queued.</p>
+   *
+   * @param stream         input stream for the file being read
+   * @param unit           buffer-sized combined file range to be read
+   * @param tracingContext tracing context used for the backend read request
+   * @param allocator      allocator used to create buffers for vectored fan-out
+   * @return {@code true} if the read was queued or attached to an existing
+   *         in-progress buffer; {@code false} if no buffer was available
+   */
+  boolean queueVectoredRead(AbfsInputStream stream,
+      CombinedFileRange unit,
+      TracingContext tracingContext,
+      IntFunction<ByteBuffer> allocator) {
+    /* Create a child tracing context for vectored read-ahead requests */
+    TracingContext readAheadTracingContext =
+        new TracingContext(tracingContext);
+    readAheadTracingContext.setPrimaryRequestID();
+    readAheadTracingContext.setReadType(ReadType.VECTORED_READ);
+
+    synchronized (this) {
+      if (isAlreadyQueued(stream, unit.getOffset())) {
+        ReadBuffer existing = findQueuedBuffer(stream, unit.getOffset());
+        if (existing != null && existing.getStream().getETag() != null
+            && stream.getETag().equals(existing.getStream().getETag())) {
+          /*
+           * For AVAILABLE buffers use actual bytes read (getLength()) for
+           * coverage check. For READING_IN_PROGRESS buffers use
+           * requestedLength as an estimate — the short-read guard will be
+           * applied later in doneReading before dispatching completion.
+           */
+          long end = existing.getOffset() + (
+              existing.getStatus() == ReadBufferStatus.AVAILABLE
+                  ? existing.getLength()
+                  : existing.getRequestedLength());
+          if (end >= unit.getOffset() + unit.getLength()) {
+            existing.setBufferType(BufferType.VECTORED);
+            existing.addVectoredUnit(unit);
+            existing.setAllocator(allocator);

Review Comment:
   Overlapping ranges are not allowed in vectored reads. validateAndSortRanges in VectoredReadUtils class takes care of this.



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "hadoop-yetus (via GitHub)" <gi...@apache.org>.
hadoop-yetus commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4235036165

   :broken_heart: **-1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime |  Logfile | Comment |
   |:----:|----------:|--------:|:--------:|:-------:|
   | +0 :ok: |  reexec  |  18m 44s |  |  Docker mode activated.  |
   |||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  0s |  |  No case conflicting files found.  |
   | +0 :ok: |  codespell  |   0m  0s |  |  codespell was not available.  |
   | +0 :ok: |  detsecrets  |   0m  0s |  |  detect-secrets was not available.  |
   | +0 :ok: |  xmllint  |   0m  0s |  |  xmllint was not available.  |
   | +1 :green_heart: |  @author  |   0m  0s |  |  The patch does not contain any @author tags.  |
   | +1 :green_heart: |  test4tests  |   0m  0s |  |  The patch appears to include 2 new or modified test files.  |
   |||| _ trunk Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  47m  6s |  |  trunk passed  |
   | +1 :green_heart: |  compile  |   1m  2s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  compile  |   1m  3s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  checkstyle  |   0m 56s |  |  trunk passed  |
   | +1 :green_heart: |  mvnsite  |   1m 10s |  |  trunk passed  |
   | -1 :x: |  javadoc  |   1m  0s | [/branch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-21.0.10+7-Ubuntu-124.04.txt](https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/8/artifact/out/branch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-21.0.10+7-Ubuntu-124.04.txt) |  hadoop-azure in trunk failed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04.  |
   | -1 :x: |  javadoc  |   0m 57s | [/branch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-17.0.18+8-Ubuntu-124.04.1.txt](https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/8/artifact/out/branch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-17.0.18+8-Ubuntu-124.04.1.txt) |  hadoop-azure in trunk failed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1.  |
   | +1 :green_heart: |  spotbugs  |   1m 36s |  |  trunk passed  |
   | +1 :green_heart: |  shadedclient  |  33m 53s |  |  branch has no errors when building and testing our client artifacts.  |
   | -0 :warning: |  patch  |  34m 27s |  |  Used diff version of patch file. Binary files and potentially other changes not applied. Please rebase and squash commits if necessary.  |
   |||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   0m 36s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 32s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javac  |   0m 32s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 34s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  javac  |   0m 34s |  |  the patch passed  |
   | +1 :green_heart: |  blanks  |   0m  0s |  |  The patch has no blanks issues.  |
   | +1 :green_heart: |  checkstyle  |   0m 26s |  |  the patch passed  |
   | +1 :green_heart: |  mvnsite  |   0m 39s |  |  the patch passed  |
   | -1 :x: |  javadoc  |   0m 29s | [/patch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-21.0.10+7-Ubuntu-124.04.txt](https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/8/artifact/out/patch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-21.0.10+7-Ubuntu-124.04.txt) |  hadoop-azure in the patch failed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04.  |
   | -1 :x: |  javadoc  |   0m 29s | [/patch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-17.0.18+8-Ubuntu-124.04.1.txt](https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/8/artifact/out/patch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-17.0.18+8-Ubuntu-124.04.1.txt) |  hadoop-azure in the patch failed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1.  |
   | +1 :green_heart: |  spotbugs  |   1m 18s |  |  the patch passed  |
   | +1 :green_heart: |  shadedclient  |  34m 18s |  |  patch has no errors when building and testing our client artifacts.  |
   |||| _ Other Tests _ |
   | +1 :green_heart: |  unit  |   2m 13s |  |  hadoop-azure in the patch passed.  |
   | +1 :green_heart: |  asflicense  |   0m 35s |  |  The patch does not generate ASF License warnings.  |
   |  |   | 151m 44s |  |  |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/8/artifact/out/Dockerfile |
   | GITHUB PR | https://github.com/apache/hadoop/pull/8400 |
   | Optional Tests | dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient codespell detsecrets xmllint spotbugs checkstyle |
   | uname | Linux 8dbb7b62d7b3 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | dev-support/bin/hadoop.sh |
   | git revision | trunk / cfcb033baeba576c0f0cbe0b9a35aa6020c4e60d |
   | Default Java | Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   | Multi-JDK versions | /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   |  Test Results | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/8/testReport/ |
   | Max. process+thread count | 590 (vs. ulimit of 10000) |
   | modules | C: hadoop-tools/hadoop-azure U: hadoop-tools/hadoop-azure |
   | Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/8/console |
   | versions | git=2.43.0 maven=3.9.11 spotbugs=4.9.7 |
   | Powered by | Apache Yetus 0.14.1 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3193719300


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStream.java:
##########
@@ -1193,7 +1218,7 @@ public int minSeekForVectorReads() {
    */
   @Override
   public int maxReadSizeForVectorReads() {
-    return S_2M;
+    return client.getAbfsConfiguration().getMaxSeekForVectoredReads();

Review Comment:
   taken



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

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


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "hadoop-yetus (via GitHub)" <gi...@apache.org>.
hadoop-yetus commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4192516707

   :confetti_ball: **+1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime |  Logfile | Comment |
   |:----:|----------:|--------:|:--------:|:-------:|
   | +0 :ok: |  reexec  |   0m 53s |  |  Docker mode activated.  |
   |||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  0s |  |  No case conflicting files found.  |
   | +0 :ok: |  codespell  |   0m  1s |  |  codespell was not available.  |
   | +0 :ok: |  detsecrets  |   0m  1s |  |  detect-secrets was not available.  |
   | +0 :ok: |  xmllint  |   0m  1s |  |  xmllint was not available.  |
   | +1 :green_heart: |  @author  |   0m  0s |  |  The patch does not contain any @author tags.  |
   | +1 :green_heart: |  test4tests  |   0m  0s |  |  The patch appears to include 2 new or modified test files.  |
   |||| _ trunk Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  46m 51s |  |  trunk passed  |
   | +1 :green_heart: |  compile  |   1m  1s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  compile  |   1m  4s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  checkstyle  |   0m 57s |  |  trunk passed  |
   | +1 :green_heart: |  mvnsite  |   1m  6s |  |  trunk passed  |
   | +1 :green_heart: |  javadoc  |   0m 59s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 57s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 36s |  |  trunk passed  |
   | +1 :green_heart: |  shadedclient  |  34m 21s |  |  branch has no errors when building and testing our client artifacts.  |
   | -0 :warning: |  patch  |  34m 54s |  |  Used diff version of patch file. Binary files and potentially other changes not applied. Please rebase and squash commits if necessary.  |
   |||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   0m 37s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 32s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javac  |   0m 32s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 35s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  javac  |   0m 35s |  |  the patch passed  |
   | +1 :green_heart: |  blanks  |   0m  0s |  |  The patch has no blanks issues.  |
   | +1 :green_heart: |  checkstyle  |   0m 25s |  |  the patch passed  |
   | +1 :green_heart: |  mvnsite  |   0m 38s |  |  the patch passed  |
   | +1 :green_heart: |  javadoc  |   0m 30s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 29s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 17s |  |  the patch passed  |
   | +1 :green_heart: |  shadedclient  |  33m 30s |  |  patch has no errors when building and testing our client artifacts.  |
   |||| _ Other Tests _ |
   | +1 :green_heart: |  unit  |   2m 12s |  |  hadoop-azure in the patch passed.  |
   | +1 :green_heart: |  asflicense  |   0m 33s |  |  The patch does not generate ASF License warnings.  |
   |  |   | 133m  1s |  |  |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/4/artifact/out/Dockerfile |
   | GITHUB PR | https://github.com/apache/hadoop/pull/8400 |
   | Optional Tests | dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient codespell detsecrets xmllint spotbugs checkstyle |
   | uname | Linux c59ec63c64b6 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | dev-support/bin/hadoop.sh |
   | git revision | trunk / e7bf14ac151dcd069f004ab3d0c71efa8accb745 |
   | Default Java | Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   | Multi-JDK versions | /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   |  Test Results | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/4/testReport/ |
   | Max. process+thread count | 576 (vs. ulimit of 10000) |
   | modules | C: hadoop-tools/hadoop-azure U: hadoop-tools/hadoop-azure |
   | Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/4/console |
   | versions | git=2.43.0 maven=3.9.11 spotbugs=4.9.7 |
   | Powered by | Apache Yetus 0.14.1 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "hadoop-yetus (via GitHub)" <gi...@apache.org>.
hadoop-yetus commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4192124947

   :broken_heart: **-1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime |  Logfile | Comment |
   |:----:|----------:|--------:|:--------:|:-------:|
   | +0 :ok: |  reexec  |   0m  0s |  |  Docker mode activated.  |
   | -1 :x: |  patch  |   0m 15s |  |  https://github.com/apache/hadoop/pull/8400 does not apply to trunk. Rebase required? Wrong Branch? See https://cwiki.apache.org/confluence/display/HADOOP/How+To+Contribute for help.  |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/7/console |
   | versions | git=2.34.1 |
   | Powered by | Apache Yetus 0.14.1 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "steveloughran (via GitHub)" <gi...@apache.org>.
steveloughran commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3080390618


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/constants/ReadType.java:
##########
@@ -48,6 +48,16 @@ public enum ReadType {
    * Only triggered when small file read optimization kicks in.
    */
   SMALLFILE_READ("SR"),
+  /**
+   * Read multiple disjoint ranges from the storage service using vectored reads.
+   * Used to coalesce and execute non-contiguous reads efficiently.
+   */
+  VECTORED_READ("VR"),
+  /**
+   * Performs a vectored direct read by fetching multiple non-contiguous
+   * ranges in a single operation.
+   */
+  VECTORED_DIRECT_READ("VDR"),

Review Comment:
   azure does multirange? nice



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "manika137 (via GitHub)" <gi...@apache.org>.
manika137 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3067811801


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV1.java:
##########
@@ -146,6 +168,124 @@ public void queueReadAhead(final AbfsInputStream stream, final long requestedOff
     }
   }
 
+  /**
+   * Queue a vectored read for a buffer-sized physical read unit.
+   *
+   * <p>The method first attempts to attach the logical unit to an already
+   * in-progress physical read for the same file and offset. If that is not
+   * possible, a free read buffer is acquired and a new backend read is
+   * queued.</p>
+   *
+   * @param stream         input stream for the file being read
+   * @param unit           buffer-sized combined file range to be read
+   * @param tracingContext tracing context used for the backend read request
+   * @param allocator      allocator used to create buffers for vectored fan-out
+   * @return {@code true} if the read was queued or attached to an existing
+   *         in-progress buffer; {@code false} if no buffer was available
+   */
+  boolean queueVectoredRead(AbfsInputStream stream,
+      CombinedFileRange unit,
+      TracingContext tracingContext,
+      IntFunction<ByteBuffer> allocator) {
+    /* Create a child tracing context for vectored read-ahead requests */
+    TracingContext readAheadTracingContext =
+        new TracingContext(tracingContext);
+    readAheadTracingContext.setPrimaryRequestID();
+    readAheadTracingContext.setReadType(ReadType.VECTORED_READ);
+
+    synchronized (this) {
+      if (isAlreadyQueued(stream, unit.getOffset())) {
+        ReadBuffer existing = findQueuedBuffer(stream, unit.getOffset());
+        if (existing != null && existing.getStream().getETag() != null
+            && stream.getETag().equals(existing.getStream().getETag())) {
+          /*
+           * For AVAILABLE buffers use actual bytes read (getLength()) for
+           * coverage check. For READING_IN_PROGRESS buffers use
+           * requestedLength as an estimate — the short-read guard will be
+           * applied later in doneReading before dispatching completion.
+           */
+          long end = existing.getOffset() + (
+              existing.getStatus() == ReadBufferStatus.AVAILABLE
+                  ? existing.getLength()
+                  : existing.getRequestedLength());
+          if (end >= unit.getOffset() + unit.getLength()) {
+            existing.setBufferType(BufferType.VECTORED);
+            existing.addVectoredUnit(unit);
+            existing.setAllocator(allocator);

Review Comment:
   could we have multiple readvector calls with overlapping ranges that could reset the allocator here? Or isAlreadyQueued section wont go through for overlapping ranges?



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3077950448


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManager.java:
##########
@@ -285,5 +310,94 @@ protected void testMimicFullUseAndAddFailedBuffer(ReadBuffer buf) {
     completedReadList.add(buf);
   }
 
+  /**
+   * Finds an existing {@link ReadBuffer} for the given stream whose buffered
+   * range covers the specified logical offset.
+   *
+   * <p>The search is performed in the read-ahead queue, in-progress list,
+   * and completed-read list, in that order.
+   *
+   * @param stream the {@link AbfsInputStream} associated with the read request
+   *
+   * @return a matching {@link ReadBuffer} if one exists, or {@code null} otherwise
+   */
+  ReadBuffer findQueuedBuffer(final AbfsInputStream stream,
+      long requestedOffset) {
+    ReadBuffer buffer;
+    buffer = findInList(getReadAheadQueue(), stream, requestedOffset);
+    if (buffer != null) {
+      return buffer;
+    }
+    buffer = findInList(getInProgressList(), stream, requestedOffset);
+    if (buffer != null) {
+      return buffer;
+    }
+    return findInList(getCompletedReadList(), stream, requestedOffset);
+  }
+
+  /**
+   * Searches the given collection of {@link ReadBuffer}s for one that belongs
+   * to the specified stream and whose buffered range covers the given offset.
+   *
+   * @param buffers the collection of {@link ReadBuffer}s to search
+   * @param stream the {@link AbfsInputStream} associated with the read request
+   *
+   * @return the matching {@link ReadBuffer}, or {@code null} if none is found
+   */
+  ReadBuffer findInList(final Collection<ReadBuffer> buffers,
+      final AbfsInputStream stream, long requestedOffset) {
+    for (ReadBuffer buffer : buffers) {
+      if (buffer.getStream() == stream

Review Comment:
   No buffer can't be null 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: common-issues-unsubscribe@hadoop.apache.org

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3071251799


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStream.java:
##########
@@ -1078,7 +1105,7 @@ public int minSeekForVectorReads() {
    */
   @Override
   public int maxReadSizeForVectorReads() {

Review Comment:
   this is the name of the method in the superclass



##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/VectoredReadHandler.java:
##########
@@ -0,0 +1,696 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.IntFunction;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.classification.VisibleForTesting;
+import org.apache.hadoop.fs.FileRange;
+import org.apache.hadoop.fs.VectoredReadUtils;
+import org.apache.hadoop.fs.azurebfs.constants.ReadType;
+import org.apache.hadoop.fs.azurebfs.enums.VectoredReadStrategy;
+import org.apache.hadoop.fs.azurebfs.utils.TracingContext;
+import org.apache.hadoop.fs.impl.CombinedFileRange;
+
+/**
+ * Handles vectored read operations by coordinating with a ReadBufferManager
+ * and applying the configured VectoredReadStrategy.
+ * This class acts as the orchestration layer that decides how vectored reads
+ * are executed, while delegating buffer management and read behavior to
+ * dedicated components.
+ */
+class VectoredReadHandler {
+
+  private static final Logger LOG = LoggerFactory.getLogger(VectoredReadHandler.class);
+
+  /**
+   * Manages allocation, lifecycle, and reuse of read buffers
+   * used during vectored read operations.
+   */
+  private final ReadBufferManager readBufferManager;
+
+  /**
+   * Strategy defining how vectored reads should be performed.
+   */
+  private final VectoredReadStrategy strategy;
+
+  /**
+   * Shared reconstruction buffers for ranges that span multiple chunks.
+   * Keyed by the original FileRange instance.
+   */
+  private final ConcurrentHashMap<RangeKey, ByteBuffer> partialBuffers =
+      new ConcurrentHashMap<>();
+
+  /**
+   * Tracks remaining bytes to be received for each logical range.
+   * Keyed by the original FileRange instance.
+   */
+  private final ConcurrentHashMap<RangeKey, AtomicInteger> pendingBytes =
+      new ConcurrentHashMap<>();
+
+  /**
+   * Creates a VectoredReadHandler using the provided ReadBufferManager.
+   * The vectored read strategy is obtained from the manager to ensure
+   * consistent configuration across the read pipeline.
+   *
+   * @param readBufferManager manager responsible for buffer handling
+   *                          and providing the vectored read strategy
+   */
+  VectoredReadHandler(ReadBufferManager readBufferManager) {
+    this.readBufferManager = readBufferManager;
+    this.strategy = readBufferManager.getVectoredReadStrategy();
+    LOG.debug("VectoredReadHandler initialized with strategy={}", strategy);
+  }
+
+  /**
+   * Perform a vectored read over multiple logical file ranges.
+   *
+   * <p>Logical ranges are first merged using a span-first strategy determined
+   * by the configured {@link VectoredReadStrategy}. The merged ranges are then
+   * split into buffer-sized physical read units and queued for asynchronous
+   * execution. If a pooled buffer is unavailable, the read falls back to a
+   * direct read path.</p>
+   *
+   * @param stream    input stream for the file being read
+   * @param ranges    logical file ranges to read; each range will be completed
+   *                  with data or failure via its associated future
+   * @param allocator allocator used to create buffers for direct reads and
+   *                  vectored fan-out
+   */
+  public void readVectored(
+      AbfsInputStream stream,
+      List<? extends FileRange> ranges,
+      IntFunction<ByteBuffer> allocator) throws EOFException {
+    LOG.debug("readVectored invoked: path={}, rangeCount={}",
+        stream.getPath(), ranges.size());
+
+    /* Initialize a future for each logical file range */
+    long fileLength = stream.getContentLength();
+    List<FileRange> validRanges = validateAndPrepareRanges(ranges, fileLength);
+
+    /* Select the maximum allowed merge span based on the configured strategy */
+    int maxSpan =
+        (strategy == VectoredReadStrategy.TPS_OPTIMIZED)
+            ? readBufferManager.getMaxSeekForVectoredReads()
+            : readBufferManager.getMaxSeekForVectoredReadsThroughput();
+
+    LOG.debug("readVectored: path={}, strategy={}, maxSpan={}",
+        stream.getPath(), strategy, maxSpan);
+
+    /* Merge logical ranges using a span-first coalescing strategy */
+    List<CombinedFileRange> merged = mergeBySpanAndGap(validRanges, maxSpan, fileLength);
+
+    LOG.debug("readVectored: path={}, mergedRangeCount={}",
+        stream.getPath(), merged.size());
+
+    /* Read buffer size acts as a hard upper bound for physical reads */
+    int readBufferSize = ReadBufferManager.getReadAheadBlockSize();
+
+    /* Split merged ranges into buffer-sized chunks and queue each for read */
+    for (CombinedFileRange unit : merged) {
+      List<CombinedFileRange> chunks = splitByBufferSize(unit, readBufferSize);
+
+      LOG.debug("readVectored: path={}, mergedOffset={}, mergedLength={}, chunkCount={}",
+          stream.getPath(), unit.getOffset(), unit.getLength(), chunks.size());
+
+      for (CombinedFileRange chunk : chunks) {
+        try {
+          VectoredReadUtils.validateRangeRequest(chunk);
+          boolean queued = queueVectoredRead(stream, chunk, allocator);
+          if (!queued) {
+            LOG.debug("readVectored: buffer pool exhausted, falling back to directRead: path={}, offset={}, length={}",
+                stream.getPath(), chunk.getOffset(), chunk.getLength());
+            directRead(stream, chunk, allocator);
+          }
+        } catch (Exception e) {
+          LOG.warn("readVectored: chunk read failed, failing underlying ranges:"
+                  + " path={}, offset={}, length={}",
+              stream.getPath(), chunk.getOffset(), chunk.getLength(), e);
+          failUnit(chunk, e);
+        }
+      }
+    }
+  }
+
+  /**
+   * Queues a vectored read request with the buffer manager.
+   *
+   * @return true if successfully queued, false if the queue is full and fallback is required.
+   */
+  @VisibleForTesting
+  boolean queueVectoredRead(AbfsInputStream stream, CombinedFileRange unit,
+      IntFunction<ByteBuffer> allocator) {
+    LOG.debug("queueVectoredRead: path={}, offset={}, length={}",
+        stream.getPath(), unit.getOffset(), unit.getLength());
+    TracingContext tracingContext = stream.getTracingContext();
+    tracingContext.setReadType(ReadType.VECTORED_READ);
+    return getReadBufferManager().queueVectoredRead(stream, unit, tracingContext, allocator);
+  }
+
+  /**
+   * Accesses the shared manager responsible for coordinating asynchronous read buffers.
+   *
+   * @return the {@link ReadBufferManager} instance.
+   */
+  public ReadBufferManager getReadBufferManager() {
+    return readBufferManager;
+  }
+
+  /**
+   * Validates and prepares a list of {@link FileRange} instances for vectored reads.
+   *
+   * <p>This method performs the following steps for each input range:
+   * <ul>
+   *   <li>Validates the range using {@link VectoredReadUtils#validateRangeRequest(FileRange)}</li>
+   *   <li>Initializes a {@link CompletableFuture} to hold the read result</li>
+   *   <li>Checks that the range falls within the bounds of the file</li>
+   * </ul>
+   *
+   * <p>Ranges that are invalid (e.g., negative offset/length or exceeding file bounds)
+   * are not included in the returned list. Instead, their associated future is
+   * completed exceptionally with an {@link EOFException}.
+   *
+   * @param ranges     the input list of logical file ranges to validate and prepare
+   * @param fileLength the total length of the file, used for bounds checking
+   * @return a list of valid {@link FileRange} instances ready for vectored read processing
+   */
+  private List<FileRange> validateAndPrepareRanges(
+      List<? extends FileRange> ranges, long fileLength) throws EOFException {
+
+    List<FileRange> validRanges = new ArrayList<>();
+
+    for (FileRange r : ranges) {
+      VectoredReadUtils.validateRangeRequest(r);
+      r.setData(new CompletableFuture<>());
+
+      long offset = r.getOffset();
+      long length = r.getLength();
+
+      if (offset < 0 || length < 0 || offset > fileLength || length > fileLength - offset) {
+        r.getData().completeExceptionally(new EOFException(
+            "Invalid range: offset=" + offset + ", length=" + length + ", fileLength=" + fileLength));
+        continue;
+      }
+      validRanges.add(r);
+    }
+    return validRanges;
+  }
+
+  /**
+   * Splits a merged logical {@link CombinedFileRange} into smaller
+   * buffer-sized physical read units.
+   *
+   * <p>Each resulting unit will have a maximum size equal to the provided
+   * {@code bufferSize}. Any handling of multi-chunk ranges or reassembly
+   * of underlying {@link FileRange} data is delegated to the fan-out logic.</p>
+   *
+   * @param unit       the combined logical range to be split
+   * @param bufferSize the maximum size (in bytes) of each physical read unit
+   * @return a list of buffer-sized {@link CombinedFileRange} instances
+   */
+  private List<CombinedFileRange> splitByBufferSize(
+      CombinedFileRange unit,
+      int bufferSize) {
+    LOG.debug("splitByBufferSize: offset={}, length={}, bufferSize={}",
+        unit.getOffset(), unit.getLength(), bufferSize);
+
+    List<CombinedFileRange> parts = new ArrayList<>();
+    long unitStart = unit.getOffset();
+    long unitEnd = unitStart + unit.getLength();
+    long start = unitStart;
+
+    while (start < unitEnd) {
+      long partEnd = Math.min(start + bufferSize, unitEnd);
+
+      CombinedFileRange part =
+          new CombinedFileRange(start, partEnd, unit.getUnderlying().get(0));
+      part.getUnderlying().clear();
+
+      for (FileRange r : unit.getUnderlying()) {
+        long rStart = r.getOffset();
+        long rEnd = rStart + r.getLength();
+        if (rEnd > start && rStart < partEnd) {
+          part.getUnderlying().add(r);
+        }
+      }
+      parts.add(part);
+      start = partEnd;
+    }
+
+    LOG.debug("splitByBufferSize: offset={}, produced {} parts",
+        unit.getOffset(), parts.size());
+    return parts;
+  }
+
+  /**
+   * Merge logical {@link FileRange}s into {@link CombinedFileRange}s using a
+   * span-first coalescing strategy.
+   *
+   * <p>Ranges are merged as long as the total span from the first offset to the
+   * end of the last range does not exceed {@code maxSpan}. Gaps between ranges
+   * are ignored.</p>
+   *
+   * @param ranges  logical file ranges to merge
+   * @param maxSpan maximum allowed span (in bytes) for a combined read
+   * @return merged {@link CombinedFileRange}s covering the input ranges
+   */
+  private List<CombinedFileRange> mergeBySpanAndGap(
+      List<? extends FileRange> ranges,
+      int maxSpan, long  fileLength) throws EOFException {
+
+    LOG.debug("mergeBySpanAndGap: rangeCount={}, maxSpan={}", ranges.size(), maxSpan);
+    List<? extends FileRange> sortedRanges = VectoredReadUtils.validateAndSortRanges(
+        ranges, Optional.of(fileLength));
+
+    List<CombinedFileRange> out = new ArrayList<>();
+    CombinedFileRange current = null;
+
+    for (FileRange r : sortedRanges) {
+      long rOffset = r.getOffset();
+      long rEnd = rOffset + r.getLength();
+
+      /* Initialize the first combined range */
+      if (current == null) {
+        current = new CombinedFileRange(rOffset, rEnd, r);
+        continue;
+      }
+
+      /* Check whether adding this range keeps the total span within the limit */
+      long newSpan = rEnd - current.getOffset();
+
+      if (newSpan <= maxSpan) {
+        current.setLength((int) newSpan);
+        current.getUnderlying().add(r);
+      } else {
+        /* Span exceeded; finalize current range and start a new one */
+        out.add(current);
+        current = new CombinedFileRange(rOffset, rEnd, r);
+      }
+    }
+
+    /* Add the final combined range, if any */
+    if (current != null) {
+      out.add(current);
+    }
+
+    LOG.debug("mergeBySpanAndGap: produced {} combined ranges", out.size());
+    return out;
+  }
+
+  /**
+   * Distributes data from a physical read buffer into the corresponding
+   * logical {@link FileRange}s.
+   *
+   * <p>This method performs a "fan-out" operation where a single physical
+   * read (represented by {@link ReadBuffer}) may contain data for multiple
+   * logical ranges. The relevant portions are copied into per-range buffers
+   * and completed once fully populated.</p>
+   *
+   * <p>Partial reads are accumulated using {@code partialBuffers} and
+   * {@code pendingBytes}. A range is only completed when all expected
+   * bytes have been received.</p>
+   *
+   * <p>Thread safety:
+   * <ul>
+   *   <li>Each logical range buffer is synchronized independently</li>
+   *   <li>Writes use {@code System.arraycopy} directly into the backing array
+   *       to avoid shared {@link ByteBuffer} position mutation</li>
+   * </ul>
+   * </p>
+   *
+   * @param buffer    the physical read buffer containing merged data
+   * @param bytesRead number of valid bytes in the buffer
+   */
+  void fanOut(ReadBuffer buffer, int bytesRead) {
+    LOG.debug("fanOut: path={}, bufferOffset={}, bytesRead={}",
+        buffer.getPath(), buffer.getOffset(), bytesRead);
+
+    List<CombinedFileRange> units = buffer.getVectoredUnits();
+    if (units == null) {
+      LOG.warn("fanOut: no vectored units found for path={}, offset={}",
+          buffer.getPath(), buffer.getOffset());
+      return;
+    }
+
+    long bufferStart = buffer.getOffset();
+    long bufferEnd = bufferStart + bytesRead;
+
+    /* Iterate over all combined logical units mapped to this buffer */
+    for (CombinedFileRange unit : units) {
+      /* Each unit may contain multiple logical FileRanges */
+      for (FileRange r : unit.getUnderlying()) {
+        CompletableFuture<ByteBuffer> future = r.getData();
+        RangeKey key = new RangeKey(r);
+
+        /* Skip already completed or cancelled ranges */
+        if (future.isCancelled()) {
+          LOG.debug("fanOut: range cancelled, cleaning up: path={}, rangeOffset={}",
+              buffer.getPath(), r.getOffset());
+          partialBuffers.remove(key);
+          pendingBytes.remove(key);
+          continue;
+        }
+        if (future.isDone()) {
+          continue;
+        }
+
+        try {
+          long rangeStart = r.getOffset();
+          long rangeEnd = rangeStart + r.getLength();
+
+          /* Compute overlap between buffer and logical range */
+          long overlapStart = Math.max(rangeStart, bufferStart);
+          long overlapEnd = Math.min(rangeEnd, bufferEnd);
+
+          /* No overlap nothing to copy */
+          if (overlapStart >= overlapEnd) {
+            LOG.debug("fanOut: no overlap for path={}, rangeOffset={}, bufferOffset={}",
+                buffer.getPath(), r.getOffset(), bufferStart);
+            continue;
+          }
+
+          int srcOffset = (int) (overlapStart - bufferStart);
+          int destOffset = (int) (overlapStart - rangeStart);
+          int length = (int) (overlapEnd - overlapStart);
+
+          LOG.debug("fanOut: copying path={}, rangeOffset={}, rangeLength={},"
+                  + " bufferOffset={}, srcOffset={}, destOffset={}, length={}",
+              buffer.getPath(), r.getOffset(), r.getLength(),
+              bufferStart, srcOffset, destOffset, length);
+
+          /* Allocate or reuse the full buffer for this logical range */
+          ByteBuffer fullBuf = partialBuffers.computeIfAbsent(
+              key, k -> buffer.getAllocator().apply(r.getLength()));
+
+          /* Track remaining bytes required to complete this range */
+          AtomicInteger pending = pendingBytes.computeIfAbsent(
+              key, k -> new AtomicInteger(r.getLength()));
+
+          synchronized (fullBuf) {
+            /* Double-check completion inside lock */
+            if (future.isDone()) {
+              continue;
+            }
+
+            ByteBuffer dst = fullBuf.duplicate();
+            dst.position(destOffset);
+            dst.put(buffer.getBuffer(), srcOffset, length);
+
+            int left = pending.addAndGet(-length);
+
+            LOG.debug("fanOut: wrote chunk: path={}, rangeOffset={}, destOffset={},"
+                    + " length={}, pendingBytes={}",
+                buffer.getPath(), r.getOffset(), destOffset, length, left);
+
+            if (left < 0) {
+              LOG.error("fanOut: pending bytes went negative  possible duplicate write:"
+                      + " path={}, rangeOffset={}, pending={}",
+                  buffer.getPath(), r.getOffset(), left);
+              future.completeExceptionally(new IllegalStateException(
+                  "Pending bytes negative for offset=" + r.getOffset()));
+              partialBuffers.remove(key);
+              pendingBytes.remove(key);
+              continue;
+            }
+
+            /* Complete future once all bytes are received */
+            if (left == 0 && !future.isDone()) {
+              /*
+               * Prepare buffer for reading.
+               * DO NOT use flip() because writes may arrive out-of-order.
+               * Instead, explicitly expose the full buffer.
+               */
+              fullBuf.position(0);
+              fullBuf.limit(fullBuf.capacity());
+
+              if (fullBuf.limit() != r.getLength()) {
+                LOG.warn("fanOut: buffer size mismatch: path={}, rangeOffset={},"
+                        + " expected={}, actual={}",
+                    buffer.getPath(), r.getOffset(), r.getLength(), fullBuf.limit());
+              }
+
+              future.complete(fullBuf);
+              partialBuffers.remove(key);
+              pendingBytes.remove(key);
+
+              LOG.debug("fanOut: completed range: path={}, rangeOffset={}, rangeLength={}",
+                  buffer.getPath(), r.getOffset(), r.getLength());
+            }
+          }
+        } catch (Exception e) {
+          LOG.warn("fanOut: exception processing range: path={}, rangeOffset={}",
+              buffer.getPath(), r.getOffset(), e);
+          partialBuffers.remove(key);
+          pendingBytes.remove(key);
+          if (!future.isDone()) {
+            future.completeExceptionally(e);
+          }
+        }
+      }
+    }
+  }
+
+  /**
+   * Fails all logical {@link FileRange}s associated with a given
+   * {@link CombinedFileRange}.
+   *
+   * <p>This method is invoked when a vectored read for the combined unit
+   * fails. It ensures that:
+   * <ul>
+   *   <li>Any partially accumulated buffers are cleaned up</li>
+   *   <li>Pending byte tracking state is removed</li>
+   *   <li>All corresponding {@link CompletableFuture}s are completed exceptionally</li>
+   * </ul>
+   * </p>
+   *
+   * @param unit the combined vectored read unit whose underlying ranges must be failed
+   * @param t    the exception that caused the failure
+   */
+  private void failUnit(CombinedFileRange unit, Throwable t) {
+    for (FileRange r : unit.getUnderlying()) {
+      RangeKey key = new RangeKey(r);
+      partialBuffers.remove(key);
+      pendingBytes.remove(key);
+      CompletableFuture<ByteBuffer> future = r.getData();
+      if (future != null && !future.isDone()) {
+        future.completeExceptionally(t);
+      }
+    }
+  }
+
+  /**
+   * Fails all {@link FileRange} futures associated with the given
+   * {@link ReadBuffer} and clears any partial state.
+   *
+   * @param buffer the read buffer whose ranges should be failed
+   * @param t      the exception causing the failure
+   */
+  void failBufferFutures(ReadBuffer buffer, Throwable t) {
+    List<CombinedFileRange> units = buffer.getVectoredUnits();
+    if (units == null) {
+      LOG.warn("fanOut: no vectored units found for path={}, offset={}",
+          buffer.getPath(), buffer.getOffset());
+      return;
+    }
+
+    for (CombinedFileRange unit : units) {
+      for (FileRange r : unit.getUnderlying()) {
+        RangeKey key = new RangeKey(r);
+        partialBuffers.remove(key);
+        pendingBytes.remove(key);
+        CompletableFuture<ByteBuffer> future = r.getData();
+        if (future != null && !future.isDone()) {
+          future.completeExceptionally(t);
+        }
+      }
+    }
+  }
+
+  /**
+   * Performs a synchronous direct read for a {@link CombinedFileRange}
+   * when pooled buffering is not available.
+   *
+   * <p>Data is accumulated into per-range partial buffers shared with
+   * {@link #fanOut}, ensuring that ranges spanning multiple chunks are
+   * correctly reassembled regardless of whether individual chunks were
+   * served via the async queue or this direct fallback path.</p>
+   *
+   * @param stream    input stream to read from
+   * @param unit      combined range to read
+   * @param allocator buffer allocator for logical ranges
+   * @throws IOException if the read fails
+   */
+  void directRead(
+      AbfsInputStream stream,
+      CombinedFileRange unit,
+      IntFunction<ByteBuffer> allocator) throws IOException {
+
+    LOG.debug("directRead: path={}, offset={}, length={}",
+        stream.getPath(), unit.getOffset(), unit.getLength());
+
+    /* Read entire combined range into a temporary buffer */
+    byte[] tmp = new byte[unit.getLength()];
+    TracingContext tracingContext = new TracingContext(stream.getTracingContext());
+    tracingContext.setReadType(ReadType.VECTORED_DIRECT_READ);
+
+    int total = 0;
+    int requested = unit.getLength();
+    while (total < requested) {
+      int n = stream.readRemote(unit.getOffset() + total, tmp, total,
+          requested - total, tracingContext);
+      if (n <= 0) {
+        throw new IOException(
+            "Unexpected end of stream during direct read: path=" + stream.getPath()
+                + ", offset=" + (unit.getOffset() + total)
+                + ", requested=" + requested);
+      }
+      total += n;
+    }
+
+    LOG.debug("directRead: read complete: path={}, offset={}, bytesRead={}",
+        stream.getPath(), unit.getOffset(), total);
+
+    long unitStart = unit.getOffset();
+    long unitEnd = unitStart + unit.getLength();
+
+    /* Distribute data to each logical FileRange */
+    for (FileRange r : unit.getUnderlying()) {
+      CompletableFuture<ByteBuffer> future = r.getData();
+      if (future == null || future.isDone()) {
+        continue;
+      }
+
+      long rangeStart = r.getOffset();
+      long rangeEnd = rangeStart + r.getLength();
+
+      /* Compute overlap between unit and logical range */
+      long overlapStart = Math.max(rangeStart, unitStart);
+      long overlapEnd = Math.min(rangeEnd, unitEnd);
+      if (overlapStart >= overlapEnd) {
+        continue;
+      }
+
+      int srcOffset = (int) (overlapStart - unitStart);
+      int destOffset = (int) (overlapStart - rangeStart);
+      int length = (int) (overlapEnd - overlapStart);
+
+      LOG.debug("directRead: copying: path={}, rangeOffset={}, rangeLength={},"
+              + " srcOffset={}, destOffset={}, length={}",
+          stream.getPath(), r.getOffset(), r.getLength(),
+          srcOffset, destOffset, length);
+
+      RangeKey key = new RangeKey(r);
+
+      /*
+       * Use the shared partialBuffers/pendingBytes maps so that ranges
+       * spanning multiple chunks are correctly reassembled even when some
+       * chunks are served via directRead and others via the async fanOut path.
+       */
+      ByteBuffer fullBuf = partialBuffers.computeIfAbsent(
+          key, k -> allocator.apply(r.getLength()));
+      AtomicInteger pending = pendingBytes.computeIfAbsent(
+          key, k -> new AtomicInteger(r.getLength()));
+
+      synchronized (fullBuf) {
+        /* Re-check inside lock in case another chunk already completed this range */
+        if (future.isDone()) {
+          continue;
+        }
+
+        if (fullBuf.hasArray()) {
+          System.arraycopy(tmp, srcOffset,
+              fullBuf.array(), fullBuf.arrayOffset() + destOffset,
+              length);
+        } else {
+          ByteBuffer dst = fullBuf.duplicate();
+          dst.position(destOffset);
+          dst.put(tmp, srcOffset, length);
+        }
+
+        int left = pending.addAndGet(-length);
+
+        LOG.debug("directRead: wrote chunk: path={}, rangeOffset={}, destOffset={},"
+                + " length={}, pendingBytes={}",
+            stream.getPath(), r.getOffset(), destOffset, length, left);
+
+        if (left < 0) {
+          LOG.error("directRead: pending bytes went negative  possible duplicate write:"
+                  + " path={}, rangeOffset={}, pending={}",
+              stream.getPath(), r.getOffset(), left);
+          future.completeExceptionally(new IllegalStateException(
+              "Pending bytes negative in directRead for offset=" + r.getOffset()));
+          partialBuffers.remove(key);
+          pendingBytes.remove(key);
+          continue;
+        }
+
+        if (left == 0) {
+          fullBuf.position(0);
+          fullBuf.limit(r.getLength());
+          future.complete(fullBuf);
+          partialBuffers.remove(key);
+          pendingBytes.remove(key);
+          LOG.debug("directRead: completed range: path={}, rangeOffset={}, rangeLength={}",
+              stream.getPath(), r.getOffset(), r.getLength());
+        }
+      }
+    }
+  }
+
+  /**
+   * Identity-based key wrapper for {@link FileRange}.
+   *
+   * <p>This class ensures that {@link FileRange} instances are compared
+   * using reference equality rather than logical equality. It is used as
+   * a key in maps where multiple ranges may have identical offsets and
+   * lengths but must be treated as distinct objects.</p>
+   *
+   * <p>Equality and hash code are based on object identity
+   * ({@code ==}) via {@link System#identityHashCode(Object)}.</p>
+   */
+  static final class RangeKey {
+    private final FileRange range;
+
+    RangeKey(FileRange range) {
+      this.range = range;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      return this == o || (o instanceof RangeKey && this.range == ((RangeKey) o).range);
+    }
+
+    @Override
+    public int hashCode() {
+      return System.identityHashCode(range);
+    }
+  }
+}

Review Comment:
   taken



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3193745606


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/constants/ConfigurationKeys.java:
##########
@@ -627,6 +627,32 @@ public static String containerProperty(String property, String fsName, String ac
    */
   public static final String FS_AZURE_TAIL_LATENCY_MAX_RETRY_COUNT = "fs.azure.tail.latency.max.retry.count";
 
+  /**
+   * Configuration key to control the vectored read strategy used by ABFS: {@value}
+   */
+  public static final String FS_AZURE_VECTORED_READ_STRATEGY = "fs.azure.vectored.read.strategy";
+
+  /**
+   * Configuration key that defines the minimum gap between adjacent read ranges
+   * for merging ranges during vectored reads in ABFS: {@value}.
+   */
+  public static final String FS_AZURE_MIN_SEEK_FOR_VECTORED_READS =
+      "fs.azure.min.seek.for.vectored.reads";
+
+  /**
+   * Configuration key that defines the maximum gap between adjacent read ranges
+   * for merging ranges during vectored reads in ABFS: {@value}.
+   */
+  public static final String FS_AZURE_MAX_SEEK_FOR_VECTORED_READS =

Review Comment:
   taken



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4386093117

   Hi @steveloughran have addressed your concerns, can you take a look once. Thanks


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "hadoop-yetus (via GitHub)" <gi...@apache.org>.
hadoop-yetus commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4387131225

   :confetti_ball: **+1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime |  Logfile | Comment |
   |:----:|----------:|--------:|:--------:|:-------:|
   | +0 :ok: |  reexec  |  18m 13s |  |  Docker mode activated.  |
   |||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  0s |  |  No case conflicting files found.  |
   | +0 :ok: |  codespell  |   0m  1s |  |  codespell was not available.  |
   | +0 :ok: |  detsecrets  |   0m  1s |  |  detect-secrets was not available.  |
   | +0 :ok: |  xmllint  |   0m  1s |  |  xmllint was not available.  |
   | +1 :green_heart: |  @author  |   0m  0s |  |  The patch does not contain any @author tags.  |
   | +1 :green_heart: |  test4tests  |   0m  0s |  |  The patch appears to include 2 new or modified test files.  |
   |||| _ trunk Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  48m 48s |  |  trunk passed  |
   | +1 :green_heart: |  compile  |   1m  3s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  compile  |   1m  3s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  checkstyle  |   0m 57s |  |  trunk passed  |
   | +1 :green_heart: |  mvnsite  |   1m  6s |  |  trunk passed  |
   | +1 :green_heart: |  javadoc  |   1m  0s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 57s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 36s |  |  trunk passed  |
   | +1 :green_heart: |  shadedclient  |  35m 23s |  |  branch has no errors when building and testing our client artifacts.  |
   | -0 :warning: |  patch  |  35m 56s |  |  Used diff version of patch file. Binary files and potentially other changes not applied. Please rebase and squash commits if necessary.  |
   |||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   0m 37s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 32s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javac  |   0m 32s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 34s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  javac  |   0m 34s |  |  the patch passed  |
   | +1 :green_heart: |  blanks  |   0m  0s |  |  The patch has no blanks issues.  |
   | +1 :green_heart: |  checkstyle  |   0m 26s |  |  the patch passed  |
   | +1 :green_heart: |  mvnsite  |   0m 39s |  |  the patch passed  |
   | +1 :green_heart: |  javadoc  |   0m 29s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 29s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 17s |  |  the patch passed  |
   | +1 :green_heart: |  shadedclient  |  33m 43s |  |  patch has no errors when building and testing our client artifacts.  |
   |||| _ Other Tests _ |
   | +1 :green_heart: |  unit  |   2m 11s |  |  hadoop-azure in the patch passed.  |
   | +1 :green_heart: |  asflicense  |   0m 35s |  |  The patch does not generate ASF License warnings.  |
   |  |   | 153m 45s |  |  |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/12/artifact/out/Dockerfile |
   | GITHUB PR | https://github.com/apache/hadoop/pull/8400 |
   | Optional Tests | dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient codespell detsecrets xmllint spotbugs checkstyle |
   | uname | Linux 2130be252f3b 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | dev-support/bin/hadoop.sh |
   | git revision | trunk / b0b922485d8acd40e87d32a287d5f6d263b99484 |
   | Default Java | Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   | Multi-JDK versions | /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   |  Test Results | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/12/testReport/ |
   | Max. process+thread count | 567 (vs. ulimit of 10000) |
   | modules | C: hadoop-tools/hadoop-azure U: hadoop-tools/hadoop-azure |
   | Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/12/console |
   | versions | git=2.43.0 maven=3.9.11 spotbugs=4.9.7 |
   | Powered by | Apache Yetus 0.14.1 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4242195791

   @steveloughran @mukund-thakur requesting you to kindly review the PR. Thanks


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4182668293

   
   ============================================================
   HNS-OAuth-DFS
   ============================================================
   
   [WARNING] Tests run: 228, Failures: 0, Errors: 0, Skipped: 2
   [WARNING] Tests run: 858, Failures: 0, Errors: 0, Skipped: 172
   [WARNING] Tests run: 170, Failures: 0, Errors: 0, Skipped: 8
   [WARNING] Tests run: 272, Failures: 0, Errors: 0, Skipped: 23
   
   ============================================================
   HNS-SharedKey-DFS
   ============================================================
   
   [WARNING] Tests run: 228, Failures: 0, Errors: 0, Skipped: 3
   [WARNING] Tests run: 861, Failures: 0, Errors: 0, Skipped: 118
   [WARNING] Tests run: 170, Failures: 0, Errors: 0, Skipped: 8
   [WARNING] Tests run: 272, Failures: 0, Errors: 0, Skipped: 10
   
   ============================================================
   AppendBlob-HNS-OAuth-DFS
   ============================================================
   
   [WARNING] Tests run: 228, Failures: 0, Errors: 0, Skipped: 2
   [WARNING] Tests run: 858, Failures: 0, Errors: 0, Skipped: 183
   [WARNING] Tests run: 147, Failures: 0, Errors: 0, Skipped: 9
   [WARNING] Tests run: 272, Failures: 0, Errors: 0, Skipped: 23
   
   ============================================================
   NonHNS-SharedKey-Blob
   ============================================================
   
   [WARNING] Tests run: 228, Failures: 0, Errors: 0, Skipped: 9
   [WARNING] Tests run: 708, Failures: 0, Errors: 0, Skipped: 143
   [WARNING] Tests run: 170, Failures: 0, Errors: 0, Skipped: 3
   [WARNING] Tests run: 272, Failures: 0, Errors: 0, Skipped: 11
   


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "manika137 (via GitHub)" <gi...@apache.org>.
manika137 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3067601972


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV1.java:
##########
@@ -146,6 +168,124 @@ public void queueReadAhead(final AbfsInputStream stream, final long requestedOff
     }
   }
 
+  /**
+   * Queue a vectored read for a buffer-sized physical read unit.
+   *
+   * <p>The method first attempts to attach the logical unit to an already
+   * in-progress physical read for the same file and offset. If that is not
+   * possible, a free read buffer is acquired and a new backend read is
+   * queued.</p>
+   *
+   * @param stream         input stream for the file being read
+   * @param unit           buffer-sized combined file range to be read
+   * @param tracingContext tracing context used for the backend read request
+   * @param allocator      allocator used to create buffers for vectored fan-out
+   * @return {@code true} if the read was queued or attached to an existing
+   *         in-progress buffer; {@code false} if no buffer was available
+   */
+  boolean queueVectoredRead(AbfsInputStream stream,
+      CombinedFileRange unit,
+      TracingContext tracingContext,
+      IntFunction<ByteBuffer> allocator) {
+    /* Create a child tracing context for vectored read-ahead requests */
+    TracingContext readAheadTracingContext =
+        new TracingContext(tracingContext);
+    readAheadTracingContext.setPrimaryRequestID();
+    readAheadTracingContext.setReadType(ReadType.VECTORED_READ);
+
+    synchronized (this) {
+      if (isAlreadyQueued(stream, unit.getOffset())) {
+        ReadBuffer existing = findQueuedBuffer(stream, unit.getOffset());
+        if (existing != null && existing.getStream().getETag() != null
+            && stream.getETag().equals(existing.getStream().getETag())) {
+          /*
+           * For AVAILABLE buffers use actual bytes read (getLength()) for
+           * coverage check. For READING_IN_PROGRESS buffers use
+           * requestedLength as an estimate — the short-read guard will be
+           * applied later in doneReading before dispatching completion.
+           */
+          long end = existing.getOffset() + (
+              existing.getStatus() == ReadBufferStatus.AVAILABLE
+                  ? existing.getLength()
+                  : existing.getRequestedLength());
+          if (end >= unit.getOffset() + unit.getLength()) {
+            existing.setBufferType(BufferType.VECTORED);
+            existing.addVectoredUnit(unit);
+            existing.setAllocator(allocator);
+            if (existing.getStatus() == ReadBufferStatus.AVAILABLE) {
+              /*
+               * Buffer is already AVAILABLE. Trigger completion immediately.
+               * Use getLength() (actual bytes) for coverage — redundant here
+               * since the outer check already used getLength() for AVAILABLE,
+               * but kept explicit for clarity.
+               */
+              LOGGER.debug("Hitchhiking onto AVAILABLE buffer {}, length {}",
+                  existing, existing.getLength());
+              handleVectoredCompletion(existing,
+                  existing.getStatus(),
+                  existing.getLength());
+            }
+            /*
+             * For READING_IN_PROGRESS: unit is attached and will be
+             * completed in doneReading once actual bytes are known.
+             * Short-read safety is enforced there via per-unit coverage check.
+             */
+            return true;

Review Comment:
   this is not only the READING_IN_PROGRESS case right- incase the buffer is UNAVAILABLE (queued but not picked up by any thread yet) it would also land 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: common-issues-unsubscribe@hadoop.apache.org

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "manika137 (via GitHub)" <gi...@apache.org>.
manika137 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3067646491


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStream.java:
##########
@@ -1078,7 +1105,7 @@ public int minSeekForVectorReads() {
    */
   @Override
   public int maxReadSizeForVectorReads() {

Review Comment:
   the method mentions the read size but we're returning the max gap 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: common-issues-unsubscribe@hadoop.apache.org

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "hadoop-yetus (via GitHub)" <gi...@apache.org>.
hadoop-yetus commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4234952745

   :broken_heart: **-1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime |  Logfile | Comment |
   |:----:|----------:|--------:|:--------:|:-------:|
   | +0 :ok: |  reexec  |   0m 22s |  |  Docker mode activated.  |
   |||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  1s |  |  No case conflicting files found.  |
   | +0 :ok: |  codespell  |   0m  0s |  |  codespell was not available.  |
   | +0 :ok: |  detsecrets  |   0m  0s |  |  detect-secrets was not available.  |
   | +0 :ok: |  xmllint  |   0m  0s |  |  xmllint was not available.  |
   | +1 :green_heart: |  @author  |   0m  0s |  |  The patch does not contain any @author tags.  |
   | +1 :green_heart: |  test4tests  |   0m  0s |  |  The patch appears to include 2 new or modified test files.  |
   |||| _ trunk Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  25m  2s |  |  trunk passed  |
   | +1 :green_heart: |  compile  |   0m 36s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  compile  |   0m 42s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  checkstyle  |   0m 36s |  |  trunk passed  |
   | +1 :green_heart: |  mvnsite  |   0m 46s |  |  trunk passed  |
   | -1 :x: |  javadoc  |   0m 38s | [/branch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-21.0.10+7-Ubuntu-124.04.txt](https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/9/artifact/out/branch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-21.0.10+7-Ubuntu-124.04.txt) |  hadoop-azure in trunk failed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04.  |
   | -1 :x: |  javadoc  |   0m 40s | [/branch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-17.0.18+8-Ubuntu-124.04.1.txt](https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/9/artifact/out/branch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-17.0.18+8-Ubuntu-124.04.1.txt) |  hadoop-azure in trunk failed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1.  |
   | +1 :green_heart: |  spotbugs  |   0m 59s |  |  trunk passed  |
   | +1 :green_heart: |  shadedclient  |  16m 15s |  |  branch has no errors when building and testing our client artifacts.  |
   | -0 :warning: |  patch  |  16m 32s |  |  Used diff version of patch file. Binary files and potentially other changes not applied. Please rebase and squash commits if necessary.  |
   |||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   0m 22s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 20s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javac  |   0m 20s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 22s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  javac  |   0m 22s |  |  the patch passed  |
   | +1 :green_heart: |  blanks  |   0m  0s |  |  The patch has no blanks issues.  |
   | +1 :green_heart: |  checkstyle  |   0m 16s |  |  the patch passed  |
   | +1 :green_heart: |  mvnsite  |   0m 24s |  |  the patch passed  |
   | -1 :x: |  javadoc  |   0m 21s | [/patch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-21.0.10+7-Ubuntu-124.04.txt](https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/9/artifact/out/patch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-21.0.10+7-Ubuntu-124.04.txt) |  hadoop-azure in the patch failed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04.  |
   | -1 :x: |  javadoc  |   0m 21s | [/patch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-17.0.18+8-Ubuntu-124.04.1.txt](https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/9/artifact/out/patch-javadoc-hadoop-tools_hadoop-azure-jdkUbuntu-17.0.18+8-Ubuntu-124.04.1.txt) |  hadoop-azure in the patch failed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1.  |
   | +1 :green_heart: |  spotbugs  |   0m 47s |  |  the patch passed  |
   | +1 :green_heart: |  shadedclient  |  15m  0s |  |  patch has no errors when building and testing our client artifacts.  |
   |||| _ Other Tests _ |
   | +1 :green_heart: |  unit  |   1m 50s |  |  hadoop-azure in the patch passed.  |
   | +1 :green_heart: |  asflicense  |   0m 21s |  |  The patch does not generate ASF License warnings.  |
   |  |   |  68m 26s |  |  |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/9/artifact/out/Dockerfile |
   | GITHUB PR | https://github.com/apache/hadoop/pull/8400 |
   | Optional Tests | dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient codespell detsecrets xmllint spotbugs checkstyle |
   | uname | Linux be7fc4980ad7 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | dev-support/bin/hadoop.sh |
   | git revision | trunk / 3c6ad3e35b3cc948de3dbb8332afcc6eddf99dde |
   | Default Java | Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   | Multi-JDK versions | /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   |  Test Results | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/9/testReport/ |
   | Max. process+thread count | 610 (vs. ulimit of 10000) |
   | modules | C: hadoop-tools/hadoop-azure U: hadoop-tools/hadoop-azure |
   | Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/9/console |
   | versions | git=2.43.0 maven=3.9.11 spotbugs=4.9.7 |
   | Powered by | Apache Yetus 0.14.1 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3071287269


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/VectoredReadHandler.java:
##########
@@ -0,0 +1,696 @@
+/**
+ * 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.fs.azurebfs.services;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.IntFunction;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hadoop.classification.VisibleForTesting;
+import org.apache.hadoop.fs.FileRange;
+import org.apache.hadoop.fs.VectoredReadUtils;
+import org.apache.hadoop.fs.azurebfs.constants.ReadType;
+import org.apache.hadoop.fs.azurebfs.enums.VectoredReadStrategy;
+import org.apache.hadoop.fs.azurebfs.utils.TracingContext;
+import org.apache.hadoop.fs.impl.CombinedFileRange;
+
+/**
+ * Handles vectored read operations by coordinating with a ReadBufferManager
+ * and applying the configured VectoredReadStrategy.
+ * This class acts as the orchestration layer that decides how vectored reads
+ * are executed, while delegating buffer management and read behavior to
+ * dedicated components.
+ */
+class VectoredReadHandler {
+
+  private static final Logger LOG = LoggerFactory.getLogger(VectoredReadHandler.class);
+
+  /**
+   * Manages allocation, lifecycle, and reuse of read buffers
+   * used during vectored read operations.
+   */
+  private final ReadBufferManager readBufferManager;
+
+  /**
+   * Strategy defining how vectored reads should be performed.
+   */
+  private final VectoredReadStrategy strategy;
+
+  /**
+   * Shared reconstruction buffers for ranges that span multiple chunks.
+   * Keyed by the original FileRange instance.
+   */
+  private final ConcurrentHashMap<RangeKey, ByteBuffer> partialBuffers =
+      new ConcurrentHashMap<>();
+
+  /**
+   * Tracks remaining bytes to be received for each logical range.
+   * Keyed by the original FileRange instance.
+   */
+  private final ConcurrentHashMap<RangeKey, AtomicInteger> pendingBytes =
+      new ConcurrentHashMap<>();
+
+  /**
+   * Creates a VectoredReadHandler using the provided ReadBufferManager.
+   * The vectored read strategy is obtained from the manager to ensure
+   * consistent configuration across the read pipeline.
+   *
+   * @param readBufferManager manager responsible for buffer handling
+   *                          and providing the vectored read strategy
+   */
+  VectoredReadHandler(ReadBufferManager readBufferManager) {
+    this.readBufferManager = readBufferManager;
+    this.strategy = readBufferManager.getVectoredReadStrategy();
+    LOG.debug("VectoredReadHandler initialized with strategy={}", strategy);
+  }
+
+  /**
+   * Perform a vectored read over multiple logical file ranges.
+   *
+   * <p>Logical ranges are first merged using a span-first strategy determined
+   * by the configured {@link VectoredReadStrategy}. The merged ranges are then
+   * split into buffer-sized physical read units and queued for asynchronous
+   * execution. If a pooled buffer is unavailable, the read falls back to a
+   * direct read path.</p>
+   *
+   * @param stream    input stream for the file being read
+   * @param ranges    logical file ranges to read; each range will be completed
+   *                  with data or failure via its associated future
+   * @param allocator allocator used to create buffers for direct reads and
+   *                  vectored fan-out
+   */
+  public void readVectored(
+      AbfsInputStream stream,
+      List<? extends FileRange> ranges,
+      IntFunction<ByteBuffer> allocator) throws EOFException {
+    LOG.debug("readVectored invoked: path={}, rangeCount={}",
+        stream.getPath(), ranges.size());
+
+    /* Initialize a future for each logical file range */
+    long fileLength = stream.getContentLength();
+    List<FileRange> validRanges = validateAndPrepareRanges(ranges, fileLength);
+
+    /* Select the maximum allowed merge span based on the configured strategy */
+    int maxSpan =
+        (strategy == VectoredReadStrategy.TPS_OPTIMIZED)
+            ? readBufferManager.getMaxSeekForVectoredReads()
+            : readBufferManager.getMaxSeekForVectoredReadsThroughput();
+
+    LOG.debug("readVectored: path={}, strategy={}, maxSpan={}",
+        stream.getPath(), strategy, maxSpan);
+
+    /* Merge logical ranges using a span-first coalescing strategy */
+    List<CombinedFileRange> merged = mergeBySpanAndGap(validRanges, maxSpan, fileLength);
+
+    LOG.debug("readVectored: path={}, mergedRangeCount={}",
+        stream.getPath(), merged.size());
+
+    /* Read buffer size acts as a hard upper bound for physical reads */
+    int readBufferSize = ReadBufferManager.getReadAheadBlockSize();
+
+    /* Split merged ranges into buffer-sized chunks and queue each for read */
+    for (CombinedFileRange unit : merged) {
+      List<CombinedFileRange> chunks = splitByBufferSize(unit, readBufferSize);
+
+      LOG.debug("readVectored: path={}, mergedOffset={}, mergedLength={}, chunkCount={}",
+          stream.getPath(), unit.getOffset(), unit.getLength(), chunks.size());
+
+      for (CombinedFileRange chunk : chunks) {
+        try {
+          VectoredReadUtils.validateRangeRequest(chunk);
+          boolean queued = queueVectoredRead(stream, chunk, allocator);
+          if (!queued) {
+            LOG.debug("readVectored: buffer pool exhausted, falling back to directRead: path={}, offset={}, length={}",
+                stream.getPath(), chunk.getOffset(), chunk.getLength());
+            directRead(stream, chunk, allocator);
+          }
+        } catch (Exception e) {
+          LOG.warn("readVectored: chunk read failed, failing underlying ranges:"
+                  + " path={}, offset={}, length={}",
+              stream.getPath(), chunk.getOffset(), chunk.getLength(), e);
+          failUnit(chunk, e);
+        }
+      }
+    }
+  }
+
+  /**
+   * Queues a vectored read request with the buffer manager.
+   *
+   * @return true if successfully queued, false if the queue is full and fallback is required.
+   */
+  @VisibleForTesting
+  boolean queueVectoredRead(AbfsInputStream stream, CombinedFileRange unit,
+      IntFunction<ByteBuffer> allocator) {
+    LOG.debug("queueVectoredRead: path={}, offset={}, length={}",
+        stream.getPath(), unit.getOffset(), unit.getLength());
+    TracingContext tracingContext = stream.getTracingContext();
+    tracingContext.setReadType(ReadType.VECTORED_READ);
+    return getReadBufferManager().queueVectoredRead(stream, unit, tracingContext, allocator);
+  }
+
+  /**
+   * Accesses the shared manager responsible for coordinating asynchronous read buffers.
+   *
+   * @return the {@link ReadBufferManager} instance.
+   */
+  public ReadBufferManager getReadBufferManager() {
+    return readBufferManager;
+  }
+
+  /**
+   * Validates and prepares a list of {@link FileRange} instances for vectored reads.
+   *
+   * <p>This method performs the following steps for each input range:
+   * <ul>
+   *   <li>Validates the range using {@link VectoredReadUtils#validateRangeRequest(FileRange)}</li>
+   *   <li>Initializes a {@link CompletableFuture} to hold the read result</li>
+   *   <li>Checks that the range falls within the bounds of the file</li>
+   * </ul>
+   *
+   * <p>Ranges that are invalid (e.g., negative offset/length or exceeding file bounds)
+   * are not included in the returned list. Instead, their associated future is
+   * completed exceptionally with an {@link EOFException}.
+   *
+   * @param ranges     the input list of logical file ranges to validate and prepare
+   * @param fileLength the total length of the file, used for bounds checking
+   * @return a list of valid {@link FileRange} instances ready for vectored read processing
+   */
+  private List<FileRange> validateAndPrepareRanges(
+      List<? extends FileRange> ranges, long fileLength) throws EOFException {
+
+    List<FileRange> validRanges = new ArrayList<>();
+
+    for (FileRange r : ranges) {
+      VectoredReadUtils.validateRangeRequest(r);
+      r.setData(new CompletableFuture<>());
+
+      long offset = r.getOffset();
+      long length = r.getLength();
+
+      if (offset < 0 || length < 0 || offset > fileLength || length > fileLength - offset) {
+        r.getData().completeExceptionally(new EOFException(
+            "Invalid range: offset=" + offset + ", length=" + length + ", fileLength=" + fileLength));
+        continue;
+      }
+      validRanges.add(r);
+    }
+    return validRanges;
+  }
+
+  /**
+   * Splits a merged logical {@link CombinedFileRange} into smaller
+   * buffer-sized physical read units.
+   *
+   * <p>Each resulting unit will have a maximum size equal to the provided
+   * {@code bufferSize}. Any handling of multi-chunk ranges or reassembly
+   * of underlying {@link FileRange} data is delegated to the fan-out logic.</p>
+   *
+   * @param unit       the combined logical range to be split
+   * @param bufferSize the maximum size (in bytes) of each physical read unit
+   * @return a list of buffer-sized {@link CombinedFileRange} instances
+   */
+  private List<CombinedFileRange> splitByBufferSize(
+      CombinedFileRange unit,
+      int bufferSize) {
+    LOG.debug("splitByBufferSize: offset={}, length={}, bufferSize={}",
+        unit.getOffset(), unit.getLength(), bufferSize);
+
+    List<CombinedFileRange> parts = new ArrayList<>();
+    long unitStart = unit.getOffset();
+    long unitEnd = unitStart + unit.getLength();
+    long start = unitStart;
+
+    while (start < unitEnd) {
+      long partEnd = Math.min(start + bufferSize, unitEnd);
+
+      CombinedFileRange part =
+          new CombinedFileRange(start, partEnd, unit.getUnderlying().get(0));
+      part.getUnderlying().clear();
+
+      for (FileRange r : unit.getUnderlying()) {
+        long rStart = r.getOffset();
+        long rEnd = rStart + r.getLength();
+        if (rEnd > start && rStart < partEnd) {
+          part.getUnderlying().add(r);
+        }
+      }
+      parts.add(part);
+      start = partEnd;
+    }
+
+    LOG.debug("splitByBufferSize: offset={}, produced {} parts",
+        unit.getOffset(), parts.size());
+    return parts;
+  }
+
+  /**
+   * Merge logical {@link FileRange}s into {@link CombinedFileRange}s using a
+   * span-first coalescing strategy.
+   *
+   * <p>Ranges are merged as long as the total span from the first offset to the
+   * end of the last range does not exceed {@code maxSpan}. Gaps between ranges
+   * are ignored.</p>
+   *
+   * @param ranges  logical file ranges to merge
+   * @param maxSpan maximum allowed span (in bytes) for a combined read
+   * @return merged {@link CombinedFileRange}s covering the input ranges
+   */
+  private List<CombinedFileRange> mergeBySpanAndGap(
+      List<? extends FileRange> ranges,
+      int maxSpan, long  fileLength) throws EOFException {
+
+    LOG.debug("mergeBySpanAndGap: rangeCount={}, maxSpan={}", ranges.size(), maxSpan);
+    List<? extends FileRange> sortedRanges = VectoredReadUtils.validateAndSortRanges(
+        ranges, Optional.of(fileLength));
+
+    List<CombinedFileRange> out = new ArrayList<>();
+    CombinedFileRange current = null;
+
+    for (FileRange r : sortedRanges) {
+      long rOffset = r.getOffset();
+      long rEnd = rOffset + r.getLength();
+
+      /* Initialize the first combined range */
+      if (current == null) {
+        current = new CombinedFileRange(rOffset, rEnd, r);
+        continue;
+      }
+
+      /* Check whether adding this range keeps the total span within the limit */
+      long newSpan = rEnd - current.getOffset();
+
+      if (newSpan <= maxSpan) {
+        current.setLength((int) newSpan);
+        current.getUnderlying().add(r);
+      } else {
+        /* Span exceeded; finalize current range and start a new one */
+        out.add(current);
+        current = new CombinedFileRange(rOffset, rEnd, r);
+      }
+    }
+
+    /* Add the final combined range, if any */
+    if (current != null) {
+      out.add(current);
+    }
+
+    LOG.debug("mergeBySpanAndGap: produced {} combined ranges", out.size());
+    return out;
+  }
+
+  /**
+   * Distributes data from a physical read buffer into the corresponding
+   * logical {@link FileRange}s.
+   *
+   * <p>This method performs a "fan-out" operation where a single physical
+   * read (represented by {@link ReadBuffer}) may contain data for multiple
+   * logical ranges. The relevant portions are copied into per-range buffers
+   * and completed once fully populated.</p>
+   *
+   * <p>Partial reads are accumulated using {@code partialBuffers} and
+   * {@code pendingBytes}. A range is only completed when all expected
+   * bytes have been received.</p>
+   *
+   * <p>Thread safety:
+   * <ul>
+   *   <li>Each logical range buffer is synchronized independently</li>
+   *   <li>Writes use {@code System.arraycopy} directly into the backing array
+   *       to avoid shared {@link ByteBuffer} position mutation</li>
+   * </ul>
+   * </p>
+   *
+   * @param buffer    the physical read buffer containing merged data
+   * @param bytesRead number of valid bytes in the buffer
+   */
+  void fanOut(ReadBuffer buffer, int bytesRead) {
+    LOG.debug("fanOut: path={}, bufferOffset={}, bytesRead={}",
+        buffer.getPath(), buffer.getOffset(), bytesRead);
+
+    List<CombinedFileRange> units = buffer.getVectoredUnits();
+    if (units == null) {
+      LOG.warn("fanOut: no vectored units found for path={}, offset={}",
+          buffer.getPath(), buffer.getOffset());
+      return;
+    }
+
+    long bufferStart = buffer.getOffset();
+    long bufferEnd = bufferStart + bytesRead;
+
+    /* Iterate over all combined logical units mapped to this buffer */
+    for (CombinedFileRange unit : units) {

Review Comment:
   Overlapping ranges are not allowed, List<? extends FileRange> sortedRanges = VectoredReadUtils.validateAndSortRanges(
           ranges, Optional.of(fileLength)); this takes care of that



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "mukund-thakur (via GitHub)" <gi...@apache.org>.
mukund-thakur commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4330476024

   > Hi @mukund-thakur gentle reminder for reviewing the PR
   
   Hi @anmolanmol1234  Thanks for implementing this in ABFS. I skimmed over the changes quickly and I think it would be better if someone from ABFS team review and commit this. I haven't touched this code in long time. I would be happy to answer interface related questions. Thanks. 


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anujmodi2021 (via GitHub)" <gi...@apache.org>.
anujmodi2021 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3107937212


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -338,6 +356,119 @@ public void queueReadAhead(final AbfsInputStream stream,
     }
   }
 
+  /**
+   * Queue a vectored read for a buffer-sized physical read unit.
+   *
+   * <p>The method first attempts to attach the logical unit to an already
+   * in-progress physical read for the same file and offset. If that is not
+   * possible, a free read buffer is acquired and a new backend read is
+   * queued.</p>
+   *
+   * @param stream         input stream for the file being read
+   * @param unit           buffer-sized combined file range to be read
+   * @param tracingContext tracing context used for the backend read request
+   * @param allocator      allocator used to create buffers for vectored fan-out
+   * @return {@code true} if the read was queued or attached to an existing
+   *         in-progress buffer; {@code false} if no buffer was available
+   */
+  boolean queueVectoredRead(AbfsInputStream stream,
+      CombinedFileRange unit,
+      TracingContext tracingContext,
+      IntFunction<ByteBuffer> allocator) {
+    /* Create a child tracing context for vectored read-ahead requests */
+    TracingContext readAheadTracingContext =
+        new TracingContext(tracingContext);
+    readAheadTracingContext.setPrimaryRequestID();
+    readAheadTracingContext.setReadType(ReadType.VECTORED_READ);
+    synchronized (this) {
+      /*
+       * Attempt to hitchhike on an existing in-progress physical read if it
+       * covers the requested logical range completely.
+       */
+      if (isAlreadyQueued(stream.getETag(), unit.getOffset())) {
+        ReadBuffer existing = findQueuedBuffer(stream, unit.getOffset());
+        if (existing != null && existing.getStream().getETag() != null  && stream.getETag()
+            .equals(existing.getStream().getETag())) {
+          long end = existing.getOffset() + (
+              existing.getStatus() == ReadBufferStatus.AVAILABLE
+                  ? existing.getLength()
+                  : existing.getRequestedLength());
+          if (end >= unit.getOffset() + unit.getLength()) {
+            existing.setBufferType(BufferType.VECTORED);
+            existing.addVectoredUnit(unit);
+            existing.setAllocator(allocator);
+            if (existing.getStatus() == ReadBufferStatus.AVAILABLE) {
+              /*
+               * Buffer is already AVAILABLE. Trigger completion immediately.
+               * Use getLength() (actual bytes) for coverage — redundant here
+               * since the outer check already used getLength() for AVAILABLE,
+               * but kept explicit for clarity.
+               */
+              LOGGER.debug("Hitchhiking onto AVAILABLE buffer {}, length {}",
+                  existing, existing.getLength());
+              handleVectoredCompletion(existing,
+                  existing.getStatus(),
+                  existing.getLength());
+            }
+            /*
+             * For AVAILABLE buffers use the actual bytes read (getLength()) for
+             * coverage check. For all other states (NOT_AVAILABLE or
+             * READING_IN_PROGRESS), use requestedLength as an estimate of the
+             * planned physical read coverage. The short-read guard will later be
+             * enforced in doneReading() once the actual bytes read are known.
+             */
+            return true;
+          }
+        }
+      }
+      /*
+       * Ensure a free buffer is available, attempting best-effort recovery
+       * through memory upscaling or eviction if necessary.
+       */
+      if (isFreeListEmpty() && !tryMemoryUpscale() && !tryEvict()) {
+        return false;
+      }
+      /*
+       * Create a logical ReadBuffer descriptor without binding pooled memory.
+       * This captures metadata required to schedule the physical read.
+       */
+      ReadBuffer buffer = new ReadBuffer();
+      buffer.setStream(stream);
+      buffer.setETag(stream.getETag());
+      buffer.setPath(stream.getPath());
+      buffer.setOffset(unit.getOffset());
+      buffer.setRequestedLength(unit.getLength());
+      buffer.setBufferType(BufferType.VECTORED);
+      buffer.setStatus(ReadBufferStatus.NOT_AVAILABLE);
+      buffer.setLatch(new CountDownLatch(1));
+      buffer.addVectoredUnit(unit);
+      buffer.setAllocator(allocator);
+      buffer.setTracingContext(readAheadTracingContext);
+      /*
+       * Perform a final free-list check before consuming pooled memory to
+       * ensure buffer availability.
+       */
+      if (isFreeListEmpty()) {
+        return false;
+      }
+      Integer bufferIndex = popFromFreeList();
+      if (bufferIndex >= bufferPool.length) {
+        /* Defensive guard; should never occur */
+        return false;
+      }
+      /*
+       * Bind the physical buffer and queue the read for asynchronous
+       * execution.
+       */
+      buffer.setBuffer(bufferPool[bufferIndex]);
+      buffer.setBufferindex(bufferIndex);
+
+      getReadAheadQueue().add(buffer);

Review Comment:
   Please add trce logging here and other places as done for normal queuing and RBMV1



##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -427,27 +558,84 @@ public ReadBuffer getNextBlockToRead() throws InterruptedException {
   public void doneReading(final ReadBuffer buffer,
       final ReadBufferStatus result,
       final int bytesActuallyRead) {
-    printTraceLog(
-        "ReadBufferWorker completed prefetch for file: {} with eTag: {}, for offset: {}, queued by stream: {}, with status: {} and bytes read: {}",
-        buffer.getPath(), buffer.getETag(), buffer.getOffset(),
-        buffer.getStream().hashCode(), result, bytesActuallyRead);
+    if (LOGGER.isTraceEnabled()) {

Review Comment:
   Please use printTraceLog(), it has check inside method



##########
hadoop-tools/hadoop-azure/pom.xml:
##########
@@ -497,6 +498,7 @@
                     <include>**/azurebfs/ITestSmallWriteOptimization.java</include>
                     <include>**/azurebfs/services/ITestReadBufferManager.java</include>
                     <include>**/azurebfs/ITestAbfsStreamStatistics*.java</include>
+                    <include>**/azurebfs/services/ITestVectoredRead.java</include>

Review Comment:
   Why they can't run in parallel?



##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -427,27 +558,84 @@ public ReadBuffer getNextBlockToRead() throws InterruptedException {
   public void doneReading(final ReadBuffer buffer,
       final ReadBufferStatus result,
       final int bytesActuallyRead) {
-    printTraceLog(
-        "ReadBufferWorker completed prefetch for file: {} with eTag: {}, for offset: {}, queued by stream: {}, with status: {} and bytes read: {}",
-        buffer.getPath(), buffer.getETag(), buffer.getOffset(),
-        buffer.getStream().hashCode(), result, bytesActuallyRead);
+    if (LOGGER.isTraceEnabled()) {

Review Comment:
   Here and everywhere



##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV1.java:
##########
@@ -208,8 +350,69 @@ public ReadBuffer getNextBlockToRead() throws InterruptedException {
   public void doneReading(final ReadBuffer buffer, final ReadBufferStatus result, final int bytesActuallyRead) {
     if (LOGGER.isTraceEnabled()) {
       LOGGER.trace("ReadBufferWorker completed read file {} for offset {} outcome {} bytes {}",
-          buffer.getStream().getPath(),  buffer.getOffset(), result, bytesActuallyRead);
+          buffer.getStream().getPath(), buffer.getOffset(), result, bytesActuallyRead);
+    }
+
+    List<CombinedFileRange> vectoredUnits = buffer.getVectoredUnits();
+    if (result == ReadBufferStatus.AVAILABLE
+        && (buffer.getBufferType() == BufferType.VECTORED && !vectoredUnits.isEmpty())) {
+
+      /*
+       * Set length BEFORE handling vectored completion so that any
+       * hitchhiked units that call existing.getLength() see the correct
+       * actual value rather than 0.
+       */
+      buffer.setLength(bytesActuallyRead);
+
+      /*
+       * Guard against short reads: units hitchhiked while buffer was
+       * READING_IN_PROGRESS used requestedLength as coverage estimate.
+       * Now that actual bytes are known, fail any units not fully covered
+       * so their callers are not left hanging on the CompletableFuture.
+       */
+      long actualEnd = buffer.getOffset() + bytesActuallyRead;
+
+      /*
+       * Fast path: check if any unit exceeds actual bytes read before
+       * doing expensive stream/collect. Short reads are rare so this
+       * avoids unnecessary allocations in the common case.
+       */
+      boolean hasUncovered = false;
+      for (CombinedFileRange u : vectoredUnits) {
+        if ((u.getOffset() + u.getLength()) > actualEnd) {
+          hasUncovered = true;
+          break;
+        }
+      }
+
+      if (hasUncovered) {
+        /*
+         * Short read detected — fail uncovered units explicitly so callers
+         * are not left hanging on their CompletableFuture.
+         */
+        Iterator<CombinedFileRange> it = vectoredUnits.iterator();
+        while (it.hasNext()) {
+          CombinedFileRange u = it.next();
+          if ((u.getOffset() + u.getLength()) > actualEnd) {
+            it.remove();
+            LOGGER.debug(

Review Comment:
   I think we should use Trace logs at most places and debug only at critical spots and errors?



##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStream.java:
##########
@@ -1078,7 +1105,7 @@ public int minSeekForVectorReads() {
    */
   @Override
   public int maxReadSizeForVectorReads() {

Review Comment:
   But why are we returning the seek size here? Why not actual read size?



##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -506,7 +694,7 @@ private ReadBuffer getFromList(final Collection<ReadBuffer> list,
       final String eTag,
       final long requestedOffset) {
     for (ReadBuffer buffer : list) {
-      if (eTag.equals(buffer.getETag())) {
+      if (eTag != null && eTag.equals(buffer.getETag())) {

Review Comment:
   We can use Objects.equals(). It will have null check



##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -749,7 +937,7 @@ private ReadBuffer getBufferFromCompletedQueue(final String eTag,
     for (ReadBuffer buffer : getCompletedReadList()) {
       // Buffer is returned if the requestedOffset is at or above buffer's
       // offset but less than buffer's length or the actual requestedLength
-      if (eTag.equals(buffer.getETag())
+      if (eTag != null && eTag.equals(buffer.getETag())

Review Comment:
   Same as above



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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "hadoop-yetus (via GitHub)" <gi...@apache.org>.
hadoop-yetus commented on PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#issuecomment-4289124580

   :confetti_ball: **+1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime |  Logfile | Comment |
   |:----:|----------:|--------:|:--------:|:-------:|
   | +0 :ok: |  reexec  |  18m 35s |  |  Docker mode activated.  |
   |||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  0s |  |  No case conflicting files found.  |
   | +0 :ok: |  codespell  |   0m  1s |  |  codespell was not available.  |
   | +0 :ok: |  detsecrets  |   0m  1s |  |  detect-secrets was not available.  |
   | +0 :ok: |  xmllint  |   0m  1s |  |  xmllint was not available.  |
   | +1 :green_heart: |  @author  |   0m  0s |  |  The patch does not contain any @author tags.  |
   | +1 :green_heart: |  test4tests  |   0m  0s |  |  The patch appears to include 2 new or modified test files.  |
   |||| _ trunk Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |  48m  9s |  |  trunk passed  |
   | +1 :green_heart: |  compile  |   1m  2s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  compile  |   1m  2s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  checkstyle  |   0m 57s |  |  trunk passed  |
   | +1 :green_heart: |  mvnsite  |   1m  7s |  |  trunk passed  |
   | +1 :green_heart: |  javadoc  |   1m  0s |  |  trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 56s |  |  trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 35s |  |  trunk passed  |
   | +1 :green_heart: |  shadedclient  |  35m 28s |  |  branch has no errors when building and testing our client artifacts.  |
   | -0 :warning: |  patch  |  36m  1s |  |  Used diff version of patch file. Binary files and potentially other changes not applied. Please rebase and squash commits if necessary.  |
   |||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   0m 36s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 32s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javac  |   0m 32s |  |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 34s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  javac  |   0m 34s |  |  the patch passed  |
   | +1 :green_heart: |  blanks  |   0m  0s |  |  The patch has no blanks issues.  |
   | +1 :green_heart: |  checkstyle  |   0m 26s |  |  the patch passed  |
   | +1 :green_heart: |  mvnsite  |   0m 38s |  |  the patch passed  |
   | +1 :green_heart: |  javadoc  |   0m 28s |  |  the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04  |
   | +1 :green_heart: |  javadoc  |   0m 29s |  |  the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1  |
   | +1 :green_heart: |  spotbugs  |   1m 18s |  |  the patch passed  |
   | +1 :green_heart: |  shadedclient  |  34m 32s |  |  patch has no errors when building and testing our client artifacts.  |
   |||| _ Other Tests _ |
   | +1 :green_heart: |  unit  |   2m 10s |  |  hadoop-azure in the patch passed.  |
   | +1 :green_heart: |  asflicense  |   0m 35s |  |  The patch does not generate ASF License warnings.  |
   |  |   | 154m  9s |  |  |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/11/artifact/out/Dockerfile |
   | GITHUB PR | https://github.com/apache/hadoop/pull/8400 |
   | Optional Tests | dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient codespell detsecrets xmllint spotbugs checkstyle |
   | uname | Linux b5723321dbb5 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | dev-support/bin/hadoop.sh |
   | git revision | trunk / 7899f501300e77087bdb2123cb2e60b640e1558e |
   | Default Java | Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   | Multi-JDK versions | /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1 |
   |  Test Results | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/11/testReport/ |
   | Max. process+thread count | 569 (vs. ulimit of 10000) |
   | modules | C: hadoop-tools/hadoop-azure U: hadoop-tools/hadoop-azure |
   | Console output | https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8400/11/console |
   | versions | git=2.43.0 maven=3.9.11 spotbugs=4.9.7 |
   | Powered by | Apache Yetus 0.14.1 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   


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

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


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


Re: [PR] HADOOP-1593. [ABFS] Add vectored read support in ABFS driver [hadoop]

Posted by "anmolanmol1234 (via GitHub)" <gi...@apache.org>.
anmolanmol1234 commented on code in PR #8400:
URL: https://github.com/apache/hadoop/pull/8400#discussion_r3117015823


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -338,6 +356,119 @@ public void queueReadAhead(final AbfsInputStream stream,
     }
   }
 
+  /**
+   * Queue a vectored read for a buffer-sized physical read unit.
+   *
+   * <p>The method first attempts to attach the logical unit to an already
+   * in-progress physical read for the same file and offset. If that is not
+   * possible, a free read buffer is acquired and a new backend read is
+   * queued.</p>
+   *
+   * @param stream         input stream for the file being read
+   * @param unit           buffer-sized combined file range to be read
+   * @param tracingContext tracing context used for the backend read request
+   * @param allocator      allocator used to create buffers for vectored fan-out
+   * @return {@code true} if the read was queued or attached to an existing
+   *         in-progress buffer; {@code false} if no buffer was available
+   */
+  boolean queueVectoredRead(AbfsInputStream stream,
+      CombinedFileRange unit,
+      TracingContext tracingContext,
+      IntFunction<ByteBuffer> allocator) {
+    /* Create a child tracing context for vectored read-ahead requests */
+    TracingContext readAheadTracingContext =
+        new TracingContext(tracingContext);
+    readAheadTracingContext.setPrimaryRequestID();
+    readAheadTracingContext.setReadType(ReadType.VECTORED_READ);
+    synchronized (this) {
+      /*
+       * Attempt to hitchhike on an existing in-progress physical read if it
+       * covers the requested logical range completely.
+       */
+      if (isAlreadyQueued(stream.getETag(), unit.getOffset())) {
+        ReadBuffer existing = findQueuedBuffer(stream, unit.getOffset());
+        if (existing != null && existing.getStream().getETag() != null  && stream.getETag()
+            .equals(existing.getStream().getETag())) {
+          long end = existing.getOffset() + (
+              existing.getStatus() == ReadBufferStatus.AVAILABLE
+                  ? existing.getLength()
+                  : existing.getRequestedLength());
+          if (end >= unit.getOffset() + unit.getLength()) {
+            existing.setBufferType(BufferType.VECTORED);
+            existing.addVectoredUnit(unit);
+            existing.setAllocator(allocator);
+            if (existing.getStatus() == ReadBufferStatus.AVAILABLE) {
+              /*
+               * Buffer is already AVAILABLE. Trigger completion immediately.
+               * Use getLength() (actual bytes) for coverage — redundant here
+               * since the outer check already used getLength() for AVAILABLE,
+               * but kept explicit for clarity.
+               */
+              LOGGER.debug("Hitchhiking onto AVAILABLE buffer {}, length {}",
+                  existing, existing.getLength());
+              handleVectoredCompletion(existing,
+                  existing.getStatus(),
+                  existing.getLength());
+            }
+            /*
+             * For AVAILABLE buffers use the actual bytes read (getLength()) for
+             * coverage check. For all other states (NOT_AVAILABLE or
+             * READING_IN_PROGRESS), use requestedLength as an estimate of the
+             * planned physical read coverage. The short-read guard will later be
+             * enforced in doneReading() once the actual bytes read are known.
+             */
+            return true;
+          }
+        }
+      }
+      /*
+       * Ensure a free buffer is available, attempting best-effort recovery
+       * through memory upscaling or eviction if necessary.
+       */
+      if (isFreeListEmpty() && !tryMemoryUpscale() && !tryEvict()) {
+        return false;
+      }
+      /*
+       * Create a logical ReadBuffer descriptor without binding pooled memory.
+       * This captures metadata required to schedule the physical read.
+       */
+      ReadBuffer buffer = new ReadBuffer();
+      buffer.setStream(stream);
+      buffer.setETag(stream.getETag());
+      buffer.setPath(stream.getPath());
+      buffer.setOffset(unit.getOffset());
+      buffer.setRequestedLength(unit.getLength());
+      buffer.setBufferType(BufferType.VECTORED);
+      buffer.setStatus(ReadBufferStatus.NOT_AVAILABLE);
+      buffer.setLatch(new CountDownLatch(1));
+      buffer.addVectoredUnit(unit);
+      buffer.setAllocator(allocator);
+      buffer.setTracingContext(readAheadTracingContext);
+      /*
+       * Perform a final free-list check before consuming pooled memory to
+       * ensure buffer availability.
+       */
+      if (isFreeListEmpty()) {
+        return false;
+      }
+      Integer bufferIndex = popFromFreeList();
+      if (bufferIndex >= bufferPool.length) {
+        /* Defensive guard; should never occur */
+        return false;
+      }
+      /*
+       * Bind the physical buffer and queue the read for asynchronous
+       * execution.
+       */
+      buffer.setBuffer(bufferPool[bufferIndex]);
+      buffer.setBufferindex(bufferIndex);
+
+      getReadAheadQueue().add(buffer);

Review Comment:
   taken



##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV1.java:
##########
@@ -208,8 +350,69 @@ public ReadBuffer getNextBlockToRead() throws InterruptedException {
   public void doneReading(final ReadBuffer buffer, final ReadBufferStatus result, final int bytesActuallyRead) {
     if (LOGGER.isTraceEnabled()) {
       LOGGER.trace("ReadBufferWorker completed read file {} for offset {} outcome {} bytes {}",
-          buffer.getStream().getPath(),  buffer.getOffset(), result, bytesActuallyRead);
+          buffer.getStream().getPath(), buffer.getOffset(), result, bytesActuallyRead);
+    }
+
+    List<CombinedFileRange> vectoredUnits = buffer.getVectoredUnits();
+    if (result == ReadBufferStatus.AVAILABLE
+        && (buffer.getBufferType() == BufferType.VECTORED && !vectoredUnits.isEmpty())) {
+
+      /*
+       * Set length BEFORE handling vectored completion so that any
+       * hitchhiked units that call existing.getLength() see the correct
+       * actual value rather than 0.
+       */
+      buffer.setLength(bytesActuallyRead);
+
+      /*
+       * Guard against short reads: units hitchhiked while buffer was
+       * READING_IN_PROGRESS used requestedLength as coverage estimate.
+       * Now that actual bytes are known, fail any units not fully covered
+       * so their callers are not left hanging on the CompletableFuture.
+       */
+      long actualEnd = buffer.getOffset() + bytesActuallyRead;
+
+      /*
+       * Fast path: check if any unit exceeds actual bytes read before
+       * doing expensive stream/collect. Short reads are rare so this
+       * avoids unnecessary allocations in the common case.
+       */
+      boolean hasUncovered = false;
+      for (CombinedFileRange u : vectoredUnits) {
+        if ((u.getOffset() + u.getLength()) > actualEnd) {
+          hasUncovered = true;
+          break;
+        }
+      }
+
+      if (hasUncovered) {
+        /*
+         * Short read detected — fail uncovered units explicitly so callers
+         * are not left hanging on their CompletableFuture.
+         */
+        Iterator<CombinedFileRange> it = vectoredUnits.iterator();
+        while (it.hasNext()) {
+          CombinedFileRange u = it.next();
+          if ((u.getOffset() + u.getLength()) > actualEnd) {
+            it.remove();
+            LOGGER.debug(

Review Comment:
   taken



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

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


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