From 7d703c2f92ba784de47ea00959ba7626597e4e94 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 24 Sep 2018 07:45:50 +0200 Subject: [PATCH] Fix AutoQueueAdjustingExecutorBuilder settings validation (#33922) Settings validation in AutoQueueAdjustingExecutorBuilder always checked against a default value which means that we never can change a max queue size that is lower than the default. This change adds tests and fixes this validation. --- .../AutoQueueAdjustingExecutorBuilder.java | 54 ++++++++++---- ...utoQueueAdjustingExecutorBuilderTests.java | 70 ++++++++++++++++++- 2 files changed, 109 insertions(+), 15 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/threadpool/AutoQueueAdjustingExecutorBuilder.java b/server/src/main/java/org/elasticsearch/threadpool/AutoQueueAdjustingExecutorBuilder.java index ec9d95c722d..45f53006ecd 100644 --- a/server/src/main/java/org/elasticsearch/threadpool/AutoQueueAdjustingExecutorBuilder.java +++ b/server/src/main/java/org/elasticsearch/threadpool/AutoQueueAdjustingExecutorBuilder.java @@ -28,8 +28,10 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.node.Node; import java.util.Arrays; +import java.util.Iterator; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadFactory; @@ -71,14 +73,42 @@ public final class AutoQueueAdjustingExecutorBuilder extends ExecutorBuilder tempMinQueueSizeSetting = Setting.intSetting(minSizeKey, minQueueSize, Setting.Property.NodeScope); this.minQueueSizeSetting = new Setting<>( - minSizeKey, - (s) -> Integer.toString(minQueueSize), - (s) -> Setting.parseInt(s, 0, tempMaxQueueSizeSetting.get(settings), minSizeKey), - Setting.Property.NodeScope); + minSizeKey, + Integer.toString(minQueueSize), + (s) -> Setting.parseInt(s, 0, minSizeKey), + new Setting.Validator() { + @Override + public void validate(Integer value, Map, Integer> settings) { + if (value > settings.get(tempMaxQueueSizeSetting)) { + throw new IllegalArgumentException("Failed to parse value [" + value + "] for setting [" + minSizeKey + + "] must be <= " + settings.get(tempMaxQueueSizeSetting)); + } + } + + @Override + public Iterator> settings() { + return Arrays.asList(tempMaxQueueSizeSetting).iterator(); + } + }, + Setting.Property.NodeScope); this.maxQueueSizeSetting = new Setting<>( maxSizeKey, - (s) -> Integer.toString(maxQueueSize), - (s) -> Setting.parseInt(s, tempMinQueueSizeSetting.get(settings), Integer.MAX_VALUE, maxSizeKey), + Integer.toString(maxQueueSize), + (s) -> Setting.parseInt(s, 0, maxSizeKey), + new Setting.Validator() { + @Override + public void validate(Integer value, Map, Integer> settings) { + if (value < settings.get(tempMinQueueSizeSetting)) { + throw new IllegalArgumentException("Failed to parse value [" + value + "] for setting [" + minSizeKey + + "] must be >= " + settings.get(tempMinQueueSizeSetting)); + } + } + + @Override + public Iterator> settings() { + return Arrays.asList(tempMinQueueSizeSetting).iterator(); + } + }, Setting.Property.NodeScope); this.frameSizeSetting = Setting.intSetting(frameSizeKey, frameSize, 100, Setting.Property.NodeScope); } @@ -141,12 +171,12 @@ public final class AutoQueueAdjustingExecutorBuilder extends ExecutorBuilder