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

Multi-instance query support #32

Merged
merged 8 commits into from Apr 19, 2022
Merged

Multi-instance query support #32

merged 8 commits into from Apr 19, 2022

Conversation

kaibocai
Copy link
Member

This PR implements logics for supporting multi-instance query (#9)
This PR includes:

  • add new API queryInstance to DurableTaskClient
  • end2end tests

@kaibocai kaibocai changed the title Kaibocai/query instance multi-instance query support Apr 15, 2022
@kaibocai kaibocai changed the title multi-instance query support Multi-instance query support Apr 15, 2022
@kaibocai kaibocai requested a review from cgillum April 15, 2022 21:30
@cgillum
Copy link
Member

cgillum commented Apr 18, 2022

Looks like there's an issue with the CI - the sidecar doesn't appear to be running correctly. We should look into introducing shorter timeouts to the integration tests so that we don't have to wait a full hour for the CI to fail.

@kaibocai
Copy link
Member Author

Looks like there's an issue with the CI - the sidecar doesn't appear to be running correctly. We should look into introducing shorter timeouts to the integration tests so that we don't have to wait a full hour for the CI to fail.

sorry that I forget to set the default timeout back after local developing, will set it back soon in next commit.

@kaibocai
Copy link
Member Author

once reset resources logics is there, the pipeline should success.

@kaibocai
Copy link
Member Author

I believe once the sidecar image is updated the pipeline should success, as it's what I saw on my local.

@cgillum
Copy link
Member

cgillum commented Apr 18, 2022

Okay, let me update the sidecar image and retry the CI.

@cgillum
Copy link
Member

cgillum commented Apr 19, 2022

CI is green after updating the sidecar image 👍🏽


public class OrchestrationStatusQueryResult {
public List<OrchestrationMetadata> OrchestrationState;
public String continuationToken;
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove the setters, make the fields private readonly, and have them populated using a constructor. That way instances of this class can be immutable, which is a useful property for ensuring code correctness.


for (int i = 0; i < 5; i++){
final int j = i;
CompletableFuture<OrchestrationMetadata> waitEvent = CompletableFuture.supplyAsync(() -> this.startOrchestrationAsync(waitForEvent, String.valueOf(j), new StringBuilder(prefix).append(".waiter.").append(j).toString(), client));
Copy link
Member

Choose a reason for hiding this comment

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

I understand how you might want to use CompletableFuture here to make the code similar to the C# version. However, C# has async/await, which makes it very easy to do non-blocking code in parallel. Java doesn't have this and CompletableFuture, unfortunately, is not always a good substitute. However, we can still express the same idea in a way that is actually quite simple and easy to understand.

Here is an example that I came up with. It's fewer lines of code and still executes everything in parallel. I think this version makes the code much more readable and maintainable:

// Run 5 orchestrations in parallel and wait for them all to finish
IntStream.range(0, 5).mapToObj(i -> {
    String instanceId = String.format("%s.waiter.%d", prefix, i);
    client.scheduleNewOrchestrationInstance(waitForEvent, String.valueOf(i), instanceId);
    return instanceId;
}).collect(Collectors.toUnmodifiableList()).forEach(id -> {
    client.waitForInstanceStart(id, defaultTimeout);
});

Note that I've also removed the helper methods, so I'm only using public APIs. It's nice if we can try to do this because it makes it easy to copy/paste the code to share with someone as a sample for how to do something similar. Adding too many helper methods like runOrchestrationAsync and startOrchestrationAsync makes this much more difficult. The C# code you looked at uses helper methods because the public APIs are not as cleanly designed as these Java APIs and don't support things like lambda expressions.

String name = ctx.getInput(String.class);
String output = ctx.waitForExternalEvent(name, String.class).get();
ctx.complete(output);
});
Copy link
Member

Choose a reason for hiding this comment

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

Is it really beneficial to save these orchestrator functions into a static map? If it's not too much ceremony, I would prefer we follow the existing code pattern and define the orchestrations and activities directly in the test method.

Copy link
Member

@cgillum cgillum left a comment

Choose a reason for hiding this comment

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

I made a few style updates on top of your latest commit, but I think this PR looks good!

@kaibocai kaibocai marked this pull request as ready for review April 19, 2022 17:10
@kaibocai kaibocai merged commit 8df1254 into main Apr 19, 2022
@kaibocai kaibocai deleted the kaibocai/query-instance branch April 19, 2022 17:10
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.

None yet

2 participants