Skip to content

Commit

Permalink
PHOENIX-2527 InsufficientMemoryException error message is misleading
Browse files Browse the repository at this point in the history
  • Loading branch information
enis committed Dec 16, 2015
1 parent 2685d54 commit b38989d
Showing 1 changed file with 10 additions and 10 deletions.
Expand Up @@ -21,15 +21,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*
* Global memory manager to track course grained memory usage across all requests.
*
*
*
* @since 0.1
*/
public class GlobalMemoryManager implements MemoryManager {
private static final Logger logger = LoggerFactory.getLogger(GlobalMemoryManager.class);

private final Object sync = new Object();
private final long maxMemoryBytes;
private final int maxWaitMs;
Expand All @@ -46,7 +46,7 @@ public GlobalMemoryManager(long maxBytes, int maxWaitMs) {
this.maxWaitMs = maxWaitMs;
this.usedMemoryBytes = 0;
}

@Override
public long getAvailableMemory() {
synchronized(sync) {
Expand Down Expand Up @@ -75,7 +75,7 @@ private long allocateBytes(long minBytes, long reqBytes) {
try {
long remainingWaitTimeMs = maxWaitMs - (System.currentTimeMillis() - startTimeMs);
if (remainingWaitTimeMs <= 0) { // Ran out of time waiting for some memory to get freed up
throw new InsufficientMemoryException("Requested memory of " + minBytes + " bytes could not be allocated from remaining memory of " + usedMemoryBytes + " bytes from global pool of " + maxMemoryBytes + " bytes after waiting for " + maxWaitMs + "ms.");
throw new InsufficientMemoryException("Requested memory of " + minBytes + " bytes could not be allocated. Using memory of " + usedMemoryBytes + " bytes from global pool of " + maxMemoryBytes + " bytes after waiting for " + maxWaitMs + "ms.");
}
sync.wait(remainingWaitTimeMs);
} catch (InterruptedException ie) {
Expand Down Expand Up @@ -106,7 +106,7 @@ public MemoryChunk allocate(long nBytes) {
protected MemoryChunk newMemoryChunk(long sizeBytes) {
return new GlobalMemoryChunk(sizeBytes);
}

private class GlobalMemoryChunk implements MemoryChunk {
private volatile long size;

Expand All @@ -123,7 +123,7 @@ public long getSize() {
return size; // TODO: does this need to be synchronized?
}
}

@Override
public void resize(long nBytes) {
if (nBytes < 0) {
Expand All @@ -141,7 +141,7 @@ public void resize(long nBytes) {
}
}
}

/**
* Check that MemoryChunk has previously been closed.
*/
Expand All @@ -159,7 +159,7 @@ protected void finalize() throws Throwable {
super.finalize();
}
}

@Override
public void close() {
synchronized(sync) {
Expand All @@ -170,4 +170,4 @@ public void close() {
}
}
}

0 comments on commit b38989d

Please sign in to comment.