@@ -1243,7 +1243,7 @@ public static final class Index extends Operation {
12431243 public static final int FORMAT_REORDERED = FORMAT_NO_DOC_TYPE + 1 ;
12441244 public static final int SERIALIZATION_FORMAT = FORMAT_REORDERED ;
12451245
1246- private final String id ;
1246+ private final BytesRef uid ;
12471247 private final long autoGeneratedIdTimestamp ;
12481248 private final long version ;
12491249 private final BytesReference source ;
@@ -1252,15 +1252,15 @@ public static final class Index extends Operation {
12521252 private static Index readFrom (StreamInput in ) throws IOException {
12531253 final int format = in .readVInt (); // SERIALIZATION_FORMAT
12541254 assert format >= FORMAT_NO_PARENT : "format was: " + format ;
1255- String id ;
1255+ BytesRef uid ;
12561256 BytesReference source ;
12571257 String routing ;
12581258 long version ;
12591259 long autoGeneratedIdTimestamp ;
12601260 long seqNo ;
12611261 long primaryTerm ;
12621262 if (format < FORMAT_REORDERED ) {
1263- id = in .readString ();
1263+ uid = Uid . encodeId ( in .readString () );
12641264 if (format < FORMAT_NO_DOC_TYPE ) {
12651265 in .readString ();
12661266 // can't assert that this is _doc because pre-8.0 indexes can have any name for a type
@@ -1279,16 +1279,16 @@ private static Index readFrom(StreamInput in) throws IOException {
12791279 autoGeneratedIdTimestamp = in .readLong ();
12801280 seqNo = in .readLong ();
12811281 primaryTerm = in .readLong ();
1282+ uid = in .readBytesRef ();
12821283 routing = in .readOptionalString ();
1283- id = in .readString ();
12841284 source = in .readBytesReference ();
12851285 }
1286- return new Index (id , seqNo , primaryTerm , version , source , routing , autoGeneratedIdTimestamp );
1286+ return new Index (uid , seqNo , primaryTerm , version , source , routing , autoGeneratedIdTimestamp );
12871287 }
12881288
12891289 public Index (Engine .Index index , Engine .IndexResult indexResult ) {
12901290 this (
1291- index .id (),
1291+ index .uid (),
12921292 indexResult .getSeqNo (),
12931293 index .primaryTerm (),
12941294 indexResult .getVersion (),
@@ -1306,9 +1306,21 @@ public Index(
13061306 BytesReference source ,
13071307 String routing ,
13081308 long autoGeneratedIdTimestamp
1309+ ) {
1310+ this (Uid .encodeId (id ), seqNo , primaryTerm , version , source , routing , autoGeneratedIdTimestamp );
1311+ }
1312+
1313+ public Index (
1314+ BytesRef uid ,
1315+ long seqNo ,
1316+ long primaryTerm ,
1317+ long version ,
1318+ BytesReference source ,
1319+ String routing ,
1320+ long autoGeneratedIdTimestamp
13091321 ) {
13101322 super (seqNo , primaryTerm );
1311- this .id = id ;
1323+ this .uid = uid ;
13121324 this .source = source ;
13131325 this .version = version ;
13141326 this .routing = routing ;
@@ -1322,14 +1334,14 @@ public Type opType() {
13221334
13231335 @ Override
13241336 public long estimateSize () {
1325- return ( 2 * id .length ()) + source .length () + (routing != null ? 2 * routing .length () : 0 ) + (4 * Long .BYTES ); // timestamp,
1337+ return uid .length + source .length () + (routing != null ? 2 * routing .length () : 0 ) + (4 * Long .BYTES ); // timestamp,
13261338 // seq_no,
13271339 // primary_term,
13281340 // and version
13291341 }
13301342
1331- public String id () {
1332- return this . id ;
1343+ public BytesRef uid () {
1344+ return uid ;
13331345 }
13341346
13351347 public String routing () {
@@ -1351,8 +1363,8 @@ protected void writeHeader(int format, StreamOutput out) throws IOException {
13511363 out .writeLong (autoGeneratedIdTimestamp );
13521364 out .writeLong (seqNo );
13531365 out .writeLong (primaryTerm );
1366+ out .writeBytesRef (uid );
13541367 out .writeOptionalString (routing );
1355- out .writeString (id );
13561368 out .writeVInt (source == null ? 0 : source .length ());
13571369 }
13581370
@@ -1363,7 +1375,7 @@ public void writeBody(final StreamOutput out) throws IOException {
13631375 : FORMAT_NO_VERSION_TYPE ;
13641376 if (format < FORMAT_REORDERED ) {
13651377 out .writeVInt (format );
1366- out .writeString (id );
1378+ out .writeString (Uid . decodeId ( uid . bytes , uid . offset , uid . length ) );
13671379 if (format < FORMAT_NO_DOC_TYPE ) {
13681380 out .writeString (MapperService .SINGLE_MAPPING_NAME );
13691381 }
@@ -1396,7 +1408,7 @@ public boolean equals(Object o) {
13961408
13971409 @ Override
13981410 public int hashCode () {
1399- int result = id .hashCode ();
1411+ int result = uid .hashCode ();
14001412 result = 31 * result + Long .hashCode (seqNo );
14011413 result = 31 * result + Long .hashCode (primaryTerm );
14021414 result = 31 * result + Long .hashCode (version );
@@ -1410,7 +1422,7 @@ public int hashCode() {
14101422 public String toString () {
14111423 return "Index{"
14121424 + "id='"
1413- + id
1425+ + Uid . decodeId ( uid . bytes , uid . offset , uid . length )
14141426 + '\''
14151427 + ", seqNo="
14161428 + seqNo
@@ -1431,7 +1443,7 @@ public static boolean equalsWithoutAutoGeneratedTimestamp(Translog.Index o1, Tra
14311443 if (o1 .version != o2 .version
14321444 || o1 .seqNo != o2 .seqNo
14331445 || o1 .primaryTerm != o2 .primaryTerm
1434- || o1 .id .equals (o2 .id ) == false
1446+ || o1 .uid .equals (o2 .uid ) == false
14351447 || Objects .equals (o1 .routing , o2 .routing ) == false ) {
14361448 return false ;
14371449 }
@@ -1475,13 +1487,13 @@ public static final class Delete extends Operation {
14751487 public static final int FORMAT_REORDERED = FORMAT_NO_DOC_TYPE + 1 ;
14761488 public static final int SERIALIZATION_FORMAT = FORMAT_REORDERED ;
14771489
1478- private final String id ;
1490+ private final BytesRef uid ;
14791491 private final long version ;
14801492
14811493 private static Delete readFrom (StreamInput in ) throws IOException {
14821494 final int format = in .readVInt ();// SERIALIZATION_FORMAT
14831495 assert format >= FORMAT_6_0 : "format was: " + format ;
1484- final String id ;
1496+ final BytesRef uid ;
14851497 final long version ;
14861498 final long seqNo ;
14871499 final long primaryTerm ;
@@ -1490,7 +1502,7 @@ private static Delete readFrom(StreamInput in) throws IOException {
14901502 in .readString ();
14911503 // Can't assert that this is _doc because pre-8.0 indexes can have any name for a type
14921504 }
1493- id = in .readString ();
1505+ uid = Uid . encodeId ( in .readString () );
14941506 if (format < FORMAT_NO_DOC_TYPE ) {
14951507 final String docType = in .readString ();
14961508 assert docType .equals (IdFieldMapper .NAME ) : docType + " != " + IdFieldMapper .NAME ;
@@ -1506,23 +1518,28 @@ private static Delete readFrom(StreamInput in) throws IOException {
15061518 version = in .readLong ();
15071519 seqNo = in .readLong ();
15081520 primaryTerm = in .readLong ();
1509- id = in .readString ();
1521+ uid = in .readBytesRef ();
15101522 }
1511- return new Delete (id , seqNo , primaryTerm , version );
1523+ return new Delete (uid , seqNo , primaryTerm , version );
15121524 }
15131525
15141526 public Delete (Engine .Delete delete , Engine .DeleteResult deleteResult ) {
1515- this (delete .id (), deleteResult .getSeqNo (), delete .primaryTerm (), deleteResult .getVersion ());
1527+ this (delete .uid (), deleteResult .getSeqNo (), delete .primaryTerm (), deleteResult .getVersion ());
15161528 }
15171529
15181530 /** utility for testing */
15191531 public Delete (String id , long seqNo , long primaryTerm ) {
15201532 this (id , seqNo , primaryTerm , Versions .MATCH_ANY );
15211533 }
15221534
1535+ /** utility for testing */
15231536 public Delete (String id , long seqNo , long primaryTerm , long version ) {
1537+ this (Uid .encodeId (id ), seqNo , primaryTerm , version );
1538+ }
1539+
1540+ public Delete (BytesRef uid , long seqNo , long primaryTerm , long version ) {
15241541 super (seqNo , primaryTerm );
1525- this .id = Objects .requireNonNull (id );
1542+ this .uid = Objects .requireNonNull (uid );
15261543 this .version = version ;
15271544 }
15281545
@@ -1533,7 +1550,7 @@ public Type opType() {
15331550
15341551 @ Override
15351552 public long estimateSize () {
1536- return ( 2 * id .length ()) + (3 * Long .BYTES ); // seq_no, primary_term, and version;
1553+ return uid .length + (3 * Long .BYTES ); // seq_no, primary_term, and version;
15371554 }
15381555
15391556 @ Override
@@ -1542,11 +1559,11 @@ protected void writeHeader(int format, StreamOutput out) throws IOException {
15421559 out .writeLong (version );
15431560 out .writeLong (seqNo );
15441561 out .writeLong (primaryTerm );
1545- out .writeString ( id );
1562+ out .writeBytesRef ( uid );
15461563 }
15471564
1548- public String id () {
1549- return id ;
1565+ public BytesRef uid () {
1566+ return uid ;
15501567 }
15511568
15521569 public long version () {
@@ -1563,10 +1580,10 @@ public void writeBody(final StreamOutput out) throws IOException {
15631580 if (format < FORMAT_NO_DOC_TYPE ) {
15641581 out .writeString (MapperService .SINGLE_MAPPING_NAME );
15651582 }
1566- out .writeString (id );
1583+ out .writeString (Uid . decodeId ( uid ) );
15671584 if (format < FORMAT_NO_DOC_TYPE ) {
15681585 out .writeString (IdFieldMapper .NAME );
1569- out .writeBytesRef (Uid . encodeId ( id ) );
1586+ out .writeBytesRef (uid );
15701587 }
15711588 out .writeLong (version );
15721589 out .writeLong (seqNo );
@@ -1587,12 +1604,12 @@ public boolean equals(Object o) {
15871604
15881605 Delete delete = (Delete ) o ;
15891606
1590- return id .equals (delete .id ) && seqNo == delete .seqNo && primaryTerm == delete .primaryTerm && version == delete .version ;
1607+ return uid .equals (delete .uid ) && seqNo == delete .seqNo && primaryTerm == delete .primaryTerm && version == delete .version ;
15911608 }
15921609
15931610 @ Override
15941611 public int hashCode () {
1595- int result = id .hashCode ();
1612+ int result = uid .hashCode ();
15961613 result += 31 * Long .hashCode (seqNo );
15971614 result = 31 * result + Long .hashCode (primaryTerm );
15981615 result = 31 * result + Long .hashCode (version );
@@ -1601,7 +1618,16 @@ public int hashCode() {
16011618
16021619 @ Override
16031620 public String toString () {
1604- return "Delete{" + "id='" + id + "', seqNo=" + seqNo + ", primaryTerm=" + primaryTerm + ", version=" + version + '}' ;
1621+ return "Delete{"
1622+ + "id='"
1623+ + Uid .decodeId (uid )
1624+ + "', seqNo="
1625+ + seqNo
1626+ + ", primaryTerm="
1627+ + primaryTerm
1628+ + ", version="
1629+ + version
1630+ + '}' ;
16051631 }
16061632 }
16071633
0 commit comments