You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2020/07/16 13:45:26 UTC

[lucene-solr] branch reference_impl updated: @212 - Honing in on shutdown.

This is an automated email from the ASF dual-hosted git repository.

markrmiller pushed a commit to branch reference_impl
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/reference_impl by this push:
     new 627c473  @212 - Honing in on shutdown.
627c473 is described below

commit 627c47332af5a268c77d41a40e2bb3aeaad4f53e
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Thu Jul 16 08:45:09 2020 -0500

    @212 - Honing in on shutdown.
---
 .../client/solrj/embedded/JettySolrRunner.java     |  2 +-
 .../solr/client/solrj/impl/Http2SolrClient.java    | 15 +++----
 .../solr/common/util/SolrQueuedThreadPool.java     | 47 +++++-----------------
 .../src/java/org/apache/solr/SolrTestCaseJ4.java   | 11 +++--
 .../apache/solr/cloud/MiniSolrCloudCluster.java    |  6 ++-
 .../org/apache/solr/cloud/SolrCloudTestCase.java   |  4 +-
 .../java/org/apache/solr/cloud/ZkTestServer.java   |  5 ++-
 7 files changed, 34 insertions(+), 56 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java b/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
index 71b4ccd..b5ea632 100644
--- a/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
+++ b/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
@@ -305,7 +305,7 @@ public class JettySolrRunner implements Closeable {
     if (config.qtp != null) {
       qtp = config.qtp;
     } else {
-      qtp = new SolrQueuedThreadPool("JettySolrRunner qtp", false);
+      qtp = new SolrQueuedThreadPool("JettySolrRunner qtp");
       qtp.setMaxThreads(Integer.getInteger("solr.maxContainerThreads", THREAD_POOL_MAX_THREADS));
       qtp.setLowThreadsThreshold(Integer.getInteger("solr.lowContainerThreadsThreshold", -1)); // we don't use this or connections will get cut
       qtp.setMinThreads(Integer.getInteger("solr.minContainerThreads", 2));
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
index 8e93642..0b2415a 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
@@ -29,20 +29,15 @@ import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executor;
-import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Phaser;
 import java.util.concurrent.Semaphore;
-import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
@@ -60,6 +55,7 @@ import org.apache.solr.client.solrj.request.UpdateRequest;
 import org.apache.solr.client.solrj.request.V2Request;
 import org.apache.solr.client.solrj.util.ClientUtils;
 import org.apache.solr.client.solrj.util.Constants;
+import org.apache.solr.common.AlreadyClosedException;
 import org.apache.solr.common.ParWork;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.StringUtils;
@@ -224,7 +220,10 @@ public class Http2SolrClient extends SolrClient {
       httpClient = new HttpClient(transport, sslContextFactory);
       httpClient.setMaxConnectionsPerDestination(4);
     }
-    httpClientExecutor = new SolrQueuedThreadPool("httpClient", false);
+    httpClientExecutor = new SolrQueuedThreadPool("httpClient");
+    httpClientExecutor.setMaxThreads(10);
+    httpClientExecutor.setMinThreads(1);
+    httpClient.setIdleTimeout(idleTimeout);
     try {
       httpClientExecutor.start();
       httpClient.setExecutor(httpClientExecutor);
@@ -238,6 +237,7 @@ public class Http2SolrClient extends SolrClient {
 
       httpClient.start();
     } catch (Exception e) {
+      close();
       throw new RuntimeException(e);
     }
     return httpClient;
@@ -823,7 +823,8 @@ public class Http2SolrClient extends SolrClient {
         try {
           available.acquire();
         } catch (InterruptedException ignored) {
-
+          ParWork.propegateInterrupt(ignored);
+          throw new AlreadyClosedException("Interrupted");
         }
       };
       completeListener = result -> {
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/SolrQueuedThreadPool.java b/solr/solrj/src/java/org/apache/solr/common/util/SolrQueuedThreadPool.java
index d236a78..886f9bc 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/SolrQueuedThreadPool.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/SolrQueuedThreadPool.java
@@ -20,6 +20,7 @@ import java.io.Closeable;
 import java.lang.invoke.MethodHandles;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.solr.common.ParWork;
 import org.apache.solr.common.util.ObjectReleaseTracker;
 import org.apache.solr.common.util.SolrNamedThreadFactory;
 import org.eclipse.jetty.util.thread.QueuedThreadPool;
@@ -28,19 +29,17 @@ import org.slf4j.LoggerFactory;
 
 public class SolrQueuedThreadPool extends QueuedThreadPool implements Closeable {
     private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-    private final boolean killStop;
     private final String name;
     private volatile Error error;
     private final Object notify = new Object();
 
 
 
-    public SolrQueuedThreadPool(String name, boolean killStop) {
+    public SolrQueuedThreadPool(String name) {
         super(10000, 15,
         15000, -1,
         null, null,
               new  SolrNamedThreadFactory(name));
-        this.killStop = killStop;
         this.name = name;
     }
 
@@ -56,43 +55,22 @@ public class SolrQueuedThreadPool extends QueuedThreadPool implements Closeable
         }
     }
 
-
-//
-//    @Override
-//    public Thread newThread(Runnable runnable) {
-//        Thread thread = new Thread(tg, runnable);
-//        thread.setDaemon(isDaemon());
-//        thread.setPriority(getThreadsPriority());
-//        thread.setName(name + "-" + thread.getId());
-//        return thread;d
-//    }
-
     public void close() {
-        TimeOut timeout = new TimeOut(15, TimeUnit.SECONDS, TimeSource.NANO_TIME);
-        while (getBusyThreads() != 0) {
-            if (timeout.hasTimedOut()) {
-                throw new RuntimeException("Timed out waiting for SolrQueuedThreadPool to close");
-            }
-            try {
-                synchronized (notify) {
-                    notify.wait(500);
-                }
-            } catch (InterruptedException e) {
-                Thread.currentThread().interrupt();
+        try {
+            doStop();
+            while (isStopping()) {
+                Thread.sleep(1);
             }
+        } catch (Exception e) {
+            ParWork.propegateInterrupt("Exception closing", e);
         }
 
-        if (error != null) {
-            throw error;
-        }
         assert ObjectReleaseTracker.release(this);
     }
 
     @Override
     protected void doStop() throws Exception {
-        if (!killStop) {
-           super.doStop();
-        }
+      super.doStop();
     }
 
     public void stdStop() throws Exception {
@@ -100,10 +78,7 @@ public class SolrQueuedThreadPool extends QueuedThreadPool implements Closeable
     }
 
     @Override
-    public void join() throws InterruptedException
-    {
-        if (!killStop) {
-            super.join();
-        }
+    public void join() throws InterruptedException {
+
     }
 }
\ No newline at end of file
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index 63c3c17..342e2d1 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -2985,15 +2985,14 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
 
   public static SolrQueuedThreadPool getQtp() {
 
-    SolrQueuedThreadPool qtp = new SolrQueuedThreadPool("solr-test-qtp", true);;
-    // qtp.setReservedThreads(0);
+    SolrQueuedThreadPool qtp = new SolrQueuedThreadPool("solr-test-qtp");;
           qtp.setName("solr-test-qtp");
-          qtp.setMaxThreads(Integer.getInteger("solr.maxContainerThreads", 10000));
+          qtp.setMaxThreads(Integer.getInteger("solr.maxContainerThreads", 50));
           qtp.setLowThreadsThreshold(Integer.getInteger("solr.lowContainerThreadsThreshold", -1)); // we don't use this or connections will get cut
-          qtp.setMinThreads(Integer.getInteger("solr.minContainerThreads", 2));
-          qtp.setIdleTimeout(Integer.getInteger("solr.containerThreadsIdle", 1000));
+          qtp.setMinThreads(Integer.getInteger("solr.minContainerThreads", 1));
+          qtp.setIdleTimeout(Integer.getInteger("solr.containerThreadsIdle", 30000));
 
-          qtp.setStopTimeout((int) TimeUnit.MINUTES.toMillis(2));
+          qtp.setStopTimeout((int) TimeUnit.SECONDS.toMillis(30));
           qtp.setReservedThreads(-1); // -1 auto sizes, important to keep
           // qtp.setStopTimeout((int) TimeUnit.MINUTES.toMillis(1));
     return qtp;
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
index c9845a3..5918aac 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
@@ -651,10 +651,12 @@ public class MiniSolrCloudCluster {
       jettys.clear();
 
       try (ParWork parWork = new ParWork(this, true)) {
-        parWork.add("jettys", solrClient, shutdowns);
+        parWork.collect(solrClient);
+         parWork.collect(shutdowns);
         if (!externalZkServer) {
-          parWork.add("zkServer", zkServer);
+          parWork.collect(zkServer);
         }
+        parWork.addCollect("miniclusterShutdown");
       }
     } finally {
       System.clearProperty("zkHost");
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java
index 67f1fd0..16ab581 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java
@@ -86,7 +86,7 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   public static final int DEFAULT_TIMEOUT = 15;
-  private static SolrQueuedThreadPool qtp;
+  private static volatile SolrQueuedThreadPool qtp;
 
   private static class Config {
     final String name;
@@ -304,7 +304,7 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
     }
     if (qtp != null) {
 
-      qtp.close();
+      qtp.stop();
       qtp = null;
     }
   }
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java b/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java
index 3f7ff92..e06337e 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java
@@ -629,7 +629,7 @@ public class ZkTestServer implements Closeable {
         chRootClient.printLayout();
       }
     } catch (Exception e) {
-      log.warn("Exception trying to print zk layout to log on shutdown", e);
+      ParWork.propegateInterrupt("Exception trying to print zk layout to log on shutdown", e);
     }
     if (chRootClient != null && zkServer != null) {
       writeZkMonitorFile();
@@ -637,7 +637,8 @@ public class ZkTestServer implements Closeable {
 
 
     try (ParWork worker = new ParWork(this, true)) {
-      worker.add("zkClients", timer, chRootClient, () -> {
+      worker.add("zkClients", timer, chRootClient);
+      worker.add("zkServer", () -> {
         if (zkServer != null) zkServer.shutdown();
         return zkServer;
       }, () -> {