ashishkumar50 commented on code in PR #9402:
URL: https://github.com/apache/ozone/pull/9402#discussion_r2601623939


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/MultipartInputStream.java:
##########
@@ -286,21 +276,28 @@ public void readVectored(List<? extends FileRange> ranges,
    * @param buffer the buffer to read data into
    * @throws IOException if there is an error reading data
    */
-  private void readRangeData(long offset, ByteBuffer buffer) throws 
IOException {
+  private void readRangeData(long offset, ByteBuffer buffer, long 
initialPosition) throws IOException {
     synchronized (this) {
-      long savedPos = getPos();
       try {
         seek(offset);
-        int remaining = buffer.remaining();
-        byte[] temp = new byte[remaining];
-        int bytesRead = read(temp, 0, remaining);
-        if (bytesRead < remaining) {
-          throw new EOFException("Could not read all requested bytes. " +
-              "Requested: " + remaining + ", Read: " + bytesRead);
+        int totalBytesToRead = buffer.remaining();
+        byte[] temp = new byte[totalBytesToRead];
+        int totalBytesRead = 0;
+
+        // Read in a loop to handle partial reads
+        while (totalBytesRead < totalBytesToRead) {
+          int bytesRead = read(temp, totalBytesRead, totalBytesToRead - 
totalBytesRead);
+          if (bytesRead < 0) {
+            throw new EOFException("End of file reached before reading fully. 
" +
+                "Requested: " + totalBytesToRead + ", Read: " + 
totalBytesRead);
+          }
+          totalBytesRead += bytesRead;
         }
-        buffer.put(temp, 0, bytesRead);
+
+        buffer.put(temp, 0, totalBytesRead);

Review Comment:
   Avoided temp now



-- 
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