Skip to content

Commit 07f65e9

Browse files
authored
Fixing race condition in DynamicMappingIT when checking for updates in mappings (elastic#129931)
1 parent 7249ac4 commit 07f65e9

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,6 @@ tests:
565565
- class: org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapperTests
566566
method: testExistsQueryMinimalMapping
567567
issue: https://github.com/elastic/elasticsearch/issues/129911
568-
- class: org.elasticsearch.index.mapper.DynamicMappingIT
569-
method: testDenseVectorDynamicMapping
570-
issue: https://github.com/elastic/elasticsearch/issues/129928
571568

572569
# Examples:
573570
#

server/src/internalClusterTest/java/org/elasticsearch/index/mapper/DynamicMappingIT.java

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -920,19 +920,27 @@ public void testDenseVectorDynamicMapping() throws Exception {
920920

921921
client().index(
922922
new IndexRequest("test").source("vector_int8", Randomness.get().doubles(BBQ_DIMS_DEFAULT_THRESHOLD - 1, 0.0, 5.0).toArray())
923+
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
923924
).get();
924925
client().index(
925926
new IndexRequest("test").source("vector_bbq", Randomness.get().doubles(BBQ_DIMS_DEFAULT_THRESHOLD, 0.0, 5.0).toArray())
927+
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
926928
).get();
927-
Map<String, Object> mappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "test")
928-
.get()
929-
.mappings()
930-
.get("test")
931-
.sourceAsMap();
932-
assertTrue(new WriteField("properties.vector_int8", () -> mappings).exists());
933-
assertTrue(new WriteField("properties.vector_int8.index_options.type", () -> mappings).get(null).toString().equals("int8_hnsw"));
934-
assertTrue(new WriteField("properties.vector_bbq", () -> mappings).exists());
935-
assertTrue(new WriteField("properties.vector_bbq.index_options.type", () -> mappings).get(null).toString().equals("bbq_hnsw"));
929+
930+
assertBusy(() -> {
931+
Map<String, Object> mappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "test")
932+
.get()
933+
.mappings()
934+
.get("test")
935+
.sourceAsMap();
936+
937+
assertTrue(new WriteField("properties.vector_int8", () -> mappings).exists());
938+
assertTrue(
939+
new WriteField("properties.vector_int8.index_options.type", () -> mappings).get(null).toString().equals("int8_hnsw")
940+
);
941+
assertTrue(new WriteField("properties.vector_bbq", () -> mappings).exists());
942+
assertTrue(new WriteField("properties.vector_bbq.index_options.type", () -> mappings).get(null).toString().equals("bbq_hnsw"));
943+
});
936944
}
937945

938946
public void testBBQDynamicMappingWhenFirstIngestingDoc() throws Exception {
@@ -954,14 +962,19 @@ public void testBBQDynamicMappingWhenFirstIngestingDoc() throws Exception {
954962
assertTrue(new WriteField("properties.vector", () -> mappings).exists());
955963
assertFalse(new WriteField("properties.vector.index_options.type", () -> mappings).exists());
956964

957-
client().index(new IndexRequest("test").source("vector", Randomness.get().doubles(BBQ_DIMS_DEFAULT_THRESHOLD, 0.0, 5.0).toArray()))
958-
.get();
959-
Map<String, Object> updatedMappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "test")
960-
.get()
961-
.mappings()
962-
.get("test")
963-
.sourceAsMap();
964-
assertTrue(new WriteField("properties.vector", () -> updatedMappings).exists());
965-
assertTrue(new WriteField("properties.vector.index_options.type", () -> updatedMappings).get(null).toString().equals("bbq_hnsw"));
965+
client().index(
966+
new IndexRequest("test").source("vector", Randomness.get().doubles(BBQ_DIMS_DEFAULT_THRESHOLD, 0.0, 5.0).toArray())
967+
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
968+
).get();
969+
970+
assertBusy(() -> {
971+
Map<String, Object> updatedMappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "test")
972+
.get()
973+
.mappings()
974+
.get("test")
975+
.sourceAsMap();
976+
assertTrue(new WriteField("properties.vector", () -> updatedMappings).exists());
977+
assertTrue(new WriteField("properties.vector.index_options.type", () -> updatedMappings).get("").toString().equals("bbq_hnsw"));
978+
});
966979
}
967980
}

0 commit comments

Comments
 (0)