Skip to content

Commit

Permalink
fix(spill): Explicitly delete spill file for FileBasedSpillBuf (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
zuston authored Nov 24, 2024
1 parent ffa04d4 commit 6d51289
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
*/
package org.apache.spark.sql.blaze.memory

import java.io.RandomAccessFile
import java.io.{File, RandomAccessFile}
import java.nio.ByteBuffer
import java.nio.channels.FileChannel
import java.util

import org.apache.spark.internal.Logging

import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled

Expand Down Expand Up @@ -85,11 +83,13 @@ class MemBasedSpillBuf extends SpillBuf with Logging {
}
}
val endTimeNs = System.nanoTime
new FileBasedSpillBuf(channel, endTimeNs - startTimeNs)
new FileBasedSpillBuf(file, channel, endTimeNs - startTimeNs)
}
}

class FileBasedSpillBuf(fileChannel: FileChannel, var diskIOTimeNs: Long) extends SpillBuf {
class FileBasedSpillBuf(file: File, fileChannel: FileChannel, var diskIOTimeNs: Long)
extends SpillBuf
with Logging {
private var readPosition: Long = 0

override def write(buf: ByteBuffer): Unit = {
Expand All @@ -114,5 +114,8 @@ class FileBasedSpillBuf(fileChannel: FileChannel, var diskIOTimeNs: Long) extend

override def release(): Unit = {
fileChannel.close()
if (!file.delete()) {
logWarning(s"Was unable to delete spill file: ${file.getAbsolutePath}")
}
}
}

0 comments on commit 6d51289

Please sign in to comment.