|
9 | 9 |
|
10 | 10 | package org.elasticsearch.ingest; |
11 | 11 |
|
| 12 | +import org.apache.lucene.util.BytesRef; |
12 | 13 | import org.elasticsearch.common.bytes.BytesReference; |
13 | | -import org.elasticsearch.common.io.stream.BytesStreamOutput; |
| 14 | +import org.elasticsearch.common.io.stream.RecyclerBytesStreamOutput; |
14 | 15 | import org.elasticsearch.common.io.stream.StreamInput; |
15 | 16 | import org.elasticsearch.common.io.stream.StreamOutput; |
| 17 | +import org.elasticsearch.common.recycler.Recycler; |
16 | 18 |
|
17 | 19 | import java.io.IOException; |
18 | 20 | import java.io.UncheckedIOException; |
@@ -64,12 +66,38 @@ private static List<ESONEntry> readKeys(StreamInput in) throws IOException { |
64 | 66 | public BytesReference getSerializedKeyBytes() { |
65 | 67 | if (serializedKeyBytes.get() == null) { |
66 | 68 | // TODO: Better estimate |
67 | | - int estimate = (int) (values.data().length() * 0.7); |
68 | 69 | // for (ESONEntry entry : keys) { |
69 | 70 | // String key = entry.key(); |
70 | 71 | // estimate += key == null ? 0 : key.length() + 5; |
71 | 72 | // } |
72 | | - try (BytesStreamOutput streamOutput = new BytesStreamOutput(estimate)) { |
| 73 | + try (RecyclerBytesStreamOutput streamOutput = new RecyclerBytesStreamOutput(new Recycler<>() { |
| 74 | + |
| 75 | + // TODO: Better estimate |
| 76 | + final int estimate = Math.max((int) (values.data().length() * 0.7), 512); |
| 77 | + |
| 78 | + @Override |
| 79 | + public V<BytesRef> obtain() { |
| 80 | + return new V<>() { |
| 81 | + @Override |
| 82 | + public BytesRef v() { |
| 83 | + return new BytesRef(new byte[estimate]); |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public boolean isRecycled() { |
| 88 | + return false; |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public void close() {} |
| 93 | + }; |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public int pageSize() { |
| 98 | + return estimate; |
| 99 | + } |
| 100 | + })) { |
73 | 101 | streamOutput.writeVInt(keys.size()); |
74 | 102 | for (ESONEntry entry : keys) { |
75 | 103 | String key = entry.key(); |
|
0 commit comments