Skip to content

Commit

Permalink
Review feedback and adding rewind() when reading byte buffers.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwendell committed Apr 27, 2014
1 parent b76b95f commit a637a18
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions core/src/main/scala/org/apache/spark/storage/DiskStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,19 @@ private class DiskStore(blockManager: BlockManager, diskManager: DiskBlockManage
val channel = new RandomAccessFile(segment.file, "r").getChannel()

val buffer =
// For small files, directly read rather than memory map
if (segment.length < minMemoryMapBytes) {
val buf = ByteBuffer.allocate(segment.length.toInt)
try {
try {
// For small files, directly read rather than memory map
if (segment.length < minMemoryMapBytes) {
val buf = ByteBuffer.allocate(segment.length.toInt)
channel.read(buf, segment.offset)
buf.rewind()
Some(buf)
} else {
Some(channel.map(MapMode.READ_ONLY, segment.offset, segment.length))
}
finally {
channel.close()
}
Some(buf)
} else {
val buf = try {
channel.map(MapMode.READ_ONLY, segment.offset, segment.length)
} finally {
channel.close()
}
Some(buf)
}
} finally {
channel.close()
}
buffer
}

Expand Down

0 comments on commit a637a18

Please sign in to comment.