Copilot commented on code in PR #11245:
URL: https://github.com/apache/ozone/pull/11245#discussion_r4020492893


##########
hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/OzoneCryptoInputStream.java:
##########
@@ -73,8 +79,18 @@ public int getBufferSize() {
     return bufferSize;
   }
 
+  /**
+   * {@link CryptoInputStream} does not synchronize its own methods, so every 
method moving the cursor of
+   * this stream is serialized here on the monitor of this stream. Otherwise a 
read or a seek could land in
+   * the middle of a positioned read and see (or undo) the cursor move that 
read does.
+   * This covers both the sequential-read API ({@link #read(byte[], int, 
int)}, {@link #read(ByteBuffer)},
+   * {@link #seek(long)}, {@link #getPos()}) and all positioned-read overloads
+   * ({@link #read(long, ByteBuffer)}, {@link #readFully(long, ByteBuffer)},
+   * {@link #read(long, byte[], int, int)}, {@link #readFully(long, byte[], 
int, int)},
+   * {@link #readFully(long, byte[])}).
+   */
   @Override
-  public int read(byte[] b, int off, int len) throws IOException {
+  public synchronized int read(byte[] b, int off, int len) throws IOException {

Review Comment:
   `skip(long)` is still inherited without being serialized on this monitor. A 
concurrent skip can run between a positioned read's seek and restore, causing 
that read to consume the wrong range or restore an incorrect cursor; 
synchronizing only read/seek/getPos does not establish the cursor invariant 
described above. Override skip under the same monitor (and audit other 
inherited cursor-moving methods).



##########
hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/OzoneFSInputStream.java:
##########
@@ -211,4 +222,19 @@ public void readFully(long position, ByteBuffer buf) 
throws IOException {
       }
     }
   }
+
+  @Override
+  public int read(long position, byte[] buffer, int offset, int length) throws 
IOException {
+    return read(position, ByteBuffer.wrap(buffer, offset, length));
+  }
+
+  @Override
+  public void readFully(long position, byte[] buffer, int offset, int length) 
throws IOException {
+    readFully(position, ByteBuffer.wrap(buffer, offset, length));
+  }
+
+  @Override
+  public void readFully(long position, byte[] buffer) throws IOException {
+    readFully(position, buffer, 0, buffer.length);
+  }

Review Comment:
   This new byte-array overload narrows the positioned-read contract by routing 
through the ByteBuffer path. For a valid `Seekable` input that does not 
implement `ByteBufferReadable`, `read(long, byte[])` now reaches the cast in 
`readAtPositionSeekRestore` and fails instead of using the existing byte-array 
seek/read/restore behavior; the `readFully` byte-array overloads inherit the 
same regression. Keep these overloads on a synchronized seek/read/restore 
byte-array path (while retaining the native `ExtendedInputStream` path where 
available).



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