ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject incubator-ignite git commit: ignite-929
Date Wed, 10 Jun 2015 21:46:36 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-929 00eb9f192 -> 87c8d8d68


ignite-929


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

Branch: refs/heads/ignite-929
Commit: 87c8d8d68d001dc94b1c8a0d587196fcb78224ec
Parents: 00eb9f1
Author: Anton Vinogradov <avinogradov@gridgain.com>
Authored: Thu Jun 11 00:44:01 2015 +0300
Committer: Anton Vinogradov <avinogradov@gridgain.com>
Committed: Thu Jun 11 00:44:01 2015 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheGateway.java      |  26 ++--
 .../cache/CacheStopAndDestroySelfTest.java      | 124 ++++++++++++++++---
 2 files changed, 121 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c8d8d6/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java
index b66fe7b..f9142d1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheGateway.java
@@ -17,12 +17,16 @@
 
 package org.apache.ignite.internal.processors.cache;
 
-import org.apache.ignite.*;
-import org.apache.ignite.internal.*;
-import org.apache.ignite.internal.util.*;
-import org.apache.ignite.internal.util.tostring.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.jetbrains.annotations.*;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.util.GridSpinReadWriteLock;
+import org.apache.ignite.internal.util.tostring.GridToStringExclude;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * Cache gateway.
@@ -35,8 +39,8 @@ public class GridCacheGateway<K, V> {
     /** Stopped flag for dynamic caches. */
     private volatile boolean stopped;
 
-    /** Closed flag for dynamic caches. */
-    private volatile boolean closed;
+    /** Client counter. */
+    private volatile AtomicInteger clients = new AtomicInteger(0);
 
     /** */
     private GridSpinReadWriteLock rwLock = new GridSpinReadWriteLock();
@@ -153,7 +157,7 @@ public class GridCacheGateway<K, V> {
             throw new IllegalStateException("Cache has been stopped: " + ctx.name());
         }
 
-        if (closed) {
+        if (clients.get() <= 0) {
             rwLock.readUnlock();
 
             throw new IllegalStateException("Cache has been closed: " + ctx.name());
@@ -246,14 +250,14 @@ public class GridCacheGateway<K, V> {
      *
      */
     public void open() {
-        closed = false;
+        clients.incrementAndGet();
     }
 
     /**
      *
      */
     public void close() {
-        closed = true;
+        clients.decrementAndGet();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/87c8d8d6/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStopAndDestroySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStopAndDestroySelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStopAndDestroySelfTest.java
index e0c18cb..9913df9 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStopAndDestroySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStopAndDestroySelfTest.java
@@ -17,24 +17,27 @@
 
 package org.apache.ignite.internal.processors.cache;
 
-import org.apache.ignite.*;
-import org.apache.ignite.cache.*;
-import org.apache.ignite.cluster.*;
-import org.apache.ignite.configuration.*;
-import org.apache.ignite.internal.managers.communication.*;
-import org.apache.ignite.internal.processors.cache.distributed.dht.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.plugin.extensions.communication.*;
-import org.apache.ignite.spi.*;
-import org.apache.ignite.spi.communication.tcp.*;
-import org.apache.ignite.spi.discovery.tcp.*;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
-import org.apache.ignite.testframework.*;
-import org.apache.ignite.testframework.junits.common.*;
-
-import java.util.*;
-import java.util.concurrent.atomic.*;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.managers.communication.GridIoMessage;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.plugin.extensions.communication.Message;
+import org.apache.ignite.spi.IgniteSpiException;
+import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * Checks stop and destroy methods behavior.
@@ -58,6 +61,9 @@ public class CacheStopAndDestroySelfTest extends GridCommonAbstractTest
{
     /** local cache name. */
     protected static String CACHE_NAME_LOC = "cache_local";
 
+    /** */
+    private static volatile boolean stop;
+
     /**
      * @return Grids count to start.
      */
@@ -720,6 +726,88 @@ public class CacheStopAndDestroySelfTest extends GridCommonAbstractTest
{
         }
     }
 
+    /**
+     * Tests concurrent close.
+     *
+     * @throws org.apache.ignite.internal.IgniteInterruptedCheckedException
+     * @throws InterruptedException
+     */
+    public void testConcurrentCloseSetWithTry() throws IgniteInterruptedCheckedException,
InterruptedException {
+        final AtomicInteger a1 = new AtomicInteger();
+        final AtomicInteger a2 = new AtomicInteger();
+        final AtomicInteger a3 = new AtomicInteger();
+        final AtomicInteger a4 = new AtomicInteger();
+
+        Thread t1 = new Thread(new Runnable() {
+            @Override public void run() {
+                closeWithTry(a1, 0);
+
+            }
+        });
+        Thread t2 = new Thread(new Runnable() {
+            @Override public void run() {
+                closeWithTry(a2, 0);
+
+            }
+        });
+        Thread t3 = new Thread(new Runnable() {
+            @Override public void run() {
+                closeWithTry(a3, 2);
+
+            }
+        });
+        Thread t4 = new Thread(new Runnable() {
+            @Override public void run() {
+                closeWithTry(a4, 2);
+
+            }
+        });
+
+        IgniteCache cache = grid(0).getOrCreateCache(getDhtConfig());
+
+        cache.close();
+
+        t1.start();
+        t2.start();
+        t3.start();
+        t4.start();
+
+        U.sleep(1000);
+
+        stop = true;
+
+        t1.join();
+        t2.join();
+        t3.join();
+        t4.join();
+
+        assert a1.get() > 1;
+        assert a2.get() > 1;
+        assert a3.get() > 1;
+        assert a4.get() > 1;
+
+        try {
+            cache.get(KEY_VAL);
+        }
+        catch (IllegalStateException e) {
+            // No-op
+        }
+    }
+
+    public void closeWithTry(AtomicInteger a, int node) {
+        while (!stop) {
+            try (IgniteCache<String, String> cache = grid(node).getOrCreateCache(getDhtConfig()))
{
+                a.incrementAndGet();
+
+                assert cache.get(KEY_VAL) == null || cache.get(KEY_VAL).equals(KEY_VAL);
+
+                cache.put(KEY_VAL, KEY_VAL);
+
+                assert cache.get(KEY_VAL).equals(KEY_VAL);
+            }
+        }
+    }
+
     /** {@inheritDoc} */
     @Override protected void beforeTest() throws Exception {
         super.beforeTest();


Mime
View raw message