geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vfor...@apache.org
Subject [18/50] [abbrv] incubator-geode git commit: [GEODE-329] fix ShutdownAllDUnitTest failure
Date Wed, 25 Nov 2015 19:07:31 GMT
[GEODE-329] fix ShutdownAllDUnitTest failure

There's a race condition that there will be 2 distributed systems are
created in one JVM.

When a DS is disconnecting, the current thread stays in wait(500) and
release the lock. Thread2 comes and found a disconnected DS, so it will
create a new DS. When the current thread waked up, it should double check
if the DS has been changed.


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

Branch: refs/heads/feature/GEODE-78
Commit: 27eceb1f49647df2207bcc966ba11631a4f5832e
Parents: f50ca04
Author: zhouxh <gzhou@pivotal.io>
Authored: Mon Sep 21 14:56:17 2015 -0700
Committer: zhouxh <gzhou@pivotal.io>
Committed: Tue Sep 29 15:21:55 2015 -0700

----------------------------------------------------------------------
 .../gemfire/distributed/DistributedSystem.java  | 38 ++++++++++----------
 1 file changed, 20 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/27eceb1f/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/DistributedSystem.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/DistributedSystem.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/DistributedSystem.java
index b7b2cd8..21be43f 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/DistributedSystem.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/DistributedSystem.java
@@ -1584,32 +1584,34 @@ public abstract class DistributedSystem implements StatisticsFactory
{
         }
 
       } else {
-        if (!existingSystems.isEmpty()) {
+        boolean existingSystemDisconnecting = true;
+        while (!existingSystems.isEmpty() && existingSystemDisconnecting) {
           Assert.assertTrue(existingSystems.size() == 1);
 
           InternalDistributedSystem existingSystem =
-            (InternalDistributedSystem) existingSystems.get(0);
-          if (existingSystem.isDisconnecting()) {
-            while (existingSystem.isConnected()) {
-              boolean interrupted = Thread.interrupted();
-              try {
-                existingSystemsLock.wait(500);
-              } 
-              catch (InterruptedException ex) {
-                interrupted = true;
-              }
-              finally {
-                if (interrupted) {
-                  Thread.currentThread().interrupt();
-                }
+              (InternalDistributedSystem) existingSystems.get(0);
+          existingSystemDisconnecting = existingSystem.isDisconnecting();
+          if (existingSystemDisconnecting) {
+            boolean interrupted = Thread.interrupted();
+            try {
+              // no notify for existingSystemsLock, just to release the sync
+              existingSystemsLock.wait(50);
+            } 
+            catch (InterruptedException ex) {
+              interrupted = true;
+            }
+            finally {
+              if (interrupted) {
+                Thread.currentThread().interrupt();
               }
             }
-          }
-
-          if (existingSystem.isConnected()) {
+          } else if (existingSystem.isConnected()) {
             existingSystem.validateSameProperties(config,
                 existingSystem.isConnected());
             return existingSystem;
+          } else {
+          // This should not happen: existingSystem.isConnected()==false && existingSystem.isDisconnecting()==false

+            throw new AssertionError("system should not be disconnecting==false and isConnected==falsed");
           }
         }
       }


Mime
View raw message