Skip to content

Conversation

original-brownbear
Copy link
Contributor

@original-brownbear original-brownbear commented Apr 25, 2022

This sets up the implementation of chunked REST response encoding
that will be able to send large responses without serializing them
in full on heap upfront.
Having all the steps of sending a response in one place together with
the pipelining logic allows adding another response type that serializes
on the transport threads alongside Netty4HttpResponse in a follow-up
that will only require changes to Netty4PipeliningHandler.
Also, this change in isolation saves loads of indirection and now (that the NIO
transport is gone) redundant abstractions, making the path of sending a REST
response all around easier to follow.

relates #82085

NOTE: I did copy a lot of the moved around code outright without too much renaming. While the resulting code could be made nicer by renaming and refactoring the way the methods are set up, I figured for this step it's far easier to review things if I copy as much as I can outright. The same reasoning went into the rather awkward way in which I made Netty4HttpPipeliningHandlerTests work for now. A follow-up aligning it better with Netty4HttpServerPipeliningTests should be able to clean this up further.

This sets up the implementation of chunked REST response encoding
that will be able to send large responses without serializing them
in full on heap upfront.
Having all the steps of sending a response in one place together with
the pipelining logic allows adding another response type that serializes
on the transport threads alongside `Netty4HttpResponse` in a follow-up
that will only require changes to `Netty4PipeliningHandler`.
Also, this change in isolation saves loads of indirection and now (that the NIO
transport is gone) redundant abstractions, making the path of sending a REST
response all around easier to follow.
@original-brownbear original-brownbear added :Distributed Coordination/Network Http and internode communication implementations >refactoring v8.3.0 labels Apr 25, 2022
@elasticmachine elasticmachine added the Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. label Apr 25, 2022
@elasticmachine
Copy link
Collaborator

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

Copy link
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.

This looks fine to me, left a couple of comments, I'd like to understand the test change more fully.

Thread.sleep(scaledRandomIntBetween(500, 1000));
} catch (InterruptedException e) {
throw new RuntimeException(e);
public void incomingRequest(HttpRequest httpRequest, HttpChannel httpChannel) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This change puzzled me a bit in that you tried to keep most other things unchanged, but here went for a more radical change. I see the need for changes (using deleted types), but for my education perhaps you can explain the need for the radical change of the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure :) See this change: https://github.com/elastic/elasticsearch/pull/86133/files#diff-5fb205d075055657d087e3445ff349bcfed01425594e604f7bf7b3d3a6dfefa9L325

we had the pipelining handler and then the handler as separate channel handlers before, now they're a single handler. So previously the test could just replace the "handler" with PossiblySlowUpstreamHandler and still test the logic in the unchanged "pipelining" handler. Now that both handlers are one, this wasn't possible any more.
So since I couldn't replace part of the handler, I left the pipeline as is and overrode the http server transport to catch the requests a little further down the stack.
Or put differently, we previously replaced this code https://github.com/elastic/elasticsearch/pull/86133/files#diff-a3368fd4145592d305c99a7c2b0a6c21c9bd6d45c828515aed1f228b69af2a79L29 in the test, now we run it in this test as well and overrode the code it calls.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation!

Copy link
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.

Please do follow-up with some of the code cleanup PRs that you mentioned once this is merge.

@original-brownbear
Copy link
Contributor Author

Thanks Henning, will do!

@original-brownbear original-brownbear merged commit 337c044 into elastic:master May 13, 2022
@original-brownbear original-brownbear deleted the simplify-netty-rest branch May 13, 2022 09:04
@original-brownbear original-brownbear restored the simplify-netty-rest branch April 18, 2023 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed Coordination/Network Http and internode communication implementations >refactoring Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v8.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants