Skip to content

Commit f827c1a

Browse files
committed
Exclude inference fields in translog assertions
1 parent 5302589 commit f827c1a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

muted-tests.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,6 @@ tests:
394394
- class: org.elasticsearch.xpack.esql.heap_attack.HeapAttackIT
395395
method: testLookupExplosionBigStringManyMatches
396396
issue: https://github.com/elastic/elasticsearch/issues/121465
397-
- class: org.elasticsearch.xpack.esql.qa.multi_node.EsqlSpecIT
398-
issue: https://github.com/elastic/elasticsearch/issues/121411
399397
- class: org.elasticsearch.xpack.migrate.action.ReindexDatastreamIndexTransportActionIT
400398
issue: https://github.com/elastic/elasticsearch/issues/121737
401399

server/src/main/java/org/elasticsearch/index/engine/TranslogOperationAsserter.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
package org.elasticsearch.index.engine;
1111

1212
import org.apache.lucene.search.similarities.BM25Similarity;
13+
import org.elasticsearch.common.Strings;
1314
import org.elasticsearch.index.cache.query.TrivialQueryCachingPolicy;
1415
import org.elasticsearch.index.mapper.DocumentParser;
1516
import org.elasticsearch.index.mapper.MappingLookup;
1617
import org.elasticsearch.index.shard.ShardId;
1718
import org.elasticsearch.index.translog.Translog;
19+
import org.elasticsearch.search.lookup.Source;
20+
import org.elasticsearch.search.lookup.SourceFilter;
1821

1922
import java.io.IOException;
2023

@@ -43,11 +46,32 @@ public boolean assertSameIndexOperation(Translog.Index o1, Translog.Index o2) th
4346
return super.assertSameIndexOperation(synthesizeSource(engineConfig, o1), o2)
4447
|| super.assertSameIndexOperation(o1, synthesizeSource(engineConfig, o2));
4548
}
49+
// TODO: Investigate why we still have different precision even after synthesizing the source, and remove this check
50+
if (engineConfig.getMapperService().mappingLookup().inferenceFields().isEmpty() == false) {
51+
return super.assertSameIndexOperation(
52+
excludeInferenceFields(o1, engineConfig.getMapperService().mappingLookup()),
53+
excludeInferenceFields(o2, engineConfig.getMapperService().mappingLookup())
54+
);
55+
}
4656
return false;
4757
}
4858
};
4959
}
5060

61+
static Translog.Index excludeInferenceFields(Translog.Index index, MappingLookup mappingLookup) {
62+
final String[] inferenceFields = mappingLookup.inferenceFields().keySet().toArray(String[]::new);
63+
final SourceFilter sourceFilter = new SourceFilter(Strings.EMPTY_ARRAY, inferenceFields);
64+
return new Translog.Index(
65+
index.id(),
66+
index.seqNo(),
67+
index.primaryTerm(),
68+
index.version(),
69+
Source.fromBytes(index.source()).filter(sourceFilter).internalSourceRef(),
70+
index.routing(),
71+
index.getAutoGeneratedIdTimestamp()
72+
);
73+
}
74+
5175
static Translog.Index synthesizeSource(EngineConfig engineConfig, Translog.Index op) throws IOException {
5276
final ShardId shardId = engineConfig.getShardId();
5377
final MappingLookup mappingLookup = engineConfig.getMapperService().mappingLookup();

0 commit comments

Comments
 (0)