-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Read Aggregations Directly from Pooled Buffers #72309
Merged
original-brownbear
merged 1 commit into
elastic:master
from
original-brownbear:pool-aggregation-bytes
Apr 28, 2021
Merged
Changes from all commits
Commits
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ | |
package org.elasticsearch.common.io.stream; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.bytes.BytesReference; | ||
import org.elasticsearch.common.bytes.ReleasableBytesReference; | ||
import org.elasticsearch.common.lease.Releasable; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
|
@@ -32,7 +33,7 @@ | |
* to force their buffering in serialized format by calling | ||
* {@link #asSerialized(Reader, NamedWriteableRegistry)}. | ||
*/ | ||
public abstract class DelayableWriteable<T extends Writeable> implements Writeable { | ||
public abstract class DelayableWriteable<T extends Writeable> implements Writeable, Releasable { | ||
/** | ||
* Build a {@linkplain DelayableWriteable} that wraps an existing object | ||
* but is serialized so that deserializing it can be delayed. | ||
|
@@ -46,7 +47,7 @@ public static <T extends Writeable> DelayableWriteable<T> referencing(T referenc | |
* when {@link #expand()} is called. | ||
*/ | ||
public static <T extends Writeable> DelayableWriteable<T> delayed(Writeable.Reader<T> reader, StreamInput in) throws IOException { | ||
return new Serialized<>(reader, in.getVersion(), in.namedWriteableRegistry(), in.readBytesReference()); | ||
return new Serialized<>(reader, in.getVersion(), in.namedWriteableRegistry(), in.readReleasableBytesReference()); | ||
} | ||
|
||
private DelayableWriteable() {} | ||
|
@@ -98,7 +99,8 @@ public Serialized<T> asSerialized(Reader<T> reader, NamedWriteableRegistry regis | |
} catch (IOException e) { | ||
throw new RuntimeException("unexpected error writing writeable to buffer", e); | ||
} | ||
return new Serialized<>(reader, Version.CURRENT, registry, buffer.bytes()); | ||
// TODO: this path is currently not used in production code, if it ever is this should start using pooled buffers | ||
return new Serialized<>(reader, Version.CURRENT, registry, ReleasableBytesReference.wrap(buffer.bytes())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. production mode activated! |
||
} | ||
|
||
@Override | ||
|
@@ -118,19 +120,25 @@ private BytesStreamOutput writeToBuffer(Version version) throws IOException { | |
return buffer; | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
//noop | ||
} | ||
} | ||
|
||
/** | ||
* A {@link Writeable} stored in serialized form. | ||
* A {@link Writeable} stored in serialized form backed by a {@link ReleasableBytesReference}. Once an instance is no longer used its | ||
* backing memory must be manually released by invoking {@link #close()} on it. | ||
*/ | ||
public static class Serialized<T extends Writeable> extends DelayableWriteable<T> { | ||
private final Writeable.Reader<T> reader; | ||
private final Version serializedAtVersion; | ||
private final NamedWriteableRegistry registry; | ||
private final BytesReference serialized; | ||
private final ReleasableBytesReference serialized; | ||
|
||
private Serialized(Writeable.Reader<T> reader, Version serializedAtVersion, | ||
NamedWriteableRegistry registry, BytesReference serialized) { | ||
private Serialized(Writeable.Reader<T> reader, Version serializedAtVersion, NamedWriteableRegistry registry, | ||
ReleasableBytesReference serialized) { | ||
this.reader = reader; | ||
this.serializedAtVersion = serializedAtVersion; | ||
this.registry = registry; | ||
|
@@ -186,6 +194,11 @@ public long getSerializedSize() { | |
// We're already serialized | ||
return serialized.length(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
serialized.close(); | ||
} | ||
} | ||
|
||
/** | ||
|
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
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.
This would literally create O(100M) sized byte arrays in a recent user issue, completely locking up GC on the coordinating node.