Skip to content
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

[ML] Migrate unallocated jobs and datafeeds #37430

Merged
merged 11 commits into from Jan 15, 2019

Conversation

davidkyle
Copy link
Member

@davidkyle davidkyle commented Jan 14, 2019

The final step of the process of migrating ml configs in #32905. This change migrates jobs & datafeed configs of open jobs once the persistent task becomes unallocated, the persistent task parameters must be updated for open jobs.

  1. Prevent allocation of job tasks where the task parameters have not been updated.
    OpenJobPersistentTasksExecutor.getAssignment will not assign a task that has the missing parameters
  2. Change MlConfigMigrator to also migrate the configs of unallocated jobs & datafeeds
  3. In the clusterstate update where configs are removed from MlMetadata also update the persistent task parameters of the unallocated tasks

I've made this a non issue for the docs as the backport in #37536 will document the change

@davidkyle davidkyle added v7.0.0 :ml Machine learning v6.7.0 labels Jan 14, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/ml-core

@davidkyle davidkyle mentioned this pull request Jan 14, 2019
43 tasks
public static Set<String> unallocatedJobIds(@Nullable PersistentTasksCustomMetaData tasks,
DiscoveryNodes nodes) {
return unallocatedJobTasks(tasks, nodes).stream()
.map(task ->task.getId().substring(JOB_TASK_ID_PREFIX.length()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#nit

Suggested change
.map(task ->task.getId().substring(JOB_TASK_ID_PREFIX.length()))
.map(task -> task.getId().substring(JOB_TASK_ID_PREFIX.length()))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be the macbook butterfly keyboard. Thanks apple I don't need the space bar much

@Nullable PersistentTasksCustomMetaData tasks,
DiscoveryNodes nodes) {
if (tasks == null) {
return Collections.emptySet();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#nit so that the collection type is the same as the return below.

Suggested change
return Collections.emptySet();
return Collections.emptyList();

@Nullable PersistentTasksCustomMetaData tasks,
DiscoveryNodes nodes) {
if (tasks == null) {
return Collections.emptySet();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#nit so that the collection type is the same as the return below.

Suggested change
return Collections.emptySet();
return Collections.emptyList();

@@ -215,13 +221,17 @@ public void writeConfigToIndex(Collection<DatafeedConfig> datafeedsToMigrate,
);
}

private void removeFromClusterState(List<String> jobsToRemoveIds, List<String> datafeedsToRemoveIds,
private void removeFromClusterState(List<Job> jobsToRemoveIds, List<DatafeedConfig> datafeedsToRemoveIds,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#nit naming change

Suggested change
private void removeFromClusterState(List<Job> jobsToRemoveIds, List<DatafeedConfig> datafeedsToRemoveIds,
private void removeFromClusterState(List<Job> jobsToRemove, List<DatafeedConfig> datafeedsToRemove,

* @param nodes The nodes in the cluster
* @return The argument {@code currentTasks}
*/
public static PersistentTasksCustomMetaData rewritePersistentTaskParams(Map<String, Job> jobs, Map<String, DatafeedConfig>datafeeds,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static PersistentTasksCustomMetaData rewritePersistentTaskParams(Map<String, Job> jobs, Map<String, DatafeedConfig>datafeeds,
public static PersistentTasksCustomMetaData rewritePersistentTaskParams(Map<String, Job> jobs, Map<String, DatafeedConfig> datafeeds,

Job job = jobs.get(params.getJobId());
if (job != null) {
logger.debug("updating persistent task params for job [{}]", params.getJobId());
params.setJob(job);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure it's acceptable to update the parameters on currentTasks? I'm not convinced that it is, because it's changing the current local cluster state. It means this node's opinion of the cluster state version N will be different from all the other nodes. And version N+1 may not even get broadcast to other nodes if the local node thinks it's identical to version N.

Unless I'm mistaken, I think you need to build a new PersistentTasksCustomMetaData object rather than updating the one from current state.

(Same problem for datafeeds immediately below. And we should look at making JobParams and DatafeedParams immutable like our other cluster state classes in a followup.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same reservations hence all the javadoc comments. There is an assertion in the full cluster restart test that the task params are actually updated so it does appear to work.

Object jobParam = XContentMapValues.extractValue("task.xpack/ml/job.params.job", task);

However reviewing PersistentTasksCustomMetaData uses the default implementation of AbstractNamedDiffable.readDiffFrom which returns the entire object and the TODO here https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/persistent/PersistentTasksCustomMetaData.java#L66 suggests that will not always be the case. Good catch I can't remember why I didn't use the builder in the first place

Copy link
Contributor

@droberts195 droberts195 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@davidkyle
Copy link
Member Author

I pushed a change to use the task builder and modify a copy of the task params.

Making JobParams and DatafeedParams immutable is more involved as they have setters that are used in many places. The problem is that those objects are use in the requests not just as persistent task parameters.

@davidkyle davidkyle merged commit bea46f7 into elastic:master Jan 15, 2019
@davidkyle davidkyle deleted the migrate-unallocated branch January 15, 2019 18:21
davidkyle added a commit to davidkyle/elasticsearch that referenced this pull request Jan 16, 2019
Migrate ml job and datafeed config of open jobs and update
the parameters of the persistent tasks as they become unallocated
during a rolling upgrade. Block allocation of ml persistent tasks
until the configs are migrated.
@davidkyle davidkyle removed the v6.7.0 label Jan 16, 2019
davidkyle added a commit to davidkyle/elasticsearch that referenced this pull request Jan 23, 2019
Migrate ml job and datafeed config of open jobs and update
the parameters of the persistent tasks as they become unallocated
during a rolling upgrade. Block allocation of ml persistent tasks
until the configs are migrated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants