Search in sources :

Example 36 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid 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 37 with IgniteUuid

use of org.apache.ignite.lang.IgniteUuid 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)

Example 38 with IgniteUuid

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

the class GridCacheSetFailoverAbstractSelfTest method testNodeRestart.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings("WhileLoopReplaceableByForEach")
public void testNodeRestart() throws Exception {
    IgniteSet<Integer> set = grid(0).set(SET_NAME, config(false));
    final int ITEMS = 10_000;
    Collection<Integer> items = new ArrayList<>(ITEMS);
    for (int i = 0; i < ITEMS; i++) items.add(i);
    set.addAll(items);
    assertEquals(ITEMS, set.size());
    AtomicBoolean stop = new AtomicBoolean();
    IgniteInternalFuture<?> killFut = startNodeKiller(stop);
    long stopTime = System.currentTimeMillis() + TEST_DURATION;
    try {
        ThreadLocalRandom rnd = ThreadLocalRandom.current();
        while (System.currentTimeMillis() < stopTime) {
            for (int i = 0; i < 10; i++) {
                try {
                    int size = set.size();
                    // TODO: IGNITE-584, check for equality when IGNITE-584 fixed.
                    assertTrue(size > 0);
                } catch (IgniteException ignore) {
                // No-op.
                }
                try {
                    Iterator<Integer> iter = set.iterator();
                    int cnt = 0;
                    while (iter.hasNext()) {
                        assertNotNull(iter.next());
                        cnt++;
                    }
                    // TODO: IGNITE-584, check for equality when IGNITE-584 fixed.
                    assertTrue(cnt > 0);
                } catch (IgniteException ignore) {
                // No-op.
                }
                int val = rnd.nextInt(ITEMS);
                assertTrue("Not contains: " + val, set.contains(val));
                val = ITEMS + rnd.nextInt(ITEMS);
                assertFalse("Contains: " + val, set.contains(val));
            }
            log.info("Remove set.");
            set.close();
            log.info("Create new set.");
            set = grid(0).set(SET_NAME, config(false));
            set.addAll(items);
        }
    } finally {
        stop.set(true);
    }
    killFut.get();
    set.close();
    if (false) {
        // TODO IGNITE-600: enable check when fixed.
        int cnt = 0;
        Set<IgniteUuid> setIds = new HashSet<>();
        for (int i = 0; i < gridCount(); i++) {
            Iterator<GridCacheMapEntry> entries = grid(i).context().cache().internalCache(DEFAULT_CACHE_NAME).map().entries().iterator();
            while (entries.hasNext()) {
                GridCacheEntryEx entry = entries.next();
                if (entry.hasValue()) {
                    cnt++;
                    if (entry.key() instanceof SetItemKey) {
                        SetItemKey setItem = (SetItemKey) entry.key();
                        if (setIds.add(setItem.setId()))
                            log.info("Unexpected set item [setId=" + setItem.setId() + ", grid: " + grid(i).name() + ", entry=" + entry + ']');
                    }
                }
            }
        }
        assertEquals("Found unexpected cache entries", 0, cnt);
    }
}
Also used : ArrayList(java.util.ArrayList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteException(org.apache.ignite.IgniteException) IgniteUuid(org.apache.ignite.lang.IgniteUuid) SetItemKey(org.apache.ignite.internal.processors.datastructures.SetItemKey) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry) HashSet(java.util.HashSet)

Example 39 with IgniteUuid

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

the class IgfsSizeSelfTest method write.

/**
     * Perform write of the files.
     *
     * @return Collection of written file descriptors.
     * @throws Exception If failed.
     */
private Collection<IgfsFile> write() throws Exception {
    Collection<IgfsFile> res = new HashSet<>(FILES_CNT, 1.0f);
    ThreadLocalRandom8 rand = ThreadLocalRandom8.current();
    for (int i = 0; i < FILES_CNT; i++) {
        // Create empty file locally.
        IgfsPath path = new IgfsPath("/file-" + i);
        igfs(0).create(path, false).close();
        IgfsMetaManager meta = igfs(0).context().meta();
        IgniteUuid fileId = meta.fileId(path);
        // Calculate file blocks.
        int fileSize = rand.nextInt(MAX_FILE_SIZE);
        int fullBlocks = fileSize / BLOCK_SIZE;
        int remainderSize = fileSize % BLOCK_SIZE;
        Collection<IgfsBlock> blocks = new ArrayList<>(fullBlocks + remainderSize > 0 ? 1 : 0);
        for (int j = 0; j < fullBlocks; j++) blocks.add(new IgfsBlock(new IgfsBlockKey(fileId, null, true, j), BLOCK_SIZE));
        if (remainderSize > 0)
            blocks.add(new IgfsBlock(new IgfsBlockKey(fileId, null, true, fullBlocks), remainderSize));
        IgfsFile file = new IgfsFile(path, fileSize, blocks);
        // Actual write.
        for (IgfsBlock block : blocks) {
            IgfsOutputStream os = igfs(0).append(path, false);
            os.write(chunk(block.length()));
            os.close();
        }
        // Add written file to the result set.
        res.add(file);
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream) ThreadLocalRandom8(org.jsr166.ThreadLocalRandom8) IgfsPath(org.apache.ignite.igfs.IgfsPath) IgniteUuid(org.apache.ignite.lang.IgniteUuid) HashSet(java.util.HashSet)

Example 40 with IgniteUuid

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

the class IgfsProcessorSelfTest method testDeleteCacheConsistency.

/** @throws Exception If failed. */
@SuppressWarnings("BusyWait")
public void testDeleteCacheConsistency() throws Exception {
    IgfsPath path = new IgfsPath("/someFile");
    String metaCacheName = grid(0).igfsx("igfs").configuration().getMetaCacheConfiguration().getName();
    String dataCacheName = grid(0).igfsx("igfs").configuration().getDataCacheConfiguration().getName();
    try (IgfsOutputStream out = igfs.create(path, true)) {
        out.write(new byte[10 * 1024 * 1024]);
    }
    IgniteUuid fileId = U.field(igfs.info(path), "fileId");
    GridCacheAdapter<IgniteUuid, IgfsEntryInfo> metaCache = ((IgniteKernal) grid(0)).internalCache(metaCacheName);
    GridCacheAdapter<IgfsBlockKey, byte[]> dataCache = ((IgniteKernal) grid(0)).internalCache(dataCacheName);
    IgfsEntryInfo info = metaCache.get(fileId);
    assertNotNull(info);
    assertTrue(info.isFile());
    assertNotNull(metaCache.get(info.id()));
    IgfsDataManager dataMgr = ((IgfsEx) igfs).context().data();
    for (int i = 0; i < info.blocksCount(); i++) assertNotNull(dataCache.get(dataMgr.blockKey(i, info)));
    igfs.delete(path, true);
    for (int i = 0; i < 25; i++) {
        if (metaCache.get(info.id()) == null)
            break;
        U.sleep(100);
    }
    assertNull(metaCache.get(info.id()));
    for (int i = 0; i < 10; i++) {
        boolean doBreak = true;
        for (int j = 0; j < info.blocksCount(); j++) {
            if (dataCache.get(dataMgr.blockKey(i, info)) != null) {
                doBreak = false;
                break;
            }
        }
        if (doBreak)
            break;
        else
            Thread.sleep(100);
    }
    for (int i = 0; i < info.blocksCount(); i++) assertNull(dataCache.get(new IgfsBlockKey(info.id(), null, false, i)));
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Aggregations

IgniteUuid (org.apache.ignite.lang.IgniteUuid)98 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)22 UUID (java.util.UUID)19 IgniteException (org.apache.ignite.IgniteException)17 HashMap (java.util.HashMap)13 Map (java.util.Map)11 IgfsPath (org.apache.ignite.igfs.IgfsPath)11 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)10 ArrayList (java.util.ArrayList)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 Nullable (org.jetbrains.annotations.Nullable)9 IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)7 TreeSet (java.util.TreeSet)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 IgfsException (org.apache.ignite.igfs.IgfsException)6 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 Event (org.apache.ignite.events.Event)5 TaskEvent (org.apache.ignite.events.TaskEvent)5 IgfsPathIsDirectoryException (org.apache.ignite.igfs.IgfsPathIsDirectoryException)5