Skip to content

Commit 7ce162d

Browse files
committed
cleanup
1 parent dfd1258 commit 7ce162d

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

core/src/main/scala/org/apache/spark/storage/memory/MemoryStore.scala

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,12 @@ private[spark] class MemoryStore(
544544
}
545545

546546
if (freedMemory >= space) {
547-
val successfulBlocks = ArrayBuffer[BlockId]()
547+
var lastSuccessfulBlock = -1
548548
try {
549549
logInfo(s"${selectedBlocks.size} blocks selected for dropping " +
550550
s"(${Utils.bytesToString(freedMemory)} bytes)")
551-
for (blockId <- selectedBlocks) {
551+
(0 until selectedBlocks.size).foreach { idx =>
552+
val blockId = selectedBlocks(idx)
552553
val entry = entries.synchronized {
553554
entries.get(blockId)
554555
}
@@ -559,23 +560,19 @@ private[spark] class MemoryStore(
559560
dropBlock(blockId, entry)
560561
afterDropAction(blockId)
561562
}
562-
successfulBlocks += blockId
563+
lastSuccessfulBlock = idx
563564
}
564565
logInfo(s"After dropping ${selectedBlocks.size} blocks, " +
565566
s"free memory is ${Utils.bytesToString(maxMemory - blocksMemoryUsed)}")
566567
freedMemory
567568
} finally {
568569
// like BlockManager.doPut, we use a finally rather than a catch to avoid having to deal
569570
// with InterruptedException
570-
if (successfulBlocks.size != selectedBlocks.size) {
571-
val blocksToClean = selectedBlocks -- successfulBlocks
572-
blocksToClean.foreach { id =>
573-
// some of the blocks may have already been unlocked, or completely removed
574-
blockInfoManager.get(id).foreach { info =>
575-
if (info.readerCount > 0 || info.writerTask != BlockInfo.NO_WRITER) {
576-
blockInfoManager.unlock(id)
577-
}
578-
}
571+
if (lastSuccessfulBlock != selectedBlocks.size - 1) {
572+
// the blocks we didn't process successfully are still locked, so we have to unlock them
573+
(lastSuccessfulBlock + 1 until selectedBlocks.size).foreach { idx =>
574+
val blockId = selectedBlocks(idx)
575+
blockInfoManager.unlock(blockId)
579576
}
580577
}
581578
}

0 commit comments

Comments
 (0)