Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-15861: ConcurrentUpdateSolrClient should work with ManagedExecutorService (#464)

Sammy Chu9fce4b55dd80
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 04ff3236176..e520e439ee9 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -125,6 +125,8 @@ Other Changes
* SOLR-16541: Eliminate the 'numShards' system property (noble)
+* SOLR-15861: ConcurrentUpdateSolrClient should work with ManagedExecutorService (Sammy Chu, Kevin Risden)
+
================== 9.1.0 ==================
New Features
diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java b/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java
index bb947881792..e249e013895 100644
--- a/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java
+++ b/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java
@@ -422,7 +422,7 @@ public class OverseerTaskProcessor implements Runnable, Closeable {
isClosed = true;
overseerTaskProcessorMetricsContext.unregister();
if (tpe != null) {
- if (!tpe.isShutdown()) {
+ if (!ExecutorUtil.isShutdown(tpe)) {
ExecutorUtil.shutdownAndAwaitTermination(tpe);
}
}
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerCollectionMessageHandler.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerCollectionMessageHandler.java
index b27798fe0a2..8c3926160cd 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerCollectionMessageHandler.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerCollectionMessageHandler.java
@@ -206,7 +206,7 @@ public class OverseerCollectionMessageHandler implements OverseerMessageHandler,
public void close() throws IOException {
this.isClosed = true;
if (tpe != null) {
- if (!tpe.isShutdown()) {
+ if (!ExecutorUtil.isShutdown(tpe)) {
ExecutorUtil.shutdownAndAwaitTermination(tpe);
}
}
diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
index 7cbd0519c34..9d61974e859 100644
--- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
+++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
@@ -843,7 +843,7 @@ public class IndexFetcher {
markReplicationStop();
dirFileFetcher = null;
localFileFetcher = null;
- if (fsyncService != null && !fsyncService.isShutdown()) fsyncService.shutdown();
+ if (fsyncService != null && !ExecutorUtil.isShutdown(fsyncService)) fsyncService.shutdown();
fsyncService = null;
stop = false;
fsyncException = null;
@@ -900,7 +900,7 @@ public class IndexFetcher {
* terminate the fsync service and wait for all the tasks to complete. If it is already terminated
*/
private void terminateAndWaitFsyncService() throws Exception {
- if (fsyncService.isTerminated()) return;
+ if (ExecutorUtil.isTerminated(fsyncService)) return;
fsyncService.shutdown();
// give a long wait say 1 hr
fsyncService.awaitTermination(3600, TimeUnit.SECONDS);
diff --git a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
index a742dce3990..6c7b014b0fa 100644
--- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
+++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
@@ -311,7 +311,7 @@ public final class ManagedIndexSchema extends IndexSchema {
collection);
Thread.currentThread().interrupt();
} finally {
- if (!parallelExecutor.isShutdown()) parallelExecutor.shutdown();
+ if (!ExecutorUtil.isShutdown(parallelExecutor)) parallelExecutor.shutdown();
}
if (log.isInfoEnabled()) {
diff --git a/solr/core/src/java/org/apache/solr/update/UpdateLog.java b/solr/core/src/java/org/apache/solr/update/UpdateLog.java
index 17a9c62d889..d78af4fdb7f 100644
--- a/solr/core/src/java/org/apache/solr/update/UpdateLog.java
+++ b/solr/core/src/java/org/apache/solr/update/UpdateLog.java
@@ -1808,7 +1808,7 @@ public class UpdateLog implements PluginInfoInitialized, SolrMetricProducer {
versionInfo.unblockUpdates();
}
- if (recoveryExecutor.isShutdown()) {
+ if (ExecutorUtil.isShutdown(recoveryExecutor)) {
throw new RuntimeException("executor is not running...");
}
ExecutorCompletionService<RecoveryInfo> cs = new ExecutorCompletionService<>(recoveryExecutor);
diff --git a/solr/core/src/java/org/apache/solr/util/OrderedExecutor.java b/solr/core/src/java/org/apache/solr/util/OrderedExecutor.java
index 923560a8ac6..65d2491ed1e 100644
--- a/solr/core/src/java/org/apache/solr/util/OrderedExecutor.java
+++ b/solr/core/src/java/org/apache/solr/util/OrderedExecutor.java
@@ -60,7 +60,7 @@ public class OrderedExecutor implements Executor {
}
try {
- if (delegate.isShutdown()) throw new RejectedExecutionException();
+ if (ExecutorUtil.isShutdown(delegate)) throw new RejectedExecutionException();
delegate.execute(
() -> {
diff --git a/solr/core/src/test/org/apache/solr/util/TestCircuitBreaker.java b/solr/core/src/test/org/apache/solr/util/TestCircuitBreaker.java
index bb85b8d4cd6..c9fe19be273 100644
--- a/solr/core/src/test/org/apache/solr/util/TestCircuitBreaker.java
+++ b/solr/core/src/test/org/apache/solr/util/TestCircuitBreaker.java
@@ -24,7 +24,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
@@ -161,20 +160,9 @@ public class TestCircuitBreaker extends SolrTestCaseJ4 {
throw new RuntimeException(e.getMessage());
}
}
-
- executor.shutdown();
- try {
- executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new RuntimeException(e.getMessage());
- }
-
- assertEquals("Number of failed queries is not correct", 1, failureCount.get());
} finally {
- if (!executor.isShutdown()) {
- executor.shutdown();
- }
+ ExecutorUtil.shutdownAndAwaitTermination(executor);
+ assertEquals("Number of failed queries is not correct", 1, failureCount.get());
}
}
@@ -222,20 +210,9 @@ public class TestCircuitBreaker extends SolrTestCaseJ4 {
throw new RuntimeException(e.getMessage());
}
}
-
- executor.shutdown();
- try {
- executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new RuntimeException(e.getMessage());
- }
-
- assertEquals("Number of failed queries is not correct", 5, failureCount.get());
} finally {
- if (!executor.isShutdown()) {
- executor.shutdown();
- }
+ ExecutorUtil.shutdownAndAwaitTermination(executor);
+ assertEquals("Number of failed queries is not correct", 5, failureCount.get());
}
}
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
index 359bde54b08..b4624843207 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
@@ -301,7 +301,7 @@ public abstract class CloudSolrClient extends SolrClient {
@Override
public void close() throws IOException {
- if (this.threadPool != null && !this.threadPool.isShutdown()) {
+ if (this.threadPool != null && !ExecutorUtil.isShutdown(this.threadPool)) {
ExecutorUtil.shutdownAndAwaitTermination(this.threadPool);
this.threadPool = null;
}
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java
index b86e75e5134..7891a51c710 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java
@@ -187,7 +187,7 @@ public class ConcurrentUpdateHttp2SolrClient extends SolrClient {
} finally {
synchronized (runners) {
// check to see if anything else was added to the queue
- if (runners.size() == 1 && !queue.isEmpty() && !scheduler.isShutdown()) {
+ if (runners.size() == 1 && !queue.isEmpty() && !ExecutorUtil.isShutdown(scheduler)) {
// If there is something else to process, keep last runner alive by staying in the
// loop.
} else {
@@ -486,7 +486,7 @@ public class ConcurrentUpdateHttp2SolrClient extends SolrClient {
int loopCount = 0;
while (!runners.isEmpty()) {
- if (scheduler.isShutdown()) break;
+ if (ExecutorUtil.isShutdown(scheduler)) break;
loopCount++;
@@ -556,7 +556,7 @@ public class ConcurrentUpdateHttp2SolrClient extends SolrClient {
long lastStallTime = -1;
int lastQueueSize = -1;
while (!queue.isEmpty()) {
- if (scheduler.isTerminated()) {
+ if (ExecutorUtil.isTerminated(scheduler)) {
log.warn(
"The task queue still has elements but the update scheduler {} is terminated. Can't process any more tasks. Queue size: {}, Runners: {}. Current thread Interrupted? {}",
scheduler,
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
index 2c2f74646db..7218a8da455 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
@@ -181,7 +181,7 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
} finally {
synchronized (runners) {
// check to see if anything else was added to the queue
- if (runners.size() == 1 && !queue.isEmpty() && !scheduler.isShutdown()) {
+ if (runners.size() == 1 && !queue.isEmpty() && !ExecutorUtil.isShutdown(scheduler)) {
// If there is something else to process, keep last runner alive by staying in the
// loop.
} else {
@@ -614,7 +614,7 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
if (log.isDebugEnabled()) blockLoops.incrementAndGet();
- if (scheduler.isShutdown()) break;
+ if (ExecutorUtil.isShutdown(scheduler)) break;
loopCount++;
@@ -685,7 +685,7 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
int lastQueueSize = -1;
while (!queue.isEmpty()) {
if (log.isDebugEnabled()) emptyQueueLoops.incrementAndGet();
- if (scheduler.isTerminated()) {
+ if (ExecutorUtil.isTerminated(scheduler)) {
log.warn(
"The task queue still has elements but the update scheduler {} is terminated. Can't process any more tasks. Queue size: {}, Runners: {}. Current thread Interrupted? {}",
scheduler,
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java b/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
index e85470d70fd..5897aea85f8 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
@@ -83,6 +83,24 @@ public class ExecutorUtil {
void clean(AtomicReference<Object> ctx);
}
+ public static boolean isShutdown(ExecutorService pool) {
+ try {
+ return pool.isShutdown();
+ } catch (IllegalStateException e) {
+ // JSR-239 ManagedExecutorService cannot query the lifecycle, so just return false
+ return false;
+ }
+ }
+
+ public static boolean isTerminated(ExecutorService pool) {
+ try {
+ return pool.isTerminated();
+ } catch (IllegalStateException e) {
+ // JSR-239 ManagedExecutorService cannot query the lifecycle, so just return false
+ return false;
+ }
+ }
+
public static void shutdownAndAwaitTermination(ExecutorService pool) {
if (pool == null) return;
pool.shutdown(); // Disable new tasks from being submitted