ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yzhda...@apache.org
Subject ignite git commit: review
Date Wed, 18 Nov 2015 15:14:58 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-638 e97d348c2 -> 8d7567eeb


review


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

Branch: refs/heads/ignite-638
Commit: 8d7567eebe061f86cffdb7f5093faa65dfed60f1
Parents: e97d348
Author: Yakov Zhdanov <yzhdanov@gridgain.com>
Authored: Wed Nov 18 18:14:48 2015 +0300
Committer: Yakov Zhdanov <yzhdanov@gridgain.com>
Committed: Wed Nov 18 18:14:48 2015 +0300

----------------------------------------------------------------------
 .../src/main/java/org/apache/ignite/Ignite.java |  7 +-
 .../apache/ignite/internal/IgniteKernal.java    |  4 +-
 .../IgniteSemaphoreAbstractSelfTest.java        | 81 +++++++++++++++++++-
 .../ignite/testframework/junits/IgniteMock.java |  2 +-
 .../junits/multijvm/IgniteProcessProxy.java     |  2 +-
 .../org/apache/ignite/IgniteSpringBean.java     |  5 +-
 6 files changed, 92 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8d7567ee/modules/core/src/main/java/org/apache/ignite/Ignite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/Ignite.java b/modules/core/src/main/java/org/apache/ignite/Ignite.java
index ef2bfe1..17221ce 100644
--- a/modules/core/src/main/java/org/apache/ignite/Ignite.java
+++ b/modules/core/src/main/java/org/apache/ignite/Ignite.java
@@ -435,12 +435,15 @@ public interface Ignite extends AutoCloseable {
      *
      * @param name Name of the semaphore.
      * @param cnt Count for new semaphore creation. Ignored if {@code create} flag is {@code
false}.
-     * @param fair {@code True} to enable fairness.
+     * @param failoverSafe {@code True} to create failover safe semaphore which means that
+     *      if any node leaves topology permits already acquired by that node are silently
released
+     *      and become available for alive nodes to acquire. If flag is {@code false} then
+     *      all threads waiting for available permits get interrupted.
      * @param create Boolean flag indicating whether data structure should be created if
does not exist.
      * @return Semaphore for the given name.
      * @throws IgniteException If semaphore could not be fetched or created.
      */
-    public IgniteSemaphore semaphore(String name, int cnt, boolean fair, boolean create)
+    public IgniteSemaphore semaphore(String name, int cnt, boolean failoverSafe, boolean
create)
         throws IgniteException;
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/8d7567ee/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index bd984f9..02096dd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -2940,13 +2940,13 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable
{
     @Nullable @Override public IgniteSemaphore semaphore(
         String name,
         int cnt,
-        boolean fair,
+        boolean failoverSafe,
         boolean create
     ) {
         guard();
 
         try {
-            return ctx.dataStructures().semaphore(name, cnt, fair, create);
+            return ctx.dataStructures().semaphore(name, cnt, failoverSafe, create);
         }
         catch (IgniteCheckedException e) {
             throw U.convertException(e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/8d7567ee/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteSemaphoreAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteSemaphoreAbstractSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteSemaphoreAbstractSelfTest.java
index 3f92150..e60aed3 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteSemaphoreAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteSemaphoreAbstractSelfTest.java
@@ -26,9 +26,11 @@ import java.util.List;
 import java.util.Random;
 import java.util.concurrent.Callable;
 import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteCompute;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.IgniteSemaphore;
+import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.util.typedef.G;
@@ -45,6 +47,7 @@ import org.junit.rules.ExpectedException;
 import static java.util.concurrent.TimeUnit.MICROSECONDS;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.MINUTES;
+import static org.apache.ignite.cache.CacheMode.LOCAL;
 
 /**
  * Cache semaphore self test.
@@ -79,9 +82,85 @@ public abstract class IgniteSemaphoreAbstractSelfTest extends IgniteAtomicsAbstr
     /**
      * @throws Exception If failed.
      */
+    public void testFailover() throws Exception {
+        if (atomicsCacheMode() == LOCAL)
+            return;
+
+        checkFailover(true);
+        checkFailover(false);
+    }
+
+    /**
+     * @param failoverSafe Failover safe flag.
+     * @throws Exception
+     */
+    private void checkFailover(boolean failoverSafe) throws Exception {
+        IgniteEx g = startGrid(NODES_CNT + 1);
+
+        // For vars locality.
+        {
+            // Ensure not exists.
+            assert g.semaphore("sem", 2, failoverSafe, false) == null;
+
+            IgniteSemaphore sem = g.semaphore(
+                "sem",
+                2,
+                failoverSafe,
+                true);
+
+            sem.acquire(2);
+
+            assert !sem.tryAcquire();
+            assertEquals(
+                0,
+                sem.availablePermits());
+        }
+
+        Ignite g0 = grid(0);
+
+        final IgniteSemaphore sem0 = g0.semaphore(
+            "sem",
+            -10,
+            false,
+            false);
+
+        assert !sem0.tryAcquire();
+        assertEquals(0, sem0.availablePermits());
+
+        IgniteInternalFuture<?> fut = multithreadedAsync(
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    sem0.acquire();
+
+                    info("Acquired in separate thread.");
+
+                    return null;
+                }
+            },
+            1);
+
+        Thread.sleep(100);
+
+        g.close();
+
+        try {
+            fut.get(500);
+        }
+        catch (IgniteCheckedException e) {
+            if (!failoverSafe && e.hasCause(InterruptedException.class))
+                info("Ignored expected exception: " + e);
+            else
+                throw e;
+        }
+
+        sem0.close();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     private void checkSemaphore() throws Exception {
         // Test API.
-
         checkAcquire();
 
         checkRelease();

http://git-wip-us.apache.org/repos/asf/ignite/blob/8d7567ee/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
index b1bac6e..1940077 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
@@ -316,7 +316,7 @@ public class IgniteMock implements Ignite {
     /** {@inheritDoc} */
     @Nullable @Override public IgniteSemaphore semaphore(String name,
         int cnt,
-        boolean fair,
+        boolean failoverSafe,
         boolean create)
     {
         return null;

http://git-wip-us.apache.org/repos/asf/ignite/blob/8d7567ee/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
index e71d635..45b82ad 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
@@ -536,7 +536,7 @@ public class IgniteProcessProxy implements IgniteEx {
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteSemaphore semaphore(String name, int cnt, boolean fair,
+    @Override public IgniteSemaphore semaphore(String name, int cnt, boolean failoverSafe,
         boolean create) throws IgniteException {
         throw new UnsupportedOperationException("Operation isn't supported yet.");
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/8d7567ee/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
index e0ebb0f..c5cde89 100644
--- a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
+++ b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
@@ -408,12 +408,13 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
     /** {@inheritDoc} */
     @Nullable @Override public IgniteSemaphore semaphore(String name,
         int cnt,
-        boolean fair,
+        boolean failoverSafe,
         boolean create)
     {
         assert g != null;
 
-        return g.semaphore(name, cnt, fair, create);
+        return g.semaphore(name, cnt,
+            failoverSafe, create);
     }
 
     /** {@inheritDoc} */


Mime
View raw message