Skip to content

Remove non-test usages of Metadata.Builder#indices #131240

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 1 commit into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.metadata.ProjectMetadata;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.cluster.service.MasterServiceTaskQueue;
import org.elasticsearch.common.Priority;
Expand Down Expand Up @@ -139,22 +139,19 @@ static class UpdateIndexMigrationVersionTask implements ClusterStateTaskListener
}

ClusterState execute(ClusterState currentState) {
IndexMetadata.Builder indexMetadataBuilder = IndexMetadata.builder(
currentState.metadata().getProject().indices().get(indexName)
);
final var project = currentState.metadata().getProject();
IndexMetadata.Builder indexMetadataBuilder = IndexMetadata.builder(project.indices().get(indexName));
indexMetadataBuilder.putCustom(
MIGRATION_VERSION_CUSTOM_KEY,
Map.of(MIGRATION_VERSION_CUSTOM_DATA_KEY, Integer.toString(indexMigrationVersion))
);
indexMetadataBuilder.version(indexMetadataBuilder.version() + 1);

final ImmutableOpenMap.Builder<String, IndexMetadata> builder = ImmutableOpenMap.builder(
currentState.metadata().getProject().indices()
);
final ImmutableOpenMap.Builder<String, IndexMetadata> builder = ImmutableOpenMap.builder(project.indices());
builder.put(indexName, indexMetadataBuilder.build());

return ClusterState.builder(currentState)
.metadata(Metadata.builder(currentState.metadata()).indices(builder.build()).build())
.putProjectMetadata(ProjectMetadata.builder(project).indices(builder.build()).build())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.cluster.coordination.FailedToCommitClusterStateException;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.metadata.ProjectMetadata;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.cluster.service.MasterServiceTaskQueue;
import org.elasticsearch.common.Priority;
Expand Down Expand Up @@ -515,7 +516,8 @@ public Map<String, String> getNewRoleDigests() {
}

Tuple<ClusterState, Map<String, String>> execute(ClusterState state) {
IndexMetadata indexMetadata = state.metadata().getProject().index(concreteSecurityIndexName);
final var project = state.metadata().getProject();
IndexMetadata indexMetadata = project.index(concreteSecurityIndexName);
if (indexMetadata == null) {
throw new IndexNotFoundException(concreteSecurityIndexName);
}
Expand All @@ -528,10 +530,12 @@ Tuple<ClusterState, Map<String, String>> execute(ClusterState state) {
indexMetadataBuilder.removeCustom(METADATA_QUERYABLE_BUILT_IN_ROLES_DIGEST_KEY);
}
indexMetadataBuilder.version(indexMetadataBuilder.version() + 1);
ImmutableOpenMap.Builder<String, IndexMetadata> builder = ImmutableOpenMap.builder(state.metadata().getProject().indices());
ImmutableOpenMap.Builder<String, IndexMetadata> builder = ImmutableOpenMap.builder(project.indices());
builder.put(concreteSecurityIndexName, indexMetadataBuilder.build());
return new Tuple<>(
ClusterState.builder(state).metadata(Metadata.builder(state.metadata()).indices(builder.build()).build()).build(),
ClusterState.builder(state)
.putProjectMetadata(ProjectMetadata.builder(project).indices(builder.build()).build())
.build(),
newRoleDigests
);
} else {
Expand Down