forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport incremental bulk execution (elastic#113215)
This commit back ports all of the work introduced in: elastic#113044 * elastic#111438 - 5e1f655 * elastic#111865 - 478baf1 * elastic#112179 - 1b77421 * elastic#112227 - cbcbc34 * elastic#112267 - c00768a * elastic#112154 - a03fb12 * elastic#112479 - 95b42a7 * elastic#112608 - ce2d648 * elastic#112629 - 0d55dc6 * elastic#112767 - 2dbbd7d * elastic#112724 - 58e3a39 * dce8a0b * elastic#112974 - 92daeeb * 529d349 * elastic#113161 - e3424bd
- Loading branch information
1 parent
0507199
commit 69c4a4f
Showing
46 changed files
with
3,163 additions
and
203 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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.