Skip to content

Commit 4343d15

Browse files
Fix SearchApplication misusing BytesStreamOutput (#127957)
Closing an xcontent builder in general also closes the underlying stream. The only reason this worked was that we were always using the no-pooling `BigArrays` which also makes the use of the circuit breaker a noop here. Found this when trying to optimize the releasable bytes stream and seeing it break. => just move the non-pooled bytes stream to simplify things
1 parent 1ed0278 commit 4343d15

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/search/SearchApplication.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
import org.elasticsearch.TransportVersions;
1313
import org.elasticsearch.common.Strings;
1414
import org.elasticsearch.common.bytes.BytesReference;
15-
import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput;
15+
import org.elasticsearch.common.io.stream.BytesStreamOutput;
1616
import org.elasticsearch.common.io.stream.StreamInput;
1717
import org.elasticsearch.common.io.stream.StreamOutput;
1818
import org.elasticsearch.common.io.stream.Writeable;
19-
import org.elasticsearch.common.util.BigArrays;
2019
import org.elasticsearch.common.xcontent.XContentHelper;
2120
import org.elasticsearch.core.Nullable;
2221
import org.elasticsearch.core.Tuple;
@@ -282,15 +281,13 @@ public String toString() {
282281
* Returns the merged {@link SearchApplication} from the current state and the provided {@param update}.
283282
* This function returns the current instance if the update is a noop.
284283
*
285-
* @param update The source of the update represented in bytes.
284+
* @param update The source of the update represented in bytes.
286285
* @param xContentType The format of the bytes.
287-
* @param bigArrays The {@link BigArrays} to use to recycle bytes array.
288-
*
289286
* @return The merged {@link SearchApplication}.
290287
*/
291-
SearchApplication merge(BytesReference update, XContentType xContentType, BigArrays bigArrays) throws IOException {
288+
SearchApplication merge(BytesReference update, XContentType xContentType) throws IOException {
292289
final Tuple<XContentType, Map<String, Object>> sourceAndContent;
293-
try (ReleasableBytesStreamOutput sourceBuffer = new ReleasableBytesStreamOutput(0, bigArrays.withCircuitBreaking())) {
290+
try (BytesStreamOutput sourceBuffer = new BytesStreamOutput()) {
294291
try (XContentBuilder builder = XContentFactory.jsonBuilder(sourceBuffer)) {
295292
toXContent(builder, EMPTY_PARAMS);
296293
}
@@ -305,7 +302,7 @@ SearchApplication merge(BytesReference update, XContentType xContentType, BigArr
305302
return this;
306303
}
307304

308-
try (ReleasableBytesStreamOutput newSourceBuffer = new ReleasableBytesStreamOutput(0, bigArrays.withCircuitBreaking())) {
305+
try (BytesStreamOutput newSourceBuffer = new BytesStreamOutput()) {
309306
try (XContentBuilder builder = XContentFactory.jsonBuilder(newSourceBuffer)) {
310307
builder.value(newSourceAsMap);
311308
}

x-pack/plugin/ent-search/src/test/java/org/elasticsearch/xpack/application/search/SearchApplicationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1717
import org.elasticsearch.common.io.stream.StreamInput;
1818
import org.elasticsearch.common.settings.Settings;
19-
import org.elasticsearch.common.util.BigArrays;
2019
import org.elasticsearch.common.xcontent.XContentHelper;
2120
import org.elasticsearch.search.SearchModule;
2221
import org.elasticsearch.test.ESTestCase;
@@ -111,7 +110,7 @@ public void testMerge() throws IOException {
111110
"updated_at_millis": 12345
112111
}""";
113112
SearchApplication app = SearchApplication.fromXContentBytes("my_search_app", new BytesArray(content), XContentType.JSON);
114-
SearchApplication updatedApp = app.merge(new BytesArray(update), XContentType.JSON, BigArrays.NON_RECYCLING_INSTANCE);
113+
SearchApplication updatedApp = app.merge(new BytesArray(update), XContentType.JSON);
115114
assertNotSame(app, updatedApp);
116115
assertThat(updatedApp.indices(), equalTo(new String[] { "my_index", "my_index_2" }));
117116
assertThat(updatedApp.analyticsCollectionName(), equalTo("my_search_app_analytics"));

0 commit comments

Comments
 (0)