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
Allow async manager to block on destroys when preempting (could block…
… up to 30s)
  • Loading branch information
timf committed Jun 13, 2011
1 parent 5da43c1 commit d48ff79
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 26 deletions.
Expand Up @@ -824,7 +824,7 @@ protected void preempt(AsyncRequest request, int quantity) {

final String sourceStr = "via async-Manager-preempt, request " +
"id = '" + request.getId() + "'";
String errorStr = home.destroyMultiple(preemptionList, sourceStr);
String errorStr = home.destroyMultiple(preemptionList, sourceStr, true);
if(errorStr != null && errorStr.length() != 0){
failRequest("pre-empting", request, errorStr, null);
}
Expand Down
Expand Up @@ -85,16 +85,28 @@ public void destroy(String id)
* including if the workspace was not found, etc. This does not cut out
* early if there is any kind of problem.
*
* (note: implement with multiple threads because the remove procedure is
* blocking)
*
* @param workspaces list of workspace IDs
* @param sourceStr string for log msgs
* @return string report on what happened
*/
public String destroyMultiple(int[] workspaces, String sourceStr);


/**
* Destroy a set of workspaces. Return a list of errors separated by \n,
* including if the workspace was not found, etc. This does not cut out
* early if there is any kind of problem.
*
* Allow parameter to set to block until work is complete (up to thirty seconds).
*
* @param workspaces list of workspace IDs
* @param sourceStr string for log msgs
* @param block set true if you want to block until complete (up to thirty seconds)
* @return string report on what happened
*/
public String destroyMultiple(int[] workspaces, String sourceStr, boolean block);


// -------------------------------------------------------------------------
// OTHER
// -------------------------------------------------------------------------
Expand Down
Expand Up @@ -30,19 +30,26 @@ public class DestroyFutureTask implements Callable {

private final int id;
private final WorkspaceHome home;

private final boolean blockForSuccess;

// -------------------------------------------------------------------------
// CONSTRUCTOR
// CONSTRUCTORS
// -------------------------------------------------------------------------

public DestroyFutureTask(int vmid,
WorkspaceHome whome) {
this(vmid, whome, false);
}

public DestroyFutureTask(int vmid,
WorkspaceHome whome,
boolean blockForSuccess) {
this.id = vmid;
if (whome == null) {
throw new IllegalArgumentException("whome may not be null");
}
this.home = whome;
this.blockForSuccess = blockForSuccess;
}


Expand All @@ -52,7 +59,7 @@ public DestroyFutureTask(int vmid,

public Object call() throws Exception {

final InstanceResource resource;
InstanceResource resource;
try {
resource = this.home.find(this.id);
} catch (DoesNotExistException e) {
Expand All @@ -68,6 +75,18 @@ public Object call() throws Exception {

this.home.destroy(this.id);

return null;
if (!this.blockForSuccess) {
return null;
}

// There should also be a higher level timeout
while (true) {
try {
Thread.sleep(1000);
resource = this.home.find(this.id);
} catch (Exception e) {
return null;
}
}
}
}
Expand Up @@ -447,39 +447,30 @@ public void destroy(String id)
}
}

/**
* Destroy a set of workspaces. Return a list of errors separated by \n,
* including if the workspace was not found, etc. This does not cut out
* early if there is any kind of problem.
*
* Implemented with multiple threads because the remove procedure is
* blocking.
*
* @param workspaces list of workspace IDs
* @param sourceStr string for log msgs, or null
* @return string report on what happened
*/
public String destroyMultiple(int[] workspaces,
String sourceStr) {
public String destroyMultiple(int[] workspaces, String sourceStr) {
return this.destroyMultiple(workspaces, sourceStr, false);
}

public String destroyMultiple(int[] workspaces, String sourceStr, boolean block) {

final FutureTask[] tasks = new FutureTask[workspaces.length];
for (int i = 0; i < workspaces.length; i++) {
tasks[i] = new FutureTask(
new DestroyFutureTask(workspaces[i], this));
new DestroyFutureTask(workspaces[i], this, block));
}

for (int i = 0; i < tasks.length; i++) {
this.executor.submit(tasks[i]);
}

final StringBuffer buf = new StringBuffer(tasks.length * 256);
final StringBuilder buf = new StringBuilder(tasks.length * 256);

// Log any unexpected errors. Wait two minutes (normal destroy time
// Log any unexpected errors. Wait thirty seconds (normal destroy time
// should be a matter of seconds even if there is high congestion).
// todo: make timeout configurable
for (int i = 0; i < tasks.length; i++) {
try {
final String msg = (String) tasks[i].get(120L, TimeUnit.SECONDS);
final String msg = (String) tasks[i].get(30L, TimeUnit.SECONDS);
if (msg != null) {
buf.append(msg);
}
Expand Down

0 comments on commit d48ff79

Please sign in to comment.