ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yzhda...@apache.org
Subject ignite git commit: fixed problem with unreleased busy locks
Date Mon, 12 Dec 2016 13:02:09 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-comm-balance-master 131340f27 -> e4dad2382


fixed problem with unreleased busy locks


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

Branch: refs/heads/ignite-comm-balance-master
Commit: e4dad238239d71ce291779c1d46c14b547d9a63d
Parents: 131340f
Author: Yakov Zhdanov <yzhdanov@gridgain.com>
Authored: Mon Dec 12 16:01:59 2016 +0300
Committer: Yakov Zhdanov <yzhdanov@gridgain.com>
Committed: Mon Dec 12 16:01:59 2016 +0300

----------------------------------------------------------------------
 .../eventstorage/GridEventStorageManager.java   | 34 ++++++++---
 .../cache/GridCacheEvictionManager.java         | 60 ++++++++++++++------
 .../dht/preloader/GridDhtPreloader.java         | 39 ++++++++-----
 .../ignite/internal/util/GridBusyLock.java      |  2 +-
 4 files changed, 98 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/e4dad238/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java
index 607bb96..b5d5ee2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageManager.java
@@ -100,6 +100,9 @@ public class GridEventStorageManager extends GridManagerAdapter<EventStorageSpi>
     /** Events of these types should be recorded. */
     private volatile int[] inclEvtTypes;
 
+    /** */
+    private boolean stopped;
+
     /**
      * Maps event type to boolean ({@code true} for recordable events).
      * This array is used for listeners notification. It may be wider,
@@ -212,7 +215,16 @@ public class GridEventStorageManager extends GridManagerAdapter<EventStorageSpi>
      * @return {@code true} if entered to busy state.
      */
     private boolean enterBusy() {
-        return busyLock.readLock().tryLock();
+        if (!busyLock.readLock().tryLock())
+            return false;
+
+        if (stopped) {
+            busyLock.readLock().unlock();
+
+            return false;
+        }
+
+        return true;
     }
 
     /**
@@ -225,15 +237,23 @@ public class GridEventStorageManager extends GridManagerAdapter<EventStorageSpi>
     /** {@inheritDoc} */
     @SuppressWarnings({"LockAcquiredButNotSafelyReleased"})
     @Override public void onKernalStop0(boolean cancel) {
-        // Acquire write lock so that any new thread could not be started.
         busyLock.writeLock().lock();
 
-        if (msgLsnr != null)
-            ctx.io().removeMessageListener(TOPIC_EVENT, msgLsnr);
+        try {
+            if (msgLsnr != null)
+                ctx.io().removeMessageListener(
+                    TOPIC_EVENT,
+                    msgLsnr);
+
+            msgLsnr = null;
 
-        msgLsnr = null;
+            lsnrs.clear();
 
-        lsnrs.clear();
+            stopped = true;
+        }
+        finally {
+            busyLock.writeLock().unlock();
+        }
     }
 
     /** {@inheritDoc} */
@@ -1203,4 +1223,4 @@ public class GridEventStorageManager extends GridManagerAdapter<EventStorageSpi>
             return lsnr.hashCode();
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/e4dad238/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
index 134e743..6fb8557 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
@@ -160,6 +160,9 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter
{
     /** Stopping flag. */
     private volatile boolean stopping;
 
+    /** Stopped flag. */
+    private boolean stopped;
+
     /** Current future. */
     private final AtomicReference<EvictionFuture> curEvictFut = new AtomicReference<>();
 
@@ -311,19 +314,28 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter
{
 
         busyLock.block();
 
-        // Stop backup worker.
-        if (evictSync && !cctx.isNear() && backupWorker != null) {
-            backupWorker.cancel();
+        try {
+            // Stop backup worker.
+            if (evictSync && !cctx.isNear() && backupWorker != null) {
+                backupWorker.cancel();
 
-            U.join(backupWorkerThread, log);
-        }
+                U.join(
+                    backupWorkerThread,
+                    log);
+            }
 
-        // Cancel all active futures.
-        for (EvictionFuture fut : futs.values())
-            fut.cancel();
+            // Cancel all active futures.
+            for (EvictionFuture fut : futs.values())
+                fut.cancel();
 
-        if (log.isDebugEnabled())
-            log.debug("Eviction manager stopped on node: " + cctx.nodeId());
+            if (log.isDebugEnabled())
+                log.debug("Eviction manager stopped on node: " + cctx.nodeId());
+        }
+        finally {
+            stopped = true;
+
+            busyLock.unblock();
+        }
     }
 
     /**
@@ -345,7 +357,7 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter
{
             log.debug("Processing eviction response [node=" + nodeId + ", localNode=" + cctx.nodeId()
+
                 ", res=" + res + ']');
 
-        if (!busyLock.enterBusy())
+        if (!enterBusy())
             return;
 
         try {
@@ -363,6 +375,22 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter
{
     }
 
     /**
+     * @return {@code True} if entered busy.
+     */
+    private boolean enterBusy() {
+        if (!busyLock.enterBusy())
+            return false;
+
+        if (stopped) {
+            busyLock.leaveBusy();
+
+            return false;
+        }
+
+        return true;
+    }
+
+    /**
      * @param nodeId Sender node ID.
      * @param req Request.
      */
@@ -370,7 +398,7 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter
{
         assert nodeId != null;
         assert req != null;
 
-        if (!busyLock.enterBusy())
+        if (!enterBusy())
             return;
 
         try {
@@ -811,7 +839,7 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter
{
         if (!cctx.isNear() && evictSync && !cctx.affinity().primary(cctx.localNode(),
e.partition(), topVer))
             return;
 
-        if (!busyLock.enterBusy())
+        if (!enterBusy())
             return;
 
         try {
@@ -1145,7 +1173,7 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter
{
 
                         fut.listen(new CI1<IgniteInternalFuture<?>>() {
                             @Override public void apply(IgniteInternalFuture<?> f)
{
-                                if (!busyLock.enterBusy()) {
+                                if (!enterBusy()) {
                                     if (log.isDebugEnabled())
                                         log.debug("Will not notify eviction future completion
(grid is stopping): " +
                                             f);
@@ -1187,7 +1215,7 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter
{
      * @param topVer Topology version on future complete.
      */
     private void onFutureCompleted(EvictionFuture fut, AffinityTopologyVersion topVer) {
-        if (!busyLock.enterBusy())
+        if (!enterBusy())
             return;
 
         try {
@@ -1366,7 +1394,7 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter
{
         if (!evictSyncAgr)
             return;
 
-        if (!busyLock.enterBusy())
+        if (!enterBusy())
             return;
 
         try {

http://git-wip-us.apache.org/repos/asf/ignite/blob/e4dad238/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java
index 41bc2fc..50567e0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPreloader.java
@@ -120,6 +120,9 @@ public class GridDhtPreloader extends GridCachePreloaderAdapter {
     /** */
     private volatile boolean stopping;
 
+    /** */
+    private boolean stopped;
+
     /** Discovery listener. */
     private final GridLocalEventListener discoLsnr = new GridLocalEventListener() {
         @Override public void onEvent(Event evt) {
@@ -222,18 +225,25 @@ public class GridDhtPreloader extends GridCachePreloaderAdapter {
         // Acquire write busy lock.
         busyLock.writeLock().lock();
 
-        if (supplier != null)
-            supplier.stop();
+        try {
+            if (supplier != null)
+                supplier.stop();
 
-        if (demander != null)
-            demander.stop();
+            if (demander != null)
+                demander.stop();
 
-        IgniteCheckedException err = stopError();
+            IgniteCheckedException err = stopError();
 
-        for (GridDhtForceKeysFuture fut : forceKeyFuts.values())
-            fut.onDone(err);
+            for (GridDhtForceKeysFuture fut : forceKeyFuts.values())
+                fut.onDone(err);
 
-        top = null;
+            top = null;
+
+            stopped = true;
+        }
+        finally {
+            busyLock.writeLock().unlock();
+        }
     }
     /**
      * @return Node stop exception.
@@ -441,13 +451,16 @@ public class GridDhtPreloader extends GridCachePreloaderAdapter {
      * @return {@code true} if entered to busy state.
      */
     private boolean enterBusy() {
-        if (busyLock.readLock().tryLock())
-            return true;
+        if (!busyLock.readLock().tryLock())
+            return false;
 
-        if (log.isDebugEnabled())
-            log.debug("Failed to enter busy state on node (exchanger is stopping): " + cctx.nodeId());
+        if (stopped) {
+            busyLock.readLock().unlock();
 
-        return false;
+            return false;
+        }
+
+        return true;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/e4dad238/modules/core/src/main/java/org/apache/ignite/internal/util/GridBusyLock.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridBusyLock.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/GridBusyLock.java
index c23e1de..76fef50 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridBusyLock.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridBusyLock.java
@@ -79,4 +79,4 @@ public class GridBusyLock {
     public void unblock() {
         lock.writeLock().unlock();
     }
-}
\ No newline at end of file
+}


Mime
View raw message