/** * @param cctx Cache context. * @return {@code true} If cache context */ private boolean hasMovingPartitions(GridCacheContext<?, ?> cctx) { GridDhtPartitionFullMap fullMap = cctx.topology().partitionMap(false); for (GridDhtPartitionMap2 map : fullMap.values()) { if (map.hasMovingPartitions()) return true; } return false; }
/** * @param ignite Grid. * @param cacheName Cache name. * @param sample Sample size. * @return Data transfer object for given cache. * @throws IgniteCheckedException If failed to create data transfer object. */ public VisorCache from(IgniteEx ignite, String cacheName, int sample) throws IgniteCheckedException { assert ignite != null; GridCacheAdapter ca = ignite.context().cache().internalCache(cacheName); // Cache was not started. if (ca == null || !ca.context().started()) return null; name = cacheName; try { swapSize = ca.swapSize(); swapKeys = ca.swapKeys(); } catch (IgniteCheckedException ignored) { swapSize = -1; swapKeys = -1; } primaryPartitions = Collections.emptyList(); backupPartitions = Collections.emptyList(); CacheConfiguration cfg = ca.configuration(); mode = cfg.getCacheMode(); boolean partitioned = (mode == CacheMode.PARTITIONED || mode == CacheMode.REPLICATED) && ca.context().affinityNode(); if (partitioned) { GridDhtCacheAdapter dca = null; if (ca instanceof GridNearCacheAdapter) dca = ((GridNearCacheAdapter) ca).dht(); else if (ca instanceof GridDhtCacheAdapter) dca = (GridDhtCacheAdapter) ca; if (dca != null) { GridDhtPartitionTopology top = dca.topology(); if (cfg.getCacheMode() != CacheMode.LOCAL && cfg.getBackups() > 0) { GridDhtPartitionMap2 map2 = top.localPartitionMap(); partitionsMap = new GridDhtPartitionMap(map2.nodeId(), map2.updateSequence(), map2.map()); } List<GridDhtLocalPartition> parts = top.localPartitions(); primaryPartitions = new ArrayList<>(parts.size()); backupPartitions = new ArrayList<>(parts.size()); for (GridDhtLocalPartition part : parts) { int p = part.id(); int sz = part.size(); // Pass -1 as topology version in order not to wait for topology version. if (part.primary(AffinityTopologyVersion.NONE)) primaryPartitions.add(new IgnitePair<>(p, sz)); else if (part.state() == GridDhtPartitionState.OWNING && part.backup(AffinityTopologyVersion.NONE)) backupPartitions.add(new IgnitePair<>(p, sz)); } } else { // Old way of collecting partitions info. ClusterNode node = ignite.cluster().localNode(); int[] pp = ca.affinity().primaryPartitions(node); primaryPartitions = new ArrayList<>(pp.length); for (int p : pp) { Set set = ca.entrySet(p); primaryPartitions.add(new IgnitePair<>(p, set != null ? set.size() : 0)); } int[] bp = ca.affinity().backupPartitions(node); backupPartitions = new ArrayList<>(bp.length); for (int p : bp) { Set set = ca.entrySet(p); backupPartitions.add(new IgnitePair<>(p, set != null ? set.size() : 0)); } } } size = ca.size(); nearSize = ca.nearSize(); dynamicDeploymentId = ca.context().dynamicDeploymentId(); dhtSize = size - nearSize; primarySize = ca.primarySize(); offHeapAllocatedSize = ca.offHeapAllocatedSize(); offHeapEntriesCnt = ca.offHeapEntriesCount(); partitions = ca.affinity().partitions(); metrics = VisorCacheMetrics.from(ignite, cacheName); estimateMemorySize(ignite, ca, sample); return this; }