Copilot commented on code in PR #6470:
URL: https://github.com/apache/paimon/pull/6470#discussion_r2459338054
##########
paimon-common/src/main/java/org/apache/paimon/fs/MultiPartUploadTwoPhaseOutputStream.java:
##########
@@ -89,10 +89,34 @@ public void write(byte[] b, int off, int len) throws
IOException {
if (closed) {
throw new IOException("Stream is closed");
}
- buffer.write(b, off, len);
- position += len;
- if (buffer.size() >= partSizeThreshold()) {
- uploadPart();
+ int remaining = len;
+ int offset = off;
+ final long threshold = partSizeThreshold();
+
+ while (remaining > 0) {
+ if (buffer.size() >= threshold) {
+ uploadPart();
+ }
+
+ int currentSize = buffer.size();
+ long spaceLong = threshold - currentSize;
+ int space =
+ spaceLong <= 0
+ ? 0
+ : (spaceLong > Integer.MAX_VALUE ?
Integer.MAX_VALUE : (int) spaceLong);
+ if (space == 0) {
+ uploadPart();
+ continue;
+ }
Review Comment:
The logic at lines 97-98 already handles the case where `buffer.size() >=
threshold`, making the condition at line 107 redundant. When line 97 is true,
`uploadPart()` is called and the buffer is reset, so `currentSize` at line 101
will be 0 and `space` cannot be 0. This check and the associated `uploadPart()`
call can be removed.
```suggestion
// The check for space == 0 and associated uploadPart() call is
redundant and removed.
```
##########
paimon-common/src/main/java/org/apache/paimon/fs/MultiPartUploadTwoPhaseOutputStream.java:
##########
@@ -89,10 +89,34 @@ public void write(byte[] b, int off, int len) throws
IOException {
if (closed) {
throw new IOException("Stream is closed");
}
- buffer.write(b, off, len);
- position += len;
- if (buffer.size() >= partSizeThreshold()) {
- uploadPart();
+ int remaining = len;
+ int offset = off;
+ final long threshold = partSizeThreshold();
+
+ while (remaining > 0) {
+ if (buffer.size() >= threshold) {
+ uploadPart();
+ }
+
+ int currentSize = buffer.size();
+ long spaceLong = threshold - currentSize;
+ int space =
+ spaceLong <= 0
+ ? 0
+ : (spaceLong > Integer.MAX_VALUE ?
Integer.MAX_VALUE : (int) spaceLong);
+ if (space == 0) {
+ uploadPart();
+ continue;
+ }
+ int count = Math.min(remaining, space);
+ buffer.write(b, offset, count);
+ offset += count;
+ remaining -= count;
+ position += count;
+
+ if (buffer.size() >= threshold) {
+ uploadPart();
+ }
Review Comment:
This condition at lines 117-119 is redundant because the loop condition at
line 96 ensures the next iteration will check `buffer.size() >= threshold` at
line 97. The check can be removed as the loop will handle it on the next
iteration.
```suggestion
```
--
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]