bluehu created IGNITE-3458: ------------------------------ Summary: poor performance on the function “primaryEntrySet()” Key: IGNITE-3458 URL: https://issues.apache.org/jira/browse/IGNITE-3458 Project: Ignite Issue Type: Improvement Components: cache Affects Versions: 1.6 Reporter: bluehu Priority: Minor Fix For: 1.6
the implement of primaryEntrySet() in ignite 1.6 is this: {code:title=GridCacheAdapter.java|borderStyle=solid} /** * @return Primary entry set. */ public Set<Cache.Entry<K, V>> primaryEntrySet() { return new EntrySet(map.entrySet(CU.cachePrimary(ctx.grid().affinity(ctx.name()), ctx.localNode()))); } {code} this function may scan all the partitions including backup partitions on local node, then filter each entry with this CacheEntryPredicate: {code:title=GridCacheUtils.java|borderStyle=solid} /** * @param aff Affinity. * @param n Node. * @return Predicate that evaluates to {@code true} if entry is primary for node. */ public static CacheEntryPredicate cachePrimary( final Affinity aff, final ClusterNode n ) { return new CacheEntryPredicateAdapter() { @Override public boolean apply(GridCacheEntryEx e) { return aff.isPrimary(n, e.key()); } }; } {code} I think it has poor performance. Since we can get the primary partitions id of localnode from GridAffinityAssignment: {code:title=GridAffinityAssignment.java|borderStyle=solid} /** * Get primary partitions for specified node ID. * * @param nodeId Node ID to get primary partitions for. * @return Primary partitions for specified node ID. */ public Set<Integer> primaryPartitions(UUID nodeId) { Set<Integer> set = primary.get(nodeId); return set == null ? Collections.<Integer>emptySet() : set; } {code} why not get primary partitions directly(not including backup partitions) and then return all the entry of primary partitions(no need use CacheEntryPredicate to judge each entry)? -- This message was sent by Atlassian JIRA (v6.3.4#6332)