Skip to content

[ML] Simplify minimum supported snapshot version handling for Machine Learning jobs #118549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 13, 2024
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
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