@@ -40,19 +40,14 @@ public static void writeIndexHeader(RecyclerBytesStreamOutput buffer, Translog.I
4040 int uidVIntLen = RecyclerBytesStreamOutput .vIntLength (uidLen );
4141 BytesRef page = buffer .tryGetPageForWrite (FIXED_INDEX_HEADER_SIZE + uidLen + uidVIntLen );
4242 if (page != null ) {
43- writeFastIndexHeader (buffer , index , page , uidLen , uidVIntLen );
43+ writeFastIndexHeader (buffer , index , page , uidVIntLen );
4444 } else {
4545 writeSlowIndexHeader (buffer , index );
4646 }
4747 }
4848
49- private static void writeFastIndexHeader (
50- RecyclerBytesStreamOutput buffer ,
51- Translog .Index index ,
52- BytesRef page ,
53- int uidLen ,
54- int uidVIntLen
55- ) throws IOException {
49+ private static void writeFastIndexHeader (RecyclerBytesStreamOutput buffer , Translog .Index index , BytesRef page , int uidVIntLen )
50+ throws IOException {
5651 BytesRef uid = index .uid ();
5752 String routing = index .routing ();
5853
@@ -67,7 +62,7 @@ private static void writeFastIndexHeader(
6762 ByteUtils .writeLongBE (index .primaryTerm (), bytes , off + 30 );
6863 StreamOutput .putVInt (bytes , uid .length , off + 38 );
6964 System .arraycopy (uid .bytes , uid .offset , bytes , off + 38 + uidVIntLen , uid .length );
70- bytes [off + 38 + uidVIntLen + uidLen ] = index .routing () == null ? (byte ) 0 : (byte ) 1 ;
65+ bytes [off + 38 + uidVIntLen + uid . length ] = index .routing () == null ? (byte ) 0 : (byte ) 1 ;
7166
7267 long variableLengthStart = buffer .position ();
7368 // Write variable length items in header
@@ -100,15 +95,19 @@ private static void writeSlowIndexHeader(RecyclerBytesStreamOutput buffer, Trans
10095 }
10196
10297 public static void writeDeleteHeader (RecyclerBytesStreamOutput buffer , Translog .Delete delete ) throws IOException {
103- BytesRef page = buffer .tryGetPageForWrite (FIXED_DELETE_HEADER_SIZE );
98+ int uidLen = delete .uid ().length ;
99+ int uidVIntLen = RecyclerBytesStreamOutput .vIntLength (uidLen );
100+ BytesRef page = buffer .tryGetPageForWrite (FIXED_DELETE_HEADER_SIZE + uidLen + uidVIntLen );
104101 if (page != null ) {
105- writeFastDeleteHeader (buffer , delete , page );
102+ writeFastDeleteHeader (delete , page , uidVIntLen );
106103 } else {
107104 writeSlowDeleteHeader (buffer , delete );
108105 }
109106 }
110107
111- private static void writeFastDeleteHeader (RecyclerBytesStreamOutput buffer , Translog .Delete delete , BytesRef page ) throws IOException {
108+ private static void writeFastDeleteHeader (Translog .Delete delete , BytesRef page , int uidVIntLen ) throws IOException {
109+ BytesRef uid = delete .uid ();
110+
112111 int off = page .offset ;
113112 byte [] bytes = page .bytes ;
114113 bytes [off + 4 ] = Translog .Operation .Type .DELETE .id ();
@@ -117,13 +116,11 @@ private static void writeFastDeleteHeader(RecyclerBytesStreamOutput buffer, Tran
117116 ByteUtils .writeLongBE (delete .version (), bytes , off + 6 );
118117 ByteUtils .writeLongBE (delete .seqNo (), bytes , off + 14 );
119118 ByteUtils .writeLongBE (delete .primaryTerm (), bytes , off + 22 );
119+ StreamOutput .putVInt (bytes , uid .length , off + 30 );
120+ System .arraycopy (uid .bytes , uid .offset , bytes , off + 30 + uidVIntLen , uid .length );
120121
121- long variableLengthStart = buffer .position ();
122- // Write variable length items in header
123- buffer .writeBytesRef (delete .uid ());
124- int variableLengthSize = (int ) (buffer .position () - variableLengthStart );
125122 // The total operation size is the header size + 4 bytes for checksum
126- int sizeOfOperation = FIXED_DELETE_HEADER_SIZE - Integer .BYTES + variableLengthSize + Integer .BYTES ;
123+ int sizeOfOperation = FIXED_DELETE_HEADER_SIZE - Integer .BYTES + uidVIntLen + uid . length + Integer .BYTES ;
127124 ByteUtils .writeIntBE (sizeOfOperation , bytes , off );
128125 }
129126
0 commit comments