-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-21475][Core] Use NIO's Files API to replace FileInputStream/FileOutputStream in some critical paths #18684
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,9 @@ | |
package org.apache.spark.shuffle.sort; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.nio.channels.FileChannel; | ||
import static java.nio.file.StandardOpenOption.*; | ||
import javax.annotation.Nullable; | ||
|
||
import scala.None$; | ||
|
@@ -30,6 +30,7 @@ | |
import scala.collection.Iterator; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.io.Closeables; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
@@ -188,17 +189,20 @@ private long[] writePartitionedFile(File outputFile) throws IOException { | |
return lengths; | ||
} | ||
|
||
final FileOutputStream out = new FileOutputStream(outputFile, true); | ||
final FileChannel out = FileChannel.open(outputFile.toPath(), | ||
ImmutableSet.of(WRITE, APPEND, CREATE)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
? |
||
final long writeStartTime = System.nanoTime(); | ||
boolean threwException = true; | ||
try { | ||
for (int i = 0; i < numPartitions; i++) { | ||
final File file = partitionWriterSegments[i].file(); | ||
if (file.exists()) { | ||
final FileInputStream in = new FileInputStream(file); | ||
final FileChannel in = FileChannel.open(file.toPath(), ImmutableSet.of(READ)); | ||
boolean copyThrewException = true; | ||
try { | ||
lengths[i] = Utils.copyStream(in, out, false, transferToEnabled); | ||
long size = in.size(); | ||
Utils.copyFileStreamNIO(in, out, 0, size); | ||
lengths[i] = size; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we modify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There're lot of other places using |
||
copyThrewException = false; | ||
} finally { | ||
Closeables.close(in, copyThrewException); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a new set for this? should we call:
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're actually the same, the one you mentioned is just a simple wrapper of the former one. I will change to yours for the simplicity.