Skip to content

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e30fd2d
draft
JVerwolf Mar 12, 2025
62bb968
Update docs/changelog/124651.yaml
JVerwolf Mar 12, 2025
ba59b56
[CI] Auto commit changes from spotless
elasticsearchmachine Mar 12, 2025
559e4d5
Fix metadata system datastream delete service
JVerwolf Mar 12, 2025
ec21ae0
Spotless
JVerwolf Mar 12, 2025
0019d10
Merge branch 'bugfix/datastreams-should-be-restorable' of github.com:…
JVerwolf Mar 12, 2025
d77f0c6
Merge branch 'main' of github.com:elastic/elasticsearch into bugfix/d…
JVerwolf Mar 12, 2025
5379635
Fix merge error
JVerwolf Mar 12, 2025
7d19d6f
Clean up comments
JVerwolf Mar 12, 2025
c1a490a
Ensure only system datastreams are deleted
JVerwolf Mar 12, 2025
1b0ce59
Add test for deleted system datastreams
JVerwolf Mar 12, 2025
530d06f
Update changelog summary for PR 124651
JVerwolf Mar 12, 2025
8df4410
Change exception
JVerwolf Mar 12, 2025
471b7c4
Merge branch 'bugfix/datastreams-should-be-restorable' of github.com:…
JVerwolf Mar 12, 2025
1cd7cdd
address feedback and update transport action
JVerwolf Mar 12, 2025
527e1f3
remove wip
JVerwolf Mar 12, 2025
165957a
Add tests
JVerwolf Mar 12, 2025
6553cf6
Update docs
JVerwolf Mar 12, 2025
4338727
Update server/src/main/java/org/elasticsearch/cluster/metadata/Metada…
JVerwolf Mar 13, 2025
fd5dc2d
PR feedback: remove stream from clusterstate update
JVerwolf Mar 13, 2025
27f7696
PR feedback: remove overloaded function for clusterstate
JVerwolf Mar 13, 2025
f9a3d97
PR feedback: remove duplicate validation
JVerwolf Mar 13, 2025
c8cc652
PR feedback: ensure system datastream alaises are restored
JVerwolf Mar 13, 2025
2199e69
PR feedback: remove Metadata#projectFor
JVerwolf Mar 13, 2025
248c101
PR feedback: update testDeleteMissing and throw ResourceNotFoundExcep…
JVerwolf Mar 13, 2025
7fd3a13
Fix alias restore
JVerwolf Mar 13, 2025
b7c760c
PR feedback: move exception further up
JVerwolf Mar 13, 2025
cf0b3b4
PR feedback: add partial snapshot test
JVerwolf Mar 13, 2025
1d35ff5
spotless
JVerwolf Mar 13, 2025
3bbd02a
Merge branch 'main' of github.com:elastic/elasticsearch into bugfix/d…
JVerwolf Mar 13, 2025
4d4fd55
Remove unused test helper
JVerwolf Mar 13, 2025
09e2b87
Remove print line
JVerwolf Mar 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/124651.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 124651
summary: "Fix system data streams to be restorable from a snapshot"
area: Infra/Core
type: bug
issues: [89261]
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
import org.elasticsearch.cluster.ProjectState;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.DataStream;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.MetadataDeleteIndexService;
import org.elasticsearch.cluster.metadata.MetadataDataStreamsService;
import org.elasticsearch.cluster.metadata.ProjectMetadata;
import org.elasticsearch.cluster.project.ProjectResolver;
import org.elasticsearch.cluster.service.ClusterService;
Expand All @@ -32,11 +31,8 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.index.Index;
import org.elasticsearch.indices.SystemIndices;
import org.elasticsearch.injection.guice.Inject;
import org.elasticsearch.snapshots.SnapshotInProgressException;
import org.elasticsearch.snapshots.SnapshotsService;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
Expand All @@ -46,6 +42,7 @@
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import static org.elasticsearch.action.datastreams.DataStreamsActionUtil.getDataStreamNames;

Expand Down Expand Up @@ -155,34 +152,11 @@ static ClusterState removeDataStream(
}
}

Set<String> snapshottingDataStreams = SnapshotsService.snapshottingDataStreams(projectState, dataStreams);
if (snapshottingDataStreams.isEmpty() == false) {
throw new SnapshotInProgressException(
"Cannot delete data streams that are being snapshotted: "
+ snapshottingDataStreams
+ ". Try again after snapshot finishes or cancel the currently running snapshot."
);
}

Set<Index> backingIndicesToRemove = new HashSet<>();
for (String dataStreamName : dataStreams) {
DataStream dataStream = project.dataStreams().get(dataStreamName);
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 member of
ClusterState newState = projectState.updatedState(builder -> {
for (String ds : dataStreams) {
LOGGER.info("removing data stream [{}]", ds);
builder.removeDataStream(ds);
}
});
return MetadataDeleteIndexService.deleteIndices(newState.projectState(projectState.projectId()), backingIndicesToRemove, settings);
return MetadataDataStreamsService.deleteDataStreams(
projectState,
dataStreams.stream().map(project.dataStreams()::get).collect(Collectors.toSet()),
settings
);
}

@Override
Expand Down
1 change: 1 addition & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ dependencies {
}
internalClusterTestImplementation(project(':modules:reindex'))
internalClusterTestImplementation(project(':modules:mapper-extras'))
internalClusterTestImplementation(project(':modules:data-streams'))
}

spotless {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.elasticsearch.indices.TestSystemIndexPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.SystemIndexPlugin;
import org.elasticsearch.snapshots.SystemIndicesSnapshotIT;
import org.elasticsearch.snapshots.SystemResourceSnapshotIT;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.xcontent.XContentType;
import org.junit.After;
Expand Down Expand Up @@ -300,7 +300,7 @@ public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings sett

@Override
public String getFeatureName() {
return SystemIndicesSnapshotIT.SystemIndexTestPlugin.class.getSimpleName();
return SystemResourceSnapshotIT.SystemIndexTestPlugin.class.getSimpleName();
}

@Override
Expand Down
Loading