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

introduce BackgroundTaskService #4

Merged
merged 3 commits into from
Jun 13, 2024

Conversation

linuxpi
Copy link
Owner

@linuxpi linuxpi commented May 9, 2024

Description

[Describe what this change achieves]

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Failing checks are inspected and point to the corresponding known issue(s) (See: Troubleshooting Failing Builds)
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)
  • Public documentation issue/PR created

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Comment on lines +27 to +30
/**
* Service to manage execution of tasks on Offline Node
*/
public class BackgroundTaskService implements LifecycleComponent {

Choose a reason for hiding this comment

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

Need to add @opensearch.internal.

Also, should we extend AbstractLifecycleComponent instead like the other services do, unless we plan to extend any other classes?

Suggested change
/**
* Service to manage execution of tasks on Offline Node
*/
public class BackgroundTaskService implements LifecycleComponent {
/**
* Service to manage execution of tasks on Offline Node
*
* @opensearch.internal
*/
public class BackgroundTaskService extends AbstractLifecycleComponent {

Comment on lines 34 to 42
private AsyncBackgroundTaskFetch backgroundTaskFetch;
/**
* TaskClient used to interact with TaskStore/Queue for Task Management and Coordination
*/
private final TaskClient taskClient;
/**
* Provides Corresponding TaskWorker to execute for each Task
*/
private final Map<TaskType, TaskWorker> taskWorkerMap;

Choose a reason for hiding this comment

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

Suggested change
private AsyncBackgroundTaskFetch backgroundTaskFetch;
/**
* TaskClient used to interact with TaskStore/Queue for Task Management and Coordination
*/
private final TaskClient taskClient;
/**
* Provides Corresponding TaskWorker to execute for each Task
*/
private final Map<TaskType, TaskWorker> taskWorkerMap;
private AsyncBackgroundTaskFetch backgroundTaskFetch;
/**
* TaskClient used to interact with TaskStore/Queue for Task Management and Coordination
*/
private final TaskClient taskClient;
/**
* Provides Corresponding TaskWorker to execute for each Task
*/
private final Map<TaskType, TaskWorker> taskWorkerMap;

Comment on lines +55 to +59
@Override
public void stop() {
backgroundTaskFetch.close();
backgroundTaskFetch.cancel();
}
Copy link

@BhumikaSaini-Amazon BhumikaSaini-Amazon May 22, 2024

Choose a reason for hiding this comment

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

close() is calling cancel() internally. Do we need the explicit cancel?

Suggested change
@Override
public void stop() {
backgroundTaskFetch.close();
backgroundTaskFetch.cancel();
}
@Override
public void stop() {
backgroundTaskFetch.close();
}

Ref:
https://github.com/opensearch-project/OpenSearch/blob/199a03e62558e005d91f4aeb5875573fc564987f/server/src/main/java/org/opensearch/common/util/concurrent/AbstractAsyncTask.java#L135-L143

Comment on lines +66 to +69
@Override
public Lifecycle.State lifecycleState() {
return null;
}

Choose a reason for hiding this comment

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

Why are we returning null?

Comment on lines +71 to +79
@Override
public void addLifecycleListener(LifecycleListener listener) {

}

@Override
public void removeLifecycleListener(LifecycleListener listener) {

}

Choose a reason for hiding this comment

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

Are these intentional?


}

public void maybeExecuteTasks() {

Choose a reason for hiding this comment

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

nit

Suggested change
public void maybeExecuteTasks() {
public void maybeExecuteUnassignedTasks() {

}
}

private class AsyncBackgroundTaskFetch extends AbstractAsyncTask {

Choose a reason for hiding this comment

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

Missing javadoc

}
}

private class AsyncBackgroundTaskFetch extends AbstractAsyncTask {

Choose a reason for hiding this comment

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

Should we name this BackgroundTaskFetch or AsyncTaskFetch, unless the current name is intentional?

Comment on lines 85 to 87
if (taskClient.claimTask(task.getTaskId())) {
taskWorkerMap.get(task.getTaskType()).executeTask(task);
}

Choose a reason for hiding this comment

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

Should this be synchronized?

@linuxpi linuxpi merged commit 481906d into feature/offline-nodes Jun 13, 2024
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants