You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "szetszwo (via GitHub)" <gi...@apache.org> on 2025/11/26 07:18:52 UTC

[PR] HDDS-13975. Limit the number of responses in stream read block. [ozone]

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

   ## What changes were proposed in this pull request?
   
   In [HDDS-13973](https://issues.apache.org/jira/browse/HDDS-13973), the client sends a single stream read block request and the datanode will reply the entire block in multiple responses. However, the client may read only a part of the block or read slowly. In such cases, the datanode will queue up all the block data in the gRPC layer.
   
   In this PR, we
   - add required length L to the request and then the datanode only replies L bytes of data;
   - support multiple checksums in a single response;
   - support pre-read;
   - change the datanode to open and close the block file only once per gRPC stream.
   
   ## What is the link to the Apache JIRA
   
   HDDS-13975
   
   ## How was this patch tested?
   
   Adding new tests.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

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


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


Re: [PR] HDDS-13975. Limit the number of responses in stream read block. [ozone]

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


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java:
##########
@@ -207,36 +219,61 @@ protected synchronized void acquireClient() throws IOException {
     checkOpen();
     if (xceiverClient == null) {
       final Pipeline pipeline = pipelineRef.get();
+      final XceiverClientSpi client;
       try {
-        xceiverClient = xceiverClientFactory.acquireClientForReadData(pipeline);
+        client = xceiverClientFactory.acquireClientForReadData(pipeline);
       } catch (IOException ioe) {
         LOG.warn("Failed to acquire client for pipeline {}, block {}", pipeline, blockID);
         throw ioe;
       }
+
+      if (client == null) {
+        throw new IOException("Failed to acquire client for " + pipeline);
+      }
+      if (!(client instanceof XceiverClientGrpc)) {
+        throw new IOException("Unexpected client class: " + client.getClass().getName() + ", " + pipeline);
+      }
+
+      xceiverClient =  (XceiverClientGrpc) client;
     }
   }
 
-  private void initialize() throws IOException {
-    if (initialized) {
-      return;
-    }
-    while (true) {
+  private synchronized void initialize() throws IOException {
+    while (streamingReader == null) {
       try {
         acquireClient();
-        streamingReader = new StreamingReader();
-        ContainerProtocolCalls.readBlock(xceiverClient, position, blockID, tokenRef.get(),
-            pipelineRef.get().getReplicaIndexes(), streamingReader);
-        initialized = true;
-        return;
-      } catch (InterruptedException ie) {
-        Thread.currentThread().interrupt();
-        handleExceptions(new IOException("Interrupted", ie));
       } catch (IOException ioe) {
         handleExceptions(ioe);
       }
+
+      streamingReader = new StreamingReader();
+      xceiverClient.initStreamRead(blockID, streamingReader);

Review Comment:
   Here is my suggestion:
   
   ```
   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 8ddd5c4220..11ce1a68d7 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
   @@ -247,8 +247,12 @@ private synchronized void initialize() throws IOException {
            handleExceptions(ioe);
          }
    
   -      streamingReader = new StreamingReader();
   -      xceiverClient.initStreamRead(blockID, streamingReader);
   +      try {
   +        streamingReader = new StreamingReader();
   +        xceiverClient.initStreamRead(blockID, streamingReader);
   +      } catch (IOException ioe) {
   +        streamingReader = null;
   +      }
        }
      }
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

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


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


Re: [PR] HDDS-13975. Limit the number of responses in stream read block. [ozone]

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


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java:
##########
@@ -207,36 +219,61 @@ protected synchronized void acquireClient() throws IOException {
     checkOpen();
     if (xceiverClient == null) {
       final Pipeline pipeline = pipelineRef.get();
+      final XceiverClientSpi client;
       try {
-        xceiverClient = xceiverClientFactory.acquireClientForReadData(pipeline);
+        client = xceiverClientFactory.acquireClientForReadData(pipeline);
       } catch (IOException ioe) {
         LOG.warn("Failed to acquire client for pipeline {}, block {}", pipeline, blockID);
         throw ioe;
       }
+
+      if (client == null) {
+        throw new IOException("Failed to acquire client for " + pipeline);
+      }
+      if (!(client instanceof XceiverClientGrpc)) {
+        throw new IOException("Unexpected client class: " + client.getClass().getName() + ", " + pipeline);
+      }
+
+      xceiverClient =  (XceiverClientGrpc) client;
     }
   }
 
-  private void initialize() throws IOException {
-    if (initialized) {
-      return;
-    }
-    while (true) {
+  private synchronized void initialize() throws IOException {
+    while (streamingReader == null) {
       try {
         acquireClient();
-        streamingReader = new StreamingReader();
-        ContainerProtocolCalls.readBlock(xceiverClient, position, blockID, tokenRef.get(),
-            pipelineRef.get().getReplicaIndexes(), streamingReader);
-        initialized = true;
-        return;
-      } catch (InterruptedException ie) {
-        Thread.currentThread().interrupt();
-        handleExceptions(new IOException("Interrupted", ie));
       } catch (IOException ioe) {
         handleExceptions(ioe);
       }
+
+      streamingReader = new StreamingReader();
+      xceiverClient.initStreamRead(blockID, streamingReader);

Review Comment:
   @chungen0126 , there are nothing to clean up for `StreamingReader`:
   ```java
   //StreamingReader
       private final BlockingQueue<ReadBlockResponseProto> responseQueue = new LinkedBlockingQueue<>();
   
       private final CompletableFuture<Void> future = new CompletableFuture<>();
       private final AtomicBoolean semaphoreReleased = new AtomicBoolean(false);
       private final AtomicReference<StreamingReadResponse> response = new AtomicReference<>();
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

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


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


Re: [PR] HDDS-13975. Limit the number of responses in stream read block. [ozone]

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


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java:
##########
@@ -207,36 +219,61 @@ protected synchronized void acquireClient() throws IOException {
     checkOpen();
     if (xceiverClient == null) {
       final Pipeline pipeline = pipelineRef.get();
+      final XceiverClientSpi client;
       try {
-        xceiverClient = xceiverClientFactory.acquireClientForReadData(pipeline);
+        client = xceiverClientFactory.acquireClientForReadData(pipeline);
       } catch (IOException ioe) {
         LOG.warn("Failed to acquire client for pipeline {}, block {}", pipeline, blockID);
         throw ioe;
       }
+
+      if (client == null) {
+        throw new IOException("Failed to acquire client for " + pipeline);
+      }
+      if (!(client instanceof XceiverClientGrpc)) {
+        throw new IOException("Unexpected client class: " + client.getClass().getName() + ", " + pipeline);
+      }
+
+      xceiverClient =  (XceiverClientGrpc) client;
     }
   }
 
-  private void initialize() throws IOException {
-    if (initialized) {
-      return;
-    }
-    while (true) {
+  private synchronized void initialize() throws IOException {
+    while (streamingReader == null) {
       try {
         acquireClient();
-        streamingReader = new StreamingReader();
-        ContainerProtocolCalls.readBlock(xceiverClient, position, blockID, tokenRef.get(),
-            pipelineRef.get().getReplicaIndexes(), streamingReader);
-        initialized = true;
-        return;
-      } catch (InterruptedException ie) {
-        Thread.currentThread().interrupt();
-        handleExceptions(new IOException("Interrupted", ie));
       } catch (IOException ioe) {
         handleExceptions(ioe);
       }
+
+      streamingReader = new StreamingReader();
+      xceiverClient.initStreamRead(blockID, streamingReader);

Review Comment:
   I see your point now.  We should set `streamingReader` only if there is no exception.  Since this is ready to merge,  let me change it in the next 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: issues-unsubscribe@ozone.apache.org

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


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


Re: [PR] HDDS-13975. Limit the number of responses in stream read block. [ozone]

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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

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


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


Re: [PR] HDDS-13975. Limit the number of responses in stream read block. [ozone]

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

   @chungen0126 , @sodonnel , thanks for reviewing 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: issues-unsubscribe@ozone.apache.org

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


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


Re: [PR] HDDS-13975. Limit the number of responses in stream read block. [ozone]

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


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java:
##########
@@ -207,36 +219,61 @@ protected synchronized void acquireClient() throws IOException {
     checkOpen();
     if (xceiverClient == null) {
       final Pipeline pipeline = pipelineRef.get();
+      final XceiverClientSpi client;
       try {
-        xceiverClient = xceiverClientFactory.acquireClientForReadData(pipeline);
+        client = xceiverClientFactory.acquireClientForReadData(pipeline);
       } catch (IOException ioe) {
         LOG.warn("Failed to acquire client for pipeline {}, block {}", pipeline, blockID);
         throw ioe;
       }
+
+      if (client == null) {
+        throw new IOException("Failed to acquire client for " + pipeline);
+      }
+      if (!(client instanceof XceiverClientGrpc)) {
+        throw new IOException("Unexpected client class: " + client.getClass().getName() + ", " + pipeline);
+      }
+
+      xceiverClient =  (XceiverClientGrpc) client;
     }
   }
 
-  private void initialize() throws IOException {
-    if (initialized) {
-      return;
-    }
-    while (true) {
+  private synchronized void initialize() throws IOException {
+    while (streamingReader == null) {
       try {
         acquireClient();
-        streamingReader = new StreamingReader();
-        ContainerProtocolCalls.readBlock(xceiverClient, position, blockID, tokenRef.get(),
-            pipelineRef.get().getReplicaIndexes(), streamingReader);
-        initialized = true;
-        return;
-      } catch (InterruptedException ie) {
-        Thread.currentThread().interrupt();
-        handleExceptions(new IOException("Interrupted", ie));
       } catch (IOException ioe) {
         handleExceptions(ioe);
       }
+
+      streamingReader = new StreamingReader();
+      xceiverClient.initStreamRead(blockID, streamingReader);

Review Comment:
   Sorry that I get it.  Could you suggest the code fix if there is any?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

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


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


Re: [PR] HDDS-13975. Limit the number of responses in stream read block. [ozone]

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

   Just curious! What happens if we read data from a past version, where their container layout was file per chunk.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

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


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


Re: [PR] HDDS-13975. Limit the number of responses in stream read block. [ozone]

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


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java:
##########
@@ -207,36 +219,61 @@ protected synchronized void acquireClient() throws IOException {
     checkOpen();
     if (xceiverClient == null) {
       final Pipeline pipeline = pipelineRef.get();
+      final XceiverClientSpi client;
       try {
-        xceiverClient = xceiverClientFactory.acquireClientForReadData(pipeline);
+        client = xceiverClientFactory.acquireClientForReadData(pipeline);
       } catch (IOException ioe) {
         LOG.warn("Failed to acquire client for pipeline {}, block {}", pipeline, blockID);
         throw ioe;
       }
+
+      if (client == null) {
+        throw new IOException("Failed to acquire client for " + pipeline);
+      }
+      if (!(client instanceof XceiverClientGrpc)) {
+        throw new IOException("Unexpected client class: " + client.getClass().getName() + ", " + pipeline);
+      }
+
+      xceiverClient =  (XceiverClientGrpc) client;
     }
   }
 
-  private void initialize() throws IOException {
-    if (initialized) {
-      return;
-    }
-    while (true) {
+  private synchronized void initialize() throws IOException {
+    while (streamingReader == null) {
       try {
         acquireClient();
-        streamingReader = new StreamingReader();
-        ContainerProtocolCalls.readBlock(xceiverClient, position, blockID, tokenRef.get(),
-            pipelineRef.get().getReplicaIndexes(), streamingReader);
-        initialized = true;
-        return;
-      } catch (InterruptedException ie) {
-        Thread.currentThread().interrupt();
-        handleExceptions(new IOException("Interrupted", ie));
       } catch (IOException ioe) {
         handleExceptions(ioe);
       }
+
+      streamingReader = new StreamingReader();
+      xceiverClient.initStreamRead(blockID, streamingReader);

Review Comment:
   Yes, but if the `StreamingReader` is not null, it won't enter the while loop which spans the `initialize` method.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

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


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


Re: [PR] HDDS-13975. Limit the number of responses in stream read block. [ozone]

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


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java:
##########
@@ -207,36 +219,61 @@ protected synchronized void acquireClient() throws IOException {
     checkOpen();
     if (xceiverClient == null) {
       final Pipeline pipeline = pipelineRef.get();
+      final XceiverClientSpi client;
       try {
-        xceiverClient = xceiverClientFactory.acquireClientForReadData(pipeline);
+        client = xceiverClientFactory.acquireClientForReadData(pipeline);
       } catch (IOException ioe) {
         LOG.warn("Failed to acquire client for pipeline {}, block {}", pipeline, blockID);
         throw ioe;
       }
+
+      if (client == null) {
+        throw new IOException("Failed to acquire client for " + pipeline);
+      }
+      if (!(client instanceof XceiverClientGrpc)) {
+        throw new IOException("Unexpected client class: " + client.getClass().getName() + ", " + pipeline);
+      }
+
+      xceiverClient =  (XceiverClientGrpc) client;
     }
   }
 
-  private void initialize() throws IOException {
-    if (initialized) {
-      return;
-    }
-    while (true) {
+  private synchronized void initialize() throws IOException {
+    while (streamingReader == null) {
       try {
         acquireClient();
-        streamingReader = new StreamingReader();
-        ContainerProtocolCalls.readBlock(xceiverClient, position, blockID, tokenRef.get(),
-            pipelineRef.get().getReplicaIndexes(), streamingReader);
-        initialized = true;
-        return;
-      } catch (InterruptedException ie) {
-        Thread.currentThread().interrupt();
-        handleExceptions(new IOException("Interrupted", ie));
       } catch (IOException ioe) {
         handleExceptions(ioe);
       }
+
+      streamingReader = new StreamingReader();
+      xceiverClient.initStreamRead(blockID, streamingReader);

Review Comment:
   Here is a simple, step-by-step explanation:
   
   1. First read(): The code enters the initialize() method.
   2. Assignment: It executes streamingReader = new StreamingReader(). The variable is no longer null.
   3. Exception: Immediately after, xceiverClient.initStreamRead() throws an exception (e.g., connection failed).
   4. Leftover State: The exception stops the process, but streamingReader is not set back to null.
   5. Second read(): The code tries to initialize() again.
   6. Skipped Logic: It checks while (streamingReader == null). Since it is not null, it skips the initialization loop.
   7. Final Result: The read fails again because the stream will never initialize.
   
   Since the streamReader can still be reset via other methods like `closeStream` or `seek`, I'm not sure if this behavior is functionally acceptable.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

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


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


Re: [PR] HDDS-13975. Limit the number of responses in stream read block. [ozone]

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


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java:
##########
@@ -207,36 +219,61 @@ protected synchronized void acquireClient() throws IOException {
     checkOpen();
     if (xceiverClient == null) {
       final Pipeline pipeline = pipelineRef.get();
+      final XceiverClientSpi client;
       try {
-        xceiverClient = xceiverClientFactory.acquireClientForReadData(pipeline);
+        client = xceiverClientFactory.acquireClientForReadData(pipeline);
       } catch (IOException ioe) {
         LOG.warn("Failed to acquire client for pipeline {}, block {}", pipeline, blockID);
         throw ioe;
       }
+
+      if (client == null) {
+        throw new IOException("Failed to acquire client for " + pipeline);
+      }
+      if (!(client instanceof XceiverClientGrpc)) {
+        throw new IOException("Unexpected client class: " + client.getClass().getName() + ", " + pipeline);
+      }
+
+      xceiverClient =  (XceiverClientGrpc) client;
     }
   }
 
-  private void initialize() throws IOException {
-    if (initialized) {
-      return;
-    }
-    while (true) {
+  private synchronized void initialize() throws IOException {
+    while (streamingReader == null) {
       try {
         acquireClient();
-        streamingReader = new StreamingReader();
-        ContainerProtocolCalls.readBlock(xceiverClient, position, blockID, tokenRef.get(),
-            pipelineRef.get().getReplicaIndexes(), streamingReader);
-        initialized = true;
-        return;
-      } catch (InterruptedException ie) {
-        Thread.currentThread().interrupt();
-        handleExceptions(new IOException("Interrupted", ie));
       } catch (IOException ioe) {
         handleExceptions(ioe);
       }
+
+      streamingReader = new StreamingReader();
+      xceiverClient.initStreamRead(blockID, streamingReader);

Review Comment:
   Sorry that I don't get it.  Could you suggest the code fix if there is any?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

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


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


Re: [PR] HDDS-13975. Limit the number of responses in stream read block. [ozone]

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

   > Just curious! What happens if we read data from a past version, where their container layout was file per chunk.
   
   That has been deprecated for a very long time. Key Value Handler will throw an exception and the user can either turn off this feature or migrate their data to the file per block 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: issues-unsubscribe@ozone.apache.org

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


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


Re: [PR] HDDS-13975. Limit the number of responses in stream read block. [ozone]

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


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java:
##########
@@ -207,36 +219,61 @@ protected synchronized void acquireClient() throws IOException {
     checkOpen();
     if (xceiverClient == null) {
       final Pipeline pipeline = pipelineRef.get();
+      final XceiverClientSpi client;
       try {
-        xceiverClient = xceiverClientFactory.acquireClientForReadData(pipeline);
+        client = xceiverClientFactory.acquireClientForReadData(pipeline);
       } catch (IOException ioe) {
         LOG.warn("Failed to acquire client for pipeline {}, block {}", pipeline, blockID);
         throw ioe;
       }
+
+      if (client == null) {
+        throw new IOException("Failed to acquire client for " + pipeline);
+      }
+      if (!(client instanceof XceiverClientGrpc)) {
+        throw new IOException("Unexpected client class: " + client.getClass().getName() + ", " + pipeline);
+      }
+
+      xceiverClient =  (XceiverClientGrpc) client;
     }
   }
 
-  private void initialize() throws IOException {
-    if (initialized) {
-      return;
-    }
-    while (true) {
+  private synchronized void initialize() throws IOException {
+    while (streamingReader == null) {
       try {
         acquireClient();
-        streamingReader = new StreamingReader();
-        ContainerProtocolCalls.readBlock(xceiverClient, position, blockID, tokenRef.get(),
-            pipelineRef.get().getReplicaIndexes(), streamingReader);
-        initialized = true;
-        return;
-      } catch (InterruptedException ie) {
-        Thread.currentThread().interrupt();
-        handleExceptions(new IOException("Interrupted", ie));
       } catch (IOException ioe) {
         handleExceptions(ioe);
       }
+
+      streamingReader = new StreamingReader();
+      xceiverClient.initStreamRead(blockID, streamingReader);

Review Comment:
   Thanks @szetszwo for the patch. Shouldn't we clean up `streamingReader` somewhere? Otherwise, when we throw an exception here, we might never be able to `initialize` it unless we close the entire stream.



##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java:
##########
@@ -207,36 +219,61 @@ protected synchronized void acquireClient() throws IOException {
     checkOpen();
     if (xceiverClient == null) {
       final Pipeline pipeline = pipelineRef.get();
+      final XceiverClientSpi client;
       try {
-        xceiverClient = xceiverClientFactory.acquireClientForReadData(pipeline);
+        client = xceiverClientFactory.acquireClientForReadData(pipeline);
       } catch (IOException ioe) {
         LOG.warn("Failed to acquire client for pipeline {}, block {}", pipeline, blockID);
         throw ioe;
       }
+
+      if (client == null) {
+        throw new IOException("Failed to acquire client for " + pipeline);
+      }
+      if (!(client instanceof XceiverClientGrpc)) {
+        throw new IOException("Unexpected client class: " + client.getClass().getName() + ", " + pipeline);
+      }
+
+      xceiverClient =  (XceiverClientGrpc) client;
     }
   }
 
-  private void initialize() throws IOException {
-    if (initialized) {
-      return;
-    }
-    while (true) {
+  private synchronized void initialize() throws IOException {
+    while (streamingReader == null) {
       try {
         acquireClient();
-        streamingReader = new StreamingReader();
-        ContainerProtocolCalls.readBlock(xceiverClient, position, blockID, tokenRef.get(),
-            pipelineRef.get().getReplicaIndexes(), streamingReader);
-        initialized = true;
-        return;
-      } catch (InterruptedException ie) {
-        Thread.currentThread().interrupt();
-        handleExceptions(new IOException("Interrupted", ie));
       } catch (IOException ioe) {
         handleExceptions(ioe);
       }
+
+      streamingReader = new StreamingReader();
+      xceiverClient.initStreamRead(blockID, streamingReader);

Review Comment:
   Thanks @szetszwo for the patch. Should we clean up `streamingReader` somewhere? Otherwise, when we throw an exception here, we might never be able to `initialize` it unless we close the entire stream.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

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


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