From a637a1828c21dc4d5678933e6bef0d07cafdb158 Mon Sep 17 00:00:00 2001 From: Patrick Wendell Date: Wed, 23 Apr 2014 14:26:45 -0700 Subject: [PATCH] Review feedback and adding rewind() when reading byte buffers. --- .../org/apache/spark/storage/DiskStore.scala | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/core/src/main/scala/org/apache/spark/storage/DiskStore.scala b/core/src/main/scala/org/apache/spark/storage/DiskStore.scala index aa623edc2f8d7..5ff92527b862d 100644 --- a/core/src/main/scala/org/apache/spark/storage/DiskStore.scala +++ b/core/src/main/scala/org/apache/spark/storage/DiskStore.scala @@ -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 }