Skip to content

Run TransportGetMappingsAction on local node #122921

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

Merged
merged 7 commits into from
Mar 15, 2025

Conversation

nielsbauman
Copy link
Contributor

This action solely needs the cluster state, it can run on any node. Additionally, it needs to be cancellable to avoid doing unnecessary work after a client failure or timeout.

Relates #101805

This action solely needs the cluster state, it can run on any node.
Additionally, it needs to be cancellable to avoid doing unnecessary work
after a client failure or timeout.

Relates elastic#101805
@nielsbauman nielsbauman added >enhancement :Data Management/Indices APIs APIs to create and manage indices and templates Team:Data Management Meta label for data/management team v9.1.0 labels Feb 19, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

@elasticsearchmachine
Copy link
Collaborator

Hi @nielsbauman, I've created a changelog YAML for you.

Copy link
Contributor Author

@nielsbauman nielsbauman left a comment

Choose a reason for hiding this comment

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

Relates to #120982

import org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskId;

import java.io.IOException;
import java.util.Map;

public class GetMappingsRequest extends ClusterInfoRequest<GetMappingsRequest> {
public class GetMappingsRequest extends LocalClusterStateRequest implements IndicesRequest.Replaceable {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar to #122885, this also gets rid of the ClusterInfo abstraction.

Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

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

LGTM after the cancellation check has been added (and perhaps add a test for it)

}

@Override
protected void doMasterOperation(
protected void localClusterStateOperation(
Copy link
Member

Choose a reason for hiding this comment

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

This one is missing a call to ((CancellableTask) task).ensureNotCancelled(); somewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(and perhaps add a test for it)

I already added a test:

public void testGetMappingsCancellation() {
createIndex("test");
runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/test/_mappings"), GetMappingsAction.NAME);
}

I think the reason the test isn't failing is that we already check for the task cancellation right before we execute this method:
if (task instanceof CancellableTask cancellableTask && cancellableTask.notifyIfCancelled(listener)) {
return;
}

In other words, all the ((CancellableTask) task).ensureNotCancelled()s I've added in the other classes aren't super valuable (in most places). They're not hurting anything, but they're not super valuable either.

I'll add it to this method too, for consistency, but let me know what you think about all this.

Copy link
Member

Choose a reason for hiding this comment

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

I was viewing the ((CancellableTask) task).ensureNotCancelled() call as a way to do a check prior to some (semi-)expensive work, to avoid doing it if it was going to be thrown away anyway. It seems like it would still have some value there, though only a little, as you say.

I'm fine either way, so I'll leave it to you whether to include them or not.

@nielsbauman
Copy link
Contributor Author

@elasticmachine update branch

@nielsbauman
Copy link
Contributor Author

@elasticmachine update branch

@nielsbauman nielsbauman merged commit 481d91c into elastic:main Mar 15, 2025
17 checks passed
@nielsbauman nielsbauman deleted the local-get-mappings branch March 15, 2025 07:59
"deprecated":{
"version":"7.8.0",
"description":"This parameter is a no-op and field mappings are always retrieved locally."
}
"deprecated":true
Copy link
Member

Choose a reason for hiding this comment

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

Was there a specific reason to remove the description and version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tbh, the reason is that I didn't add a description and version to any of the actions I converted similarly already because I didn't know they existed. It didn't seem worth it to go back and update all the previous ones to include a description and version, so I went for consistency here. Do you think it is worth to go back and update the previous ones to specify a description and version?

Copy link
Member

Choose a reason for hiding this comment

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

No that's fine, especially as we're trying to move away from manually editing rest-api-spec. Thanks for the explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/Indices APIs APIs to create and manage indices and templates >enhancement Team:Data Management Meta label for data/management team v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants