HoustonPutman commented on a change in pull request #120:
URL: https://github.com/apache/solr/pull/120#discussion_r688030970
##########
File path:
solr/contrib/s3-repository/src/java/org/apache/solr/s3/S3BackupRepository.java
##########
@@ -255,40 +255,31 @@ public void copyIndexFileFrom(Directory sourceDir, String
sourceFileName, URI de
String blobPath = getS3Path(filePath);
Instant start = Instant.now();
if (log.isDebugEnabled()) {
- log.debug("Upload started to blob'{}'", blobPath);
+ log.debug("Upload started to S3 '{}'", blobPath);
}
- IndexInput indexInput = null;
- OutputStream outputStream = null;
- try {
+ try (IndexInput indexInput = sourceDir.openInput(sourceFileName,
IOContext.DEFAULT)) {
client.createDirectory(getS3Path(dest));
- indexInput = sourceDir.openInput(sourceFileName,
IOContext.DEFAULT);
- outputStream = client.pushStream(blobPath);
+ try (OutputStream outputStream = client.pushStream(blobPath)) {
- byte[] buffer = new byte[CHUNK_SIZE];
- int bufferLen;
- long remaining = indexInput.length();
+ byte[] buffer = new byte[CHUNK_SIZE];
+ int bufferLen;
+ long remaining = indexInput.length();
- while (remaining > 0) {
- bufferLen = remaining >= CHUNK_SIZE ? CHUNK_SIZE : (int)
remaining;
+ while (remaining > 0) {
+ bufferLen = remaining >= CHUNK_SIZE ? CHUNK_SIZE : (int)
remaining;
- indexInput.readBytes(buffer, 0, bufferLen);
- outputStream.write(buffer, 0, bufferLen);
- remaining -= bufferLen;
- }
- outputStream.flush();
- } finally {
- if (indexInput != null) {
- indexInput.close();
- }
- if (outputStream != null) {
- outputStream.close();
+ indexInput.readBytes(buffer, 0, bufferLen);
+ outputStream.write(buffer, 0, bufferLen);
+ remaining -= bufferLen;
+ }
+ outputStream.flush();
Review comment:
Yes, there is indeed a flush on close. Will remove this.
--
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]