Search in sources :

Example 76 with IgniteBiTuple

use of org.apache.ignite.lang.IgniteBiTuple in project ignite by apache.

the class HadoopExternalTaskExecutor method run.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("ConstantConditions")
@Override
public void run(final HadoopJobEx job, final Collection<HadoopTaskInfo> tasks) throws IgniteCheckedException {
    if (!busyLock.tryReadLock()) {
        if (log.isDebugEnabled())
            log.debug("Failed to start hadoop tasks (grid is stopping, will ignore).");
        return;
    }
    try {
        HadoopProcess proc = runningProcsByJobId.get(job.id());
        HadoopTaskType taskType = F.first(tasks).type();
        if (taskType == HadoopTaskType.SETUP || taskType == HadoopTaskType.ABORT || taskType == HadoopTaskType.COMMIT) {
            if (proc == null || proc.terminated()) {
                runningProcsByJobId.remove(job.id(), proc);
                // Start new process for ABORT task since previous processes were killed.
                proc = startProcess(job, jobTracker.plan(job.id()));
                if (log.isDebugEnabled())
                    log.debug("Starting new process for maintenance task [jobId=" + job.id() + ", proc=" + proc + ", taskType=" + taskType + ']');
            }
        } else
            assert proc != null : "Missing started process for task execution request: " + job.id() + ", tasks=" + tasks;
        final HadoopProcess proc0 = proc;
        proc.initFut.listen(new CI1<IgniteInternalFuture<IgniteBiTuple<Process, HadoopProcessDescriptor>>>() {

            @Override
            public void apply(IgniteInternalFuture<IgniteBiTuple<Process, HadoopProcessDescriptor>> f) {
                if (!busyLock.tryReadLock())
                    return;
                try {
                    f.get();
                    proc0.addTasks(tasks);
                    if (log.isDebugEnabled())
                        log.debug("Sending task execution request to child process [jobId=" + job.id() + ", proc=" + proc0 + ", tasks=" + tasks + ']');
                    sendExecutionRequest(proc0, job, tasks);
                } catch (IgniteCheckedException e) {
                    notifyTasksFailed(tasks, FAILED, e);
                } finally {
                    busyLock.readUnlock();
                }
            }
        });
    } finally {
        busyLock.readUnlock();
    }
}
Also used : HadoopTaskType(org.apache.ignite.internal.processors.hadoop.HadoopTaskType) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 77 with IgniteBiTuple

use of org.apache.ignite.lang.IgniteBiTuple in project ignite by apache.

the class GridOffHeapPartitionedMapAbstractSelfTest method testIteratorMultithreaded.

/**
 * @throws Exception If failed.
 */
public void testIteratorMultithreaded() throws Exception {
    initCap = 10;
    map = newMap();
    final AtomicInteger rehashes = new AtomicInteger();
    final AtomicInteger releases = new AtomicInteger();
    map.eventListener(new GridOffHeapEventListener() {

        @Override
        public void onEvent(GridOffHeapEvent evt) {
            switch(evt) {
                case REHASH:
                    rehashes.incrementAndGet();
                    break;
                case RELEASE:
                    releases.incrementAndGet();
                    break;
                // No-op.
                default:
            }
        }
    });
    final int max = 1024;
    final ConcurrentMap<String, String> m = new ConcurrentHashMap<>(max * parts);
    final AtomicInteger part = new AtomicInteger();
    multithreaded(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            int p = part.getAndIncrement();
            for (int i = 0; i < max; i++) {
                String key = string();
                String val = string();
                // info("Storing [i=" + i + ", key=" + key + ", val=" + val + ']');
                String old = m.putIfAbsent(key, val);
                if (old != null)
                    val = old;
                assertTrue(map.put(p, hash(key), key.getBytes(), val.getBytes()));
                assertTrue(map.contains(p, hash(key), key.getBytes()));
                assertNotNull(map.get(p, hash(key), key.getBytes()));
                assertEquals(new String(map.get(p, hash(key), key.getBytes())), val);
            }
            try (GridCloseableIterator<IgniteBiTuple<byte[], byte[]>> it = map.iterator()) {
                while (it.hasNext()) {
                    IgniteBiTuple<byte[], byte[]> t = it.next();
                    String k = new String(t.get1());
                    String v = new String(t.get2());
                    // info("Entry [k=" + k + ", v=" + v + ']');
                    assertEquals(m.get(k), v);
                }
            }
            return null;
        }
    }, parts);
    int cnt = 0;
    try (GridCloseableIterator<IgniteBiTuple<byte[], byte[]>> it = map.iterator()) {
        while (it.hasNext()) {
            IgniteBiTuple<byte[], byte[]> t = it.next();
            String k = new String(t.get1());
            String v = new String(t.get2());
            // info("Entry [k=" + k + ", v=" + v + ']');
            assertEquals(m.get(k), v);
            cnt++;
        }
    }
    assertEquals(map.size(), cnt);
    assertEquals(max * parts, map.size());
    info("Stats [size=" + map.size() + ", rehashes=" + rehashes + ", releases=" + releases + ']');
    assertTrue(rehashes.get() > 0);
    assertEquals(rehashes.get(), releases.get());
}
Also used : GridCloseableIterator(org.apache.ignite.internal.util.lang.GridCloseableIterator) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 78 with IgniteBiTuple

use of org.apache.ignite.lang.IgniteBiTuple in project ignite by apache.

the class GridOffHeapPartitionedMapAbstractSelfTest method testIteratorRemoveMultithreaded.

/**
 * @throws Exception If failed.
 */
public void testIteratorRemoveMultithreaded() throws Exception {
    initCap = 10;
    map = newMap();
    final int max = 1024;
    final Map<String, String> m = new ConcurrentHashMap<>(max * parts);
    for (int i = 0; i < max; i++) {
        String key = string();
        String val = string();
        m.put(key, val);
        map.put(0, hash(key), key.getBytes(), val.getBytes());
    }
    final AtomicBoolean running = new AtomicBoolean(true);
    IgniteInternalFuture<?> iterFut = multithreadedAsync(new Runnable() {

        @Override
        public void run() {
            try {
                while (running.get()) {
                    try (GridCloseableIterator<IgniteBiTuple<byte[], byte[]>> it = map.iterator()) {
                        while (it.hasNext()) {
                            IgniteBiTuple<byte[], byte[]> tup = it.next();
                            String key = new String(tup.get1());
                            String val = new String(tup.get2());
                            String exp = m.get(key);
                            assertEquals(exp, val);
                        }
                    }
                }
            } catch (IgniteCheckedException e) {
                fail("Unexpected exception caught: " + e);
            }
        }
    }, 1);
    for (String key : m.keySet()) map.remove(0, hash(key), key.getBytes());
    running.set(false);
    iterFut.get();
    map.destruct();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCloseableIterator(org.apache.ignite.internal.util.lang.GridCloseableIterator) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 79 with IgniteBiTuple

use of org.apache.ignite.lang.IgniteBiTuple in project ignite by apache.

the class ColumnDecisionTreeTrainerTest method testByGen.

/**
 */
private <D extends ContinuousRegionInfo> void testByGen(int totalPts, HashMap<Integer, Integer> catsInfo, SplitDataGenerator<DenseLocalOnHeapVector> gen, IgniteFunction<ColumnDecisionTreeTrainerInput, ? extends ContinuousSplitCalculator<D>> calc, IgniteFunction<ColumnDecisionTreeTrainerInput, IgniteFunction<DoubleStream, Double>> catImpCalc, IgniteFunction<DoubleStream, Double> regCalc, Random rnd) {
    List<IgniteBiTuple<Integer, DenseLocalOnHeapVector>> lst = gen.points(totalPts, (i, rn) -> i).collect(Collectors.toList());
    int featCnt = gen.featuresCnt();
    Collections.shuffle(lst, rnd);
    SparseDistributedMatrix m = new SparseDistributedMatrix(totalPts, featCnt + 1, StorageConstants.COLUMN_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
    Map<Integer, List<LabeledVectorDouble>> byRegion = new HashMap<>();
    int i = 0;
    for (IgniteBiTuple<Integer, DenseLocalOnHeapVector> bt : lst) {
        byRegion.putIfAbsent(bt.get1(), new LinkedList<>());
        byRegion.get(bt.get1()).add(asLabeledVector(bt.get2().getStorage().data()));
        m.setRow(i, bt.get2().getStorage().data());
        i++;
    }
    ColumnDecisionTreeTrainer<D> trainer = new ColumnDecisionTreeTrainer<>(3, calc, catImpCalc, regCalc, ignite);
    DecisionTreeModel mdl = trainer.train(new MatrixColumnDecisionTreeTrainerInput(m, catsInfo));
    byRegion.keySet().forEach(k -> {
        LabeledVectorDouble sp = byRegion.get(k).get(0);
        Tracer.showAscii(sp.features());
        X.println("Actual and predicted vectors [act=" + sp.label() + " " + ", pred=" + mdl.apply(sp.features()) + "]");
        assert mdl.apply(sp.features()) == sp.doubleLabel();
    });
}
Also used : MatrixColumnDecisionTreeTrainerInput(org.apache.ignite.ml.trees.trainers.columnbased.MatrixColumnDecisionTreeTrainerInput) LabeledVectorDouble(org.apache.ignite.ml.structures.LabeledVectorDouble) DecisionTreeModel(org.apache.ignite.ml.trees.models.DecisionTreeModel) ContinuousSplitCalculators(org.apache.ignite.ml.trees.trainers.columnbased.contsplitcalcs.ContinuousSplitCalculators) IgniteFunction(org.apache.ignite.ml.math.functions.IgniteFunction) ColumnDecisionTreeTrainerInput(org.apache.ignite.ml.trees.trainers.columnbased.ColumnDecisionTreeTrainerInput) HashMap(java.util.HashMap) Random(java.util.Random) SparseDistributedMatrix(org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix) Collectors(java.util.stream.Collectors) DoubleStream(java.util.stream.DoubleStream) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) List(java.util.List) Map(java.util.Map) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) X(org.apache.ignite.internal.util.typedef.X) Tracer(org.apache.ignite.ml.math.Tracer) LinkedList(java.util.LinkedList) StorageConstants(org.apache.ignite.ml.math.StorageConstants) RegionCalculators(org.apache.ignite.ml.trees.trainers.columnbased.regcalcs.RegionCalculators) Collections(java.util.Collections) ColumnDecisionTreeTrainer(org.apache.ignite.ml.trees.trainers.columnbased.ColumnDecisionTreeTrainer) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector) SparseDistributedMatrix(org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix) LabeledVectorDouble(org.apache.ignite.ml.structures.LabeledVectorDouble) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) HashMap(java.util.HashMap) MatrixColumnDecisionTreeTrainerInput(org.apache.ignite.ml.trees.trainers.columnbased.MatrixColumnDecisionTreeTrainerInput) DecisionTreeModel(org.apache.ignite.ml.trees.models.DecisionTreeModel) List(java.util.List) LinkedList(java.util.LinkedList) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector) ColumnDecisionTreeTrainer(org.apache.ignite.ml.trees.trainers.columnbased.ColumnDecisionTreeTrainer)

Example 80 with IgniteBiTuple

use of org.apache.ignite.lang.IgniteBiTuple in project ignite by apache.

the class GridRestProcessor method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    if (isRestEnabled()) {
        if (notStartOnClient()) {
            U.quietAndInfo(log, "REST protocols do not start on client node. " + "To start the protocols on client node set '-DIGNITE_REST_START_ON_CLIENT=true' system property.");
            return;
        }
        // Register handlers.
        addHandler(new GridCacheCommandHandler(ctx));
        addHandler(new GridTaskCommandHandler(ctx));
        addHandler(new GridTopologyCommandHandler(ctx));
        addHandler(new GridVersionCommandHandler(ctx));
        addHandler(new DataStructuresCommandHandler(ctx));
        addHandler(new QueryCommandHandler(ctx));
        addHandler(new GridLogCommandHandler(ctx));
        addHandler(new GridChangeStateCommandHandler(ctx));
        addHandler(new UserActionCommandHandler(ctx));
        // Start protocols.
        startTcpProtocol();
        startHttpProtocol();
        for (GridRestProtocol proto : protos) {
            Collection<IgniteBiTuple<String, Object>> props = proto.getProperties();
            if (props != null) {
                for (IgniteBiTuple<String, Object> p : props) {
                    String key = p.getKey();
                    if (key == null)
                        continue;
                    if (ctx.hasNodeAttribute(key))
                        throw new IgniteCheckedException("Node attribute collision for attribute [processor=GridRestProcessor, attr=" + key + ']');
                    ctx.addNodeAttribute(key, p.getValue());
                }
            }
        }
    }
}
Also used : GridCacheCommandHandler(org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheCommandHandler) GridTaskCommandHandler(org.apache.ignite.internal.processors.rest.handlers.task.GridTaskCommandHandler) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) GridVersionCommandHandler(org.apache.ignite.internal.processors.rest.handlers.version.GridVersionCommandHandler) DataStructuresCommandHandler(org.apache.ignite.internal.processors.rest.handlers.datastructures.DataStructuresCommandHandler) UserActionCommandHandler(org.apache.ignite.internal.processors.rest.handlers.user.UserActionCommandHandler) GridTopologyCommandHandler(org.apache.ignite.internal.processors.rest.handlers.top.GridTopologyCommandHandler) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridLogCommandHandler(org.apache.ignite.internal.processors.rest.handlers.log.GridLogCommandHandler) GridChangeStateCommandHandler(org.apache.ignite.internal.processors.rest.handlers.cluster.GridChangeStateCommandHandler) QueryCommandHandler(org.apache.ignite.internal.processors.rest.handlers.query.QueryCommandHandler)

Aggregations

IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)93 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)42 ArrayList (java.util.ArrayList)25 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)21 HashMap (java.util.HashMap)20 List (java.util.List)20 IgniteException (org.apache.ignite.IgniteException)20 IOException (java.io.IOException)18 Map (java.util.Map)16 UUID (java.util.UUID)16 ClusterNode (org.apache.ignite.cluster.ClusterNode)13 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)13 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)13 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)12 Collection (java.util.Collection)10 Collections (java.util.Collections)10 Iterator (java.util.Iterator)10 Random (java.util.Random)10 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)10 Collectors (java.util.stream.Collectors)9