Skip to content

Remove ToXContent interface from ChunkedToXContent#90409

Merged
original-brownbear merged 6 commits intoelastic:mainfrom
original-brownbear:remove-to-xcontent-from-chunked
Oct 9, 2022
Merged

Remove ToXContent interface from ChunkedToXContent#90409
original-brownbear merged 6 commits intoelastic:mainfrom
original-brownbear:remove-to-xcontent-from-chunked

Conversation

@original-brownbear
Copy link
Copy Markdown
Contributor

@original-brownbear original-brownbear commented Sep 27, 2022

Making sure that none of the chunked implementations also implement toXContent. Added some utilities for working with chunked xcontent that mirror xcontent utilities to keep the changeset as quiet as possible. No big production code changes here except for adding another layer of abstraction to broadcast responses to be able to differentiate between chunked and not chunked.
Otherwise, this mostly affects test code paths.

Making sure that none of the chunked implementations also implement
`toXContent`. Added some utilities for working with chunked xcontent
that mirror xcontent utilities to keep the changeset as quiet as possible.
No big production code changes here, this mostly affects test code paths.
@original-brownbear original-brownbear added >test Issues or PRs that are addressing/adding tests :Distributed/Network Http and internode communication implementations v8.6.0 labels Sep 27, 2022
@elasticsearchmachine elasticsearchmachine added the Team:Distributed Meta label for distributed team. label Sep 27, 2022
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

Copy link
Copy Markdown
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

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

Thanks for doing this Armin. I hope we can maybe have the most mechanic part of the change done in a separate PR?

/**
* Return a {@link String} that is the json representation of the provided {@link ChunkedToXContent}.
*/
public static String toString(ChunkedToXContent chunkedToXContent) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we avoid this and the following method? Seems like bugs if we invoke them, given that they produce Strings that could be too large to handle?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree, this sucks. But it's not a new issue and IMO this change at least makes the problem areas clear. The toString output is unchanged from what it was. Maybe a good move would be to just deprecate these outright and then fix them in a follow up by changing the toString output. This isn't entirely trivial since we'd have to come up with a new format for each implementation on a case by case basis so I'd rather not have those discussions here I think :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That sounds good to me, i.e., deprecate them here and then fix in follow-up(s).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done added deprecation :)


import java.io.IOException;

public abstract class AbstractXContentSerializingTestCase<T extends ToXContent & Writeable> extends AbstractSerializationTestCase<T> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it be possible to split out the part of the change that extracts this new class and uses it everywhere? That would make this PR easier to review. I.e., we make that refactor first to use this class everywhere and then we can more easily review this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, it's most of this change I guess :) -> #90707

Copy link
Copy Markdown
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

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

Looks good, just a couple things I'd like to see changed.

import java.io.IOException;
import java.util.List;

public class BroadCastXContentResponse extends BroadcastResponse implements ToXContentObject {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if it was better to rename BroadcastResponse to AbstractBroadcastResponse and thus let this class be called BroadcastResponse, i.e., the normal non chunked case has a name with no extra naming?

Also, notice that it should be lower-case c in Broadcast.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. I went with BaseBroadcastResponse though since we do use the parent class explicitly in a couple spots at the moment and abstract felt wrong. Makes for less noise overall, though the diff looks less nice now for the class itself.

/**
* Return a {@link String} that is the json representation of the provided {@link ChunkedToXContent}.
*/
public static String toString(ChunkedToXContent chunkedToXContent) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That sounds good to me, i.e., deprecate them here and then fix in follow-up(s).

Copy link
Copy Markdown
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

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

LGTM.

private final DefaultShardOperationFailedException[] shardFailures;

@SuppressWarnings("unchecked")
protected static <T extends BaseBroadcastResponse> void declareBroadcastFields(ConstructingObjectParser<T, Void> PARSER) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This one nags me, but clearly not caused by your PR.

@original-brownbear
Copy link
Copy Markdown
Contributor Author

Thanks Henning!

@original-brownbear original-brownbear merged commit 41ede4e into elastic:main Oct 9, 2022
@original-brownbear original-brownbear deleted the remove-to-xcontent-from-chunked branch October 9, 2022 19:51
weizijun added a commit to weizijun/elasticsearch that referenced this pull request Oct 10, 2022
* main: (150 commits)
  Remove ToXContent interface from ChunkedToXContent (elastic#90409)
  Remove extra SearchService constructor (elastic#90733)
  Update min version for the diagnosis yaml test (elastic#90731)
  Use the AggTestConfig object in testCase (elastic#90699)
  [DOCS] Add links to clear trained model deployment cache API (elastic#90727)
  Assert wildcards are not expanded as specified by request options  (elastic#90641)
  [TEST] Fix exit snapshot restore exit condition (elastic#90696)
  [TEST] Change to atomic file contents save (elastic#90695)
  Update forbiddenapis to 3.4 (elastic#90624)
  [Tests] Don't use concurrent search in scripted field type tests (elastic#90712)
  [ML] Move scaling is possible check for starting trained model (elastic#90706)
  Add new base test case for chunked xcontent types  (elastic#90707)
  Fix testRedNoBlockedIndicesAndRedAllRoleNodes (elastic#90671)
  Fix nullpointer in docs test setup (elastic#90660)
  Don't produce build logs artifact when in a composite build
  Fixing a race condition in EnrichCoordinatorProxyAction that can leave an item stuck in its queue (elastic#90688)
  docs: update fleet/agent pipeline docs (elastic#90659)
  [HealthAPI] Use plural consistently in resource types (elastic#90682)
  [Testing] Enable bwc and fix sorting for 500_date_range (elastic#90681)
  Add profiling and documentation for dfs phase (elastic#90536)
  ...

# Conflicts:
#	x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateDoubleMetricFieldMapperTests.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed/Network Http and internode communication implementations Team:Distributed Meta label for distributed team. >test Issues or PRs that are addressing/adding tests v8.6.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants