use of org.apache.ignite.internal.visor.cache.VisorCache 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));
}
}
Aggregations