|
@@ -16,6 +16,7 @@ import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.common.UUIDs;
|
|
|
import org.elasticsearch.common.bytes.BytesArray;
|
|
|
import org.elasticsearch.common.bytes.BytesReference;
|
|
|
+import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|
|
import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
@@ -1550,26 +1551,15 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
|
|
|
* use {@link #readOperations(StreamInput, String)} to read it back.
|
|
|
*/
|
|
|
public static void writeOperations(StreamOutput outStream, List<Operation> toWrite) throws IOException {
|
|
|
- final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(BigArrays.NON_RECYCLING_INSTANCE);
|
|
|
- try {
|
|
|
- outStream.writeInt(toWrite.size());
|
|
|
- final BufferedChecksumStreamOutput checksumStreamOutput = new BufferedChecksumStreamOutput(out);
|
|
|
- for (Operation op : toWrite) {
|
|
|
- out.reset();
|
|
|
- final long start = out.position();
|
|
|
- out.skip(Integer.BYTES);
|
|
|
- writeOperationNoSize(checksumStreamOutput, op);
|
|
|
- long end = out.position();
|
|
|
- int operationSize = (int) (out.position() - Integer.BYTES - start);
|
|
|
- out.seek(start);
|
|
|
- out.writeInt(operationSize);
|
|
|
- out.seek(end);
|
|
|
- out.bytes().writeTo(outStream);
|
|
|
- }
|
|
|
- } finally {
|
|
|
- Releasables.close(out);
|
|
|
+ final BytesStreamOutput out = new BytesStreamOutput();
|
|
|
+ outStream.writeInt(toWrite.size());
|
|
|
+ final BufferedChecksumStreamOutput checksumStreamOutput = new BufferedChecksumStreamOutput(out);
|
|
|
+ for (Operation op : toWrite) {
|
|
|
+ out.reset();
|
|
|
+ writeOperationNoSize(checksumStreamOutput, op);
|
|
|
+ outStream.writeInt(Math.toIntExact(out.position()));
|
|
|
+ out.bytes().writeTo(outStream);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public static void writeOperationNoSize(BufferedChecksumStreamOutput out, Translog.Operation op) throws IOException {
|