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

Make the Task object available to the action caller #16033

Merged
merged 1 commit into from
Jan 19, 2016

Conversation

imotov
Copy link
Contributor

@imotov imotov commented Jan 16, 2016

Sometimes action callers might be interested in having access to the task that they have just initiated. This changes allows a caller to get access to the Task object of an action that it just started if the action runs on the same node and supports the task management.

@nik9000 do you want to review it?

@imotov imotov added >feature review :Distributed/Task Management Issues for anything around the Tasks API - both persistent and node level. v5.0.0-alpha1 labels Jan 16, 2016
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<ListTasksResponse> response = new AtomicReference<>();
final Client client;
boolean useDataClient = randomBoolean();
Copy link
Member

Choose a reason for hiding this comment

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

if useDataClient is false you still might end up with a data client, right? its more like forceDataNodeClient?

@nik9000
Copy link
Member

nik9000 commented Jan 16, 2016

Makes sense to me. I hadn't thought about it not being available to the transport client but it makes sense and should work fine for my purpose. I'd copy that javadoc about it returning null to ActionRequestBuilder as well.

@imotov imotov added discuss and removed review labels Jan 16, 2016
@imotov
Copy link
Contributor Author

imotov commented Jan 16, 2016

@nik9000 I thought more about it. Do we actually need to expose it all the way up to the client level for your use case? In the scenario where the task is actually available in this PR (the caller is calling execute on the node client) the caller typically has direct access to Transport*Action. So, it can directly call TransportAction#execute instead of going through the client. I feel like that would be a cleaner approach anyway.

If there is a real need to expose the task information all the way to the client level then there should be no difference between a node client and a transport client and we need to devise some method to ship the started task id back to the caller, which is much more complicated. Since the task might be executed on a remote node, we cannot return the Task object. It has to be some sort of TaskInfo object. It also has to be returned in an asynchronous way, because network communication might be involved.

So, if TransportAction level access would work for you, I am going to revise this PR to remove exposing task on the client level. If you need client level access, we should have a quick discussion about it earlier next week, since there are several ways of achieving it.

What do you think?

@nik9000
Copy link
Member

nik9000 commented Jan 17, 2016

Right. I see your way of thinking and I think I agree. If it can't work for TransportClient I don't think it should be part of the interface.

While I'd love for clients to have access to task information - TaskInfo would be wonderful, but I had a quick look and I don't see any kind of "I've started your request" message that we could piggy back on so I don't think its worth it doing.

TransportAction level access will work I think. It'll make something like #15687 more complicated but that is life.

@nik9000
Copy link
Member

nik9000 commented Jan 17, 2016

So if you amend the PR to drop the Client level stuff and just do TransportAction level stuff you still have my LGTM.

@nik9000
Copy link
Member

nik9000 commented Jan 17, 2016

Even better, it looks like without Client level changes this PR is about 2 lines.

@clintongormley
Copy link

Not sure I follow the conversation above, but I'd imagine doing a reindex request with ?wait_for_completion=false and getting back a task ID which I can then monitor.

@nik9000
Copy link
Member

nik9000 commented Jan 18, 2016

Not sure I follow the conversation above, but I'd imagine doing a reindex request with ?wait_for_completion=false and getting back a task ID which I can then monitor.

Yup. That is what it'll do regardless of what we do above. This is more a question of "where do tasks show up in the API" and "what do rest tasks have to do to return the task ID rather than wait for completion" and "does the java client get to use them easily." The answers are "not in the client API. not yet anyway" and "get one or two more dependencies injected than normal and use them in obvious ways" and "no".

@imotov imotov mentioned this pull request Jan 18, 2016
12 tasks
@imotov
Copy link
Contributor Author

imotov commented Jan 18, 2016

@nik9000 I pushed the new version. I think I like it much more :)

@imotov imotov added review and removed discuss labels Jan 18, 2016
@nik9000
Copy link
Member

nik9000 commented Jan 18, 2016

LGTM. Its much simpler. If we want to give the clients some kind of task object on every request we'll do it as a separate PR.

Sometimes action callers might be interested in having an access to the task that they have just initiated. This changes allows callers to get access to the Task object of the actions that they just started if the action supports the task management.
@imotov imotov merged commit d9a0122 into elastic:master Jan 19, 2016
@@ -66,7 +66,7 @@ protected TransportAction(Settings settings, String actionName, ThreadPool threa
return future;
}

public final void execute(Request request, ActionListener<Response> listener) {
public final Task execute(Request request, ActionListener<Response> listener) {
Task task = taskManager.register("transport", actionName, request);
if (task == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

when do we expect task to be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bleskes I added an option for an action to opt out from task management tracking. If the TransportRequest#createTask method returns null instead of a task object, this action is not tracked by the task manager and the register call returns null.

I forgot to document this behavior. Thanks for the reminder. I will add comments in a bit.

@imotov imotov deleted the expose-task-to-the-caller branch May 1, 2020 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed/Task Management Issues for anything around the Tasks API - both persistent and node level. >feature v5.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants