Skip to content

Commit e7634a0

Browse files
Fixes after merge
1 parent d7f45b0 commit e7634a0

File tree

7 files changed

+17
-68
lines changed

7 files changed

+17
-68
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataMigrateToDataStreamService.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static ClusterState migrateToDataStream(
156156
ProjectMetadata.Builder mb = ProjectMetadata.builder(project);
157157
for (Index index : alias.getIndices()) {
158158
IndexMetadata im = project.index(index);
159-
prepareBackingIndex(mb, im, request.aliasName, mapperSupplier, true, false, Settings.EMPTY);
159+
prepareBackingIndex(mb, im, request.aliasName, mapperSupplier, true, false, false, Settings.EMPTY);
160160
}
161161
ClusterState updatedState = ClusterState.builder(projectState.cluster()).putProjectMetadata(mb).build();
162162

@@ -201,17 +201,6 @@ static void validateRequest(ProjectMetadata project, MigrateToDataStreamClusterS
201201
}
202202
}
203203

204-
// hides the index, optionally removes the alias, and adds data stream timestamp field mapper
205-
static void prepareBackingIndex(
206-
ProjectMetadata.Builder b,
207-
IndexMetadata im,
208-
String dataStreamName,
209-
Function<IndexMetadata, MapperService> mapperSupplier,
210-
boolean removeAlias
211-
) throws IOException {
212-
prepareBackingIndex(b, im, dataStreamName, mapperSupplier, removeAlias, false, false, Settings.EMPTY);
213-
}
214-
215204
/**
216205
* Hides the index, optionally removes the alias, adds data stream timestamp field mapper, and configures any additional settings
217206
* needed for the index to be included within a data stream.

server/src/main/java/org/elasticsearch/cluster/routing/allocation/shards/ShardsAvailabilityHealthIndicatorService.java

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,8 @@ public List<HealthIndicatorImpact> getImpacts() {
11521152

11531153
/**
11541154
* Returns the diagnosis for unassigned primary and replica shards.
1155-
* @param verbose true if the diagnosis should be generated, false if they should be omitted.
1155+
*
1156+
* @param verbose true if the diagnosis should be generated, false if they should be omitted.
11561157
* @param maxAffectedResourcesCount the max number of affected resources to be returned as part of the diagnosis
11571158
* @return The diagnoses list the indicator identified. Alternatively, an empty list if none were found or verbose is false.
11581159
*/
@@ -1243,23 +1244,6 @@ static List<Diagnosis.Resource> getRestoreFromSnapshotAffectedResources(
12431244
}
12441245
}
12451246

1246-
Map<String, Set<ProjectIndexName>> featureToDsBackingIndices = getSystemDsBackingIndicesForProjects(
1247-
systemIndices,
1248-
affectedProjects,
1249-
metadata
1250-
);
1251-
1252-
// the shards_availability indicator works with indices so let's remove the feature states data streams backing indices from
1253-
// the list of affected indices (the feature state will cover the restore of these indices too)
1254-
for (Map.Entry<String, Set<ProjectIndexName>> featureToBackingIndices : featureToDsBackingIndices.entrySet()) {
1255-
for (ProjectIndexName featureIndex : featureToBackingIndices.getValue()) {
1256-
if (restoreFromSnapshotIndices.contains(featureIndex)) {
1257-
affectedFeatureStates.add(featureToBackingIndices.getKey());
1258-
affectedIndices.remove(featureIndex);
1259-
}
1260-
}
1261-
}
1262-
12631247
if (affectedIndices.isEmpty() == false) {
12641248
affectedResources.add(
12651249
new Diagnosis.Resource(
@@ -1281,7 +1265,7 @@ static List<Diagnosis.Resource> getRestoreFromSnapshotAffectedResources(
12811265
}
12821266

12831267
/**
1284-
* Retrieve the system indices for the projects and group them by Feature
1268+
* Retrieve the system indices and indices backing system data streams for the projects and group them by Feature
12851269
*/
12861270
private static Map<String, Set<ProjectIndexName>> getSystemIndicesForProjects(
12871271
SystemIndices systemIndices,
@@ -1293,7 +1277,7 @@ private static Map<String, Set<ProjectIndexName>> getSystemIndicesForProjects(
12931277
.collect(
12941278
Collectors.toMap(
12951279
SystemIndices.Feature::getName,
1296-
feature -> feature.getIndexDescriptors()
1280+
feature -> feature.getSystemResourceDescriptors()
12971281
.stream()
12981282
.flatMap(
12991283
descriptor -> projects.stream()
@@ -1307,34 +1291,6 @@ private static Map<String, Set<ProjectIndexName>> getSystemIndicesForProjects(
13071291
)
13081292
);
13091293
}
1310-
1311-
/**
1312-
* Retrieve the backing indices for system data stream for the projects and group them by Feature
1313-
*/
1314-
private static Map<String, Set<ProjectIndexName>> getSystemDsBackingIndicesForProjects(
1315-
SystemIndices systemIndices,
1316-
Set<ProjectId> projects,
1317-
Metadata metadata
1318-
) {
1319-
return systemIndices.getFeatures()
1320-
.stream()
1321-
.collect(
1322-
toMap(
1323-
SystemIndices.Feature::getName,
1324-
feature -> feature.getDataStreamDescriptors()
1325-
.stream()
1326-
.flatMap(
1327-
descriptor -> projects.stream()
1328-
.flatMap(
1329-
projectId -> descriptor.getBackingIndexNames(metadata.getProject(projectId))
1330-
.stream()
1331-
.map(index -> new ProjectIndexName(projectId, index))
1332-
)
1333-
)
1334-
.collect(Collectors.toSet())
1335-
)
1336-
);
1337-
}
13381294
}
13391295

13401296
public static class SearchableSnapshotsState {

x-pack/plugin/migrate/src/main/java/org/elasticsearch/system_indices/task/SystemDataStreamMigrationInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.elasticsearch.cluster.metadata.DataStream;
1111
import org.elasticsearch.cluster.metadata.IndexMetadata;
12+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1213
import org.elasticsearch.indices.SystemDataStreamDescriptor;
1314
import org.elasticsearch.indices.SystemIndices;
1415

x-pack/plugin/migrate/src/main/java/org/elasticsearch/system_indices/task/SystemIndexMigrationInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.client.internal.OriginSettingClient;
1515
import org.elasticsearch.cluster.metadata.IndexMetadata;
1616
import org.elasticsearch.cluster.metadata.Metadata;
17+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1718
import org.elasticsearch.cluster.service.ClusterService;
1819
import org.elasticsearch.common.settings.IndexScopedSettings;
1920
import org.elasticsearch.common.settings.Setting;

x-pack/plugin/migrate/src/main/java/org/elasticsearch/system_indices/task/SystemIndexMigrator.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public SystemIndexMigrator(
119119

120120
public void run(SystemIndexMigrationTaskState taskState) {
121121
ClusterState clusterState = clusterService.state();
122+
ProjectMetadata projectMetadata = clusterState.metadata().getProject();
122123

123124
final String stateIndexName;
124125
final String stateFeatureName;
@@ -138,7 +139,7 @@ public void run(SystemIndexMigrationTaskState taskState) {
138139
return;
139140
}
140141

141-
if (stateIndexName != null && clusterState.metadata().getProject().hasIndexAbstraction(stateIndexName) == false) {
142+
if (stateIndexName != null && projectMetadata.hasIndexAbstraction(stateIndexName) == false) {
142143
markAsFailed(new IndexNotFoundException(stateIndexName, "cannot migrate because that index does not exist"));
143144
return;
144145
}
@@ -156,8 +157,8 @@ public void run(SystemIndexMigrationTaskState taskState) {
156157

157158
systemIndices.getFeatures()
158159
.stream()
159-
.flatMap(feature -> SystemResourceMigrationFactory.fromFeature(feature, clusterState.metadata(), indexScopedSettings))
160-
.filter(migrationInfo -> needToBeMigrated(migrationInfo.getIndices(clusterState.metadata().getProject())))
160+
.flatMap(feature -> SystemResourceMigrationFactory.fromFeature(feature, projectMetadata, indexScopedSettings))
161+
.filter(migrationInfo -> needToBeMigrated(migrationInfo.getIndices(projectMetadata)))
161162
.sorted() // Stable order between nodes
162163
.collect(Collectors.toCollection(() -> migrationQueue));
163164

@@ -190,7 +191,7 @@ public void run(SystemIndexMigrationTaskState taskState) {
190191
+ nextMigrationInfo.getFeatureName()
191192
+ "] of locally computed queue, see logs";
192193
if (nextMigrationInfo.getCurrentResourceName().equals(stateIndexName) == false) {
193-
if (clusterState.metadata().getProject().hasIndexAbstraction(stateIndexName) == false) {
194+
if (projectMetadata.hasIndexAbstraction(stateIndexName) == false) {
194195
// If we don't have that index at all, and also don't have the next one
195196
markAsFailed(
196197
new IllegalStateException(

x-pack/plugin/migrate/src/main/java/org/elasticsearch/system_indices/task/SystemResourceMigrationFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
package org.elasticsearch.system_indices.task;
99

1010
import org.elasticsearch.cluster.metadata.DataStream;
11-
import org.elasticsearch.cluster.metadata.Metadata;
11+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1212
import org.elasticsearch.common.settings.IndexScopedSettings;
1313
import org.elasticsearch.indices.SystemIndices;
1414

@@ -25,7 +25,7 @@ class SystemResourceMigrationFactory {
2525
*/
2626
static Stream<SystemResourceMigrationInfo> fromFeature(
2727
SystemIndices.Feature feature,
28-
Metadata metadata,
28+
ProjectMetadata metadata,
2929
IndexScopedSettings indexScopedSettings
3030
) {
3131
return Stream.concat(
@@ -36,7 +36,7 @@ static Stream<SystemResourceMigrationInfo> fromFeature(
3636

3737
private static Stream<SystemIndexMigrationInfo> getSystemIndicesMigrationInfos(
3838
SystemIndices.Feature feature,
39-
Metadata metadata,
39+
ProjectMetadata metadata,
4040
IndexScopedSettings indexScopedSettings
4141
) {
4242
return feature.getIndexDescriptors()
@@ -54,7 +54,7 @@ private static Stream<SystemIndexMigrationInfo> getSystemIndicesMigrationInfos(
5454

5555
private static Stream<SystemDataStreamMigrationInfo> getSystemDataStreamsMigrationInfos(
5656
SystemIndices.Feature feature,
57-
Metadata metadata
57+
ProjectMetadata metadata
5858
) {
5959
return feature.getDataStreamDescriptors().stream().map(descriptor -> {
6060
DataStream dataStream = metadata.dataStreams().get(descriptor.getDataStreamName());

x-pack/plugin/migrate/src/main/java/org/elasticsearch/system_indices/task/SystemResourceMigrationInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.client.internal.OriginSettingClient;
1313
import org.elasticsearch.cluster.metadata.IndexMetadata;
1414
import org.elasticsearch.cluster.metadata.Metadata;
15+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1516
import org.elasticsearch.cluster.service.ClusterService;
1617
import org.elasticsearch.indices.SystemIndices;
1718
import org.elasticsearch.plugins.SystemIndexPlugin;

0 commit comments

Comments
 (0)