Search in sources :

Example 1 with VisorCache

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

Aggregations

CacheMetrics (org.apache.ignite.cache.CacheMetrics)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)1 GridCacheAdapter (org.apache.ignite.internal.processors.cache.GridCacheAdapter)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 GridCacheProcessor (org.apache.ignite.internal.processors.cache.GridCacheProcessor)1 VisorCache (org.apache.ignite.internal.visor.cache.VisorCache)1 VisorExceptionWrapper (org.apache.ignite.internal.visor.util.VisorExceptionWrapper)1