Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/138122.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 138122
summary: Add validation for updating `num_threads`
area: Machine Learning
type: bug
issues:
- 137129
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ public ElasticsearchInternalServiceSettings updateServiceSettings(Map<String, Ob
var validationException = new ValidationException();
var mutableServiceSettings = new HashMap<>(serviceSettings);

if (serviceSettings.containsKey(NUM_THREADS)) {
validationException.addValidationError(Strings.format("[%s] cannot be updated", NUM_THREADS));
}

var numAllocations = extractOptionalPositiveInteger(
mutableServiceSettings,
NUM_ALLOCATIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.ValidationException;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.logging.DeprecationLogger;
Expand Down Expand Up @@ -2205,6 +2206,17 @@ public void test_providedTimeoutPropagateProperly() throws InterruptedException
assertEquals(providedTimeout, requestCaptor.getValue().getInferenceTimeout());
}

public void testUpdateServiceSettings_ThrowsExceptionWhenNumThreadsIsUpdated() {
var existingSettings = new ElasticsearchInternalServiceSettings(1, 4, "test-model", null, null);

Map<String, Object> serviceSettingsWithNumThreads = Map.of(ElasticsearchInternalServiceSettings.NUM_THREADS, 8);
var exception = expectThrows(
ValidationException.class,
() -> existingSettings.updateServiceSettings(serviceSettingsWithNumThreads)
);
assertThat(exception.getMessage(), containsString("[num_threads] cannot be updated"));
}

private ElasticsearchInternalService createService(Client client) {
var cs = mock(ClusterService.class);
var cSettings = new ClusterSettings(Settings.EMPTY, Set.of(MachineLearningField.MAX_LAZY_ML_NODES));
Expand Down