-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Bug Fix: System Data Streams Should Be Restorable #124651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JVerwolf
merged 32 commits into
elastic:main
from
JVerwolf:bugfix/datastreams-should-be-restorable
Mar 14, 2025
Merged
Changes from 14 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
e30fd2d
draft
JVerwolf 62bb968
Update docs/changelog/124651.yaml
JVerwolf ba59b56
[CI] Auto commit changes from spotless
559e4d5
Fix metadata system datastream delete service
JVerwolf ec21ae0
Spotless
JVerwolf 0019d10
Merge branch 'bugfix/datastreams-should-be-restorable' of github.com:…
JVerwolf d77f0c6
Merge branch 'main' of github.com:elastic/elasticsearch into bugfix/d…
JVerwolf 5379635
Fix merge error
JVerwolf 7d19d6f
Clean up comments
JVerwolf c1a490a
Ensure only system datastreams are deleted
JVerwolf 1b0ce59
Add test for deleted system datastreams
JVerwolf 530d06f
Update changelog summary for PR 124651
JVerwolf 8df4410
Change exception
JVerwolf 471b7c4
Merge branch 'bugfix/datastreams-should-be-restorable' of github.com:…
JVerwolf 1cd7cdd
address feedback and update transport action
JVerwolf 527e1f3
remove wip
JVerwolf 165957a
Add tests
JVerwolf 6553cf6
Update docs
JVerwolf 4338727
Update server/src/main/java/org/elasticsearch/cluster/metadata/Metada…
JVerwolf fd5dc2d
PR feedback: remove stream from clusterstate update
JVerwolf 27f7696
PR feedback: remove overloaded function for clusterstate
JVerwolf f9a3d97
PR feedback: remove duplicate validation
JVerwolf c8cc652
PR feedback: ensure system datastream alaises are restored
JVerwolf 2199e69
PR feedback: remove Metadata#projectFor
JVerwolf 248c101
PR feedback: update testDeleteMissing and throw ResourceNotFoundExcep…
JVerwolf 7fd3a13
Fix alias restore
JVerwolf b7c760c
PR feedback: move exception further up
JVerwolf cf0b3b4
PR feedback: add partial snapshot test
JVerwolf 1d35ff5
spotless
JVerwolf 3bbd02a
Merge branch 'main' of github.com:elastic/elasticsearch into bugfix/d…
JVerwolf 4d4fd55
Remove unused test helper
JVerwolf 09e2b87
Remove print line
JVerwolf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 124651 | ||
| summary: "System Data Streams Should Be Restorable" | ||
| area: Infra/Core | ||
| type: bug | ||
| issues: [] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
402 changes: 371 additions & 31 deletions
402
server/src/internalClusterTest/java/org/elasticsearch/snapshots/SystemIndicesSnapshotIT.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
server/src/main/java/org/elasticsearch/cluster/metadata/MetadataDeleteDataStreamService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.cluster.metadata; | ||
|
|
||
| import org.elasticsearch.cluster.ClusterState; | ||
| import org.elasticsearch.cluster.ProjectState; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.core.FixForMultiProject; | ||
| import org.elasticsearch.index.Index; | ||
| import org.elasticsearch.logging.LogManager; | ||
| import org.elasticsearch.logging.Logger; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| public class MetadataDeleteDataStreamService { | ||
JVerwolf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private static final Logger LOGGER = LogManager.getLogger(MetadataDeleteDataStreamService.class); | ||
|
|
||
| /** | ||
| * Removes the given data streams from the Cluster State. | ||
JVerwolf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * @param clusterState The cluster state | ||
| * @param dataStreams The data streams to remove | ||
| * @param settings The settings | ||
| * @return The updated Cluster State | ||
| */ | ||
| @FixForMultiProject // Once callers have Project State we can update/remove this method. | ||
| public static ClusterState deleteDataStreams(ClusterState clusterState, Set<DataStream> dataStreams, Settings settings) { | ||
| final Map<ProjectId, Set<DataStream>> byProject = new HashMap<>(); | ||
| for (DataStream dataStream : dataStreams) { | ||
| final ProjectMetadata project = clusterState.metadata().projectFor(dataStream); | ||
| byProject.computeIfAbsent(project.id(), ignore -> new HashSet<>()).add(dataStream); | ||
| } | ||
|
|
||
| for (final Map.Entry<ProjectId, Set<DataStream>> entry : byProject.entrySet()) { | ||
| clusterState = deleteDataStream(clusterState.projectState(entry.getKey()), entry.getValue(), settings); | ||
| } | ||
| return clusterState; | ||
| } | ||
|
|
||
| /** | ||
| * Removes the given data streams from the Project State. | ||
JVerwolf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * @param projectState The project state | ||
| * @param dataStreams The data streams to remove | ||
| * @param settings The settings | ||
| * @return The updated Project State | ||
| */ | ||
| public static ClusterState deleteDataStream(ProjectState projectState, Set<DataStream> dataStreams, Settings settings) { | ||
| if (dataStreams.isEmpty()) { | ||
| return projectState.cluster(); | ||
| } | ||
|
|
||
| Set<Index> backingIndicesToRemove = new HashSet<>(); | ||
| for (DataStream dataStream : dataStreams) { | ||
| assert dataStream != null; | ||
| backingIndicesToRemove.addAll(dataStream.getIndices()); | ||
| backingIndicesToRemove.addAll(dataStream.getFailureIndices()); | ||
| } | ||
|
|
||
| // first delete the data streams and then the indices: | ||
| // (this to avoid data stream validation from failing when deleting an index that is part of a data stream | ||
| // without updating the data stream) | ||
| // TODO: change order when "delete index api" also updates the data stream the "index to be removed" is a member of | ||
| ClusterState newState = projectState.updatedState(builder -> { | ||
| dataStreams.stream().map(DataStream::getName).forEach(ds -> { | ||
| LOGGER.info("removing data stream [{}]", ds); | ||
| builder.removeDataStream(ds); | ||
| }); | ||
| }); | ||
| return MetadataDeleteIndexService.deleteIndices(newState.projectState(projectState.projectId()), backingIndicesToRemove, settings); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.