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;
}
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;
}
Aggregations