Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a separate condition that checks for a completely infeasible memo…
…ry request. This greatly reduces the number of corner cases related to GH-26
  • Loading branch information
timf committed Jun 13, 2011
1 parent 3511c12 commit 5da43c1
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 5 deletions.
@@ -0,0 +1,20 @@
package org.nimbustools.api.services.rm;

public class ImpossibleAmountOfMemoryException extends ResourceRequestDeniedException {

public ImpossibleAmountOfMemoryException() {
super();
}

public ImpossibleAmountOfMemoryException(String message) {
super(message);
}

public ImpossibleAmountOfMemoryException(String message, Throwable e) {
super(message, e);
}

public ImpossibleAmountOfMemoryException(Exception e) {
super(e);
}
}
Expand Up @@ -202,6 +202,9 @@ public void updateCursorPosition(long currentPosition)
public List<ResourcepoolEntry> getAvailableEntriesSortedByFreeMemoryPercentage(int requestedMem)

throws WorkspaceDatabaseException;

// returns true if memory request is bigger than any VMM could ever handle
public boolean isInfeasibleRequest(int requestedMem) throws WorkspaceDatabaseException;

//Spot Instances

Expand Down
Expand Up @@ -207,6 +207,10 @@ public interface PersistenceAdapterConstants {
"SELECT * FROM resourcepool_entries WHERE active = 1 AND " +
"available_memory >= ? " +
"ORDER BY (available_memory/maximum_memory) ASC";

public static final String SQL_SELECT_INFEASIBLE_MEMORY =
"SELECT COUNT(DISTINCT hostname) FROM resourcepool_entries WHERE active = 1 AND " +
"? <= maximum_memory";

public static final String SQL_INSERT_SPOT_PRICE =
"INSERT INTO spot_prices VALUES(?,?)";
Expand Down Expand Up @@ -290,6 +294,7 @@ public interface PersistenceAdapterConstants {
SQL_SELECT_TOTAL_AVAILABLE_MEMORY,
SQL_SELECT_TOTAL_MAX_MEMORY,
SQL_SELECT_TOTAL_PREEMPTABLE_MEMORY,
SQL_SELECT_INFEASIBLE_MEMORY,
SQL_SELECT_USED_NON_PREEMPTABLE_MEMORY,
SQL_INSERT_SPOT_PRICE,
SQL_SELECT_LAST_SPOT_PRICE,
Expand Down
Expand Up @@ -2419,6 +2419,50 @@ private int readCounter(int n, String prepd)
}
}
}

public boolean isInfeasibleRequest(int requestedMem)
throws WorkspaceDatabaseException{

Connection c = null;
PreparedStatement pstmt = null;
ResultSet rs = null;

try {
c = getConnection();
pstmt = c.prepareStatement(SQL_SELECT_INFEASIBLE_MEMORY);
pstmt.setInt(1, requestedMem);
rs = pstmt.executeQuery();

if (rs == null || !rs.next()) {
throw new WorkspaceDatabaseException("Should always have a result");
} else {
int numPossibleVmms = rs.getInt(1);
if (numPossibleVmms > 0) {
return false;
} else {
return true;
}
}

} catch(SQLException e) {
logger.error("",e);
throw new WorkspaceDatabaseException(e);
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
if (rs != null) {
rs.close();
}
if (c != null) {
returnConnection(c);
}
} catch (SQLException sql) {
logger.error("SQLException in finally cleanup", sql);
}
}
}

public List<ResourcepoolEntry> getAvailableEntriesSortedByFreeMemoryPercentage(int requestedMem)
throws WorkspaceDatabaseException{
Expand Down
Expand Up @@ -39,6 +39,7 @@
import org.globus.workspace.service.binding.vm.VirtualMachine;
import org.globus.workspace.service.binding.vm.VirtualMachineDeployment;
import org.nimbustools.api.services.rm.DoesNotExistException;
import org.nimbustools.api.services.rm.ImpossibleAmountOfMemoryException;
import org.nimbustools.api.services.rm.ManageException;
import org.nimbustools.api.services.rm.NotEnoughMemoryException;
import org.nimbustools.api.services.rm.ResourceRequestDeniedException;
Expand Down Expand Up @@ -424,6 +425,8 @@ private String[] reserveSpace(final int[] vmids,
throw new ProgrammingError(
"returned node should not be null");
}
} catch (ImpossibleAmountOfMemoryException e) {
throw e;
} catch (NotEnoughMemoryException e) {
if(!preemptable){
try {
Expand All @@ -441,6 +444,11 @@ private String[] reserveSpace(final int[] vmids,

Integer neededMem = (vmids.length-i)*memory;

if (usedPreemptable == 0) {
// impossible to fulfill the request
throw e;
}

if(realAvailable >= neededMem){
//There will be sufficient space to
//fulfill this reservation
Expand Down
Expand Up @@ -21,6 +21,7 @@
import org.globus.workspace.Lager;
import org.globus.workspace.persistence.PersistenceAdapter;
import org.globus.workspace.persistence.WorkspaceDatabaseException;
import org.nimbustools.api.services.rm.ImpossibleAmountOfMemoryException;
import org.nimbustools.api.services.rm.NotEnoughMemoryException;
import org.nimbustools.api.services.rm.ResourceRequestDeniedException;
import org.nimbustools.api.services.rm.ManageException;
Expand Down Expand Up @@ -218,7 +219,12 @@ static String getResourcePoolEntry(int mem,

if (trace) {
traceLookingForResource(mem, neededAssociations, greedy);
}
}

if (db.isInfeasibleRequest(mem)) {
throw new ImpossibleAmountOfMemoryException(mem + "MB memory request is too " +
"large to ever be fulfilled");
}

//availableEntries is never empty
final List<ResourcepoolEntry> availableEntries =
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.nimbustools.api.repr.CreateRequest;
import org.nimbustools.api.repr.CreateResult;
import org.nimbustools.api.services.admin.RemoteNodeManagement;
import org.nimbustools.api.services.rm.ImpossibleAmountOfMemoryException;
import org.nimbustools.api.services.rm.Manager;
import org.nimbustools.api.services.rm.NotEnoughMemoryException;
import org.springframework.test.annotation.DirtiesContext;
Expand Down Expand Up @@ -96,12 +97,12 @@ public void tooMuchMemory() throws Exception {
final Caller caller = this.populator().getCaller();
final CreateRequest request =
this.populator().getCreateRequest("suite:issue26:tooMuchMemory", 240, 3584, 1);
boolean notEnoughMemory = false;
boolean impossibleMemory = false;
try {
final CreateResult result = rm.create(request, caller);
} catch (NotEnoughMemoryException e) {
notEnoughMemory = true;
} catch (ImpossibleAmountOfMemoryException e) {
impossibleMemory = true;
}
assertTrue(notEnoughMemory);
assertTrue(impossibleMemory);
}
}

0 comments on commit 5da43c1

Please sign in to comment.