Skip to content

Commit

Permalink
Fix bug in calculating free space in current page.
Browse files Browse the repository at this point in the history
This broke off-heap mode.
  • Loading branch information
JoshRosen committed May 3, 2015
1 parent f17fa8f commit 8958584
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class UnsafeShuffleWriter<K, V> implements ShuffleWriter<K, V> {
private MapStatus mapStatus = null;

private MemoryBlock currentPage = null;
private long currentPagePosition = PAGE_SIZE;
private long currentPagePosition = -1;

/**
* Are we in the process of stopping? Because map tasks can call stop() with success = true
Expand Down Expand Up @@ -110,11 +110,17 @@ public void write(scala.collection.Iterator<Product2<K, V>> records) {
}

private void ensureSpaceInDataPage(long requiredSpace) throws Exception {
final long spaceInCurrentPage;
if (currentPage != null) {
spaceInCurrentPage = PAGE_SIZE - (currentPagePosition - currentPage.getBaseOffset());
} else {
spaceInCurrentPage = 0;
}
if (requiredSpace > PAGE_SIZE) {
// TODO: throw a more specific exception?
throw new Exception("Required space " + requiredSpace + " is greater than page size (" +
PAGE_SIZE + ")");
} else if (requiredSpace > (PAGE_SIZE - currentPagePosition)) {
} else if (requiredSpace > spaceInCurrentPage) {
currentPage = memoryManager.allocatePage(PAGE_SIZE);
currentPagePosition = currentPage.getBaseOffset();
allocatedPages.add(currentPage);
Expand Down

0 comments on commit 8958584

Please sign in to comment.