Skip to content

Commit

Permalink
Avoid creating null output stream in S3SingleDriverLogStore
Browse files Browse the repository at this point in the history
Fixes #366
  • Loading branch information
easel committed Feb 7, 2020
1 parent 21d2af1 commit d6ee1ef
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,12 @@ class S3SingleDriverLogStore(
override def write(path: Path, actions: Iterator[String], overwrite: Boolean = false): Unit = {
val (fs, resolvedPath) = resolved(path)
val lockedPath = getPathKey(resolvedPath)
var stream: FSDataOutputStream = null
acquirePathLock(lockedPath)
try {
if (exists(fs, resolvedPath) && !overwrite) {
throw new java.nio.file.FileAlreadyExistsException(resolvedPath.toUri.toString)
}
val countingStream = new CountingOutputStream(stream)
stream = fs.create(resolvedPath, overwrite)
val stream = new CountingOutputStream(fs.create(resolvedPath, overwrite))
actions.map(_ + "\n").map(_.getBytes(UTF_8)).foreach(stream.write)
stream.close()

Expand All @@ -183,7 +181,7 @@ class S3SingleDriverLogStore(

// Cache the information of written files to help fix the inconsistency in future listings
writtenPathCache.put(lockedPath,
FileMetadata(countingStream.getCount(), System.currentTimeMillis()))
FileMetadata(stream.getCount(), System.currentTimeMillis()))
} catch {
// Convert Hadoop's FileAlreadyExistsException to Java's FileAlreadyExistsException
case e: org.apache.hadoop.fs.FileAlreadyExistsException =>
Expand Down

0 comments on commit d6ee1ef

Please sign in to comment.