Skip to content

Commit 23008be

Browse files
authored
[ML] Simplify minimum supported snapshot version handling for Machine Learning jobs (#118549)
Since in 9.0 we don't need to support snapshots prior to 7.17, we can simplify the changes made in #81039 and re-introduce a single contant to manage the minimum supported snapshot version.
1 parent 1b4f5eb commit 23008be

File tree

6 files changed

+13
-20
lines changed

6 files changed

+13
-20
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,8 @@ public final class MachineLearningField {
6464
License.OperationMode.PLATINUM
6565
);
6666

67-
// Ideally this would be 7.0.0, but it has to be 6.4.0 because due to an oversight it's impossible
68-
// for the Java code to distinguish the model states for versions 6.4.0 to 7.9.3 inclusive.
69-
public static final MlConfigVersion MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION = MlConfigVersion.fromString("6.4.0");
70-
// We tell the user we support model snapshots newer than 7.0.0 as that's the major version
71-
// boundary, even though behind the scenes we have to support back to 6.4.0.
72-
public static final MlConfigVersion MIN_REPORTED_SUPPORTED_SNAPSHOT_VERSION = MlConfigVersion.V_7_0_0;
67+
// This is the last version when we changed the ML job snapshot format.
68+
public static final MlConfigVersion MIN_SUPPORTED_SNAPSHOT_VERSION = MlConfigVersion.V_8_3_0;
7369

7470
private MachineLearningField() {}
7571

x-pack/plugin/deprecation/qa/rest/src/javaRestTest/java/org/elasticsearch/xpack/deprecation/MlDeprecationIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void testMlDeprecationChecks() throws Exception {
6363
indexDoc(
6464
".ml-anomalies-.write-" + jobId,
6565
jobId + "_model_snapshot_2",
66-
"{\"job_id\":\"deprecation_check_job\",\"snapshot_id\":\"2\",\"snapshot_doc_count\":1,\"min_version\":\"8.0.0\"}"
66+
"{\"job_id\":\"deprecation_check_job\",\"snapshot_id\":\"2\",\"snapshot_doc_count\":1,\"min_version\":\"8.3.0\"}"
6767
);
6868
client().performRequest(new Request("POST", "/.ml-anomalies-*/_refresh"));
6969

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/MlDeprecationChecker.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
import java.util.Map;
2727
import java.util.Optional;
2828

29-
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION;
30-
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_REPORTED_SUPPORTED_SNAPSHOT_VERSION;
29+
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_SUPPORTED_SNAPSHOT_VERSION;
3130

3231
public class MlDeprecationChecker implements DeprecationChecker {
3332

@@ -69,13 +68,13 @@ static Optional<DeprecationIssue> checkDataFeedAggregations(DatafeedConfig dataf
6968
}
7069

7170
static Optional<DeprecationIssue> checkModelSnapshot(ModelSnapshot modelSnapshot) {
72-
if (modelSnapshot.getMinVersion().before(MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION)) {
71+
if (modelSnapshot.getMinVersion().before(MIN_SUPPORTED_SNAPSHOT_VERSION)) {
7372
StringBuilder details = new StringBuilder(
7473
String.format(
7574
Locale.ROOT,
7675
"Delete model snapshot [%s] or update it to %s or greater.",
7776
modelSnapshot.getSnapshotId(),
78-
MIN_REPORTED_SUPPORTED_SNAPSHOT_VERSION
77+
MIN_SUPPORTED_SNAPSHOT_VERSION
7978
)
8079
);
8180
if (modelSnapshot.getLatestRecordTimeStamp() != null) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public void testOpenJobWithOldSnapshot() {
195195
assertThat(
196196
ex.getMessage(),
197197
containsString(
198-
"[open-job-with-old-model-snapshot] job model snapshot [snap_1] has min version before [7.0.0], "
198+
"[open-job-with-old-model-snapshot] job model snapshot [snap_1] has min version before [8.3.0], "
199199
+ "please revert to a newer model snapshot or reset the job"
200200
)
201201
);

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@
5858

5959
import static org.elasticsearch.core.Strings.format;
6060
import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN;
61-
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION;
62-
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_REPORTED_SUPPORTED_SNAPSHOT_VERSION;
61+
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_SUPPORTED_SNAPSHOT_VERSION;
6362
import static org.elasticsearch.xpack.ml.job.task.OpenJobPersistentTasksExecutor.checkAssignmentState;
6463

6564
/*
@@ -214,7 +213,7 @@ public void onFailure(Exception e) {
214213
return;
215214
}
216215
assert modelSnapshot.getPage().results().size() == 1;
217-
if (modelSnapshot.getPage().results().get(0).getMinVersion().onOrAfter(MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION)) {
216+
if (modelSnapshot.getPage().results().get(0).getMinVersion().onOrAfter(MIN_SUPPORTED_SNAPSHOT_VERSION)) {
218217
modelSnapshotValidationListener.onResponse(true);
219218
return;
220219
}
@@ -224,7 +223,7 @@ public void onFailure(Exception e) {
224223
+ "please revert to a newer model snapshot or reset the job",
225224
jobParams.getJobId(),
226225
jobParams.getJob().getModelSnapshotId(),
227-
MIN_REPORTED_SUPPORTED_SNAPSHOT_VERSION.toString()
226+
MIN_SUPPORTED_SNAPSHOT_VERSION.toString()
228227
)
229228
);
230229
}, failure -> {

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/task/OpenJobPersistentTasksExecutor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@
7373
import static org.elasticsearch.core.Strings.format;
7474
import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN;
7575
import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin;
76-
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION;
77-
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_REPORTED_SUPPORTED_SNAPSHOT_VERSION;
76+
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_SUPPORTED_SNAPSHOT_VERSION;
7877
import static org.elasticsearch.xpack.core.ml.MlTasks.AWAITING_UPGRADE;
7978
import static org.elasticsearch.xpack.core.ml.MlTasks.PERSISTENT_TASK_MASTER_NODE_TIMEOUT;
8079
import static org.elasticsearch.xpack.ml.job.JobNodeSelector.AWAITING_LAZY_ASSIGNMENT;
@@ -436,7 +435,7 @@ private void verifyCurrentSnapshotVersion(String jobId, ActionListener<Boolean>
436435
}
437436
assert snapshot.getPage().results().size() == 1;
438437
ModelSnapshot snapshotObj = snapshot.getPage().results().get(0);
439-
if (snapshotObj.getMinVersion().onOrAfter(MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION)) {
438+
if (snapshotObj.getMinVersion().onOrAfter(MIN_SUPPORTED_SNAPSHOT_VERSION)) {
440439
listener.onResponse(true);
441440
return;
442441
}
@@ -446,7 +445,7 @@ private void verifyCurrentSnapshotVersion(String jobId, ActionListener<Boolean>
446445
+ "please revert to a newer model snapshot or reset the job",
447446
jobId,
448447
jobSnapshotId,
449-
MIN_REPORTED_SUPPORTED_SNAPSHOT_VERSION.toString()
448+
MIN_SUPPORTED_SNAPSHOT_VERSION.toString()
450449
)
451450
);
452451
}, snapshotFailure -> {

0 commit comments

Comments
 (0)