|
14 | 14 | import org.elasticsearch.common.UUIDs;
|
15 | 15 | import org.elasticsearch.common.bytes.BytesReference;
|
16 | 16 | import org.elasticsearch.common.io.DiskIoBufferPool;
|
| 17 | +import org.elasticsearch.common.io.Streams; |
17 | 18 | import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
18 | 19 | import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput;
|
19 | 20 | import org.elasticsearch.common.io.stream.StreamInput;
|
|
59 | 60 | import java.util.regex.Matcher;
|
60 | 61 | import java.util.regex.Pattern;
|
61 | 62 | import java.util.stream.Stream;
|
| 63 | +import java.util.zip.CRC32; |
| 64 | +import java.util.zip.CheckedOutputStream; |
62 | 65 |
|
63 | 66 | import static org.elasticsearch.core.Strings.format;
|
64 | 67 | import static org.elasticsearch.index.translog.TranslogConfig.EMPTY_TRANSLOG_BUFFER_SIZE;
|
@@ -1586,8 +1589,15 @@ public static void writeOperationNoSize(BufferedChecksumStreamOutput out, Transl
|
1586 | 1589 | public static void writeOperationWithSize(BytesStreamOutput out, Translog.Operation op) throws IOException {
|
1587 | 1590 | final long start = out.position();
|
1588 | 1591 | out.skip(Integer.BYTES);
|
1589 |
| - writeOperationNoSize(new BufferedChecksumStreamOutput(out), op); |
1590 |
| - final long end = out.position(); |
| 1592 | + final long checksumStart = start + Integer.BYTES; |
| 1593 | + op.writeTo(out); |
| 1594 | + final long checksumEnd = out.position(); |
| 1595 | + final CRC32 cs = new CRC32(); |
| 1596 | + out.bytes() |
| 1597 | + .slice(Math.toIntExact(checksumStart), Math.toIntExact(checksumEnd - checksumStart)) |
| 1598 | + .writeTo(new CheckedOutputStream(Streams.NULL_OUTPUT_STREAM, cs)); |
| 1599 | + out.writeInt((int) cs.getValue()); |
| 1600 | + final long end = checksumEnd + Integer.BYTES; |
1591 | 1601 | final int operationSize = (int) (end - Integer.BYTES - start);
|
1592 | 1602 | out.seek(start);
|
1593 | 1603 | out.writeInt(operationSize);
|
|
0 commit comments