Skip to content

Commit

Permalink
fix spill logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kecookier committed Dec 17, 2024
1 parent 5d90bce commit c09e1a6
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,30 @@ public class RetryOnOomMemoryTarget implements TreeMemoryTarget {
public long borrow(long size) {
long granted = target.borrow(size);
if (granted < size) {

LOGGER.info(
"Exceed Spark perTaskLimit with maxTaskSizeDynamic when "
+ "require:{} got:{}, try spill all.",
size,
granted);
final long spilled = TreeMemoryTargets.spillTree(target, Long.MAX_VALUE);
LOGGER.info("Retrying spill require:{} got:{}", size, granted);
final long spilled = retryingSpill(Long.MAX_VALUE);
final long remaining = size - granted;
if (spilled >= remaining) {
granted += target.borrow(remaining);
}
LOGGER.info("Retrying spill spilled:{} final granted:{}", spilled, granted);
}
return granted;
}

private long retryingSpill(long size) {
TreeMemoryTarget rootTarget = target;
while (true) {
try {
rootTarget = rootTarget.parent();
} catch (IllegalStateException e) {
// Reached the root node
break;
}
}
return TreeMemoryTargets.spillTree(rootTarget, size);
}

@Override
public long repay(long size) {
return target.repay(size);
Expand Down

0 comments on commit c09e1a6

Please sign in to comment.