Skip to content

Commit 0f2f00a

Browse files
author
David Roberts
authored
[ML] Resolve 7.0.0 TODOs in ML code (#36842)
This change cleans up a number of ugly BWC workarounds in the ML code. 7.0 cannot run in a mixed version cluster with versions prior to 6.7, so code that deals with these old versions is no longer required. Closes #29963
1 parent 1236461 commit 0f2f00a

File tree

18 files changed

+78
-247
lines changed

18 files changed

+78
-247
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public class OpenJobAction extends Action<AcknowledgedResponse> {
3939
public static final OpenJobAction INSTANCE = new OpenJobAction();
4040
public static final String NAME = "cluster:admin/xpack/ml/job/open";
4141

42-
4342
private OpenJobAction() {
4443
super(NAME);
4544
}
@@ -132,15 +131,12 @@ public String toString() {
132131

133132
public static class JobParams implements XPackPlugin.XPackPersistentTaskParams {
134133

135-
/** TODO Remove in 7.0.0 */
136-
public static final ParseField IGNORE_DOWNTIME = new ParseField("ignore_downtime");
137134
public static final ParseField TIMEOUT = new ParseField("timeout");
138135
public static final ParseField JOB = new ParseField("job");
139136

140137
public static ObjectParser<JobParams, Void> PARSER = new ObjectParser<>(MlTasks.JOB_TASK_NAME, true, JobParams::new);
141138
static {
142139
PARSER.declareString(JobParams::setJobId, Job.ID);
143-
PARSER.declareBoolean((p, v) -> {}, IGNORE_DOWNTIME);
144140
PARSER.declareString((params, val) ->
145141
params.setTimeout(TimeValue.parseTimeValue(val, TIMEOUT.getPreferredName())), TIMEOUT);
146142
PARSER.declareObject(JobParams::setJob, (p, c) -> Job.LENIENT_PARSER.apply(p, c).build(), JOB);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfig.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ public class DatafeedConfig extends AbstractDiffable<DatafeedConfig> implements
130130
public static final ParseField AGGREGATIONS = new ParseField("aggregations");
131131
public static final ParseField AGGS = new ParseField("aggs");
132132
public static final ParseField SCRIPT_FIELDS = new ParseField("script_fields");
133-
public static final ParseField SOURCE = new ParseField("_source");
134133
public static final ParseField CHUNKING_CONFIG = new ParseField("chunking_config");
135134
public static final ParseField HEADERS = new ParseField("headers");
136135
public static final ParseField DELAYED_DATA_CHECK_CONFIG = new ParseField("delayed_data_check_config");
@@ -185,9 +184,6 @@ private static ObjectParser<Builder, Void> createParser(boolean ignoreUnknownFie
185184
return parsedScriptFields;
186185
}, SCRIPT_FIELDS);
187186
parser.declareInt(Builder::setScrollSize, SCROLL_SIZE);
188-
// TODO this is to read former _source field. Remove in v7.0.0
189-
parser.declareBoolean((builder, value) -> {
190-
}, SOURCE);
191187
parser.declareObject(Builder::setChunkingConfig, ignoreUnknownFields ? ChunkingConfig.LENIENT_PARSER : ChunkingConfig.STRICT_PARSER,
192188
CHUNKING_CONFIG);
193189

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/AnalysisConfig.java

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -136,30 +136,7 @@ public AnalysisConfig(StreamInput in) throws IOException {
136136
detectors = Collections.unmodifiableList(in.readList(Detector::new));
137137
influencers = Collections.unmodifiableList(in.readList(StreamInput::readString));
138138

139-
// BWC for result_finalization_window and overlapping_buckets
140-
// TODO Remove in 7.0.0
141-
if (in.getVersion().before(Version.V_6_6_0)) {
142-
in.readOptionalBoolean();
143-
in.readOptionalLong();
144-
}
145139
multivariateByFields = in.readOptionalBoolean();
146-
147-
// BWC for removed multiple_bucket_spans
148-
// TODO Remove in 7.0.0
149-
if (in.getVersion().before(Version.V_6_5_0)) {
150-
if (in.readBoolean()) {
151-
final int arraySize = in.readVInt();
152-
for (int i = 0; i < arraySize; i++) {
153-
in.readTimeValue();
154-
}
155-
}
156-
}
157-
158-
// BWC for removed per-partition normalization
159-
// TODO Remove in 7.0.0
160-
if (in.getVersion().before(Version.V_6_5_0)) {
161-
in.readBoolean();
162-
}
163140
}
164141

165142
@Override
@@ -180,25 +157,7 @@ public void writeTo(StreamOutput out) throws IOException {
180157
out.writeList(detectors);
181158
out.writeStringList(influencers);
182159

183-
// BWC for result_finalization_window and overlapping_buckets
184-
// TODO Remove in 7.0.0
185-
if (out.getVersion().before(Version.V_6_6_0)) {
186-
out.writeOptionalBoolean(null);
187-
out.writeOptionalLong(null);
188-
}
189160
out.writeOptionalBoolean(multivariateByFields);
190-
191-
// BWC for removed multiple_bucket_spans
192-
// TODO Remove in 7.0.0
193-
if (out.getVersion().before(Version.V_6_5_0)) {
194-
out.writeBoolean(false);
195-
}
196-
197-
// BWC for removed per-partition normalization
198-
// TODO Remove in 7.0.0
199-
if (out.getVersion().before(Version.V_6_5_0)) {
200-
out.writeBoolean(false);
201-
}
202161
}
203162

204163
/**

x-pack/plugin/ml/qa/basic-multi-node/src/test/java/org/elasticsearch/xpack/ml/integration/MlBasicMultiNodeIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ private Response createDatafeed(String datafeedId, String jobId) throws Exceptio
266266
xContentBuilder.field("job_id", jobId);
267267
xContentBuilder.array("indexes", "airline-data");
268268
xContentBuilder.array("types", "_doc");
269-
xContentBuilder.field("_source", true);
270269
xContentBuilder.endObject();
271270
Request request = new Request("PUT", MachineLearning.BASE_PATH + "datafeeds/" + datafeedId);
272271
request.setJsonEntity(Strings.toString(xContentBuilder));

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.cluster.metadata.IndexMetaData;
1818
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
1919
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
20+
import org.elasticsearch.cluster.node.DiscoveryNode;
2021
import org.elasticsearch.cluster.node.DiscoveryNodes;
2122
import org.elasticsearch.cluster.routing.UnassignedInfo;
2223
import org.elasticsearch.cluster.service.ClusterService;
@@ -259,7 +260,8 @@ public class MachineLearning extends Plugin implements ActionPlugin, AnalysisPlu
259260

260261
public static final Setting<Boolean> ML_ENABLED =
261262
Setting.boolSetting("node.ml", XPackSettings.MACHINE_LEARNING_ENABLED, Property.NodeScope);
262-
public static final String ML_ENABLED_NODE_ATTR = "ml.enabled";
263+
// This is not used in v7 and higher, but users are still prevented from setting it directly to avoid confusion
264+
private static final String PRE_V7_ML_ENABLED_NODE_ATTR = "ml.enabled";
263265
public static final String MAX_OPEN_JOBS_NODE_ATTR = "ml.max_open_jobs";
264266
public static final String MACHINE_MEMORY_NODE_ATTR = "ml.machine_memory";
265267
public static final Setting<Integer> CONCURRENT_JOB_ALLOCATIONS =
@@ -289,6 +291,14 @@ public MachineLearning(Settings settings, Path configPath) {
289291

290292
protected XPackLicenseState getLicenseState() { return XPackPlugin.getSharedLicenseState(); }
291293

294+
public static boolean isMlNode(DiscoveryNode node) {
295+
Map<String, String> nodeAttributes = node.getAttributes();
296+
try {
297+
return Integer.parseInt(nodeAttributes.get(MAX_OPEN_JOBS_NODE_ATTR)) > 0;
298+
} catch (NumberFormatException e) {
299+
return false;
300+
}
301+
}
292302

293303
public List<Setting<?>> getSettings() {
294304
return Collections.unmodifiableList(
@@ -299,16 +309,14 @@ public List<Setting<?>> getSettings() {
299309
MAX_LAZY_ML_NODES,
300310
MAX_MACHINE_MEMORY_PERCENT,
301311
AutodetectBuilder.DONT_PERSIST_MODEL_STATE_SETTING,
302-
AutodetectBuilder.MAX_ANOMALY_RECORDS_SETTING,
303312
AutodetectBuilder.MAX_ANOMALY_RECORDS_SETTING_DYNAMIC,
304-
AutodetectProcessManager.MAX_RUNNING_JOBS_PER_NODE,
305313
AutodetectProcessManager.MAX_OPEN_JOBS_PER_NODE,
306314
AutodetectProcessManager.MIN_DISK_SPACE_OFF_HEAP,
307315
MlConfigMigrationEligibilityCheck.ENABLE_CONFIG_MIGRATION));
308316
}
309317

310318
public Settings additionalSettings() {
311-
String mlEnabledNodeAttrName = "node.attr." + ML_ENABLED_NODE_ATTR;
319+
String mlEnabledNodeAttrName = "node.attr." + PRE_V7_ML_ENABLED_NODE_ATTR;
312320
String maxOpenJobsPerNodeNodeAttrName = "node.attr." + MAX_OPEN_JOBS_NODE_ATTR;
313321
String machineMemoryAttrName = "node.attr." + MACHINE_MEMORY_NODE_ATTR;
314322

@@ -320,12 +328,12 @@ public Settings additionalSettings() {
320328
Settings.Builder additionalSettings = Settings.builder();
321329
Boolean allocationEnabled = ML_ENABLED.get(settings);
322330
if (allocationEnabled != null && allocationEnabled) {
323-
// TODO: the simple true/false flag will not be required once all supported versions have the number - consider removing in 7.0
324-
addMlNodeAttribute(additionalSettings, mlEnabledNodeAttrName, "true");
325331
addMlNodeAttribute(additionalSettings, maxOpenJobsPerNodeNodeAttrName,
326332
String.valueOf(AutodetectProcessManager.MAX_OPEN_JOBS_PER_NODE.get(settings)));
327333
addMlNodeAttribute(additionalSettings, machineMemoryAttrName,
328334
Long.toString(machineMemoryFromStats(OsProbe.getInstance().osStats())));
335+
// This is not used in v7 and higher, but users are still prevented from setting it directly to avoid confusion
336+
disallowMlNodeAttributes(mlEnabledNodeAttrName);
329337
} else {
330338
disallowMlNodeAttributes(mlEnabledNodeAttrName, maxOpenJobsPerNodeNodeAttrName, machineMemoryAttrName);
331339
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ private int mlNodeCount(final ClusterState clusterState) {
143143

144144
int mlNodeCount = 0;
145145
for (DiscoveryNode node : clusterState.getNodes()) {
146-
String enabled = node.getAttributes().get(MachineLearning.ML_ENABLED_NODE_ATTR);
147-
if (Boolean.parseBoolean(enabled)) {
146+
if (MachineLearning.isMlNode(node)) {
148147
++mlNodeCount;
149148
}
150149
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,7 @@ private void deleteQuantiles(ParentTaskAssigningClient parentTaskClient, String
399399
// The quantiles type and doc ID changed in v5.5 so delete both the old and new format
400400
DeleteByQueryRequest request = new DeleteByQueryRequest(AnomalyDetectorsIndex.jobStateIndexName());
401401
// Just use ID here, not type, as trying to delete different types spams the logs with an exception stack trace
402-
IdsQueryBuilder query = new IdsQueryBuilder().addIds(Quantiles.documentId(jobId),
403-
// TODO: remove in 7.0
404-
Quantiles.v54DocumentId(jobId));
402+
IdsQueryBuilder query = new IdsQueryBuilder().addIds(Quantiles.documentId(jobId));
405403
request.setQuery(query);
406404
request.setIndicesOptions(MlIndicesUtils.addIgnoreUnavailable(IndicesOptions.lenientExpandOpen()));
407405
request.setAbortOnVersionConflict(false);
@@ -436,9 +434,7 @@ private void deleteCategorizerState(ParentTaskAssigningClient parentTaskClient,
436434
// The categorizer state type and doc ID changed in v5.5 so delete both the old and new format
437435
DeleteByQueryRequest request = new DeleteByQueryRequest(AnomalyDetectorsIndex.jobStateIndexName());
438436
// Just use ID here, not type, as trying to delete different types spams the logs with an exception stack trace
439-
IdsQueryBuilder query = new IdsQueryBuilder().addIds(CategorizerState.documentId(jobId, docNum),
440-
// TODO: remove in 7.0
441-
CategorizerState.v54DocumentId(jobId, docNum));
437+
IdsQueryBuilder query = new IdsQueryBuilder().addIds(CategorizerState.documentId(jobId, docNum));
442438
request.setQuery(query);
443439
request.setIndicesOptions(MlIndicesUtils.addIgnoreUnavailable(IndicesOptions.lenientExpandOpen()));
444440
request.setAbortOnVersionConflict(false);

0 commit comments

Comments
 (0)