4242import org .elasticsearch .index .IndexSettings ;
4343import org .elasticsearch .index .VersionType ;
4444import org .elasticsearch .index .engine .Engine ;
45+ import org .elasticsearch .index .mapper .Uid ;
4546import org .elasticsearch .index .seqno .SequenceNumbersService ;
4647import org .elasticsearch .index .shard .AbstractIndexShardComponent ;
4748import org .elasticsearch .index .shard .IndexShardComponent ;
5859import java .util .Collections ;
5960import java .util .Iterator ;
6061import java .util .List ;
62+ import java .util .Objects ;
6163import java .util .Optional ;
6264import java .util .concurrent .atomic .AtomicBoolean ;
6365import java .util .concurrent .locks .ReadWriteLock ;
@@ -919,8 +921,8 @@ public static class Index implements Operation {
919921 private final String id ;
920922 private final long autoGeneratedIdTimestamp ;
921923 private final String type ;
922- private long seqNo = SequenceNumbersService . UNASSIGNED_SEQ_NO ;
923- private long primaryTerm = 0 ;
924+ private final long seqNo ;
925+ private final long primaryTerm ;
924926 private final long version ;
925927 private final VersionType versionType ;
926928 private final BytesReference source ;
@@ -950,6 +952,9 @@ public Index(StreamInput in) throws IOException {
950952 if (format >= FORMAT_SEQ_NO ) {
951953 seqNo = in .readLong ();
952954 primaryTerm = in .readLong ();
955+ } else {
956+ seqNo = SequenceNumbersService .UNASSIGNED_SEQ_NO ;
957+ primaryTerm = 0 ;
953958 }
954959 }
955960
@@ -976,6 +981,7 @@ public Index(String type, String id, long seqNo, long version, VersionType versi
976981 this .id = id ;
977982 this .source = new BytesArray (source );
978983 this .seqNo = seqNo ;
984+ this .primaryTerm = 0 ;
979985 this .version = version ;
980986 this .versionType = versionType ;
981987 this .routing = routing ;
@@ -1113,27 +1119,42 @@ public long getAutoGeneratedIdTimestamp() {
11131119
11141120 public static class Delete implements Operation {
11151121
1116- private static final int FORMAT_5_X = 2 ;
1117- private static final int FORMAT_SEQ_NO = FORMAT_5_X + 1 ;
1122+ public static final int FORMAT_5_0 = 2 ; // 5.0 - 5.5
1123+ private static final int FORMAT_SINGLE_TYPE = FORMAT_5_0 + 1 ; // 5.5 - 6.0
1124+ private static final int FORMAT_SEQ_NO = FORMAT_SINGLE_TYPE + 1 ; // 6.0 - *
11181125 public static final int SERIALIZATION_FORMAT = FORMAT_SEQ_NO ;
11191126
1120- private String type , id ;
1121- private Term uid ;
1122- private long seqNo = SequenceNumbersService . UNASSIGNED_SEQ_NO ;
1123- private long primaryTerm = 0 ;
1124- private long version = Versions . MATCH_ANY ;
1125- private VersionType versionType = VersionType . INTERNAL ;
1127+ private final String type , id ;
1128+ private final Term uid ;
1129+ private final long seqNo ;
1130+ private final long primaryTerm ;
1131+ private final long version ;
1132+ private final VersionType versionType ;
11261133
11271134 public Delete (StreamInput in ) throws IOException {
11281135 final int format = in .readVInt ();// SERIALIZATION_FORMAT
1129- assert format >= FORMAT_5_X : "format was: " + format ;
1130- uid = new Term (in .readString (), in .readString ());
1136+ assert format >= FORMAT_5_0 : "format was: " + format ;
1137+ if (format >= FORMAT_SINGLE_TYPE ) {
1138+ type = in .readString ();
1139+ id = in .readString ();
1140+ uid = new Term (in .readString (), in .readString ());
1141+ } else {
1142+ uid = new Term (in .readString (), in .readString ());
1143+ // the uid was constructed from the type and id so we can
1144+ // extract them back
1145+ Uid uidObject = Uid .createUid (uid .text ());
1146+ type = uidObject .type ();
1147+ id = uidObject .id ();
1148+ }
11311149 this .version = in .readLong ();
11321150 this .versionType = VersionType .fromValue (in .readByte ());
11331151 assert versionType .validateVersionForWrites (this .version );
11341152 if (format >= FORMAT_SEQ_NO ) {
11351153 seqNo = in .readLong ();
11361154 primaryTerm = in .readLong ();
1155+ } else {
1156+ seqNo = SequenceNumbersService .UNASSIGNED_SEQ_NO ;
1157+ primaryTerm = 0 ;
11371158 }
11381159 }
11391160
@@ -1147,8 +1168,8 @@ public Delete(String type, String id, long seqNo, Term uid) {
11471168 }
11481169
11491170 public Delete (String type , String id , Term uid , long seqNo , long primaryTerm , long version , VersionType versionType ) {
1150- this .type = type ;
1151- this .id = id ;
1171+ this .type = Objects . requireNonNull ( type ) ;
1172+ this .id = Objects . requireNonNull ( id ) ;
11521173 this .uid = uid ;
11531174 this .seqNo = seqNo ;
11541175 this .primaryTerm = primaryTerm ;
@@ -1204,6 +1225,8 @@ public Source getSource() {
12041225 @ Override
12051226 public void writeTo (StreamOutput out ) throws IOException {
12061227 out .writeVInt (SERIALIZATION_FORMAT );
1228+ out .writeString (type );
1229+ out .writeString (id );
12071230 out .writeString (uid .field ());
12081231 out .writeString (uid .text ());
12091232 out .writeLong (version );
0 commit comments