# IGNITE-54-55 Iterate over primary partition only.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/f9fe11e3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/f9fe11e3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/f9fe11e3 Branch: refs/heads/ignite-160 Commit: f9fe11e36e8a171b5d630322c4fb60e0445464cc Parents: cbf4bfc Author: sevdokimov <[email protected]> Authored: Thu Feb 5 15:39:10 2015 +0300 Committer: sevdokimov <[email protected]> Committed: Thu Feb 5 15:39:10 2015 +0300 ---------------------------------------------------------------------- .../processors/cache/GridCacheAdapter.java | 45 +++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f9fe11e3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java index fffea58..98bb46c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java @@ -31,6 +31,7 @@ import org.apache.ignite.internal.compute.*; import org.apache.ignite.internal.processors.cache.affinity.*; import org.apache.ignite.internal.processors.cache.datastructures.*; import org.apache.ignite.internal.processors.cache.distributed.dht.*; +import org.apache.ignite.internal.processors.cache.distributed.near.*; import org.apache.ignite.internal.processors.cache.dr.*; import org.apache.ignite.internal.processors.cache.query.*; import org.apache.ignite.internal.processors.cache.transactions.*; @@ -5228,7 +5229,6 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>, /** * @param cacheName Cache name. * @param topVer Topology version. - * @param rmvBatchSz Remove batch size. */ private GlobalRemoveAllCallable(String cacheName, long topVer) { this.cacheName = cacheName; @@ -5245,25 +5245,50 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>, final GridCache<K,V> cache = grid.cachex(cacheName); - final GridCacheContext<K, V> ctx = grid.context().cache().<K, V>internalCache(cacheName).context(); + GridCacheAdapter<K, V> cacheAdapter = grid.context().cache().internalCache(cacheName); + + final GridCacheContext<K, V> ctx = cacheAdapter.context(); if (ctx.affinity().affinityTopologyVersion() != topVer) return null; // Ignore this remove request because remove request will be sent again. - assert cache != null; + if (cacheAdapter instanceof GridNearCacheAdapter) + cacheAdapter = ((GridNearCacheAdapter)cacheAdapter).dht(); + + if (cacheAdapter instanceof GridDhtCacheAdapter) { + GridDhtCacheAdapter<K, V> dht = (GridDhtCacheAdapter)cacheAdapter; + + for (GridDhtLocalPartition<K, V> locPart : dht.topology().currentLocalPartitions()) { + if (locPart.primary(topVer)) { + for (GridDhtCacheEntry<K, V> o : locPart.entries()) { + keys.add(o.key()); + + if (keys.size() >= REMOVE_ALL_BATCH_SIZE) { + cache.removeAll(keys); + + keys.clear(); + } + } + } + } + } + else { + assert cache != null; - for (K k : cache.keySet()) { - if (ctx.affinity().primary(ctx.localNode(), k, topVer)) - keys.add(k); + for (K k : cache.keySet()) { + if (ctx.affinity().primary(ctx.localNode(), k, topVer)) + keys.add(k); - if (keys.size() >= REMOVE_ALL_BATCH_SIZE) { - cache.removeAll(keys); + if (keys.size() >= REMOVE_ALL_BATCH_SIZE) { + cache.removeAll(keys); - keys.clear(); + keys.clear(); + } } } - cache.removeAll(keys); + if (!keys.isEmpty()) + cache.removeAll(keys); return null; }
