Skip to content

Commit 74d92ae

Browse files
committed
* Clarified documentation regarding results_index_rollover_max_size
* Added the ability to set results_index_rollover_max_size to -1B to configure the nightly maintenance task not to trigger indices rollover
1 parent 58540ae commit 74d92ae

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

docs/reference/elasticsearch/configuration-reference/machine-learning-settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ $$$xpack.ml.max_open_jobs$$$
8787
: ([Dynamic](docs-content://deploy-manage/stack-settings.md#dynamic-cluster-setting)) The rate at which the nightly maintenance task deletes expired model snapshots and results. The setting is a proxy to the [`requests_per_second`](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-delete-by-query) parameter used in the delete by query requests and controls throttling. When the {{operator-feature}} is enabled, this setting can be updated only by operator users. Valid values must be greater than `0.0` or equal to `-1.0`, where `-1.0` means a default value is used. Defaults to `-1.0`
8888

8989
`xpack.ml.results_index_rollover_max_size`
90-
: ([Dynamic](docs-content://deploy-manage/stack-settings.md#dynamic-cluster-setting)) The maximum size the anomaly detection results indices can reach before being rolled over by the nightly maintenance task. When the {{operator-feature}} is enabled, this setting can be updated only by operator users. Valid values must be greater than or equal to `0B`. A value of `0B` means the indices will always be rolled over. Defaults to `50GB`.
90+
: ([Dynamic](docs-content://deploy-manage/stack-settings.md#dynamic-cluster-setting)) The maximum size the anomaly detection results indices can reach before being rolled over by the nightly maintenance task. When the {{operator-feature}} is enabled, this setting can be updated only by operator users. Valid values must be greater than or equal to `-1B`. A value of `-1B` means the indices will never be rolled over. A value of `0B` means the indices will always be rolled over, regardless of size. Defaults to `50GB`.
9191

9292
`xpack.ml.node_concurrent_job_allocations`
9393
: ([Dynamic](docs-content://deploy-manage/stack-settings.md#dynamic-cluster-setting)) The maximum number of jobs that can concurrently be in the `opening` state on each node. Typically, jobs spend a small amount of time in this state before they move to `open` state. Jobs that must restore large models when they are opening spend more time in the `opening` state. When the {{operator-feature}} is enabled, this setting can be updated only by operator users. Defaults to `2`.

x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlDailyMaintenanceServiceRolloverResultsIndicesIT.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@ public void testTriggerRollResultsIndicesIfNecessaryTask_givenNoIndices() throws
102102
}
103103
}
104104

105+
public void testTriggerRollResultsIndicesIfNecessaryTask_givenMinusOnRolloverMaxSize() throws Exception {
106+
// The null case, nothing to do.
107+
108+
// set the rollover max size to -1B so the indices should not be rolled over
109+
maintenanceService.setRolloverMaxSize(ByteSizeValue.MINUS_ONE);
110+
111+
// Create jobs that will use the default results indices - ".ml-anomalies-shared-*"
112+
Job.Builder[] jobs_with_default_index = { createJob("job_using_default_index"), createJob("another_job_using_default_index") };
113+
114+
// Create jobs that will use custom results indices - ".ml-anomalies-custom-fred-*"
115+
Job.Builder[] jobs_with_custom_index = {
116+
createJob("job_using_custom_index").setResultsIndexName("fred"),
117+
createJob("another_job_using_custom_index").setResultsIndexName("fred") };
118+
119+
runTestScenarioWithNoRolloverOccurring(jobs_with_default_index, "shared");
120+
runTestScenarioWithNoRolloverOccurring(jobs_with_custom_index, "custom-fred");
121+
}
122+
105123
public void testTriggerRollResultsIndicesIfNecessaryTask_givenUnmetConditions() throws Exception {
106124
// Create jobs that will use the default results indices - ".ml-anomalies-shared-*"
107125
Job.Builder[] jobs_with_default_index = { createJob("job_using_default_index"), createJob("another_job_using_default_index") };
@@ -111,8 +129,8 @@ public void testTriggerRollResultsIndicesIfNecessaryTask_givenUnmetConditions()
111129
createJob("job_using_custom_index").setResultsIndexName("fred"),
112130
createJob("another_job_using_custom_index").setResultsIndexName("fred") };
113131

114-
runTestScenarioWithUnmetConditions(jobs_with_default_index, "shared");
115-
runTestScenarioWithUnmetConditions(jobs_with_custom_index, "custom-fred");
132+
runTestScenarioWithNoRolloverOccurring(jobs_with_default_index, "shared");
133+
runTestScenarioWithNoRolloverOccurring(jobs_with_custom_index, "custom-fred");
116134
}
117135

118136
public void testTriggerRollResultsIndicesIfNecessaryTask_withMixedIndexTypes() throws Exception {
@@ -207,7 +225,7 @@ public void testTriggerRollResultsIndicesIfNecessaryTask() throws Exception {
207225
runTestScenario(jobs_with_custom_index, "custom-fred");
208226
}
209227

210-
private void runTestScenarioWithUnmetConditions(Job.Builder[] jobs, String indexNamePart) throws Exception {
228+
private void runTestScenarioWithNoRolloverOccurring(Job.Builder[] jobs, String indexNamePart) throws Exception {
211229
String firstJobId = jobs[0].getId();
212230
String secondJobId = jobs[1].getId();
213231
String indexWildcard = AnomalyDetectorsIndex.jobResultsIndexPrefix() + indexNamePart + "*";

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ public void loadExtensions(ExtensionLoader loader) {
722722
public static final Setting<ByteSizeValue> RESULTS_INDEX_ROLLOVER_MAX_SIZE = Setting.byteSizeSetting(
723723
"xpack.ml.results_index_rollover_max_size",
724724
ByteSizeValue.of(50, ByteSizeUnit.GB),
725-
ByteSizeValue.ofBytes(0L),
725+
ByteSizeValue.ofBytes(-1L),
726726
ByteSizeValue.ofBytes(Long.MAX_VALUE),
727727
Property.OperatorDynamic,
728728
Property.NodeScope

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlDailyMaintenanceService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@
8181
*/
8282
public class MlDailyMaintenanceService implements Releasable {
8383

84-
// The service to use for creating log messages.
8584
private static final Logger logger = LogManager.getLogger(MlDailyMaintenanceService.class);
8685

86+
// The maximum value of a random offset used to calculate the time the nightly maintenance tasks are triggered on a given cluster.
87+
// This is added in order to avoid multiple clusters running the maintenance tasks at the same time.
8788
private static final int MAX_TIME_OFFSET_MINUTES = 120;
8889

8990
private final ThreadPool threadPool;
@@ -419,7 +420,7 @@ public void triggerRollResultsIndicesIfNecessaryTask(ActionListener<Acknowledged
419420
ClusterState clusterState = clusterService.state();
420421

421422
String[] indices = findIndicesNeedingRollover(clusterState);
422-
if (indices.length == 0) {
423+
if (rolloverMaxSize == ByteSizeValue.MINUS_ONE || indices.length == 0) {
423424
// Early bath
424425
finalListener.onResponse(AcknowledgedResponse.TRUE);
425426
return;

0 commit comments

Comments
 (0)