Search in sources :

Example 16 with GridDhtCacheAdapter

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter in project ignite by apache.

the class GridDsiPerfJob method execute.

/**
 * @return Result.
 */
@SuppressWarnings("ConstantConditions")
@Override
public Object execute() {
    ConcurrentMap<String, T2<AtomicLong, AtomicLong>> nodeLoc = ignite.cluster().nodeLocalMap();
    T2<AtomicLong, AtomicLong> cntrs = nodeLoc.get("cntrs");
    if (cntrs == null) {
        T2<AtomicLong, AtomicLong> other = nodeLoc.putIfAbsent("cntrs", cntrs = new T2<>(new AtomicLong(), new AtomicLong(System.currentTimeMillis())));
        if (other != null)
            cntrs = other;
    }
    long cnt = cntrs.get1().incrementAndGet();
    GridNearCacheAdapter near = (GridNearCacheAdapter) ((IgniteKernal) ignite).internalCache(cacheName);
    GridDhtCacheAdapter dht = near.dht();
    doWork();
    long start = cntrs.get2().get();
    long now = System.currentTimeMillis();
    long dur = now - start;
    if (dur > 20000 && cntrs.get2().compareAndSet(start, System.currentTimeMillis())) {
        cntrs.get1().set(0);
        long txPerSec = cnt / (dur / 1000);
        X.println("Stats [tx/sec=" + txPerSec + ", nearSize=" + near.size() + ", dhtSize=" + dht.size() + ']');
        return new T3<>(txPerSec, near.size(), dht.size());
    }
    return null;
}
Also used : GridAtomicLong(org.apache.ignite.internal.util.GridAtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridDhtCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter) T2(org.apache.ignite.internal.util.typedef.T2) T3(org.apache.ignite.internal.util.typedef.T3)

Example 17 with GridDhtCacheAdapter

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter in project ignite by apache.

the class GridCacheMultithreadedFailoverTest method compareCaches.

/**
 * Compare caches.
 *
 * @param expVals Expected values.
 * @return {@code True} if check passed successfully.
 * @throws Exception If failed.
 */
@SuppressWarnings({ "TooBroadScope" })
private boolean compareCaches(Map<Integer, Integer> expVals) throws Exception {
    List<IgniteCache<Integer, Integer>> caches = new ArrayList<>(dataNodes());
    List<GridDhtCacheAdapter<Integer, Integer>> dhtCaches = null;
    for (int i = 0; i < dataNodes(); i++) {
        IgniteCache<Integer, Integer> cache = G.ignite(nodeName(i)).cache(CACHE_NAME);
        assert cache != null;
        caches.add(cache);
        GridCacheAdapter<Integer, Integer> cache0 = (GridCacheAdapter<Integer, Integer>) ((IgniteKernal) cache.unwrap(Ignite.class)).<Integer, Integer>getCache(CACHE_NAME);
        if (cache0.isNear()) {
            if (dhtCaches == null)
                dhtCaches = new ArrayList<>(dataNodes());
            dhtCaches.add(((GridNearCacheAdapter<Integer, Integer>) cache0).dht());
        }
    }
    // Compare key sets on each cache.
    Collection<Integer> cacheKeys = new HashSet<>();
    Collection<Integer> dhtCacheKeys = new HashSet<>();
    for (int i = 0; i < dataNodes(); i++) {
        for (Cache.Entry<Integer, Integer> entry : caches.get(i)) cacheKeys.add(entry.getKey());
        if (dhtCaches != null)
            dhtCacheKeys.addAll(dhtCaches.get(i).keySet());
    }
    boolean failed = false;
    if (!F.eq(expVals.keySet(), cacheKeys)) {
        Collection<Integer> expOnly = new HashSet<>();
        Collection<Integer> cacheOnly = new HashSet<>();
        expOnly.addAll(expVals.keySet());
        expOnly.removeAll(cacheKeys);
        cacheOnly.addAll(cacheKeys);
        cacheOnly.removeAll(expVals.keySet());
        if (!expOnly.isEmpty())
            log.error("Cache does not contain expected keys: " + expOnly);
        if (!cacheOnly.isEmpty())
            log.error("Cache does contain unexpected keys: " + cacheOnly);
        failed = true;
    }
    if (dhtCaches != null && !F.eq(expVals.keySet(), dhtCacheKeys)) {
        Collection<Integer> expOnly = new HashSet<>();
        Collection<Integer> cacheOnly = new HashSet<>();
        expOnly.addAll(expVals.keySet());
        expOnly.removeAll(dhtCacheKeys);
        cacheOnly.addAll(dhtCacheKeys);
        cacheOnly.removeAll(expVals.keySet());
        if (!expOnly.isEmpty())
            log.error("DHT cache does not contain expected keys: " + expOnly);
        if (!cacheOnly.isEmpty())
            log.error("DHT cache does contain unexpected keys: " + cacheOnly);
        failed = true;
    }
    // Compare values.
    Collection<Integer> failedKeys = new HashSet<>();
    for (Map.Entry<Integer, Integer> entry : expVals.entrySet()) {
        for (int i = 0; i < dataNodes(); i++) {
            if (!F.eq(caches.get(i).get(entry.getKey()), entry.getValue()))
                failedKeys.add(entry.getKey());
        }
    }
    if (!failedKeys.isEmpty()) {
        log.error("Cache content is incorrect for " + failedKeys.size() + " keys:");
        for (Integer key : failedKeys) {
            for (int i = 0; i < dataNodes(); i++) {
                IgniteCache<Integer, Integer> cache = caches.get(i);
                UUID nodeId = G.ignite(nodeName(i)).cluster().localNode().id();
                if (!F.eq(cache.get(key), expVals.get(key)))
                    log.error("key=" + key + ", expVal=" + expVals.get(key) + ", nodeId=" + nodeId);
            }
        }
        failed = true;
    }
    return !failed;
}
Also used : GridDhtCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter) IgniteCache(org.apache.ignite.IgniteCache) ArrayList(java.util.ArrayList) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashSet(java.util.HashSet) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Aggregations

GridDhtCacheAdapter (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter)17 ArrayList (java.util.ArrayList)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 IgniteCache (org.apache.ignite.IgniteCache)4 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 UUID (java.util.UUID)3 Cache (javax.cache.Cache)3 CacheStore (org.apache.ignite.cache.store.CacheStore)3 IgniteKernal (org.apache.ignite.internal.IgniteKernal)3 CacheDataStructuresManager (org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager)3 GridDhtCache (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCache)3 GridDhtAtomicCache (org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache)3 GridDhtColocatedCache (org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache)3 GridNearAtomicCache (org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache)3 GridNearTransactionalCache (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTransactionalCache)3 GridCacheDrManager (org.apache.ignite.internal.processors.cache.dr.GridCacheDrManager)3 GridLocalCache (org.apache.ignite.internal.processors.cache.local.GridLocalCache)3 GridLocalAtomicCache (org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache)3