ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [17/26] incubator-ignite git commit: # ignite-57 async support for clear()
Date Mon, 09 Feb 2015 20:45:32 GMT
# ignite-57 async support for clear()


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

Branch: refs/heads/ignite-sql-tests
Commit: f659b3f107216035977991e0a7350bc6ae172f84
Parents: 9140a08
Author: sboikov <semen.boikov@inria.fr>
Authored: Fri Feb 6 22:01:06 2015 +0300
Committer: sboikov <semen.boikov@inria.fr>
Committed: Fri Feb 6 22:01:06 2015 +0300

----------------------------------------------------------------------
 .../java/org/apache/ignite/IgniteCache.java     |  2 --
 .../apache/ignite/cache/CacheProjection.java    |  5 ++++
 .../processors/cache/GridCacheAdapter.java      | 26 +++++++++++++++++++
 .../cache/GridCacheProjectionImpl.java          |  5 ++++
 .../processors/cache/GridCacheProxyImpl.java    | 12 +++++++++
 .../processors/cache/IgniteCacheProxy.java      |  9 +++----
 .../cache/GridCacheAbstractFullApiSelfTest.java | 27 ++++++++++++++++++--
 ...idCacheNearOnlyMultiNodeFullApiSelfTest.java | 17 +++++++++---
 8 files changed, 91 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f659b3f1/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
index ce0f4b4..73cb87a 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
@@ -390,8 +390,6 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K,
V>, IgniteAsyncS
     @IgniteAsyncSupported
     @Override public void clear();
 
-    public boolean clear(Collection<K> keys);
-
     /** {@inheritDoc} */
     @IgniteAsyncSupported
     @Override public <T> T invoke(K key, EntryProcessor<K, V, T> entryProcessor,
Object... arguments);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f659b3f1/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java
index bca1ae4..2a9ac69 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java
@@ -1417,6 +1417,11 @@ public interface CacheProjection<K, V> extends Iterable<CacheEntry<K,
V>> {
     public void clear() throws IgniteCheckedException;
 
     /**
+     * @return Clear future.
+     */
+    public IgniteInternalFuture<?> clearAsync();
+
+    /**
      * Clears cache on all nodes that store it's data. That is, caches are cleared on remote
      * nodes and local node, as opposed to {@link CacheProjection#clearLocally()} method
which only
      * clears local node's cache.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f659b3f1/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 0f2158e..dc2c28b 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
@@ -1503,6 +1503,32 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K,
V>,
     }
 
     /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<?> clearAsync() {
+        Collection<ClusterNode> nodes = ctx.grid().forCacheNodes(name()).nodes();
+
+        if (!nodes.isEmpty()) {
+            IgniteInternalFuture<Object> fut =
+                    ctx.closures().callAsyncNoFailover(BROADCAST, new GlobalClearAllCallable(name()),
nodes, true);
+
+            return fut.chain(new CX1<IgniteInternalFuture<Object>, Object>()
{
+                @Override public Object applyx(IgniteInternalFuture<Object> fut) throws
IgniteCheckedException {
+                    try {
+                        return fut.get();
+                    }
+                    catch (ClusterGroupEmptyCheckedException ignore) {
+                        if (log.isDebugEnabled())
+                            log.debug("All remote nodes left while cache clearLocally [cacheName="
+ name() + "]");
+
+                        return null;
+                    }
+                }
+            });
+        }
+        else
+            return new GridFinishedFuture<>(ctx.kernalContext());
+    }
+
+    /** {@inheritDoc} */
     @Override public boolean compact(K key) throws IgniteCheckedException {
         return compact(key, (IgnitePredicate<CacheEntry<K, V>>[])null);
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f659b3f1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java
index b4ac195..d36d013 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java
@@ -1073,6 +1073,11 @@ public class GridCacheProjectionImpl<K, V> implements GridCacheProjectionEx<K,
V
     }
 
     /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<?> clearAsync() {
+        return cache.clearAsync();
+    }
+
+    /** {@inheritDoc} */
     @Override public void clear(long timeout) throws IgniteCheckedException {
         cache.clear(timeout);
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f659b3f1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
index ee8a89f..cf97017 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
@@ -1327,6 +1327,18 @@ public class GridCacheProxyImpl<K, V> implements GridCacheProxy<K,
V>, Externali
     }
 
     /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<?> clearAsync() {
+        GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
+
+        try {
+            return delegate.clearAsync();
+        }
+        finally {
+            gate.leave(prev);
+        }
+    }
+
+    /** {@inheritDoc} */
     @Override public void clear(long timeout) throws IgniteCheckedException {
         GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f659b3f1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index a733ed2..50abfb9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -754,7 +754,10 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter<IgniteCach
         GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
 
         try {
-            delegate.clear();
+            if (isAsync())
+                setFuture(delegate.clearAsync());
+            else
+                delegate.clear();
         }
         catch (IgniteCheckedException e) {
             throw cacheException(e);
@@ -764,10 +767,6 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter<IgniteCach
         }
     }
 
-    @Override public boolean clear(Collection<K> keys) {
-        throw new UnsupportedOperationException();
-    }
-
     /** {@inheritDoc} */
     @Override public <T> T invoke(K key, EntryProcessor<K, V, T> entryProcessor,
Object... args)
         throws EntryProcessorException {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f659b3f1/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 ce06330..eef0470 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
@@ -2495,9 +2495,24 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
     }
 
     /**
-     * @throws Exception In case of error.
+     * @throws Exception If failed.
      */
     public void testGlobalClearAll() throws Exception {
+        globalClearAll(false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGlobalClearAllAsync() throws Exception {
+        globalClearAll(true);
+    }
+
+    /**
+     * @param async If {@code true} uses async method.
+     * @throws Exception If failed.
+     */
+    protected void globalClearAll(boolean async) throws Exception {
         // 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++) {
@@ -2505,7 +2520,15 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
                 jcache(i).put(key, 1);
         }
 
-        jcache().clear();
+        if (async) {
+            IgniteCache<String, Integer> asyncCache = jcache().withAsync();
+
+            asyncCache.clear();
+
+            asyncCache.future().get();
+        }
+        else
+            jcache().clear();
 
         for (int i = 0; i < gridCount(); i++)
             assert jcache(i).localSize() == 0;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f659b3f1/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 715d53f..483a878 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
@@ -241,8 +241,11 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
         }
     }
 
-    /** {@inheritDoc} */
-    @Override public void testGlobalClearAll() throws Exception {
+    /**
+     * @param async If {@code true} uses async method.
+     * @throws Exception If failed.
+     */
+    @Override protected void globalClearAll(boolean async) throws Exception {
         // 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++) {
@@ -251,7 +254,15 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
                     jcache(i).put(key, 1);
         }
 
-        jcache().clear();
+        if (async) {
+            IgniteCache<String, Integer> asyncCache = jcache().withAsync();
+
+            asyncCache.clear();
+
+            asyncCache.future().get();
+        }
+        else
+            jcache().clear();
 
         for (int i = 0; i < gridCount(); i++)
             assertTrue(String.valueOf(jcache(i)), jcache(i).localSize() == 0);


Mime
View raw message