Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ public void reset() {
numKeys = 0;
numValues = 0;
freeArray(longArray);
longArray = null;
while (dataPages.size() > 0) {
MemoryBlock dataPage = dataPages.removeLast();
freePage(dataPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.spark.SparkConf;
import org.apache.spark.executor.ShuffleWriteMetrics;
import org.apache.spark.memory.MemoryMode;
import org.apache.spark.memory.SparkOutOfMemoryError;
import org.apache.spark.memory.TestMemoryConsumer;
import org.apache.spark.memory.TaskMemoryManager;
import org.apache.spark.memory.TestMemoryManager;
Expand Down Expand Up @@ -726,4 +727,22 @@ public void avoidDeadlock() throws InterruptedException {
}
}

@Test
public void freeAfterFailedReset() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind adding a one-line comment in the body of the test noting that this is a regression test for SPARK-29244?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Added.

// SPARK-29244: BytesToBytesMap.free after a OOM reset operation should not cause failure.
memoryManager.limit(5000);
BytesToBytesMap map =
new BytesToBytesMap(taskMemoryManager, blockManager, serializerManager, 256, 0.5, 4000);
// Force OOM on next memory allocation.
memoryManager.markExecutionAsOutOfMemoryOnce();
try {
map.reset();
Assert.fail("Expected SparkOutOfMemoryError to be thrown");
} catch (SparkOutOfMemoryError e) {
// Expected exception; do nothing.
} finally {
map.free();
}
Copy link
Contributor

@JoshRosen JoshRosen Oct 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though this test suite fails without the longArray = null change, it turns out that another (wrong!) way to make this test pass would be to simply remove the free(longArray) call and leak memory.

Unfortunately, though, that doesn't cause the test to fail! It turns out that the

  @After
  public void tearDown() {
    Utils.deleteRecursively(tempDir);
    tempDir = null;

    if (taskMemoryManager != null) {
      Assert.assertEquals(0L, taskMemoryManager.cleanUpAllAllocatedMemory());
      long leakedMemory = taskMemoryManager.getMemoryConsumptionForThisTask();
      taskMemoryManager = null;
      Assert.assertEquals(0L, leakedMemory);
    }
  }

doesn't work as expected because TestMemoryManager doesn't properly implement per-taskAttemptId memory-consumption tracking.

I've opened #25985 to fix that problem. That doesn't need to block merging of this patch, however.

}

}