Search in sources :

Example 6 with CountedCompleter

use of jsr166y.CountedCompleter in project h2o-3 by h2oai.

the class MRThrow method testContinuationThrow.

@Test
public void testContinuationThrow() throws InterruptedException, ExecutionException {
    int sz = H2O.CLOUD.size();
    Vec vec = Vec.makeZero((sz + 1) * FileVec.DFLT_CHUNK_SIZE + 1);
    try {
        for (int i = 0; i < H2O.CLOUD._memary.length; ++i) {
            final ByteHistoThrow bh = new ByteHistoThrow(H2O.CLOUD._memary[i]);
            final boolean[] ok = new boolean[] { false };
            try {
                CountedCompleter cc = new CountedCompleter() {

                    @Override
                    public void compute() {
                        tryComplete();
                    }

                    @Override
                    public boolean onExceptionalCompletion(Throwable ex, CountedCompleter cc) {
                        ok[0] = ex.getMessage().contains("test");
                        return super.onExceptionalCompletion(ex, cc);
                    }
                };
                bh.setCompleter(cc);
                bh.dfork(vec);
                // If the chosen file is too small for the cluster, some nodes will have *no* work
                // and so no exception is thrown.
                cc.join();
            } catch (RuntimeException re) {
                assertTrue(re.getMessage().contains("test") || re.getCause().getMessage().contains("test"));
            //        } catch( ExecutionException e ) { // caught on self
            //          assertTrue(e.getMessage().contains("test"));
            } catch (java.lang.AssertionError ae) {
                // Standard junit failure reporting assertion
                throw ae;
            } catch (Throwable ex) {
                ex.printStackTrace();
                fail("Unexpected exception" + ex.toString());
            }
        }
    } finally {
        // remove from DKV
        if (vec != null)
            vec.remove();
    }
}
Also used : Vec(water.fvec.Vec) FileVec(water.fvec.FileVec) CountedCompleter(jsr166y.CountedCompleter)

Example 7 with CountedCompleter

use of jsr166y.CountedCompleter in project h2o-2 by h2oai.

the class FrameExtractor method compute2.

@Override
public void compute2() {
    // Lock all possible data
    dataset.read_lock(jobKey);
    // Create a template vector for each segment
    final Vec[][] templates = makeTemplates();
    final int nsplits = templates.length;
    assert templates.length == numOfOutputs() : "Number of outputs and number of created templates differ!";
    final Vec[] datasetVecs = dataset.vecs();
    // Create output frames
    splits = new Frame[nsplits];
    for (int s = 0; s < nsplits; s++) {
        Frame split = new Frame(destKeys[s], dataset.names(), templates[s]);
        split.delete_and_lock(jobKey);
        splits[s] = split;
    }
    // Launch number of distributed FJ for each split part
    setPendingCount(1);
    H2O.submitTask(new H2OCountedCompleter(FrameExtractor.this) {

        @Override
        public void compute2() {
            setPendingCount(nsplits);
            for (int s = 0; s < nsplits; s++) {
                MRTask2 mrt = createNewWorker(new // Completer for this task
                H2OCountedCompleter(// Completer for this task
                this) {

                    @Override
                    public void compute2() {
                    }

                    @Override
                    public boolean onExceptionalCompletion(Throwable ex, CountedCompleter caller) {
                        synchronized (FrameExtractor.this) {
                            // synchronized on this since can be accessed from different workers
                            workersExceptions = workersExceptions != null ? Arrays.copyOf(workersExceptions, workersExceptions.length + 1) : new Throwable[1];
                            workersExceptions[workersExceptions.length - 1] = ex;
                        }
                        // we handle the exception so wait perform normal completion
                        tryComplete();
                        return false;
                    }
                }, datasetVecs, s);
                assert mrt.getCompleter() != null : "The `createNewWorker` method violates API contract and forgets to setup given counted completer!";
                mrt.asyncExec(splits[s]);
            }
            // complete the computation of nsplits-tasks
            tryComplete();
        }
    });
    // complete the computation of thrown tasks
    tryComplete();
}
Also used : H2OCountedCompleter(water.H2O.H2OCountedCompleter) H2OCountedCompleter(water.H2O.H2OCountedCompleter) CountedCompleter(jsr166y.CountedCompleter)

Example 8 with CountedCompleter

use of jsr166y.CountedCompleter in project h2o-2 by h2oai.

the class MRThrow method testContinuationThrow.

@Test
public void testContinuationThrow() throws InterruptedException, ExecutionException {
    File file = find_test_file("target/h2o.jar");
    Key h2okey = load_test_file(file);
    NFSFileVec nfs = DKV.get(h2okey).get();
    try {
        for (int i = 0; i < H2O.CLOUD._memary.length; ++i) {
            ByteHistoThrow bh = new ByteHistoThrow();
            bh._throwAt = H2O.CLOUD._memary[i].toString();
            final boolean[] ok = new boolean[] { false };
            try {
                bh.setCompleter(new CountedCompleter() {

                    @Override
                    public void compute() {
                    }

                    @Override
                    public boolean onExceptionalCompletion(Throwable ex, CountedCompleter cc) {
                        ok[0] = ex.getMessage().contains("test");
                        return true;
                    }
                });
                // invoke should throw DistrDTibutedException wrapped up in RunTimeException
                bh.dfork(nfs).get();
                assertTrue(ok[0]);
            } catch (ExecutionException eex) {
                assertTrue(eex.getCause().getMessage().contains("test"));
            } catch (Throwable ex) {
                ex.printStackTrace();
                fail("Unexpected exception" + ex.toString());
            }
        }
    } finally {
        // so once a map() call fails, other map calls can lazily load data after we call delete()
        try {
            Thread.sleep(100);
        } catch (InterruptedException ignore) {
        }
        Lockable.delete(h2okey);
    }
}
Also used : NFSFileVec(water.fvec.NFSFileVec) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File) CountedCompleter(jsr166y.CountedCompleter) Test(org.junit.Test)

Aggregations

CountedCompleter (jsr166y.CountedCompleter)8 H2OCountedCompleter (water.H2O.H2OCountedCompleter)5 File (java.io.File)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1 FileVec (water.fvec.FileVec)1 NFSFileVec (water.fvec.NFSFileVec)1 Vec (water.fvec.Vec)1