Skip to content

Commit

Permalink
Guard against calling fileSegment() before commitAndClose() has been …
Browse files Browse the repository at this point in the history
…called.
  • Loading branch information
JoshRosen committed May 28, 2015
1 parent 96811b4 commit 16564eb
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private[spark] class DiskBlockObjectWriter(
private var objOut: SerializationStream = null
private var initialized = false
private var hasBeenClosed = false
private var commitAndCloseHasBeenCalled = false

/**
* Cursors used to represent positions in the file.
Expand Down Expand Up @@ -171,6 +172,7 @@ private[spark] class DiskBlockObjectWriter(
finalPosition = file.length()
// In certain compression codecs, more bytes are written after close() is called
writeMetrics.incShuffleBytesWritten(finalPosition - reportedPosition)
commitAndCloseHasBeenCalled = true
}

// Discard current writes. We do this by flushing the outstanding writes and then
Expand Down Expand Up @@ -228,6 +230,10 @@ private[spark] class DiskBlockObjectWriter(
}

override def fileSegment(): FileSegment = {
if (!commitAndCloseHasBeenCalled) {
throw new IllegalStateException(
"fileSegment() is only valid after commitAndClose() has been called")
}
new FileSegment(file, initialPosition, finalPosition - initialPosition)
}

Expand Down

0 comments on commit 16564eb

Please sign in to comment.