Skip to content

Commit

Permalink
Make AsyncPersistedState.resetVotingConfiguration fast (#88050)
Browse files Browse the repository at this point in the history
Using the builder just to update that one field in the metadata means
running through the name collision checks on the metadata which are very
expensive. In the many-shards benchmark run it takes ~2% of total CPU
time just for this operation.
Even though this is running async on a thread off the critical path I think
it's worthwhile fixing this to free up some CPU for other tasks.
  • Loading branch information
original-brownbear authored Jun 27, 2022
1 parent 31e7e4c commit 1cbb135
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,34 @@ public Metadata withLifecycleState(final Index index, final LifecycleExecutionSt
);
}

public Metadata withCoordinationMetadata(CoordinationMetadata coordinationMetadata) {
return new Metadata(
clusterUUID,
clusterUUIDCommitted,
version,
coordinationMetadata,
transientSettings,
persistentSettings,
settings,
hashesOfConsistentSettings,
totalNumberOfShards,
totalOpenIndexShards,
indices,
aliasedIndices,
templates,
customs,
allIndices,
visibleIndices,
allOpenIndices,
visibleOpenIndices,
allClosedIndices,
visibleClosedIndices,
indicesLookup,
mappingsByHash,
oldestIndexVersion
);
}

public long version() {
return this.version;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ static ClusterState resetVotingConfiguration(ClusterState clusterState) {
.lastCommittedConfiguration(staleStateConfiguration)
.build();
return ClusterState.builder(clusterState)
.metadata(Metadata.builder(clusterState.metadata()).coordinationMetadata(newCoordinationMetadata).build())
.metadata(clusterState.metadata().withCoordinationMetadata(newCoordinationMetadata))
.build();
}

Expand Down

0 comments on commit 1cbb135

Please sign in to comment.