You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by st...@apache.org on 2023/07/18 13:16:22 UTC
[hadoop] branch trunk updated: HADOOP-18809. S3A prefetch read/write file operations should guard channel close (#5853)
This is an automated email from the ASF dual-hosted git repository.
stevel pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push:
new 38ac2f73499 HADOOP-18809. S3A prefetch read/write file operations should guard channel close (#5853)
38ac2f73499 is described below
commit 38ac2f73499ac8259bf385292e3787427fec6567
Author: Viraj Jasani <vj...@apache.org>
AuthorDate: Tue Jul 18 07:16:12 2023 -0600
HADOOP-18809. S3A prefetch read/write file operations should guard channel close (#5853)
Contributed by Viraj Jasani
---
.../fs/impl/prefetch/SingleFilePerBlockCache.java | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/impl/prefetch/SingleFilePerBlockCache.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/impl/prefetch/SingleFilePerBlockCache.java
index a84a79eb778..6aacb4d7c84 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/impl/prefetch/SingleFilePerBlockCache.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/impl/prefetch/SingleFilePerBlockCache.java
@@ -271,12 +271,12 @@ public class SingleFilePerBlockCache implements BlockCache {
protected int readFile(Path path, ByteBuffer buffer) throws IOException {
int numBytesRead = 0;
int numBytes;
- FileChannel channel = FileChannel.open(path, StandardOpenOption.READ);
- while ((numBytes = channel.read(buffer)) > 0) {
- numBytesRead += numBytes;
+ try (FileChannel channel = FileChannel.open(path, StandardOpenOption.READ)) {
+ while ((numBytes = channel.read(buffer)) > 0) {
+ numBytesRead += numBytes;
+ }
+ buffer.limit(buffer.position());
}
- buffer.limit(buffer.position());
- channel.close();
return numBytesRead;
}
@@ -460,11 +460,11 @@ public class SingleFilePerBlockCache implements BlockCache {
protected void writeFile(Path path, ByteBuffer buffer) throws IOException {
buffer.rewind();
- WritableByteChannel writeChannel = Files.newByteChannel(path, CREATE_OPTIONS);
- while (buffer.hasRemaining()) {
- writeChannel.write(buffer);
+ try (WritableByteChannel writeChannel = Files.newByteChannel(path, CREATE_OPTIONS)) {
+ while (buffer.hasRemaining()) {
+ writeChannel.write(buffer);
+ }
}
- writeChannel.close();
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org