Skip to content

Commit 33557b1

Browse files
wee
1 parent eff8d0f commit 33557b1

File tree

1 file changed

+12
-2
lines changed
  • server/src/main/java/org/elasticsearch/index/translog

1 file changed

+12
-2
lines changed

server/src/main/java/org/elasticsearch/index/translog/Translog.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.common.UUIDs;
1515
import org.elasticsearch.common.bytes.BytesReference;
1616
import org.elasticsearch.common.io.DiskIoBufferPool;
17+
import org.elasticsearch.common.io.Streams;
1718
import org.elasticsearch.common.io.stream.BytesStreamOutput;
1819
import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput;
1920
import org.elasticsearch.common.io.stream.StreamInput;
@@ -59,6 +60,8 @@
5960
import java.util.regex.Matcher;
6061
import java.util.regex.Pattern;
6162
import java.util.stream.Stream;
63+
import java.util.zip.CRC32;
64+
import java.util.zip.CheckedOutputStream;
6265

6366
import static org.elasticsearch.core.Strings.format;
6467
import static org.elasticsearch.index.translog.TranslogConfig.EMPTY_TRANSLOG_BUFFER_SIZE;
@@ -1586,8 +1589,15 @@ public static void writeOperationNoSize(BufferedChecksumStreamOutput out, Transl
15861589
public static void writeOperationWithSize(BytesStreamOutput out, Translog.Operation op) throws IOException {
15871590
final long start = out.position();
15881591
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;
15911601
final int operationSize = (int) (end - Integer.BYTES - start);
15921602
out.seek(start);
15931603
out.writeInt(operationSize);

0 commit comments

Comments
 (0)