yandrey321 commented on code in PR #12159:
URL: https://github.com/apache/ozone/pull/12159#discussion_r4691454988


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java:
##########
@@ -519,6 +538,9 @@ private void handleExceptions(IOException cause) throws 
IOException {
          root instanceof TimeoutIOException) {
       if (shouldRetryRead(root, retryPolicy, retries++)) {
         recordFailedStreamingDatanode();
+        if (streamingReader != null) {

Review Comment:
   Only retried failures abandon the sequential reader. A failure that is 
rethrown still half-closes the stream.
   
   Scenario: the request can't be sent and the retries are used up, or poll() 
is interrupted (a plain IOException, which is not retriable). handleExceptions 
rethrows without abandon(), and the reader's future is not failed. The caller 
then closes the stream, closeStream sees isFailed() == false and half-closes. 
The datanode keeps serving the outstanding
   request, up to the 32 MB pre-read window by default, to a reader nobody 
reads: the waste this PR removes for failover.
   (A poll timeout is not affected: poll() already calls setFailed.)
   Introduced gap: the PR's goal is "a failed streaming read is cancelled", and 
this path is left out.
   
   Suggestion: abandon the reader in the throw branches as well, or abandon it 
on any exception in dataAvailableToRead before rethrowing.



##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java:
##########
@@ -774,8 +808,10 @@ private void 
failOnErrorResponse(ContainerProtos.ContainerCommandResponseProto e
     public void onError(Throwable throwable) {
       if (throwable instanceof StatusRuntimeException
           && ((StatusRuntimeException) throwable).getStatus().getCode() == 
CANCELLED) {
-        // This is expected when the client cancels the stream.
-        setCompleted();
+        // This is expected when the client cancels the stream, including a 
failed stream it tears down.
+        if (!isFailed()) {

Review Comment:
   A CANCELLED status the client did not cause is still treated as a normal end 
of stream.
   Scenario: the datanode or something on the path resets the stream with 
RST_STREAM CANCEL (e.g. a datanode shutting down). onError gets CANCELLED while 
the reader is neither done nor failed, so it calls setCompleted(). poll() then 
returns null and read() returns EOF before blockLength. 
KeyInputStream.checkPartBytesRead then fails the read with an "Inconsistent 
read" error, and there is no failover to another replica. A positioned read 
returns a short count.
   Pre-existing (the base code calls setCompleted on every CANCELLED), but this 
PR changes this branch.
   With this PR, every cancel the client sends happens after the reader's 
future is complete: closeStream completes or fails it first, and 
failOnErrorResponse/onNext call setFailed before requestObserver.onError.
   So a CANCELLED that arrives while !future.isDone() did not come from this 
client.
   
   `if (!future.isDone()) setFailed(throwable);` instead of `if (!isFailed()) 
setCompleted();`. Then the read fails with the real cause. Whether a CANCELLED 
from the datanode should be retried can be a follow-up.



##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java:
##########
@@ -387,12 +391,27 @@ private synchronized void closeReader(String reason) {
   }
 
   private static void closeStream(StreamingReader reader) {
-    reader.onCompleted();
+    final boolean failed = reader.isFailed();
+    if (failed) {
+      reader.releaseResources();
+    } else {
+      reader.onCompleted();

Review Comment:
   close() and seek-driven closeReader still half-close a healthy stream that
   has outstanding pre-read.
   
   Scenario: the application reads a few bytes and closes, or releaseClient 
runs while requestedLength > position. The half-close leaves the call open 
until the datanode has streamed the whole outstanding request (up to 
ozone.client.stream.read.pre-read-size, 32 MB by default). The responses are 
queued into a reader nobody reads.
   Pre-existing, not introduced by this PR.
   
   can be addressed as follow-up Jira: cancel instead of half-close whenever 
requestedLength > position at close, using the same path this PR adds.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to