|
52 | 52 | import org.elasticsearch.common.Strings; |
53 | 53 | import org.elasticsearch.common.UUIDs; |
54 | 54 | import org.elasticsearch.common.collect.ImmutableOpenMap; |
| 55 | +import org.elasticsearch.common.logging.HeaderWarning; |
55 | 56 | import org.elasticsearch.common.lucene.Lucene; |
56 | 57 | import org.elasticsearch.common.regex.Regex; |
57 | 58 | import org.elasticsearch.common.settings.ClusterSettings; |
@@ -398,6 +399,8 @@ private void startRestore( |
398 | 399 | Map<String, DataStream> dataStreamsToRestore = result.v1(); |
399 | 400 | Map<String, DataStreamAlias> dataStreamAliasesToRestore = result.v2(); |
400 | 401 |
|
| 402 | + validateDatastreamTemplatesExistAndWarnIfMissing(dataStreamsToRestore, snapshotInfo); |
| 403 | + |
401 | 404 | // Remove the data streams from the list of requested indices |
402 | 405 | requestIndices.removeAll(dataStreamsToRestore.keySet()); |
403 | 406 |
|
@@ -510,6 +513,30 @@ private void startRestore( |
510 | 513 | ); |
511 | 514 | } |
512 | 515 |
|
| 516 | + private void validateDatastreamTemplatesExistAndWarnIfMissing(Map<String, DataStream> dataStreamsToRestore, SnapshotInfo snapshotInfo) { |
| 517 | + var templatePatterns = clusterService.state() |
| 518 | + .metadata() |
| 519 | + .templatesV2() |
| 520 | + .values() |
| 521 | + .stream() |
| 522 | + .filter(cit -> cit.getDataStreamTemplate() != null) |
| 523 | + .flatMap(cit -> cit.indexPatterns().stream()) |
| 524 | + .collect(Collectors.toSet()); |
| 525 | + |
| 526 | + for (String name : dataStreamsToRestore.keySet()) { |
| 527 | + if (templatePatterns.stream().noneMatch(pattern -> Regex.simpleMatch(pattern, name))) { |
| 528 | + String warningMessage = format( |
| 529 | + "Snapshot [%s] contains data stream [%s] but custer does not have a matching index template. This will cause" |
| 530 | + + " rollover to fail until a matching index template is created", |
| 531 | + snapshotInfo.snapshotId(), |
| 532 | + name |
| 533 | + ); |
| 534 | + logger.warn(() -> warningMessage); |
| 535 | + HeaderWarning.addWarning(warningMessage); |
| 536 | + } |
| 537 | + } |
| 538 | + } |
| 539 | + |
513 | 540 | @SuppressForbidden(reason = "legacy usage of unbatched task") // TODO add support for batching here |
514 | 541 | private void submitUnbatchedTask(@SuppressWarnings("SameParameterValue") String source, ClusterStateUpdateTask task) { |
515 | 542 | clusterService.submitUnbatchedStateUpdateTask(source, task); |
|
0 commit comments