szetszwo commented on code in PR #9946:
URL: https://github.com/apache/ozone/pull/9946#discussion_r2976726754


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java:
##########
@@ -177,6 +179,17 @@ private synchronized boolean dataAvailableToRead(int 
length, boolean preRead) th
     return bufferHasRemaining();
   }
 
+  private synchronized void advancePosition(long delta) {
+    position += delta;
+    maybeReleaseStreamOnEof();
+  }
+
+  private synchronized void maybeReleaseStreamOnEof() {
+    if (position >= blockLength && streamingReader != null) {

Review Comment:
   - The condition `streamingReader != null` seems not needed.
   - Combine maybeReleaseStreamOnEof() with `advancePosition(..)`.
   
   ```java
     private synchronized void advancePosition(long delta) {
       position += delta;
       if (position >= blockLength) {
         closeStream();
       }
     }
   ```



##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java:
##########
@@ -158,14 +159,15 @@ synchronized int readFully(ByteBuffer targetBuf, boolean 
preRead) throws IOExcep
       tmpBuf.limit(tmpBuf.position() + toCopy);
       targetBuf.put(tmpBuf);
       buffer.position(tmpBuf.position());
-      position += toCopy;
+      advancePosition(toCopy);
       read += toCopy;
     }
     return read > 0 ? read : EOF;
   }
 
   private synchronized boolean dataAvailableToRead(int length, boolean 
preRead) throws IOException {
     if (position >= blockLength) {
+      maybeReleaseStreamOnEof();

Review Comment:
   Since `position` is only updated in advancePosition(..) but not here, we 
don't have to close stream 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: [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