Index executors: Use directExecutor for negative thread values

This will make it easier to test index-related logic in tests. We still
use 0 as a default way of setting the JVM threads.

Change-Id: If186a23ee4e79c49306bf9f286a24841d99e6531
This commit is contained in:
Patrick Hiesel
2018-07-04 10:54:26 +02:00
parent 15e6a73d94
commit bdbee9cf8e
3 changed files with 16 additions and 11 deletions

View File

@@ -2779,16 +2779,16 @@ Number of threads to use for indexing in normal interactive operations. Setting
it to 0 disables the dedicated thread pool and indexing will be done in the same it to 0 disables the dedicated thread pool and indexing will be done in the same
thread as the operation. thread as the operation.
+ +
If not set or set to a negative value, defaults to 1 plus half of the number of If not set or set to a zero, defaults to the number of logical CPUs as returned
logical CPUs as returned by the JVM. by the JVM. If set to a negative value, defaults to a direct executor.
[[index.batchThreads]]index.batchThreads:: [[index.batchThreads]]index.batchThreads::
+ +
Number of threads to use for indexing in background operations, such as Number of threads to use for indexing in background operations, such as
online schema upgrades. online schema upgrades.
+ +
If not set or set to a negative value, defaults to the number of logical If not set or set to a zero, defaults to the number of logical CPUs as returned
CPUs as returned by the JVM. by the JVM. If set to a negative value, defaults to a direct executor.
[[index.onlineUpgrade]]index.onlineUpgrade:: [[index.onlineUpgrade]]index.onlineUpgrade::
+ +

View File

@@ -397,6 +397,8 @@ public abstract class AbstractDaemonTest {
baseConfig.setString("sshd", null, "listenAddress", "off"); baseConfig.setString("sshd", null, "listenAddress", "off");
} }
baseConfig.setInt("index", null, "batchThreads", -1);
baseConfig.setInt("receive", null, "changeUpdateThreads", 4); baseConfig.setInt("receive", null, "changeUpdateThreads", 4);
Module module = createModule(); Module module = createModule();
if (classDesc.equals(methodDesc) && !classDesc.sandboxed() && !methodDesc.sandboxed()) { if (classDesc.equals(methodDesc) && !classDesc.sandboxed() && !methodDesc.sandboxed()) {

View File

@@ -104,7 +104,7 @@ public class IndexModule extends LifecycleModule {
public IndexModule( public IndexModule(
ListeningExecutorService interactiveExecutor, ListeningExecutorService batchExecutor) { ListeningExecutorService interactiveExecutor, ListeningExecutorService batchExecutor) {
this.threads = -1; this.threads = 0;
this.interactiveExecutor = interactiveExecutor; this.interactiveExecutor = interactiveExecutor;
this.batchExecutor = batchExecutor; this.batchExecutor = batchExecutor;
this.closeExecutorsOnShutdown = false; this.closeExecutorsOnShutdown = false;
@@ -211,11 +211,12 @@ public class IndexModule extends LifecycleModule {
return interactiveExecutor; return interactiveExecutor;
} }
int threads = this.threads; int threads = this.threads;
if (threads <= 0) { if (threads < 0) {
threads = config.getInt("index", null, "threads", 0); return MoreExecutors.newDirectExecutorService();
} } else if (threads == 0) {
if (threads <= 0) { threads =
threads = Runtime.getRuntime().availableProcessors() / 2 + 1; config.getInt(
"index", null, "threads", Runtime.getRuntime().availableProcessors() / 2 + 1);
} }
return MoreExecutors.listeningDecorator( return MoreExecutors.listeningDecorator(
workQueue.createQueue(threads, "Index-Interactive", true)); workQueue.createQueue(threads, "Index-Interactive", true));
@@ -230,7 +231,9 @@ public class IndexModule extends LifecycleModule {
return batchExecutor; return batchExecutor;
} }
int threads = config.getInt("index", null, "batchThreads", 0); int threads = config.getInt("index", null, "batchThreads", 0);
if (threads <= 0) { if (threads < 0) {
return MoreExecutors.newDirectExecutorService();
} else if (threads == 0) {
threads = Runtime.getRuntime().availableProcessors(); threads = Runtime.getRuntime().availableProcessors();
} }
return MoreExecutors.listeningDecorator(workQueue.createQueue(threads, "Index-Batch", true)); return MoreExecutors.listeningDecorator(workQueue.createQueue(threads, "Index-Batch", true));