-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add REST content aggregator #117787
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
Closed
Closed
Add REST content aggregator #117787
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
650738e
wip
mhl-b 983b877
remove old http continue test
mhl-b cf907fa
remove HttpObjectAggregator
mhl-b 81e4811
Merge remote-tracking branch 'upstream/main' into rest-content-aggreg…
mhl-b eecc278
cleanup
mhl-b df42681
Merge remote-tracking branch 'upstream/main' into rest-content-aggreg…
mhl-b a749650
Merge remote-tracking branch 'upstream/main' into rest-content-aggreg…
mhl-b 3c92567
100-continue test fix
mhl-b c0b6db4
Merge remote-tracking branch 'upstream/main' into rest-content-aggreg…
mhl-b 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 117787 | ||
| summary: "Move HTTP content aggregation from Netty to RestController" | ||
| area: Network | ||
| type: enhancement | ||
| issues: [] |
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
102 changes: 102 additions & 0 deletions
102
modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/AutoReadSync.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,102 @@ | ||
| /* | ||
| * 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.Channel; | ||
| import io.netty.channel.ChannelConfig; | ||
| import io.netty.util.AttributeKey; | ||
|
|
||
| import java.util.BitSet; | ||
|
|
||
| /** | ||
| * AutoReadSync provides coordinated access to the {@link ChannelConfig#setAutoRead(boolean)}. | ||
| * We use autoRead flag for the data flow control in the channel pipeline to prevent excessive | ||
| * buffering inside channel handlers. Every actor in the pipeline should obtain its own {@link Handle} | ||
| * by calling {@link AutoReadSync#getHandle} channel. Channel autoRead is enabled as long as all Handles | ||
| * are enabled. If one of handles disables autoRead, channel autoRead disables too. | ||
| * Simply, {@code channel.setAutoRead(allHandlesTrue)}. | ||
| * <br><br> | ||
| * TODO: this flow control should be removed when {@link Netty4HttpHeaderValidator} moves to RestController. | ||
| * And whole control flow can be simplified to {@link io.netty.handler.flow.FlowControlHandler}. | ||
| */ | ||
| class AutoReadSync { | ||
|
|
||
| private static final AttributeKey<AutoReadSync> AUTO_READ_SYNC_KEY = AttributeKey.valueOf("AutoReadSync"); | ||
| private final Channel channel; | ||
| private final ChannelConfig config; | ||
|
|
||
| // A pool of reusable handles and their states. Handle id is a sequence number in the set. | ||
| // Handles bitset is a pool of ids. Toggles bitset is a set of autoRead states. | ||
| // Default value for toggle is 0, which means autoRead is enabled. | ||
| private final BitSet handles; | ||
| private final BitSet toggles; | ||
|
|
||
| AutoReadSync(Channel channel) { | ||
| this.channel = channel; | ||
| this.config = channel.config(); | ||
| this.handles = new BitSet(); | ||
| this.toggles = new BitSet(); | ||
| } | ||
|
|
||
| static Handle getHandle(Channel channel) { | ||
| assert channel.eventLoop().inEventLoop(); | ||
| var autoRead = channel.attr(AUTO_READ_SYNC_KEY).get(); | ||
| if (autoRead == null) { | ||
| autoRead = new AutoReadSync(channel); | ||
| channel.attr(AUTO_READ_SYNC_KEY).set(autoRead); | ||
| } | ||
| return autoRead.getHandle(); | ||
| } | ||
|
|
||
| Handle getHandle() { | ||
| var handleId = handles.nextClearBit(0); // next unused handle id | ||
| handles.set(handleId, true); // acquire lease | ||
| return new Handle(handleId); | ||
| } | ||
|
|
||
| class Handle { | ||
| private final int id; | ||
| private boolean released; | ||
|
|
||
| Handle(int id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| private void assertState() { | ||
| assert channel.eventLoop().inEventLoop(); | ||
| assert released == false; | ||
| } | ||
|
|
||
| boolean isEnabled() { | ||
| assertState(); | ||
| return toggles.get(id) == false; | ||
| } | ||
|
|
||
| void enable() { | ||
| assertState(); | ||
| toggles.set(id, false); | ||
| config.setAutoRead(toggles.isEmpty()); | ||
| } | ||
|
|
||
| void disable() { | ||
| assertState(); | ||
| toggles.set(id, true); | ||
| config.setAutoRead(false); | ||
| } | ||
|
|
||
| void release() { | ||
| assertState(); | ||
| enable(); | ||
| handles.set(id, false); | ||
| released = true; | ||
| } | ||
| } | ||
|
|
||
| } |
84 changes: 0 additions & 84 deletions
84
...es/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpAggregator.java
This file was deleted.
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.
Could we make this method interrupt-safe rather than pushing that responsibility up to the caller? I.e. catch
InterruptedException, reinstate the thread's interrupt status flag, and throw anAssertionErrorsince we do not expect to be interrupted in these tests.