Skip to content

Commit a0289db

Browse files
authored
Improving performance of get data streams API by avoiding getting effective mappings (#138948)
1 parent 7f7e44e commit a0289db

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

docs/changelog/138948.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 138948
2+
summary: Improving performance of get data streams API by avoiding getting effective
3+
mappings
4+
area: Data streams
5+
type: bug
6+
issues: []

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.elasticsearch.cluster.metadata.DataStreamLifecycle;
3333
import org.elasticsearch.cluster.metadata.IndexMetadata;
3434
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
35+
import org.elasticsearch.cluster.metadata.MetadataCreateDataStreamService;
3536
import org.elasticsearch.cluster.metadata.MetadataDataStreamsService;
3637
import org.elasticsearch.cluster.metadata.MetadataIndexTemplateService;
3738
import org.elasticsearch.cluster.metadata.ProjectMetadata;
@@ -278,12 +279,21 @@ static GetDataStreamAction.Response innerOperation(
278279
} else {
279280
indexTemplate = MetadataIndexTemplateService.findV2Template(state.metadata(), dataStream.getName(), false);
280281
if (indexTemplate != null) {
281-
final Settings settings;
282-
try {
283-
settings = metadataDataStreamsService.getEffectiveSettings(state.metadata(), dataStream);
284-
} catch (IOException e) {
285-
throw new RuntimeException("Failed to get effective settings for data stream: " + dataStream.getName(), e);
286-
}
282+
/*
283+
* Here we intentionally avoid the full MetadataDataStreamService::getEffectiveSettings and instead do a shortcut that
284+
* does not merge all mappings together in order to fetch the settings from additional settings providers. The reason
285+
* is that this code can be called fairly frequently, and we do not need that information here -- we get settings from
286+
* additional settings providers below in resolveMode, and those settings do not require any information from mappings.
287+
*/
288+
ComposableIndexTemplate template = MetadataCreateDataStreamService.lookupTemplateForDataStream(
289+
dataStream.getName(),
290+
state.metadata()
291+
);
292+
Settings templateSettings = MetadataIndexTemplateService.resolveSettings(
293+
template,
294+
state.metadata().componentTemplates()
295+
);
296+
final Settings settings = templateSettings.merge(dataStream.getSettings());
287297
ilmPolicyName = settings.get(IndexMetadata.LIFECYCLE_NAME);
288298
if (indexMode == null && state.metadata().templatesV2().get(indexTemplate) != null) {
289299
try {

modules/data-streams/src/yamlRestTest/resources/rest-api-spec/test/data_stream/280_data_stream_mappings-timeseries.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
- match: { data_streams.0.name: my-data-stream-1 }
4040
- match: { data_streams.0.mappings: {} }
4141
- match: { data_streams.0.effective_mappings: null }
42+
- match: { data_streams.0.index_mode: time_series }
4243

4344
- do:
4445
indices.put_data_stream_mappings:
@@ -78,6 +79,7 @@
7879
- match: { data_streams.0.name: my-data-stream-1 }
7980
- match: { data_streams.0.mappings.properties.name.type: "keyword" }
8081
- match: { data_streams.0.effective_mappings: null }
82+
- match: { data_streams.0.index_mode: time_series }
8183
- set: { data_streams.0.indices.0.index_name: oldIndexName }
8284
- set: { data_streams.0.indices.1.index_name: newIndexName }
8385

@@ -141,6 +143,7 @@
141143
- match: { data_streams.0.name: my-component-only-data-stream-1 }
142144
- match: { data_streams.0.mappings: {} }
143145
- match: { data_streams.0.effective_mappings: null }
146+
- match: { data_streams.0.index_mode: time_series }
144147

145148
- do:
146149
indices.put_data_stream_mappings:
@@ -202,6 +205,7 @@
202205
- match: { data_streams.0.effective_mappings: null }
203206
- set: { data_streams.0.indices.0.index_name: oldIndexName }
204207
- set: { data_streams.0.indices.1.index_name: newIndexName }
208+
- match: { data_streams.0.index_mode: time_series }
205209

206210
- do:
207211
indices.get_mapping:
@@ -269,6 +273,7 @@
269273
- match: { data_streams.0.name: my-data-stream-1 }
270274
- match: { data_streams.0.mappings: {} }
271275
- match: { data_streams.0.effective_mappings: null }
276+
- match: { data_streams.0.index_mode: time_series }
272277

273278
- do:
274279
indices.put_index_template:
@@ -297,6 +302,7 @@
297302
- match: { data_streams.0.name: my-data-stream-1 }
298303
- match: { data_streams.0.mappings: {} }
299304
- match: { data_streams.0.effective_mappings: null }
305+
- match: { data_streams.0.index_mode: time_series }
300306

301307
- do:
302308
indices.rollover:
@@ -320,6 +326,7 @@
320326
- match: { data_streams.0.name: my-data-stream-1 }
321327
- match: { data_streams.0.mappings: { } }
322328
- match: { data_streams.0.effective_mappings: null }
329+
- match: { data_streams.0.index_mode: standard }
323330
- set: { data_streams.0.indices.0.index_name: oldIndexName }
324331
- set: { data_streams.0.indices.1.index_name: newIndexName }
325332

@@ -380,6 +387,7 @@
380387
- match: { data_streams.0.name: test-data-stream-1 }
381388
- match: { data_streams.0.mappings: {} }
382389
- match: { data_streams.0.effective_mappings: null }
390+
- match: { data_streams.0.index_mode: time_series }
383391

384392
- do:
385393
indices.rollover:
@@ -403,6 +411,7 @@
403411
- match: { data_streams.0.name: test-data-stream-1 }
404412
- match: { data_streams.0.mappings: { } }
405413
- match: { data_streams.0.effective_mappings: null }
414+
- match: { data_streams.0.index_mode: time_series }
406415
- set: { data_streams.0.indices.0.index_name: oldIndexName }
407416
- set: { data_streams.0.indices.1.index_name: newIndexName }
408417

@@ -449,6 +458,7 @@
449458
- match: { data_streams.0.name: my-data-stream-1 }
450459
- match: { data_streams.0.mappings: {} }
451460
- match: { data_streams.0.effective_mappings: null }
461+
- match: { data_streams.0.index_mode: time_series }
452462

453463
- do:
454464
indices.put_index_template:
@@ -477,6 +487,7 @@
477487
- match: { data_streams.0.name: my-data-stream-1 }
478488
- match: { data_streams.0.mappings: {} }
479489
- match: { data_streams.0.effective_mappings: null }
490+
- match: { data_streams.0.index_mode: time_series }
480491

481492
- do:
482493
indices.rollover:
@@ -500,6 +511,7 @@
500511
- match: { data_streams.0.name: my-data-stream-1 }
501512
- match: { data_streams.0.mappings: { } }
502513
- match: { data_streams.0.effective_mappings: null }
514+
- match: { data_streams.0.index_mode: standard }
503515
- set: { data_streams.0.indices.0.index_name: oldIndexName }
504516
- set: { data_streams.0.indices.1.index_name: newIndexName }
505517

@@ -561,6 +573,7 @@
561573
- match: { data_streams.0.name: test-data-stream-1 }
562574
- match: { data_streams.0.mappings: {} }
563575
- match: { data_streams.0.effective_mappings: null }
576+
- match: { data_streams.0.index_mode: time_series }
564577

565578
- do:
566579
indices.rollover:
@@ -584,5 +597,6 @@
584597
- match: { data_streams.0.name: test-data-stream-1 }
585598
- match: { data_streams.0.mappings: { } }
586599
- match: { data_streams.0.effective_mappings: null }
600+
- match: { data_streams.0.index_mode: time_series }
587601
- set: { data_streams.0.indices.0.index_name: oldIndexName }
588602
- set: { data_streams.0.indices.1.index_name: newIndexName }

0 commit comments

Comments
 (0)