wujinhu commented on code in PR #4912: URL: https://github.com/apache/hadoop/pull/4912#discussion_r1144329309
########## hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSBlockOutputStream.java: ########## @@ -138,64 +168,74 @@ public synchronized void write(int b) throws IOException { @Override public synchronized void write(byte[] b, int off, int len) throws IOException { - if (closed) { - throw new IOException("Stream closed."); + OSSDataBlocks.validateWriteArgs(b, off, len); + checkOpen(); + if (len == 0) { + return; } - blockStream.write(b, off, len); - blockWritten += len; - if (blockWritten >= blockSize) { - uploadCurrentPart(); - blockWritten = 0L; + OSSDataBlocks.DataBlock block = createBlockIfNeeded(); + int written = block.write(b, off, len); + blockWritten += written; + int remainingCapacity = block.remainingCapacity(); + if (written < len) { + // not everything was written — the block has run out + // of capacity + // Trigger an upload then process the remainder. + LOG.debug("writing more data than block has capacity -triggering upload"); + uploadCurrentBlock(); + // tail recursion is mildly expensive, but given buffer sizes must be MB. + // it's unlikely to recurse very deeply. + this.write(b, off + written, len - written); Review Comment: Good suggestion, will optimize the code. -- 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: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org