Skip to content

mgmt resources, sync implementation for TaskGroup #45068

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

Open
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

XiaofeiCao
Copy link
Contributor

@XiaofeiCao XiaofeiCao commented Apr 22, 2025

Description

Part of sync-stack support for mgmt premium, and core-v2 if we want to keep premium packages.

Goal

  1. Provide sync interfaces for TaskGroup invocation without Reactor..
  2. Support specifying Executor to achieve task execution parallelism.

Context

A rough flow of TaskGroup.invokeAsync:
image

About this PR

TaskGroup.invoke's major change is in step4 -> Concurrently execute tasks.
Instead of Flux.merge, use CompletableFuture.allOf to join all CompletableFutures kicked off by CompletableFuture.supplyAsync with default or specified Executor.

Specify Executor by setting syncExecutor in InvocationContext, and execute via TaskGroup.invoke(InvocationContext).

To run task in the same thread as TaskGroup.invoke, set syncExecutor to Runnable::run.

Default Executor(if not specified) is ForkJoinPool.commonPool(), which is also the default Executor for CompletableFuture.

Test

Added tests in the same package as async ones, with Sync prefix.

Future works

  1. New sync APIs in resource base models, with Reactor as its default implementation.
  2. Override these new sync Resource API implementations for all packages.
  3. Remove Reactor default implementations for sync APIs.

Please add an informative description that covers that changes made by the pull request and link all relevant issues.

If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@XiaofeiCao XiaofeiCao changed the title mgmt resources, sync implementation mgmt resources, sync implementation for TaskGroup Apr 22, 2025
@github-actions github-actions bot added the Mgmt This issue is related to a management-plane library. label Apr 22, 2025
@azure-sdk
Copy link
Collaborator

azure-sdk commented Apr 22, 2025

API Change Check

APIView identified API level changes in this PR and created the following API reviews

com.azure.resourcemanager:azure-resourcemanager-resources

@azure-sdk
Copy link
Collaborator

API change check

APIView has identified API level changes in this PR and created following API reviews.

com.azure.resourcemanager:azure-resourcemanager-resources

@XiaofeiCao XiaofeiCao changed the title mgmt resources, sync implementation for TaskGroup [WIP] mgmt resources, sync implementation for TaskGroup Apr 25, 2025
@XiaofeiCao XiaofeiCao changed the title [WIP] mgmt resources, sync implementation for TaskGroup mgmt resources, sync implementation for TaskGroup Apr 25, 2025
Comment on lines 8 to 9
*/
final class ErroredDependencyTaskException extends Exception {
final class ErroredDependencyTaskException extends RuntimeException {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not expected for user to catch this Exception. It'll be caught only in TaskGroup implementation.

Choose a reason for hiding this comment

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

maybe a slightly easy-to-read name, errored feels strange? FailedDependencyTaskException?

@XiaofeiCao XiaofeiCao marked this pull request as ready for review April 27, 2025 08:55
@XiaofeiCao
Copy link
Contributor Author

XiaofeiCao commented Apr 27, 2025

Not sure why pipeline revapi keeps complaining about breaking change of TaskGroup.failedFuture from 2.50.0.

This method wasn't even added in 2.50.0.

My local build and check doesn't have this issue...

Copy link
Member

@weidongxu-microsoft weidongxu-microsoft left a comment

Choose a reason for hiding this comment

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

I did a quick read and didn't see problem.

However, merging of the PR would mean that it be under revapi check.

PS: also not sure why failedFuture errors (and the old Analysis CI passes).

Comment on lines 8 to 9
*/
final class ErroredDependencyTaskException extends Exception {
final class ErroredDependencyTaskException extends RuntimeException {

Choose a reason for hiding this comment

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

maybe a slightly easy-to-read name, errored feels strange? FailedDependencyTaskException?

Comment on lines +966 to +970
public InvocationContext withSyncTaskExecutor(Executor syncExecutor) {
Objects.requireNonNull(syncExecutor);
this.syncExecutor = syncExecutor;
return this;
}

Choose a reason for hiding this comment

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

Is this supposed to be called by our lib in its API (when create the TaskGroup), or by user? Likely won't be user?

Copy link
Contributor Author

@XiaofeiCao XiaofeiCao Apr 28, 2025

Choose a reason for hiding this comment

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

It'll be called by our libs. E.g. CreatableUpdatableImpl.

I planned to also put this configuration in ResourceManagerUtils, where user can set ReactorScheduler in InternalContext. E.g. setSyncTaskExecutor.

Surely we can use ResourceManagerUtils directly in TaskGroup, though I thought a separation of layers could be useful(TaskGroup vs CreatableUpdatableImpl).

@XiaofeiCao
Copy link
Contributor Author

XiaofeiCao commented Apr 29, 2025

Created a new PR with commits squashed.
#45139

Seems revapi issue has gone for that one...

@XiaofeiCao XiaofeiCao changed the title mgmt resources, sync implementation for TaskGroup [DO NOT REVIEW]mgmt resources, sync implementation for TaskGroup Apr 29, 2025
@XiaofeiCao XiaofeiCao marked this pull request as draft April 29, 2025 10:53
@XiaofeiCao
Copy link
Contributor Author

close by #45139

@XiaofeiCao XiaofeiCao closed this May 6, 2025
@XiaofeiCao XiaofeiCao reopened this May 6, 2025
@XiaofeiCao
Copy link
Contributor Author

Seems the revapi issue in pullrequest CI has been fixed. Will still use this PR.

@XiaofeiCao XiaofeiCao marked this pull request as ready for review May 6, 2025 08:15
@XiaofeiCao XiaofeiCao changed the title [DO NOT REVIEW]mgmt resources, sync implementation for TaskGroup mgmt resources, sync implementation for TaskGroup May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Do Not Merge Mgmt This issue is related to a management-plane library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants