|
22 | 22 | import org.elasticsearch.common.io.stream.Writeable; |
23 | 23 | import org.elasticsearch.common.lucene.uid.Versions; |
24 | 24 | import org.elasticsearch.common.util.BigArrays; |
| 25 | +import org.elasticsearch.common.xcontent.XContentHelper; |
25 | 26 | import org.elasticsearch.core.IOUtils; |
26 | 27 | import org.elasticsearch.core.Nullable; |
27 | 28 | import org.elasticsearch.core.Releasable; |
|
35 | 36 | import org.elasticsearch.index.shard.AbstractIndexShardComponent; |
36 | 37 | import org.elasticsearch.index.shard.IndexShardComponent; |
37 | 38 | import org.elasticsearch.index.shard.ShardId; |
| 39 | +import org.elasticsearch.search.lookup.Source; |
| 40 | +import org.elasticsearch.xcontent.XContentParserConfiguration; |
38 | 41 |
|
39 | 42 | import java.io.Closeable; |
40 | 43 | import java.io.EOFException; |
@@ -1226,9 +1229,9 @@ public Type opType() { |
1226 | 1229 | @Override |
1227 | 1230 | public long estimateSize() { |
1228 | 1231 | return (2 * id.length()) + source.length() + (routing != null ? 2 * routing.length() : 0) + (4 * Long.BYTES); // timestamp, |
1229 | | - // seq_no, |
1230 | | - // primary_term, |
1231 | | - // and version |
| 1232 | + // seq_no, |
| 1233 | + // primary_term, |
| 1234 | + // and version |
1232 | 1235 | } |
1233 | 1236 |
|
1234 | 1237 | public String id() { |
@@ -1275,7 +1278,7 @@ public boolean equals(Object o) { |
1275 | 1278 | } |
1276 | 1279 |
|
1277 | 1280 | Index other = (Index) o; |
1278 | | - return autoGeneratedIdTimestamp == other.autoGeneratedIdTimestamp && equalsWithoutAutoGeneratedTimestamp(this, other); |
| 1281 | + return autoGeneratedIdTimestamp == other.autoGeneratedIdTimestamp && equalsWithoutAutoGeneratedTimestamp(this, other, true); |
1279 | 1282 | } |
1280 | 1283 |
|
1281 | 1284 | @Override |
@@ -1311,15 +1314,43 @@ public long getAutoGeneratedIdTimestamp() { |
1311 | 1314 | return autoGeneratedIdTimestamp; |
1312 | 1315 | } |
1313 | 1316 |
|
1314 | | - public static boolean equalsWithoutAutoGeneratedTimestamp(Translog.Index o1, Translog.Index o2) { |
1315 | | - return o1.version == o2.version |
1316 | | - && o1.seqNo == o2.seqNo |
1317 | | - && o1.primaryTerm == o2.primaryTerm |
1318 | | - && o1.id.equals(o2.id) |
1319 | | - && o1.source.equals(o2.source) |
1320 | | - && Objects.equals(o1.routing, o2.routing); |
1321 | | - } |
| 1317 | + public static boolean equalsWithoutAutoGeneratedTimestamp(Translog.Index o1, Translog.Index o2, boolean checkSourceBytes) { |
| 1318 | + if (o1.version != o2.version |
| 1319 | + || o1.seqNo != o2.seqNo |
| 1320 | + || o1.primaryTerm != o2.primaryTerm |
| 1321 | + || o1.id.equals(o2.id) == false |
| 1322 | + || Objects.equals(o1.routing, o2.routing) == false) { |
| 1323 | + return false; |
| 1324 | + } |
| 1325 | + |
| 1326 | + if (checkSourceBytes) { |
| 1327 | + return o1.source.equals(o2.source); |
| 1328 | + } |
1322 | 1329 |
|
| 1330 | + var s1 = Source.fromBytes(o1.source); |
| 1331 | + var s2 = Source.fromBytes(o2.source); |
| 1332 | + try ( |
| 1333 | + var actualParser = XContentHelper.createParserNotCompressed( |
| 1334 | + XContentParserConfiguration.EMPTY, |
| 1335 | + s1.internalSourceRef(), |
| 1336 | + s1.sourceContentType() |
| 1337 | + ) |
| 1338 | + ) { |
| 1339 | + var actualMap = actualParser.map(); |
| 1340 | + try ( |
| 1341 | + var expectedParser = XContentHelper.createParserNotCompressed( |
| 1342 | + XContentParserConfiguration.EMPTY, |
| 1343 | + s2.internalSourceRef(), |
| 1344 | + s2.sourceContentType() |
| 1345 | + ) |
| 1346 | + ) { |
| 1347 | + var expectedMap = expectedParser.map(); |
| 1348 | + return expectedMap.equals(actualMap); |
| 1349 | + } |
| 1350 | + } catch (IOException exc) { |
| 1351 | + return false; |
| 1352 | + } |
| 1353 | + } |
1323 | 1354 | } |
1324 | 1355 |
|
1325 | 1356 | public static final class Delete extends Operation { |
|
0 commit comments