package water.util;

import water.*;

public class RemoveAllKeysTask extends DRemoteTask {
  public RemoveAllKeysTask() {}

  @Override public void lcompute() {
    int keysetSize = H2O.keySet().size();
    int numNodes = H2O.CLOUD._memary.length;
    int nodeIdx = H2O.SELF.index();
    Log.info("Removing "+keysetSize+" keys on this node; nodeIdx("+nodeIdx+") numNodes("+numNodes+")");

    // First cancel all jobs and wait for them to be done.
    for (Job job : Job.all()) {
      job.cancel();
      Job.waitUntilJobEnded(job.self());
    }

    // Now remove all keys.
    Futures fs = new Futures();
    for( Key key : H2O.keySet() ) {
      DKV.remove(key, fs);
    }
    fs.blockForPending();

    Log.info("Keys remaining: "+H2O.store_size());

    tryComplete();
  }

  @Override public void reduce(DRemoteTask drt) {
  }

  @Override public byte priority() { return H2O.GUI_PRIORITY; }
}

@@ -489,24 +489,60 @@
 b.cancel();%0A
+      if(job.cancelled()) continue;%0A
       Job.wa
@@ -670,18 +670,16 @@
 ySet() )
- %7B
 %0A      D
@@ -698,21 +698,16 @@
 y, fs);%0A
-    %7D
 %0A    fs.

don't wait if job canceled is true