# ignite-57

Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/d58e8085
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/d58e8085
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/d58e8085

Branch: refs/heads/ignite-176
Commit: d58e8085af062ac591ce4b57c3adcd39786efbb7
Parents: 41ed9a1
Author: sboikov <semen.boi...@inria.fr>
Authored: Mon Feb 9 23:03:56 2015 +0300
Committer: sboikov <semen.boi...@inria.fr>
Committed: Mon Feb 9 23:03:56 2015 +0300

----------------------------------------------------------------------
 .../ignite/internal/ClusterGroupAdapter.java    |  6 +++
 .../apache/ignite/internal/ClusterGroupEx.java  |  9 ++++
 .../processors/cache/GridCacheAdapter.java      | 45 ++++++++------------
 .../cache/GridCacheAbstractFullApiSelfTest.java | 28 ++++++------
 ...eAtomicNearOnlyMultiNodeFullApiSelfTest.java |  1 -
 ...idCacheNearOnlyMultiNodeFullApiSelfTest.java | 18 +++++---
 6 files changed, 59 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d58e8085/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupAdapter.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupAdapter.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupAdapter.java
index d966434..eb74712 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupAdapter.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupAdapter.java
@@ -556,6 +556,12 @@ public class ClusterGroupAdapter implements 
ClusterGroupEx, Externalizable {
     }
 
     /** {@inheritDoc} */
+    @Override public ClusterGroup forCacheNodes(@Nullable String cacheName,
+        Set<CacheDistributionMode> distributionModes) {
+        return forPredicate(new CachesFilter(cacheName, distributionModes));
+    }
+
+    /** {@inheritDoc} */
     @Override public final ClusterGroup forHost(ClusterNode node) {
         A.notNull(node, "node");
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d58e8085/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupEx.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupEx.java 
b/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupEx.java
index ac1fffa..faaab85 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupEx.java
@@ -17,7 +17,9 @@
 
 package org.apache.ignite.internal;
 
+import org.apache.ignite.cache.*;
 import org.apache.ignite.cluster.*;
+import org.jetbrains.annotations.*;
 
 import java.util.*;
 
@@ -32,4 +34,11 @@ public interface ClusterGroupEx extends ClusterGroup {
      * @return Internal projection.
      */
     public ClusterGroupEx forSubjectId(UUID subjId);
+
+    /**
+     * @param cacheName Cache name.
+     * @param distributionModes Cache distribution modes.
+     * @return Cluster group.
+     */
+    public ClusterGroup forCacheNodes(@Nullable String cacheName, 
Set<CacheDistributionMode> distributionModes);
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d58e8085/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 6cd9e49..fdee08e 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
@@ -82,6 +82,12 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
     /** clearLocally() split threshold. */
     public static final int CLEAR_ALL_SPLIT_THRESHOLD = 10000;
 
+    /** Distribution modes to include into global size calculation. */
+    private static final Set<CacheDistributionMode> SIZE_NODES = EnumSet.of(
+        CacheDistributionMode.NEAR_PARTITIONED,
+        CacheDistributionMode.PARTITIONED_ONLY,
+        CacheDistributionMode.NEAR_ONLY);
+
     /** Deserialization stash. */
     private static final ThreadLocal<IgniteBiTuple<String, String>> stash = 
new ThreadLocal<IgniteBiTuple<String,
                 String>>() {
@@ -4083,31 +4089,6 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
         return e == null || e.obsolete() ? null : e.wrap(true);
     }
 
-    /**
-     * @return Random entry.
-     * @throws IgniteCheckedException If failed.
-     */
-    public Cache.Entry<K, V> randomCacheEntry() throws IgniteCheckedException {
-        boolean keepPortable = ctx.keepPortable();
-
-        while (true) {
-            GridCacheMapEntry<K, V> e = map.randomEntry();
-
-            if (e == null)
-                return null;
-
-            try {
-                Cache.Entry<K, V> entry = toCacheEntry(e, !keepPortable);
-
-                if (entry != null)
-                    return entry;
-            }
-            catch (GridCacheEntryRemovedException ignore) {
-                // No-op.
-            }
-        }
-    }
-
     /** {@inheritDoc} */
     @Override public int size(CachePeekMode[] peekModes) throws 
IgniteCheckedException {
         if (isLocal())
@@ -4120,7 +4101,16 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
     @Override public IgniteInternalFuture<Integer> sizeAsync(CachePeekMode[] 
peekModes) {
         assert peekModes != null;
 
-        Collection<ClusterNode> nodes = 
ctx.grid().forCacheNodes(name()).nodes();
+        PeekModes modes = parsePeekModes(peekModes);
+
+        ClusterGroup grp;
+
+        if (modes.near)
+            grp = ctx.grid().forCacheNodes(name(), SIZE_NODES);
+        else
+            grp = ctx.grid().forDataNodes(name());
+
+        Collection<ClusterNode> nodes = grp.nodes();
 
         if (nodes.isEmpty())
             return new GridFinishedFuture<>(ctx.kernalContext(), 0);
@@ -4129,7 +4119,8 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
             ctx.closures().broadcastNoFailover(new SizeCallable(ctx.name(), 
peekModes), null, nodes);
 
         return fut.chain(new CX1<IgniteInternalFuture<Collection<Integer>>, 
Integer>() {
-            @Override public Integer 
applyx(IgniteInternalFuture<Collection<Integer>> fut) throws 
IgniteCheckedException {
+            @Override public Integer 
applyx(IgniteInternalFuture<Collection<Integer>> fut)
+            throws IgniteCheckedException {
                 Collection<Integer> res = fut.get();
 
                 int totalSize = 0;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d58e8085/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java
index e3fb1b5..420b19d 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java
@@ -2199,13 +2199,15 @@ public abstract class GridCacheAbstractFullApiSelfTest 
extends GridCacheAbstract
      * @throws Exception In case of error.
      */
     private void globalRemoveAll(boolean async) throws Exception {
-        jcache().put("key1", 1);
-        jcache().put("key2", 2);
-        jcache().put("key3", 3);
+        IgniteCache<String, Integer> cache = jcache();
+
+        cache.put("key1", 1);
+        cache.put("key2", 2);
+        cache.put("key3", 3);
 
         checkSize(F.asSet("key1", "key2", "key3"));
 
-        IgniteCache<String, Integer> asyncCache = jcache().withAsync();
+        IgniteCache<String, Integer> asyncCache = cache.withAsync();
 
         if (async) {
             asyncCache.removeAll(F.asSet("key1", "key2"));
@@ -2213,7 +2215,7 @@ public abstract class GridCacheAbstractFullApiSelfTest 
extends GridCacheAbstract
             asyncCache.future().get();
         }
         else
-            jcache().removeAll(F.asSet("key1", "key2"));
+            cache.removeAll(F.asSet("key1", "key2"));
 
         checkSize(F.asSet("key3"));
 
@@ -2222,9 +2224,9 @@ public abstract class GridCacheAbstractFullApiSelfTest 
extends GridCacheAbstract
         checkContainsKey(true, "key3");
 
         // Put values again.
-        jcache().put("key1", 1);
-        jcache().put("key2", 2);
-        jcache().put("key3", 3);
+        cache.put("key1", 1);
+        cache.put("key2", 2);
+        cache.put("key3", 3);
 
         if (async) {
             IgniteCache<String, Integer> asyncCache0 = jcache(gridCount() > 1 
? 1 : 0).withAsync();
@@ -2236,14 +2238,14 @@ public abstract class GridCacheAbstractFullApiSelfTest 
extends GridCacheAbstract
         else
             jcache(gridCount() > 1 ? 1 : 0).removeAll();
 
-        assert cache().isEmpty();
+        assertEquals(0, cache.localSize());
         long entryCnt = hugeRemoveAllEntryCount();
 
         for (int i = 0; i < entryCnt; i++)
-            cache().put(String.valueOf(i), i);
+            cache.put(String.valueOf(i), i);
 
         for (int i = 0; i < entryCnt; i++)
-            assertEquals(Integer.valueOf(i), cache().get(String.valueOf(i)));
+            assertEquals(Integer.valueOf(i), cache.get(String.valueOf(i)));
 
         if (async) {
             asyncCache.removeAll();
@@ -2251,10 +2253,10 @@ public abstract class GridCacheAbstractFullApiSelfTest 
extends GridCacheAbstract
             asyncCache.future().get();
         }
         else
-            cache().removeAll();
+            cache.removeAll();
 
         for (int i = 0; i < entryCnt; i++)
-            assertNull(cache().get(String.valueOf(i)));
+            assertNull(cache.get(String.valueOf(i)));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d58e8085/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java
index deebb63..a431d83 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java
@@ -112,7 +112,6 @@ public class 
GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest extends GridCacheNe
 
         for (String key : keys)
             assertEquals((Integer)i++, nearCache.localPeek(key, 
CachePeekMode.ONHEAP));
-
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d58e8085/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java
index ca2e3c5..945b05b 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java
@@ -98,7 +98,7 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest 
extends GridCachePartitio
 
             GridCacheAttributes[] nodeAttrs = 
node.attribute(IgniteNodeAttributes.ATTR_CACHE);
 
-            info("Cache attribtues for node [nodeId=" + node.id() + ", attrs=" 
+
+            info("Cache attributes for node [nodeId=" + node.id() + ", attrs=" 
+
                 Arrays.asList(nodeAttrs) + ']');
         }
 
@@ -238,23 +238,27 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest 
extends GridCachePartitio
         // Save entries only on their primary nodes. If we didn't do so, 
clearLocally() will not remove all entries
         // because some of them were blocked due to having readers.
         for (int i = 0; i < gridCount(); i++) {
-            if (i != nearIdx)
-                for (String key : primaryKeysForCache(jcache(i), 3))
+            if (i != nearIdx) {
+                for (String key : primaryKeysForCache(jcache(i), 3, 100_000))
                     jcache(i).put(key, 1);
+            }
         }
 
         if (async) {
-            IgniteCache<String, Integer> asyncCache = jcache().withAsync();
+            IgniteCache<String, Integer> asyncCache = 
jcache(nearIdx).withAsync();
 
             asyncCache.clear();
 
             asyncCache.future().get();
         }
         else
-            jcache().clear();
+            jcache(nearIdx).clear();
 
-        for (int i = 0; i < gridCount(); i++)
-            assertEquals(ignite(i).name(), 0, jcache(i).localSize());
+        for (int i = 0; i < gridCount(); i++) {
+            assertEquals("Unexpected size [node=" + ignite(i).name() + ", 
nearIdx=" + nearIdx + ']',
+                0,
+                jcache(i).localSize());
+        }
     }
 
     /** {@inheritDoc} */

Reply via email to