geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [06/50] [abbrv] incubator-geode git commit: GEODE-863: Gfsh-started locator exits after a successful auto-reconnect
Date Mon, 01 Feb 2016 20:55:23 GMT
GEODE-863: Gfsh-started locator exits after a successful auto-reconnect

Modified InternalLocator.waitToStop() to work with auto-reconnect.
Modified InternalDistributedSystem to keep log appenders open during
auto-reconnect.
Added test of waitToStop to ReconnectDUnitTest.
Modified LocatorLauncher to show error details.


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

Branch: refs/heads/feature/GEODE-773-2
Commit: 4e211e2c2f771a4c399ce2be8dd0eb85f9b63740
Parents: 1ccf226
Author: Bruce Schuchardt <bschuchardt@pivotal.io>
Authored: Wed Jan 27 08:24:42 2016 -0800
Committer: Bruce Schuchardt <bschuchardt@pivotal.io>
Committed: Wed Jan 27 08:28:11 2016 -0800

----------------------------------------------------------------------
 .../gemfire/distributed/LocatorLauncher.java    | 13 +++++++
 .../internal/InternalDistributedSystem.java     | 26 +++++++------
 .../distributed/internal/InternalLocator.java   | 14 ++++---
 .../gemfire/cache30/ReconnectDUnitTest.java     | 39 ++++++++++++++++++++
 4 files changed, 76 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4e211e2c/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/LocatorLauncher.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/LocatorLauncher.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/LocatorLauncher.java
index 6846905..d13dae5 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/LocatorLauncher.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/LocatorLauncher.java
@@ -35,6 +35,8 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.logging.Level;
+
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
@@ -667,6 +669,13 @@ public final class LocatorLauncher extends AbstractLauncher<String>
{
    * @param cause the Throwable thrown during the startup or wait operation on the Locator.
    */
   private void failOnStart(final Throwable cause) {
+
+    if (cause != null) {
+      logger.log(Level.INFO, "locator is exiting due to an exception", cause);
+    } else {
+      logger.log(Level.INFO, "locator is exiting normally");
+    }
+    
     if (this.locator != null) {
       this.locator.stop();
       this.locator = null;
@@ -712,6 +721,10 @@ public final class LocatorLauncher extends AbstractLauncher<String>
{
       t = e;
       throw e;
     }
+    catch (Throwable e) {
+      t = e;
+      throw e;
+    }
     finally {
       failOnStart(t);
     }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4e211e2c/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystem.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystem.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystem.java
index 087407a..b3c636a 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystem.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystem.java
@@ -1326,12 +1326,14 @@ public class InternalDistributedSystem
           shutdownListeners = doDisconnects(attemptingToReconnect, reason);
         }
     
-        if (this.logWriterAppender != null) {
-          LogWriterAppenders.stop(LogWriterAppenders.Identifier.MAIN);
-        }
-        if (this.securityLogWriterAppender != null) {
-          // LOG:SECURITY: old code did NOT invoke this
-          LogWriterAppenders.stop(LogWriterAppenders.Identifier.SECURITY);
+        if (!this.attemptingToReconnect) {
+          if (this.logWriterAppender != null) {
+            LogWriterAppenders.stop(LogWriterAppenders.Identifier.MAIN);
+          }
+          if (this.securityLogWriterAppender != null) {
+            // LOG:SECURITY: old code did NOT invoke this
+            LogWriterAppenders.stop(LogWriterAppenders.Identifier.SECURITY);
+          }
         }
         
         AlertAppender.getInstance().shuttingDown();
@@ -1376,11 +1378,13 @@ public class InternalDistributedSystem
         this.sampler = null;
       }
 
-      if (this.logWriterAppender != null) {
-        LogWriterAppenders.destroy(LogWriterAppenders.Identifier.MAIN);
-      }
-      if (this.securityLogWriterAppender != null) {
-        LogWriterAppenders.destroy(LogWriterAppenders.Identifier.SECURITY);
+      if (!this.attemptingToReconnect) {
+        if (this.logWriterAppender != null) {
+          LogWriterAppenders.destroy(LogWriterAppenders.Identifier.MAIN);
+        }
+        if (this.securityLogWriterAppender != null) {
+          LogWriterAppenders.destroy(LogWriterAppenders.Identifier.SECURITY);
+        }
       }
 
       // NOTE: no logging after this point :-)

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4e211e2c/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalLocator.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalLocator.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalLocator.java
index c346a45..0f27d36 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalLocator.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalLocator.java
@@ -923,6 +923,10 @@ public class InternalLocator extends Locator implements ConnectListener
{
    */
   public void stop(boolean forcedDisconnect, boolean stopForReconnect, boolean waitForDisconnect)
{
     final boolean isDebugEnabled = logger.isDebugEnabled();
+    
+    this.stoppedForReconnect = stopForReconnect;
+    this.forcedDisconnect = forcedDisconnect;
+    
     if (this.server.isShuttingDown()) {
       // fix for bug 46156
       // If we are already shutting down don't do all of this again.
@@ -949,9 +953,7 @@ public class InternalLocator extends Locator implements ConnectListener
{
       }
       return;
     }
-    this.stoppedForReconnect = stopForReconnect;
-    this.forcedDisconnect = forcedDisconnect;
-    
+
     if (this.server.isAlive()) {
       logger.info(LocalizedMessage.create(LocalizedStrings.InternalLocator_STOPPING__0, this));
       try {
@@ -1041,15 +1043,16 @@ public class InternalLocator extends Locator implements ConnectListener
{
   public void waitToStop() throws InterruptedException {
     boolean restarted;
     do {
+      DistributedSystem ds = this.myDs;
       restarted = false;
       this.server.join();
       if (this.stoppedForReconnect) {
         logger.info("waiting for distributed system to disconnect...");
-        while (this.myDs.isConnected()) {
+        while (ds.isConnected()) {
           Thread.sleep(5000);
         }
         logger.info("waiting for distributed system to reconnect...");
-        restarted = this.myDs.waitUntilReconnected(-1, TimeUnit.SECONDS);
+        restarted = ds.waitUntilReconnected(-1, TimeUnit.SECONDS);
         if (restarted) {
           logger.info("system restarted");
         } else {
@@ -1060,6 +1063,7 @@ public class InternalLocator extends Locator implements ConnectListener
{
           logger.info("waiting for services to restart...");
           rs.join();
           this.restartThread = null;
+          logger.info("done waiting for services to restart");
         }
       }
     } while (restarted);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4e211e2c/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/ReconnectDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/ReconnectDUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/ReconnectDUnitTest.java
index b4a73bc..cdc3283 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/ReconnectDUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/ReconnectDUnitTest.java
@@ -61,12 +61,14 @@ import com.gemstone.gemfire.test.dunit.SerializableCallable;
 import com.gemstone.gemfire.test.dunit.SerializableRunnable;
 import com.gemstone.gemfire.test.dunit.VM;
 
+@SuppressWarnings("serial")
 public class ReconnectDUnitTest extends CacheTestCase
 {
   static int locatorPort;
   static Locator locator;
   static DistributedSystem savedSystem;
   static int locatorVMNumber = 3;
+  static Thread gfshThread;
   
   Properties dsProperties;
   
@@ -506,8 +508,10 @@ public class ReconnectDUnitTest extends CacheTestCase
     try {
       
       dm = getDMID(vm0);
+      createGfshWaitingThread(vm0);
       forceDisconnect(vm0);
       newdm = waitForReconnect(vm0);
+      assertGfshWaitingThreadAlive(vm0);
 
       boolean running = (Boolean)vm0.invoke(new SerializableCallable("check for running locator")
{
         public Object call() {
@@ -551,6 +555,10 @@ public class ReconnectDUnitTest extends CacheTestCase
           if (loc != null) {
             loc.stop();
           }
+          if (gfshThread != null && gfshThread.isAlive()) {
+            gfshThread.interrupt();
+          }
+          gfshThread = null;
         }
       });
       deleteLocatorStateFile(locPort);
@@ -558,6 +566,37 @@ public class ReconnectDUnitTest extends CacheTestCase
     }
   }
   
+  @SuppressWarnings("serial")
+  private void createGfshWaitingThread(VM vm) {
+    vm.invoke(new SerializableRunnable("create Gfsh-like waiting thread") {
+      public void run() {
+        final Locator loc = Locator.getLocator();
+        assertNotNull(loc);
+        gfshThread = new Thread("ReconnectDUnitTest_Gfsh_thread") {
+          public void run() {
+            try {
+              ((InternalLocator)loc).waitToStop();
+            } catch (InterruptedException e) {
+              System.out.println(Thread.currentThread().getName() + " interrupted - exiting");
+            }
+          }
+        };
+        gfshThread.setDaemon(true);
+        gfshThread.start();
+        System.out.println("created gfsh thread: " + gfshThread);
+      }
+    });
+  }
+  
+  @SuppressWarnings("serial")
+  private void assertGfshWaitingThreadAlive(VM vm) {
+    vm.invoke(new SerializableRunnable("assert gfshThread is still waiting") {
+      public void run() {
+        assertTrue(gfshThread.isAlive());
+      }
+    });
+  }
+  
   /**
    * Test the reconnect behavior when the required roles are missing.
    * Reconnect is triggered as a Reliability policy. The test is to


Mime
View raw message