This is an automated email from the ASF dual-hosted git repository.

smengcl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 403f9d42fe3 HDDS-16680. StreamBlockInputStream returns EOF instead of 
failing over when an error response arrives during poll() (#11388)
403f9d42fe3 is described below

commit 403f9d42fe3f629416852817f2b98baddbfb3fd7
Author: Sergey Soldatov <[email protected]>
AuthorDate: Sat Oct 17 14:30:20 2026 -0700

    HDDS-16680. StreamBlockInputStream returns EOF instead of failing over when 
an error response arrives during poll() (#11388)
---
 .../hdds/scm/storage/StreamBlockInputStream.java   |  5 ++-
 .../scm/storage/TestStreamBlockInputStream.java    | 45 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git 
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java
 
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java
index c162553ee81..8bde1f569cf 100644
--- 
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java
+++ 
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java
@@ -643,6 +643,8 @@ ReadBlockResponseProto poll() throws IOException {
         // checked first, an item delivered by onNext() just before 
onCompleted()
         // fired would be silently dropped, causing data corruption.
         if (future.isDone()) {
+          // The stream may have failed while waiting above; surface the error 
instead of returning EOF.
+          checkError();
           return null; // Stream ended, queue is empty
         }
 
@@ -653,7 +655,8 @@ ReadBlockResponseProto poll() throws IOException {
           if (setFailed(e)) {
             throw e;
           }
-          return null;
+          // The stream completed concurrently: re-check for an error or a 
queued response instead of returning EOF.
+          continue;
         }
       }
     }
diff --git 
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestStreamBlockInputStream.java
 
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestStreamBlockInputStream.java
index ceb4497fd33..725297738e2 100644
--- 
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestStreamBlockInputStream.java
+++ 
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestStreamBlockInputStream.java
@@ -1236,6 +1236,51 @@ public void testFailFastOnGrpcOutOfRangeStatus() throws 
Exception {
     }
   }
 
+  /**
+   * An error response (e.g. UNKNOWN_BCSID from a replica that has not applied 
the block yet) arrives
+   * asynchronously, while poll() is waiting on the empty response queue. It 
must surface as an IOException
+   * so that handleExceptions() can fail over, not as EOF.
+   */
+  @Test
+  public void testErrorResponseDuringPollWaitIsNotEof() throws Exception {
+    OzoneClientConfig clientConfig = newStreamReadConfig();
+    clientConfig.setMaxReadRetryCount(0);
+    ClientCallStreamObserver<ContainerCommandRequestProto> requestObserver = 
mock(ClientCallStreamObserver.class);
+
+    AtomicReference<Thread> responseThreadRef = new AtomicReference<>();
+    XceiverClientGrpc xceiverClient = 
mockCapturingStreamingReadClient(requestObserver, reader -> {
+      // Deliver the error well inside the first poll() wait (100 ms), as a 
gRPC executor thread would.
+      Thread responseThread = new Thread(() -> {
+        try {
+          Thread.sleep(50);
+        } catch (InterruptedException ignored) {
+          Thread.currentThread().interrupt();
+        }
+        reader.onNext(ContainerCommandResponseProto.newBuilder()
+            .setCmdType(Type.ReadBlock)
+            .setResult(ContainerProtos.Result.UNKNOWN_BCSID)
+            .setMessage("Unable to find the block with bcsID 2")
+            .build());
+      });
+      responseThreadRef.set(responseThread);
+      responseThread.start();
+    });
+    XceiverClientFactory xceiverClientFactory = 
mock(XceiverClientFactory.class);
+    
when(xceiverClientFactory.acquireClientForReadData(any(Pipeline.class))).thenReturn(xceiverClient);
+
+    try (StreamBlockInputStream sbis = new StreamBlockInputStream(
+        new BlockID(1L, 23L), 1024L, mockStandalonePipeline(), null, 
xceiverClientFactory,
+        NO_REFRESH, clientConfig)) {
+      ByteBuffer buf = ByteBuffer.allocate(1024);
+      IOException thrown = assertThrows(IOException.class, () -> 
sbis.read(buf),
+          "an error response during the poll wait should surface as an 
IOException, not EOF");
+      responseThreadRef.get().join();
+
+      assertThat(hasCause(thrown, StorageContainerException.class)).isTrue();
+      assertThat(hasCause(thrown, TimeoutIOException.class)).isFalse();
+    }
+  }
+
   /**
    * A streamed error response (e.g. CONTAINER_NOT_FOUND) is retried after 
refreshing the block location,
    * for both sequential and positioned reads.


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

Reply via email to