/** * @param ccfg Cache configuration. * @return Data transfer object for affinity configuration properties. */ public static VisorCacheAffinityConfiguration from(CacheConfiguration ccfg) { AffinityFunction aff = ccfg.getAffinity(); Boolean excludeNeighbors = null; if (aff instanceof RendezvousAffinityFunction) { RendezvousAffinityFunction hashAffFunc = (RendezvousAffinityFunction) aff; excludeNeighbors = hashAffFunc.isExcludeNeighbors(); } VisorCacheAffinityConfiguration cfg = new VisorCacheAffinityConfiguration(); cfg.function = compactClass(aff); cfg.mapper = compactClass(ccfg.getAffinityMapper()); cfg.partitions = aff.partitions(); cfg.partitionedBackups = ccfg.getBackups(); cfg.excludeNeighbors = excludeNeighbors; return cfg; }
/** * @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; }