Skip to content

Commit

Permalink
[FLINK-9584][connector] Properly close output streams in Bucketing-/R…
Browse files Browse the repository at this point in the history
…ollingSink

This closes apache#6164.
  • Loading branch information
sihuazhou authored and zentol committed Jul 11, 2018
1 parent 5dbb6dd commit 04a7cd4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,9 @@ private Method reflectTruncate(FileSystem fs) {
}

// verify that truncate actually works
FSDataOutputStream outputStream;
Path testPath = new Path(UUID.randomUUID().toString());
try {
outputStream = fs.create(testPath);
try (FSDataOutputStream outputStream = fs.create(testPath)) {
outputStream.writeUTF("hello");
outputStream.close();
} catch (IOException e) {
LOG.error("Could not create file for checking if truncate works.", e);
throw new RuntimeException("Could not create file for checking if truncate works.", e);
Expand Down Expand Up @@ -702,9 +699,9 @@ private void handleRestoredBucketState(BucketState bucketState) {
Path validLengthFilePath = getValidLengthPathFor(partPath);
if (!fs.exists(validLengthFilePath) && fs.exists(partPath)) {
LOG.debug("Writing valid-length file for {} to specify valid length {}", partPath, bucketState.currentFileValidLength);
FSDataOutputStream lengthFileOut = fs.create(validLengthFilePath);
lengthFileOut.writeUTF(Long.toString(bucketState.currentFileValidLength));
lengthFileOut.close();
try (FSDataOutputStream lengthFileOut = fs.create(validLengthFilePath)) {
lengthFileOut.writeUTF(Long.toString(bucketState.currentFileValidLength));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,12 +631,9 @@ private Method reflectTruncate(FileSystem fs) {
}

// verify that truncate actually works
FSDataOutputStream outputStream;
Path testPath = new Path(UUID.randomUUID().toString());
try {
outputStream = fs.create(testPath);
try (FSDataOutputStream outputStream = fs.create(testPath)) {
outputStream.writeUTF("hello");
outputStream.close();
} catch (IOException e) {
LOG.error("Could not create file for checking if truncate works.", e);
throw new RuntimeException("Could not create file for checking if truncate works. " +
Expand Down Expand Up @@ -880,9 +877,9 @@ private void handlePendingInProgressFile(String file, long validLength) {
Path validLengthFilePath = getValidLengthPathFor(partPath);
if (!fs.exists(validLengthFilePath) && fs.exists(partPath)) {
LOG.debug("Writing valid-length file for {} to specify valid length {}", partPath, validLength);
FSDataOutputStream lengthFileOut = fs.create(validLengthFilePath);
lengthFileOut.writeUTF(Long.toString(validLength));
lengthFileOut.close();
try (FSDataOutputStream lengthFileOut = fs.create(validLengthFilePath)) {
lengthFileOut.writeUTF(Long.toString(validLength));
}
}
}

Expand Down

0 comments on commit 04a7cd4

Please sign in to comment.