Skip to content

Commit 30f8b51

Browse files
committed
More reorder
1 parent 9722a0f commit 30f8b51

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,9 +1276,9 @@ private static Index readFrom(StreamInput in) throws IOException {
12761276
primaryTerm = in.readLong();
12771277
} else {
12781278
version = in.readLong();
1279-
autoGeneratedIdTimestamp = in.readLong();
12801279
seqNo = in.readLong();
12811280
primaryTerm = in.readLong();
1281+
autoGeneratedIdTimestamp = in.readLong();
12821282
uid = in.readBytesRef();
12831283
routing = in.readOptionalString();
12841284
source = in.readBytesReference();
@@ -1360,9 +1360,9 @@ public long version() {
13601360
protected void writeHeader(int format, StreamOutput out) throws IOException {
13611361
out.writeVInt(format);
13621362
out.writeLong(version);
1363-
out.writeLong(autoGeneratedIdTimestamp);
13641363
out.writeLong(seqNo);
13651364
out.writeLong(primaryTerm);
1365+
out.writeLong(autoGeneratedIdTimestamp);
13661366
out.writeBytesRef(uid);
13671367
out.writeOptionalString(routing);
13681368
out.writeVInt(source == null ? 0 : source.length());

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ public final class TranslogHeaderWriter {
2828
public static final int FIXED_DELETE_HEADER_SIZE = 30;
2929
public static final int FIXED_NO_OP_HEADER_SIZE = 21;
3030

31+
public static final int OPERATION_TYPE_OFFSET = 4;
32+
public static final int SERIALIZATION_FORMAT_OFFSET = 5;
33+
public static final int VERSION_OFFSET = 6;
34+
public static final int SEQ_NO_OFFSET = 14;
35+
public static final int PRIMARY_TERM_OFFSET = 22;
36+
37+
public static final int INDEX_AUTO_GENERATED_ID_TIMESTAMP_OFFSET = 30;
38+
public static final int INDEX_UID_LENGTH_OFFSET = 38;
39+
3140
private TranslogHeaderWriter() {
3241
// This class depends on the serialization format fitting in a single vInt byte. If we advance pass 127 we need to tweak the logic
3342
// to write 2 bytes.
@@ -53,16 +62,16 @@ private static void writeFastIndexHeader(RecyclerBytesStreamOutput buffer, Trans
5362

5463
int off = page.offset;
5564
byte[] bytes = page.bytes;
56-
bytes[off + 4] = Translog.Operation.Type.INDEX.id();
65+
bytes[off + OPERATION_TYPE_OFFSET] = Translog.Operation.Type.INDEX.id();
5766
// This is technically a vInt in the serialization, but until we advance past 127 we can just directly serialize as a byte
58-
bytes[off + 5] = (byte) Translog.Index.SERIALIZATION_FORMAT;
59-
ByteUtils.writeLongBE(index.version(), bytes, off + 6);
60-
ByteUtils.writeLongBE(index.getAutoGeneratedIdTimestamp(), bytes, off + 14);
61-
ByteUtils.writeLongBE(index.seqNo(), bytes, off + 22);
62-
ByteUtils.writeLongBE(index.primaryTerm(), bytes, off + 30);
63-
StreamOutput.putVInt(bytes, uid.length, off + 38);
64-
System.arraycopy(uid.bytes, uid.offset, bytes, off + 38 + uidVIntLen, uid.length);
65-
bytes[off + 38 + uidVIntLen + uid.length] = index.routing() == null ? (byte) 0 : (byte) 1;
67+
bytes[off + SERIALIZATION_FORMAT_OFFSET] = (byte) Translog.Index.SERIALIZATION_FORMAT;
68+
ByteUtils.writeLongBE(index.version(), bytes, off + VERSION_OFFSET);
69+
ByteUtils.writeLongBE(index.seqNo(), bytes, off + SEQ_NO_OFFSET);
70+
ByteUtils.writeLongBE(index.primaryTerm(), bytes, off + PRIMARY_TERM_OFFSET);
71+
ByteUtils.writeLongBE(index.getAutoGeneratedIdTimestamp(), bytes, off + INDEX_AUTO_GENERATED_ID_TIMESTAMP_OFFSET);
72+
StreamOutput.putVInt(bytes, uid.length, off + INDEX_UID_LENGTH_OFFSET);
73+
System.arraycopy(uid.bytes, uid.offset, bytes, off + INDEX_UID_LENGTH_OFFSET + uidVIntLen, uid.length);
74+
bytes[off + INDEX_UID_LENGTH_OFFSET + uidVIntLen + uid.length] = index.routing() == null ? (byte) 0 : (byte) 1;
6675

6776
long variableLengthStart = buffer.position();
6877
// Write variable length items in header
@@ -111,12 +120,12 @@ private static void writeFastDeleteHeader(Translog.Delete delete, BytesRef page,
111120

112121
int off = page.offset;
113122
byte[] bytes = page.bytes;
114-
bytes[off + 4] = Translog.Operation.Type.DELETE.id();
123+
bytes[off + OPERATION_TYPE_OFFSET] = Translog.Operation.Type.DELETE.id();
115124
// This is technically a vInt in the serialization, but until we advance past 127 we can just directly serialize as a byte
116-
bytes[off + 5] = (byte) Translog.Delete.SERIALIZATION_FORMAT;
117-
ByteUtils.writeLongBE(delete.version(), bytes, off + 6);
118-
ByteUtils.writeLongBE(delete.seqNo(), bytes, off + 14);
119-
ByteUtils.writeLongBE(delete.primaryTerm(), bytes, off + 22);
125+
bytes[off + SERIALIZATION_FORMAT_OFFSET] = (byte) Translog.Delete.SERIALIZATION_FORMAT;
126+
ByteUtils.writeLongBE(delete.version(), bytes, off + VERSION_OFFSET);
127+
ByteUtils.writeLongBE(delete.seqNo(), bytes, off + SEQ_NO_OFFSET);
128+
ByteUtils.writeLongBE(delete.primaryTerm(), bytes, off + PRIMARY_TERM_OFFSET);
120129
StreamOutput.putVInt(bytes, uid.length, off + FIXED_DELETE_HEADER_SIZE);
121130
System.arraycopy(uid.bytes, uid.offset, bytes, off + FIXED_DELETE_HEADER_SIZE + uidVIntLen, uid.length);
122131

@@ -142,7 +151,7 @@ public static void writeNoOpHeader(RecyclerBytesStreamOutput buffer, Translog.No
142151
if (bytesRef != null) {
143152
int off = bytesRef.offset;
144153
byte[] bytes = bytesRef.bytes;
145-
bytes[off + 4] = Translog.Operation.Type.NO_OP.id();
154+
bytes[off + OPERATION_TYPE_OFFSET] = Translog.Operation.Type.NO_OP.id();
146155
ByteUtils.writeLongBE(noop.seqNo(), bytes, off + 5);
147156
ByteUtils.writeLongBE(noop.primaryTerm(), bytes, off + 13);
148157

0 commit comments

Comments
 (0)