Skip to content

Remove Redundant Cluster State Update Response Classes #63646

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

Conversation

original-brownbear
Copy link
Contributor

These intermediary response types don't contain any information
outside of what the shard acknowledged and acknowledged responses
contain so this PR removes them.
Also, it adds three constants for the three possible states of
ShardsAcknowledgedResponse.

Follow up to #63335

These intermediary response types don't contain any information
outside of what the shard acknowledged and acknowledged responses
contain so this PR removes them.
Also, it adds three constants for the three possible states of
`ShardsAcknowledgedResponse`.

Follow up to elastic#63335
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Core)

@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Oct 14, 2020
/**
* {@link AckedClusterStateUpdateTask} that responds with a plain {@link AcknowledgedResponse}.
*/
public abstract class SimpleAckedStateUpdateTask extends AckedClusterStateUpdateTask<AcknowledgedResponse> {
Copy link
Member

Choose a reason for hiding this comment

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

Please let's not use the term "simple". Why isn't this just part of AckedClusterStateUpdateTask?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why isn't this just part of AckedClusterStateUpdateTask?

🤦 yea that's much better :) I pushed 996b582 , thanks!


@SuppressWarnings("unchecked")
protected Response newResponse(boolean acknowledged) {
return (Response) AcknowledgedResponse.of(acknowledged);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this cast should be necessary. If we are saying all response classes for AckedClusterStateUpdateTask should be an AcknowledgedResponse, then why is it a generic? Should the generic be extending AcknowledgedResponse?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this but annoyingly org.elasticsearch.xpack.ilm.action.TransportRemoveIndexLifecyclePolicyAction uses a Response class that doesn't extend AcknowledgedResponse which prevents us from doing this.
At least I couldn't find a quick+dry way around the problem for now other than what I had before with subclassing AckedClusterStateUpdateTask but even that was a lot of extra code, the current version seems simplest to me because changing the response in the ILM action isn't so trivial BwC wise?

Copy link
Member

Choose a reason for hiding this comment

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

Is that ILM class actually utilizing the "acked" part of AckedClusterStateUpdateTask then? It seems odd based on naming alone that there is nothing asked about the response?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually it isn't using any of the acked mechanics so I turned it into a normal update in 926442c and then constrained the type of the response some to actually by an acknowledged response.

Still need the cast though unfortunately, we can only get around that by sub-classing for plain AcknowledgedResponse I think (this is because the listener might have a more constrained type than AcknowledgedResponse so without the cast the generic type constraints aren't met).

Copy link
Member

@rjernst rjernst Nov 2, 2020

Choose a reason for hiding this comment

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

I only see two classes that concretely implement AckedClusterStateUpdateTask. Yet they seem to override everything. What benefit does the generic type give us? It seems the abstract class could concretely use AcknowledgedResponse, and those two subclasses can override and refine the response type of newResponse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point, the generic is pointless. I removed it in 8ca8862 . Still requires one annoying case in the constructor, but much nicer IMO.

We do have a few more than 2 overrides to the response type though in the anonymous implementations. Some of those look completely redundant (e.g. org.elasticsearch.xpack.core.ilm.action.DeleteLifecycleAction.Response though and could be removed in a follow-up).

Let me know what you think :)

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

Looks much better to me, thanks!


private final ActionListener<Response> listener;
private final ActionListener<AcknowledgedResponse> listener;
Copy link
Member

Choose a reason for hiding this comment

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

We could use ? extends here as well so a cast is not necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That won't work unfortunately. If we bound by ? extends then it could be that the listener is actually a listener for some subclass of AcknowledgedResponse so that gives a compile time error ... it always seems like this should work though :)

@original-brownbear
Copy link
Contributor Author

Thanks Ryan!

@original-brownbear original-brownbear merged commit d904d48 into elastic:master Nov 3, 2020
@original-brownbear original-brownbear deleted the singleton-ack-cs-resp branch November 3, 2020 20:48
original-brownbear added a commit that referenced this pull request Nov 10, 2020
These intermediary response types don't contain any information
outside of what the shard acknowledged and acknowledged responses
contain so this PR removes them.
Also, it adds three constants for the three possible states of
`ShardsAcknowledgedResponse`.

Follow up to #63335
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Core Core issues without another label >non-issue Team:Core/Infra Meta label for core/infra team v7.11.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants