-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Use latest setting value when initializing setting watch #134091
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d74a7bf
Use latest setting value when initializing setting watch
rjernst 0168983
Update docs/changelog/134091.yaml
rjernst ca37434
[CI] Auto commit changes from spotless
9f444b2
Merge branch 'main' into settings/watch_after_apply
rjernst 530b854
Merge branch 'main' into settings/watch_after_apply
rjernst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pr: 134091 | ||
summary: Use latest setting value when initializing setting watch | ||
area: Infra/Settings | ||
type: bug | ||
issues: | ||
- 133701 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...r/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterSettingsTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.settings; | ||
|
||
import org.elasticsearch.common.settings.ClusterSettings; | ||
import org.elasticsearch.common.settings.Setting; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.util.Set; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class ClusterSettingsTests extends ESTestCase { | ||
|
||
public void testWatchAfterApply() { | ||
Setting<String> clusterSetting = Setting.simpleString("cluster.setting", Setting.Property.NodeScope, Setting.Property.Dynamic); | ||
Settings nodeSettings = Settings.builder().put("cluster.setting", "initial_value").build(); | ||
|
||
ClusterSettings clusterSettings = new ClusterSettings(nodeSettings, Set.of(clusterSetting)); | ||
Settings newSettings = Settings.builder().put("cluster.setting", "updated_value").build(); | ||
clusterSettings.applySettings(newSettings); | ||
|
||
// the value should be current when initializing the consumer | ||
clusterSettings.initializeAndWatch(clusterSetting, value -> { assertThat(value, equalTo("updated_value")); }); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this comment I understand you are trying to avoid doing
Settings.builder().put(this.settings).put(this.lastSettingsApplied).build()
like in other functions, correct?Is there an advantage? Is it correct? (is
lastSettingsApplied
always a superset ofsettings
?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Building a combined Settings object is heavyweight. It requires combing the internal maps that each Settings object contains.
If the latter settings object contains a setting we are looking for, it would have overridden the value when combined, so looking at the latter first should mimic the combined behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that, but I was wondering if it really matters in this case - I might be mistaken, but this is an initialization method, so probably it's not on a hot path.
As long as it's correct I like the optimization though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While true, it's also called for every setting that is watched, currently 43 uses. Seems silly to reconstruct the same settings object 43 times (but also not worth the complexity to cache it in a threadsafe way).