-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Implement incremental bulk execution #113044
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5e1f655
Add http request content stream support (#111438)
mhl-b 478baf1
Allow incremental bulk request execution (#111865)
Tim-Brooks 1b77421
handle 100-continue and oversized streaming request (#112179)
mhl-b cbcbc34
release stream chunk queue on bad request (#112227)
mhl-b c00768a
Split bulks based on memory usage (#112267)
Tim-Brooks a03fb12
Incremental bulk integration with rest layer (#112154)
Tim-Brooks 95b42a7
Ensure incremental bulk setting is set atomically (#112479)
Tim-Brooks ce2d648
Reduce autoread changes in header validator (#112608)
Tim-Brooks 0d55dc6
fix leaking listener (#112629)
mhl-b 2dbbd7d
Ensure http content copied for safe buffers (#112767)
Tim-Brooks 58e3a39
Ensure partial bulks released if channel closes (#112724)
Tim-Brooks dce8a0b
merge main
mhl-b 92daeeb
Properly handle empty incremental bulk requests (#112974)
Tim-Brooks 529d349
Fix spotless in netty stream class
Tim-Brooks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
695 changes: 695 additions & 0 deletions
695
...nalClusterTest/java/org/elasticsearch/http/netty4/Netty4IncrementalRequestHandlingIT.java
Large diffs are not rendered by default.
Oops, something went wrong.
84 changes: 84 additions & 0 deletions
84
...es/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpAggregator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.http.netty4; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.handler.codec.http.FullHttpRequest; | ||
import io.netty.handler.codec.http.FullHttpResponse; | ||
import io.netty.handler.codec.http.HttpContent; | ||
import io.netty.handler.codec.http.HttpObject; | ||
import io.netty.handler.codec.http.HttpObjectAggregator; | ||
import io.netty.handler.codec.http.HttpRequest; | ||
import io.netty.handler.codec.http.HttpResponseStatus; | ||
import io.netty.handler.codec.http.HttpUtil; | ||
|
||
import org.elasticsearch.http.HttpPreRequest; | ||
import org.elasticsearch.http.netty4.internal.HttpHeadersAuthenticatorUtils; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* A wrapper around {@link HttpObjectAggregator}. Provides optional content aggregation based on | ||
* predicate. {@link HttpObjectAggregator} also handles Expect: 100-continue and oversized content. | ||
* Unfortunately, Netty does not provide handlers for oversized messages beyond HttpObjectAggregator. | ||
*/ | ||
public class Netty4HttpAggregator extends HttpObjectAggregator { | ||
private static final Predicate<HttpPreRequest> IGNORE_TEST = (req) -> req.uri().startsWith("/_test/request-stream") == false; | ||
|
||
private final Predicate<HttpPreRequest> decider; | ||
private boolean aggregating = true; | ||
private boolean ignoreContentAfterContinueResponse = false; | ||
|
||
public Netty4HttpAggregator(int maxContentLength, Predicate<HttpPreRequest> decider) { | ||
super(maxContentLength); | ||
this.decider = decider; | ||
} | ||
|
||
@Override | ||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { | ||
assert msg instanceof HttpObject; | ||
if (msg instanceof HttpRequest request) { | ||
var preReq = HttpHeadersAuthenticatorUtils.asHttpPreRequest(request); | ||
aggregating = decider.test(preReq) && IGNORE_TEST.test(preReq); | ||
} | ||
if (aggregating || msg instanceof FullHttpRequest) { | ||
super.channelRead(ctx, msg); | ||
} else { | ||
handle(ctx, (HttpObject) msg); | ||
} | ||
} | ||
|
||
private void handle(ChannelHandlerContext ctx, HttpObject msg) { | ||
if (msg instanceof HttpRequest request) { | ||
var continueResponse = newContinueResponse(request, maxContentLength(), ctx.pipeline()); | ||
if (continueResponse != null) { | ||
// there are 3 responses expected: 100, 413, 417 | ||
// on 100 we pass request further and reply to client to continue | ||
// on 413/417 we ignore following content | ||
ctx.writeAndFlush(continueResponse); | ||
var resp = (FullHttpResponse) continueResponse; | ||
if (resp.status() != HttpResponseStatus.CONTINUE) { | ||
ignoreContentAfterContinueResponse = true; | ||
return; | ||
} | ||
HttpUtil.set100ContinueExpected(request, false); | ||
} | ||
ignoreContentAfterContinueResponse = false; | ||
ctx.fireChannelRead(msg); | ||
} else { | ||
var httpContent = (HttpContent) msg; | ||
if (ignoreContentAfterContinueResponse) { | ||
httpContent.release(); | ||
} else { | ||
ctx.fireChannelRead(msg); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this somewhat unnecessary, could the decider not work on the uri directly instead or even the
HttpRequest
(the decider is quite intimate anyway). Happy to leave as is for now ofc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. IMO we definitely have room for improvement here. There is a ticket tracking improved handling in this area.