Skip to content

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

Merged
masseyke merged 6 commits intoelastic:mainfrom
masseyke:fix/ConcurrentModificationException-in-settings-update
Apr 1, 2025
Merged

Preventing ConcurrentModificationException when updating settings for more than one index#126077
masseyke merged 6 commits intoelastic:mainfrom
masseyke:fix/ConcurrentModificationException-in-settings-update

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 DO NOT USE. Use ":Distributed/Indices APIs" or ":StorageEngine/Templates" instead. v9.0.0 v8.18.1 v8.19.0 v9.1.0 labels Apr 1, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Data Management (obsolete) DO NOT USE. This team no longer exists. 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.

// 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 DO NOT USE. Use ":Distributed/Indices APIs" or ":StorageEngine/Templates" instead. Team:Data Management (obsolete) DO NOT USE. This team no longer exists. v8.18.1 v8.19.0 v9.0.0 v9.1.0

3 participants