Search in sources :

Example 6 with GridCacheAdapter

use of org.apache.ignite.internal.processors.cache.GridCacheAdapter in project ignite by apache.

the class IgniteCollectionAbstractTest method getQueueCache.

/**
 * @param queue Ignite queue.
 * @return Cache configuration.
 */
protected CacheConfiguration getQueueCache(IgniteQueue queue) {
    GridCacheQueueAdapter delegate = GridTestUtils.getFieldValue(queue, "delegate");
    GridCacheAdapter cache = GridTestUtils.getFieldValue(delegate, GridCacheQueueAdapter.class, "cache");
    return cache.configuration();
}
Also used : GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridCacheQueueAdapter(org.apache.ignite.internal.processors.datastructures.GridCacheQueueAdapter)

Example 7 with GridCacheAdapter

use of org.apache.ignite.internal.processors.cache.GridCacheAdapter in project ignite by apache.

the class GridCacheSetAbstractSelfTest method testCleanup.

/**
 * @param collocated Collocation flag.
 * @throws Exception If failed.
 */
private void testCleanup(boolean collocated) throws Exception {
    CollectionConfiguration colCfg = config(collocated);
    final IgniteSet<Integer> set0 = grid(0).set(SET_NAME, colCfg);
    assertNotNull(set0);
    final Collection<Set<Integer>> sets = new ArrayList<>();
    for (int i = 0; i < gridCount(); i++) {
        IgniteSet<Integer> set = grid(i).set(SET_NAME, null);
        assertNotNull(set);
        sets.add(set);
    }
    Collection<Integer> items = new ArrayList<>(10_000);
    for (int i = 0; i < 10_000; i++) items.add(i);
    set0.addAll(items);
    assertEquals(10_000, set0.size());
    final AtomicBoolean stop = new AtomicBoolean();
    final AtomicInteger val = new AtomicInteger(10_000);
    IgniteInternalFuture<?> fut;
    try {
        fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                try {
                    while (!stop.get()) {
                        for (Set<Integer> set : sets) set.add(val.incrementAndGet());
                    }
                } catch (IllegalStateException e) {
                    log.info("Set removed: " + e);
                }
                return null;
            }
        }, 5, "set-add-thread");
        set0.close();
    } finally {
        stop.set(true);
    }
    fut.get();
    int cnt = 0;
    GridCacheContext cctx = GridTestUtils.getFieldValue(set0, "cctx");
    boolean separated = separated(set0);
    if (separated)
        awaitPartitionMapExchange();
    for (int i = 0; i < gridCount(); i++) {
        GridCacheAdapter cache = grid(i).context().cache().internalCache(cctx.name());
        if (separated) {
            assertNull("Cache " + cctx.name() + " was not destroyed.", cache);
            continue;
        }
        for (Object e : cache.localEntries(new CachePeekMode[] { CachePeekMode.ALL })) {
            cnt++;
            log.info("Unexpected entry: " + e);
        }
    }
    assertEquals("Found unexpected cache entries", 0, cnt);
    for (final Set<Integer> set : sets) {
        GridTestUtils.assertThrows(log, new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                set.add(10);
                return null;
            }
        }, IllegalStateException.class, null);
    }
}
Also used : HashSet(java.util.HashSet) IgniteSet(org.apache.ignite.IgniteSet) Set(java.util.Set) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) ArrayList(java.util.ArrayList) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter)

Example 8 with GridCacheAdapter

use of org.apache.ignite.internal.processors.cache.GridCacheAdapter in project ignite by apache.

the class VisorNodeDataCollectorJob method caches.

/**
 * Collect caches.
 *
 * @param res Job result.
 * @param arg Task argument.
 */
protected void caches(VisorNodeDataCollectorJobResult res, VisorNodeDataCollectorTaskArg arg) {
    try {
        IgniteConfiguration cfg = ignite.configuration();
        GridCacheProcessor cacheProc = ignite.context().cache();
        Set<String> cacheGrps = arg.getCacheGroups();
        boolean all = F.isEmpty(cacheGrps);
        int partitions = 0;
        double total = 0;
        double ready = 0;
        List<VisorCache> resCaches = res.getCaches();
        boolean rebalanceInProgress = false;
        for (CacheGroupContext grp : cacheProc.cacheGroups()) {
            boolean first = true;
            for (GridCacheContext cache : grp.caches()) {
                long start0 = U.currentTimeMillis();
                String cacheName = cache.name();
                try {
                    if (isProxyCache(ignite, cacheName) || isRestartingCache(ignite, cacheName))
                        continue;
                    GridCacheAdapter ca = cacheProc.internalCache(cacheName);
                    if (ca == null || !ca.context().started())
                        continue;
                    if (first) {
                        CacheMetrics cm = ca.localMetrics();
                        partitions += cm.getTotalPartitionsCount();
                        long keysTotal = cm.getEstimatedRebalancingKeys();
                        long keysReady = cm.getRebalancedKeys();
                        if (keysReady >= keysTotal)
                            keysReady = Math.max(keysTotal - 1, 0);
                        total += keysTotal;
                        ready += keysReady;
                        if (!rebalanceInProgress && cm.getRebalancingPartitionsCount() > 0)
                            rebalanceInProgress = true;
                        first = false;
                    }
                    boolean addToRes = arg.getSystemCaches() || !(isSystemCache(cacheName));
                    if (addToRes && (all || cacheGrps.contains(ca.configuration().getGroupName())))
                        resCaches.add(new VisorCache(ignite, ca, arg.isCollectCacheMetrics()));
                } catch (IllegalStateException | IllegalArgumentException e) {
                    if (debug && ignite.log() != null)
                        ignite.log().error("Ignored cache: " + cacheName, e);
                } finally {
                    if (debug)
                        log(ignite.log(), "Collected cache: " + cacheName, getClass(), start0);
                }
            }
        }
        if (partitions == 0)
            res.setRebalance(NOTHING_TO_REBALANCE);
        else if (total == 0 && rebalanceInProgress)
            res.setRebalance(MINIMAL_REBALANCE);
        else
            res.setRebalance(total > 0 && rebalanceInProgress ? Math.max(ready / total, MINIMAL_REBALANCE) : REBALANCE_COMPLETE);
    } catch (Exception e) {
        res.setRebalance(REBALANCE_NOT_AVAILABLE);
        res.setCachesEx(new VisorExceptionWrapper(e));
    }
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) VisorCache(org.apache.ignite.internal.visor.cache.VisorCache) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) VisorExceptionWrapper(org.apache.ignite.internal.visor.util.VisorExceptionWrapper) GridCacheProcessor(org.apache.ignite.internal.processors.cache.GridCacheProcessor) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 9 with GridCacheAdapter

use of org.apache.ignite.internal.processors.cache.GridCacheAdapter in project ignite by apache.

the class GridCacheSetFailoverAbstractSelfTest method testNodeRestart.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("WhileLoopReplaceableByForEach")
@Test
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();
                    assertEquals(ITEMS, size);
                } catch (IgniteException ignore) {
                // No-op.
                }
                try {
                    Iterator<Integer> iter = set.iterator();
                    int cnt = 0;
                    while (iter.hasNext()) {
                        assertNotNull(iter.next());
                        cnt++;
                    }
                    assertEquals(ITEMS, cnt);
                } 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++) {
            GridCacheAdapter cache = grid(i).context().cache().internalCache(DEFAULT_CACHE_NAME);
            Iterator<GridCacheMapEntry> entries = cache.map().entries(cache.context().cacheId()).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) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) 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) Test(org.junit.Test)

Example 10 with GridCacheAdapter

use of org.apache.ignite.internal.processors.cache.GridCacheAdapter in project ignite by apache.

the class GridCacheSequenceApiSelfAbstractTest method testCacheSets.

/**
 * @throws Exception If failed.
 */
@Test
public void testCacheSets() throws Exception {
    // Make new atomic sequence in cache.
    IgniteAtomicSequence seq = grid().atomicSequence(UUID.randomUUID().toString(), 0, true);
    seq.incrementAndGet();
    final String cacheName = DataStructuresProcessor.ATOMICS_CACHE_NAME + "@default-ds-group";
    GridCacheAdapter cache = ((IgniteKernal) grid()).internalCache(cacheName);
    assertNotNull(cache);
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            grid().cache(cacheName);
            return null;
        }
    }, IllegalStateException.class, null);
    for (String seqName : seqNames) assert null != cache.get(new GridCacheInternalKeyImpl(seqName, "default-ds-group"));
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridCacheInternalKeyImpl(org.apache.ignite.internal.processors.datastructures.GridCacheInternalKeyImpl) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) IgniteException(org.apache.ignite.IgniteException) Test(org.junit.Test)

Aggregations

GridCacheAdapter (org.apache.ignite.internal.processors.cache.GridCacheAdapter)50 IgniteEx (org.apache.ignite.internal.IgniteEx)18 Map (java.util.Map)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 Ignite (org.apache.ignite.Ignite)12 IgniteException (org.apache.ignite.IgniteException)12 IgniteKernal (org.apache.ignite.internal.IgniteKernal)12 ArrayList (java.util.ArrayList)11 UUID (java.util.UUID)11 Test (org.junit.Test)11 IgniteCache (org.apache.ignite.IgniteCache)10 HashMap (java.util.HashMap)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)9 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)9 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)8 HashSet (java.util.HashSet)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)7 DynamicCacheDescriptor (org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)7