Search in sources :

Example 16 with IgniteBiTuple

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

the class GridOffHeapPartitionedMapAbstractSelfTest method testPartitionIterator.

/**
     * @throws Exception If failed.
     */
public void testPartitionIterator() 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:
            }
        }
    });
    int max = 1024;
    for (int p = 0; p < parts; p++) {
        Map<String, String> m = new HashMap<>(max);
        for (int i = 0; i < max; i++) {
            String key = string();
            String val = string();
            // info("Storing [i=" + i + ", key=" + key + ", val=" + val + ']');
            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);
            m.put(key, val);
            int cnt = 0;
            try (GridCloseableIterator<IgniteBiTuple<byte[], byte[]>> it = map.iterator(p)) {
                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(), p * max + 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 : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple)

Example 17 with IgniteBiTuple

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

the class GridOffHeapPartitionedMapAbstractSelfTest method testPartitionIteratorMultithreaded.

/**
     * @throws Exception If failed.
     */
public void testPartitionIteratorMultithreaded() 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 = 64;
    int threads = 5;
    final Map<String, String> m = new ConcurrentHashMap8<>(max);
    multithreaded(new Callable() {

        @Override
        public Object call() throws Exception {
            for (int p = 0; p < parts; p++) {
                for (int i = 0; i < max; i++) {
                    String key = string();
                    String val = string();
                    // info("Storing [i=" + i + ", key=" + key + ", val=" + val + ']');
                    m.put(key, val);
                    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(p)) {
                        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;
        }
    }, threads);
    assertEquals(max * threads * 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) ConcurrentHashMap8(org.jsr166.ConcurrentHashMap8) Callable(java.util.concurrent.Callable) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 18 with IgniteBiTuple

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

the class HadoopJobTracker method logPlan.

/**
     * Log map-reduce plan if needed.
     *
     * @param info Job info.
     * @param plan Plan.
     */
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
private void logPlan(HadoopJobInfo info, HadoopMapReducePlan plan) {
    if (log.isDebugEnabled()) {
        Map<UUID, IgniteBiTuple<Collection<HadoopInputSplit>, int[]>> map = new HashMap<>();
        for (UUID nodeId : plan.mapperNodeIds()) map.put(nodeId, new IgniteBiTuple<Collection<HadoopInputSplit>, int[]>(plan.mappers(nodeId), null));
        for (UUID nodeId : plan.reducerNodeIds()) {
            int[] reducers = plan.reducers(nodeId);
            IgniteBiTuple<Collection<HadoopInputSplit>, int[]> entry = map.get(nodeId);
            if (entry == null)
                map.put(nodeId, new IgniteBiTuple<Collection<HadoopInputSplit>, int[]>(null, reducers));
            else
                entry.set2(reducers);
        }
        StringBuilder details = new StringBuilder("[");
        boolean first = true;
        for (Map.Entry<UUID, IgniteBiTuple<Collection<HadoopInputSplit>, int[]>> entry : map.entrySet()) {
            if (first)
                first = false;
            else
                details.append(", ");
            UUID nodeId = entry.getKey();
            Collection<HadoopInputSplit> mappers = entry.getValue().get1();
            if (mappers == null)
                mappers = Collections.emptyList();
            int[] reducers = entry.getValue().get2();
            if (reducers == null)
                reducers = new int[0];
            details.append("[nodeId=" + nodeId + ", mappers=" + mappers.size() + ", reducers=" + reducers.length + ", mapperDetails=" + mappers + ", reducerDetails=" + Arrays.toString(reducers) + ']');
        }
        details.append(']');
        log.debug("Prepared map-reduce plan [jobName=" + info.jobName() + ", mappers=" + plan.mappers() + ", reducers=" + plan.reducers() + ", details=" + details + ']');
    }
}
Also used : HashMap(java.util.HashMap) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) HadoopInputSplit(org.apache.ignite.hadoop.HadoopInputSplit) Collection(java.util.Collection) UUID(java.util.UUID) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 19 with IgniteBiTuple

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

the class WeightedRandomLoadBalancingSpi method onContextInitialized0.

/** {@inheritDoc} */
@Override
protected void onContextInitialized0(IgniteSpiContext spiCtx) throws IgniteSpiException {
    getSpiContext().addLocalEventListener(evtLsnr = new GridLocalEventListener() {

        @Override
        public void onEvent(Event evt) {
            assert evt instanceof TaskEvent || evt instanceof JobEvent;
            if (evt.type() == EVT_TASK_FINISHED || evt.type() == EVT_TASK_FAILED) {
                IgniteUuid sesId = ((TaskEvent) evt).taskSessionId();
                taskTops.remove(sesId);
                if (log.isDebugEnabled())
                    log.debug("Removed task topology from topology cache for session: " + sesId);
            } else // Here we set mapped property and later cache will be ignored
            if (evt.type() == EVT_JOB_MAPPED) {
                IgniteUuid sesId = ((JobEvent) evt).taskSessionId();
                IgniteBiTuple<Boolean, WeightedTopology> weightedTop = taskTops.get(sesId);
                if (weightedTop != null)
                    weightedTop.set1(true);
                if (log.isDebugEnabled())
                    log.debug("Job has been mapped. Ignore cache for session: " + sesId);
            }
        }
    }, EVT_TASK_FAILED, EVT_TASK_FINISHED, EVT_JOB_MAPPED);
}
Also used : JobEvent(org.apache.ignite.events.JobEvent) GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) IgniteUuid(org.apache.ignite.lang.IgniteUuid) TaskEvent(org.apache.ignite.events.TaskEvent) JobEvent(org.apache.ignite.events.JobEvent) TaskEvent(org.apache.ignite.events.TaskEvent) Event(org.apache.ignite.events.Event)

Example 20 with IgniteBiTuple

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

the class SparseDistributedMatrixTest method buildKeySet.

/** Build key set for SparseDistributedMatrix. */
private Set<IgniteBiTuple<Integer, IgniteUuid>> buildKeySet(SparseDistributedMatrix m) {
    Set<IgniteBiTuple<Integer, IgniteUuid>> set = new HashSet<>();
    SparseDistributedMatrixStorage storage = (SparseDistributedMatrixStorage) m.getStorage();
    IgniteUuid uuid = storage.getUUID();
    int size = storage.storageMode() == StorageConstants.ROW_STORAGE_MODE ? storage.rowSize() : storage.columnSize();
    for (int i = 0; i < size; i++) set.add(new IgniteBiTuple<>(i, uuid));
    return set;
}
Also used : IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) IgniteUuid(org.apache.ignite.lang.IgniteUuid) SparseDistributedMatrixStorage(org.apache.ignite.ml.math.impls.storage.matrix.SparseDistributedMatrixStorage) HashSet(java.util.HashSet)

Aggregations

IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)64 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)35 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)18 IgniteException (org.apache.ignite.IgniteException)17 ArrayList (java.util.ArrayList)14 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)13 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)13 ClusterNode (org.apache.ignite.cluster.ClusterNode)11 HashMap (java.util.HashMap)10 UUID (java.util.UUID)10 IOException (java.io.IOException)9 List (java.util.List)9 Map (java.util.Map)8 CacheStorePartialUpdateException (org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException)8 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)8 LinkedHashMap (java.util.LinkedHashMap)7 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Event (org.apache.ignite.events.Event)6 IgfsPath (org.apache.ignite.igfs.IgfsPath)6