Skip to content

Commit 952d95c

Browse files
author
Andrew Or
committed
Update tests for branch-1.6
1 parent 0d95847 commit 952d95c

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

core/src/main/scala/org/apache/spark/memory/UnifiedMemoryManager.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ private[spark] class UnifiedMemoryManager private[memory] (
5757
storageRegionSize,
5858
maxMemory - storageRegionSize) {
5959

60+
assertInvariant()
61+
6062
// We always maintain this invariant:
61-
assert(onHeapExecutionMemoryPool.poolSize + storageMemoryPool.poolSize == maxMemory)
63+
private def assertInvariant(): Unit = {
64+
assert(onHeapExecutionMemoryPool.poolSize + storageMemoryPool.poolSize == maxMemory)
65+
}
6266

6367
override def maxStorageMemory: Long = synchronized {
6468
maxMemory - onHeapExecutionMemoryPool.memoryUsed
@@ -77,7 +81,7 @@ private[spark] class UnifiedMemoryManager private[memory] (
7781
numBytes: Long,
7882
taskAttemptId: Long,
7983
memoryMode: MemoryMode): Long = synchronized {
80-
assert(onHeapExecutionMemoryPool.poolSize + storageMemoryPool.poolSize == maxMemory)
84+
assertInvariant()
8185
assert(numBytes >= 0)
8286
memoryMode match {
8387
case MemoryMode.ON_HEAP =>
@@ -137,7 +141,7 @@ private[spark] class UnifiedMemoryManager private[memory] (
137141
blockId: BlockId,
138142
numBytes: Long,
139143
evictedBlocks: mutable.Buffer[(BlockId, BlockStatus)]): Boolean = synchronized {
140-
assert(onHeapExecutionMemoryPool.poolSize + storageMemoryPool.poolSize == maxMemory)
144+
assertInvariant()
141145
assert(numBytes >= 0)
142146
if (numBytes > maxStorageMemory) {
143147
// Fail fast if the block simply won't fit

core/src/test/scala/org/apache/spark/memory/UnifiedMemoryManagerSuite.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,17 +265,17 @@ class UnifiedMemoryManagerSuite extends MemoryManagerSuite with PrivateMethodTes
265265
val memoryMode = MemoryMode.ON_HEAP
266266
// Acquire 1000 then release 600 bytes of storage memory, leaving the
267267
// storage memory pool at 1000 bytes but only 400 bytes of which are used.
268-
assert(mm.acquireStorageMemory(dummyBlock, 1000L, memoryMode))
269-
mm.releaseStorageMemory(600L, memoryMode)
268+
assert(mm.acquireStorageMemory(dummyBlock, 1000L, evictedBlocks))
269+
mm.releaseStorageMemory(600L)
270270
// Before the fix for SPARK-15260, we would first shrink the storage pool by the amount of
271271
// unused storage memory (600 bytes), try to evict blocks, then enlarge the execution pool
272272
// by the same amount. If the eviction threw an exception, then we would shrink one pool
273273
// without enlarging the other, resulting in an assertion failure.
274274
intercept[RuntimeException] {
275275
mm.acquireExecutionMemory(1000L, 0, memoryMode)
276276
}
277-
val assertInvariants = PrivateMethod[Unit]('assertInvariants)
278-
mm.invokePrivate[Unit](assertInvariants())
277+
val assertInvariant = PrivateMethod[Unit]('assertInvariant)
278+
mm.invokePrivate[Unit](assertInvariant())
279279
}
280280

281281
}

0 commit comments

Comments
 (0)