Check no write after read in FileSingleStreamSpiller
@@ -63,6 +63,7 @@ public class FileSingleStreamSpiller
private final ListeningExecutorService executor;
+ private boolean writable = true;
private ListenableFuture<?> spillInProgress = Futures.immediateFuture(null);
public FileSingleStreamSpiller(
@@ -103,6 +104,8 @@ public class FileSingleStreamSpiller
private void writePages(Iterator<Page> pageIterator)
{
+ checkState(writable, "Spilling no longer allowed. The spiller has been made non-writable on first read for subsequent reads to be consistent");
+
try (SliceOutput output = new OutputStreamSliceOutput(new FileOutputStream(targetFileName.toFile(), true), BUFFER_SIZE)) {
memoryContext.setBytes(BUFFER_SIZE);
while (pageIterator.hasNext()) {
@@ -124,6 +127,9 @@ public class FileSingleStreamSpiller
private Iterator<Page> readPages()
{
+ checkState(writable, "Repeated reads are disallowed to prevent potential resource leaks");
+ writable = false;
+
try {
InputStream input = new FileInputStream(targetFileName.toFile());
memoryContext.setBytes(BUFFER_SIZE);
