Skip to content

Commit b63f9b9

Browse files
authored
Fix translog bwc serialization (#36676)
Serializing of a Translog#Index from v7.0.0 to 6.x is broken since #29224 where we removed the _parent field. Relates #29224
1 parent 9b1534b commit b63f9b9

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,9 @@ private void write(final StreamOutput out) throws IOException {
12271227
out.writeString(type);
12281228
out.writeBytesReference(source);
12291229
out.writeOptionalString(routing);
1230+
if (format < FORMAT_NO_PARENT) {
1231+
out.writeOptionalString(null); // _parent
1232+
}
12301233
out.writeLong(version);
12311234
if (format < FORMAT_NO_VERSION_TYPE) {
12321235
out.writeByte(VersionType.EXTERNAL.getValue());

server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.lucene.util.LineFileDocs;
3636
import org.apache.lucene.util.LuceneTestCase;
3737
import org.elasticsearch.Assertions;
38+
import org.elasticsearch.Version;
3839
import org.elasticsearch.cluster.metadata.IndexMetaData;
3940
import org.elasticsearch.common.Randomness;
4041
import org.elasticsearch.common.Strings;
@@ -72,6 +73,7 @@
7273
import org.elasticsearch.index.translog.Translog.Location;
7374
import org.elasticsearch.test.ESTestCase;
7475
import org.elasticsearch.test.IndexSettingsModule;
76+
import org.elasticsearch.test.VersionUtils;
7577
import org.hamcrest.Matchers;
7678
import org.junit.After;
7779
import org.junit.Before;
@@ -2814,9 +2816,12 @@ public void testTranslogOpSerialization() throws Exception {
28142816
Engine.IndexResult eIndexResult = new Engine.IndexResult(1, randomPrimaryTerm, randomSeqNum, true);
28152817
Translog.Index index = new Translog.Index(eIndex, eIndexResult);
28162818

2819+
Version wireVersion = VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT);
28172820
BytesStreamOutput out = new BytesStreamOutput();
2821+
out.setVersion(wireVersion);
28182822
Translog.Operation.writeOperation(out, index);
28192823
StreamInput in = out.bytes().streamInput();
2824+
in.setVersion(wireVersion);
28202825
Translog.Index serializedIndex = (Translog.Index) Translog.Operation.readOperation(in);
28212826
assertEquals(index, serializedIndex);
28222827

@@ -2826,8 +2831,10 @@ public void testTranslogOpSerialization() throws Exception {
28262831
Translog.Delete delete = new Translog.Delete(eDelete, eDeleteResult);
28272832

28282833
out = new BytesStreamOutput();
2834+
out.setVersion(wireVersion);
28292835
Translog.Operation.writeOperation(out, delete);
28302836
in = out.bytes().streamInput();
2837+
in.setVersion(wireVersion);
28312838
Translog.Delete serializedDelete = (Translog.Delete) Translog.Operation.readOperation(in);
28322839
assertEquals(delete, serializedDelete);
28332840
}

0 commit comments

Comments
 (0)