forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE][ML] Add cluster setting that enables/disables config migration
This commit adds a cluster settings called `xpack.ml.enable_config_migration`. The setting is `true` by default. When set to `false`, no config migration will be attempted and non-migrated resources (e.g. jobs, datafeeds) will be able to be updated normally. Relates elastic#32905
- Loading branch information
1 parent
28b99f0
commit 6aeaad1
Showing
15 changed files
with
559 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlConfigMigrationEligibilityCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.ml; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.settings.Setting; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.persistent.PersistentTasksCustomMetaData; | ||
import org.elasticsearch.xpack.core.ml.MlMetadata; | ||
import org.elasticsearch.xpack.core.ml.MlTasks; | ||
import org.elasticsearch.xpack.core.ml.job.config.Job; | ||
|
||
/** | ||
* Checks whether migration can start and whether ML resources (e.g. jobs, datafeeds) | ||
* are eligible to be migrated from the cluster state into the config index | ||
*/ | ||
public class MlConfigMigrationEligibilityCheck { | ||
|
||
private static final Version MIN_NODE_VERSION = Version.V_6_6_0; | ||
|
||
public static final Setting<Boolean> ENABLE_CONFIG_MIGRATION = Setting.boolSetting( | ||
"xpack.ml.enable_config_migration", true, Setting.Property.Dynamic, Setting.Property.NodeScope); | ||
|
||
private volatile boolean isConfigMigrationEnabled; | ||
|
||
public MlConfigMigrationEligibilityCheck(Settings settings, ClusterService clusterService) { | ||
isConfigMigrationEnabled = ENABLE_CONFIG_MIGRATION.get(settings); | ||
clusterService.getClusterSettings().addSettingsUpdateConsumer(ENABLE_CONFIG_MIGRATION, this::setConfigMigrationEnabled); | ||
} | ||
|
||
private void setConfigMigrationEnabled(boolean configMigrationEnabled) { | ||
this.isConfigMigrationEnabled = configMigrationEnabled; | ||
} | ||
|
||
/** | ||
* Can migration start? Returns: | ||
* False if config migration is disabled via the setting {@link #ENABLE_CONFIG_MIGRATION} | ||
* False if the min node version of the cluster is before {@link #MIN_NODE_VERSION} | ||
* True otherwise | ||
* @param clusterState The cluster state | ||
* @return A boolean that dictates if config migration can start | ||
*/ | ||
public boolean canStartMigration(ClusterState clusterState) { | ||
if (isConfigMigrationEnabled == false) { | ||
return false; | ||
} | ||
|
||
Version minNodeVersion = clusterState.nodes().getMinNodeVersion(); | ||
if (minNodeVersion.before(MIN_NODE_VERSION)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Is the job a eligible for migration? Returns: | ||
* False if {@link #canStartMigration(ClusterState)} returns {@code false} | ||
* False if the {@link Job#isDeleting()} | ||
* False if the job has a persistent task | ||
* True otherwise i.e. the job is present, not deleting | ||
* and does not have a persistent task. | ||
* | ||
* @param jobId The job Id | ||
* @param clusterState The cluster state | ||
* @return A boolean depending on the conditions listed above | ||
*/ | ||
public boolean jobIsEligibleForMigration(String jobId, ClusterState clusterState) { | ||
if (canStartMigration(clusterState) == false) { | ||
return false; | ||
} | ||
|
||
MlMetadata mlMetadata = MlMetadata.getMlMetadata(clusterState); | ||
Job job = mlMetadata.getJobs().get(jobId); | ||
|
||
if (job == null || job.isDeleting()) { | ||
return false; | ||
} | ||
|
||
PersistentTasksCustomMetaData persistentTasks = clusterState.metaData().custom(PersistentTasksCustomMetaData.TYPE); | ||
return MlTasks.openJobIds(persistentTasks).contains(jobId) == false; | ||
} | ||
|
||
/** | ||
* Is the datafeed a eligible for migration? Returns: | ||
* False if {@link #canStartMigration(ClusterState)} returns {@code false} | ||
* False if the datafeed is not in the cluster state | ||
* False if the datafeed has a persistent task | ||
* True otherwise i.e. the datafeed is present and does not have a persistent task. | ||
* | ||
* @param datafeedId The datafeed Id | ||
* @param clusterState The cluster state | ||
* @return A boolean depending on the conditions listed above | ||
*/ | ||
public boolean datafeedIsEligibleForMigration(String datafeedId, ClusterState clusterState) { | ||
if (canStartMigration(clusterState) == false) { | ||
return false; | ||
} | ||
|
||
MlMetadata mlMetadata = MlMetadata.getMlMetadata(clusterState); | ||
if (mlMetadata.getDatafeeds().containsKey(datafeedId) == false) { | ||
return false; | ||
} | ||
|
||
PersistentTasksCustomMetaData persistentTasks = clusterState.metaData().custom(PersistentTasksCustomMetaData.TYPE); | ||
return MlTasks.startedDatafeedIds(persistentTasks).contains(datafeedId) == false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.