Skip to content

Preventing ConcurrentModificationException when updating settings for more than one index #126077

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

Conversation

masseyke
Copy link
Member

@masseyke masseyke commented Apr 1, 2025

In #101723 we added the ability to update settings that require an index to be closed, by adding a URL parameter called reopen. However, if you attempt to update one of these settings on more than one index at a time, it fails with a ConcurrentModificationException because we remove items from a Set that we are iterating through. This fixes it by creating a defensive copy of the Set.

@masseyke masseyke added :Data Management/Indices APIs APIs to create and manage indices and templates v9.0.0 v8.18.1 v8.19.0 v9.1.0 labels Apr 1, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Data Management Meta label for data/management team label Apr 1, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

@masseyke masseyke added the >bug label Apr 1, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @masseyke, I've created a changelog YAML for you.

@@ -219,7 +219,7 @@ ClusterState execute(ClusterState currentState) {
// We have non-dynamic settings and open indices. We will unassign all of the shards in these indices so that the new
// changed settings are applied when the shards are re-assigned.
routingTableBuilder = RoutingTable.builder(allocationService.getShardRoutingRoleStrategy(), currentRoutingTable);
for (Index index : openIndices) {
for (Index index : new HashSet<>(openIndices)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This HashSet constructor itself iterates over its parameter. Are we concerned about modifications while the constructor is running?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is single-threaded code. The openIndices object never escapes this thread.

Copy link
Contributor

@prdoyle prdoyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I already know the answer to my question above.

@masseyke masseyke added the auto-backport Automatically create backport pull requests when merged label Apr 1, 2025
@masseyke masseyke merged commit bb76210 into elastic:main Apr 1, 2025
17 checks passed
@masseyke masseyke deleted the fix/ConcurrentModificationException-in-settings-update branch April 1, 2025 22:10
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
9.0 Commit could not be cherrypicked due to conflicts
8.18 Commit could not be cherrypicked due to conflicts
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 126077

@masseyke
Copy link
Member Author

masseyke commented Apr 2, 2025

💚 All backports created successfully

Status Branch Result
8.x
9.0
8.18

Questions ?

Please refer to the Backport tool documentation

masseyke added a commit to masseyke/elasticsearch that referenced this pull request Apr 2, 2025
… more than one index (elastic#126077)

(cherry picked from commit bb76210)

# Conflicts:
#	server/src/main/java/org/elasticsearch/cluster/metadata/MetadataUpdateSettingsService.java
masseyke added a commit to masseyke/elasticsearch that referenced this pull request Apr 2, 2025
… more than one index (elastic#126077)

(cherry picked from commit bb76210)

# Conflicts:
#	server/src/main/java/org/elasticsearch/cluster/metadata/MetadataUpdateSettingsService.java
masseyke added a commit that referenced this pull request Apr 2, 2025
masseyke added a commit that referenced this pull request Apr 2, 2025
masseyke added a commit that referenced this pull request Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged backport pending >bug :Data Management/Indices APIs APIs to create and manage indices and templates Team:Data Management Meta label for data/management team v8.18.1 v8.19.0 v9.0.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants