Skip to content

Commit

Permalink
[ML] Simplify minimum supported snapshot version handling for Machine…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
valeriy42 authored Dec 13, 2024
1 parent 1b4f5eb commit 23008be
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,8 @@ public final class MachineLearningField {
License.OperationMode.PLATINUM
);

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

private MachineLearningField() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void testMlDeprecationChecks() throws Exception {
indexDoc(
".ml-anomalies-.write-" + jobId,
jobId + "_model_snapshot_2",
"{\"job_id\":\"deprecation_check_job\",\"snapshot_id\":\"2\",\"snapshot_doc_count\":1,\"min_version\":\"8.0.0\"}"
"{\"job_id\":\"deprecation_check_job\",\"snapshot_id\":\"2\",\"snapshot_doc_count\":1,\"min_version\":\"8.3.0\"}"
);
client().performRequest(new Request("POST", "/.ml-anomalies-*/_refresh"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
import java.util.Map;
import java.util.Optional;

import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION;
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_REPORTED_SUPPORTED_SNAPSHOT_VERSION;
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_SUPPORTED_SNAPSHOT_VERSION;

public class MlDeprecationChecker implements DeprecationChecker {

Expand Down Expand Up @@ -69,13 +68,13 @@ static Optional<DeprecationIssue> checkDataFeedAggregations(DatafeedConfig dataf
}

static Optional<DeprecationIssue> checkModelSnapshot(ModelSnapshot modelSnapshot) {
if (modelSnapshot.getMinVersion().before(MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION)) {
if (modelSnapshot.getMinVersion().before(MIN_SUPPORTED_SNAPSHOT_VERSION)) {
StringBuilder details = new StringBuilder(
String.format(
Locale.ROOT,
"Delete model snapshot [%s] or update it to %s or greater.",
modelSnapshot.getSnapshotId(),
MIN_REPORTED_SUPPORTED_SNAPSHOT_VERSION
MIN_SUPPORTED_SNAPSHOT_VERSION
)
);
if (modelSnapshot.getLatestRecordTimeStamp() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void testOpenJobWithOldSnapshot() {
assertThat(
ex.getMessage(),
containsString(
"[open-job-with-old-model-snapshot] job model snapshot [snap_1] has min version before [7.0.0], "
"[open-job-with-old-model-snapshot] job model snapshot [snap_1] has min version before [8.3.0], "
+ "please revert to a newer model snapshot or reset the job"
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@

import static org.elasticsearch.core.Strings.format;
import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN;
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION;
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_REPORTED_SUPPORTED_SNAPSHOT_VERSION;
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_SUPPORTED_SNAPSHOT_VERSION;
import static org.elasticsearch.xpack.ml.job.task.OpenJobPersistentTasksExecutor.checkAssignmentState;

/*
Expand Down Expand Up @@ -214,7 +213,7 @@ public void onFailure(Exception e) {
return;
}
assert modelSnapshot.getPage().results().size() == 1;
if (modelSnapshot.getPage().results().get(0).getMinVersion().onOrAfter(MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION)) {
if (modelSnapshot.getPage().results().get(0).getMinVersion().onOrAfter(MIN_SUPPORTED_SNAPSHOT_VERSION)) {
modelSnapshotValidationListener.onResponse(true);
return;
}
Expand All @@ -224,7 +223,7 @@ public void onFailure(Exception e) {
+ "please revert to a newer model snapshot or reset the job",
jobParams.getJobId(),
jobParams.getJob().getModelSnapshotId(),
MIN_REPORTED_SUPPORTED_SNAPSHOT_VERSION.toString()
MIN_SUPPORTED_SNAPSHOT_VERSION.toString()
)
);
}, failure -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@
import static org.elasticsearch.core.Strings.format;
import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN;
import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin;
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION;
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_REPORTED_SUPPORTED_SNAPSHOT_VERSION;
import static org.elasticsearch.xpack.core.ml.MachineLearningField.MIN_SUPPORTED_SNAPSHOT_VERSION;
import static org.elasticsearch.xpack.core.ml.MlTasks.AWAITING_UPGRADE;
import static org.elasticsearch.xpack.core.ml.MlTasks.PERSISTENT_TASK_MASTER_NODE_TIMEOUT;
import static org.elasticsearch.xpack.ml.job.JobNodeSelector.AWAITING_LAZY_ASSIGNMENT;
Expand Down Expand Up @@ -436,7 +435,7 @@ private void verifyCurrentSnapshotVersion(String jobId, ActionListener<Boolean>
}
assert snapshot.getPage().results().size() == 1;
ModelSnapshot snapshotObj = snapshot.getPage().results().get(0);
if (snapshotObj.getMinVersion().onOrAfter(MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION)) {
if (snapshotObj.getMinVersion().onOrAfter(MIN_SUPPORTED_SNAPSHOT_VERSION)) {
listener.onResponse(true);
return;
}
Expand All @@ -446,7 +445,7 @@ private void verifyCurrentSnapshotVersion(String jobId, ActionListener<Boolean>
+ "please revert to a newer model snapshot or reset the job",
jobId,
jobSnapshotId,
MIN_REPORTED_SUPPORTED_SNAPSHOT_VERSION.toString()
MIN_SUPPORTED_SNAPSHOT_VERSION.toString()
)
);
}, snapshotFailure -> {
Expand Down

0 comments on commit 23008be

Please sign in to comment.