Skip to content

Commit 33b0a22

Browse files
committed
Avoid changing tsid creating strategy for an index
This avoids that the tsid and routing is calculated differently on the same index. Doing so would have the following consequences: * De-duplication would not work, for example, when a client re-transmits a batch as the id (which is based on the tsid) will be different. * When replaying a translog operation, the re-computed tsid and id will differ from the id stored in the translog. This would lead to a failure of the index operation.
1 parent 56d0d43 commit 33b0a22

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

modules/data-streams/src/main/java/org/elasticsearch/datastreams/DataStreamIndexSettingsProvider.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,13 @@ public void onUpdateMappings(IndexMetadata indexMetadata, DocumentMapper documen
172172
boolean hasChanges = indexDimensions.size() != newIndexDimensions.size()
173173
&& new HashSet<>(indexDimensions).equals(new HashSet<>(newIndexDimensions)) == false;
174174
if (matchesAllDimensions == false) {
175-
// If the new dimensions don't match all potential dimension fields, we need to unset index.dimensions
176-
// and set index.routing_path instead.
177-
// This can happen if a new dynamic template with time_series_dimension: true is added to an existing index.
178-
additionalSettings.putList(INDEX_DIMENSIONS.getKey(), List.of());
179-
additionalSettings.putList(INDEX_ROUTING_PATH.getKey(), newIndexDimensions);
175+
throw new IllegalArgumentException(
176+
"Cannot add dimension fields via dynamic templates or mappings for an index with "
177+
+ INDEX_DIMENSIONS.getKey()
178+
+ ". "
179+
+ "Please change the index template and roll over the data stream "
180+
+ "instead of modifying the mappings of the backing indices."
181+
);
180182
} else if (hasChanges) {
181183
additionalSettings.putList(INDEX_DIMENSIONS.getKey(), newIndexDimensions);
182184
}

modules/data-streams/src/test/java/org/elasticsearch/datastreams/DataStreamIndexSettingsProviderTests.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -956,10 +956,18 @@ public void testAddDynamicTemplate() throws Exception {
956956
}
957957
""";
958958
// we don't support index.dimensions with dynamic templates so we'll unset index.dimensions
959-
Settings result = onUpdateMappings(null, "labels.*", mapping);
960-
assertThat(result.size(), equalTo(2));
961-
assertThat(IndexMetadata.INDEX_DIMENSIONS.get(result), empty());
962-
assertThat(IndexMetadata.INDEX_ROUTING_PATH.get(result), containsInAnyOrder("labels.*"));
959+
IllegalArgumentException exception = assertThrows(
960+
IllegalArgumentException.class,
961+
() -> onUpdateMappings(null, "labels.*", mapping)
962+
);
963+
assertThat(
964+
exception.getMessage(),
965+
equalTo(
966+
"Cannot add dimension fields via dynamic templates or mappings for an index with index.dimensions. "
967+
+ "Please change the index template and roll over the data stream "
968+
+ "instead of modifying the mappings of the backing indices."
969+
)
970+
);
963971
}
964972

965973
private Settings generateTsdbSettings(String mapping, Instant now) throws IOException {

0 commit comments

Comments
 (0)