Skip to content

Conversation

@probakowski
Copy link
Contributor

@probakowski probakowski commented Sep 11, 2019

Setting.exist() will no longer return true if there's setting in keystore with the same name.

Closes #41830

Setting.exist will no longer return true if there's setting in keystore with the same name.
Also removed synchronization on keySet to lower congestion, possibly constructing
keySet multiple times, which should be cheap though.

Closes elastic#41830
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@rjernst
Copy link
Member

rjernst commented Sep 11, 2019

I think having this alternate version of keySet will further confuse things. Please see my comments on the original issue. We should be able to make the behavior consistent within the current methods.

@probakowski
Copy link
Contributor Author

probakowski commented Sep 11, 2019

I've seen the comments there, but I don't see how we can get both get and exist behave consistently with current methods.
Setting.get and SecureSetting.get now do the same thing - throw exception when setting is in wrong place (keystore or yaml respectively) after checks added in #42209
Still, Setting.exist will be happy with both keystore (where get will throw exception) and yaml, where SecureSetting.exist will only accept keystore. As we don't have public access right now to unsecure settings only, we can't fix Setting.exist. So we can either:

  1. "Break" SecureSetting.exist to behave as Setting.exist - can be done without adding/opening anything but doesn't look like good idea
  2. Add Settings.unsecureKeySet that skip secure settings
  3. Add Settings.keySet with parameter as in this PR
  4. Add explicit Settings.containsSecureSetting and Settings.containsUnsecureSetting and skip keySet altogether in both exist methods
    For me the best is either 3 or 4, WDYT?

@rjernst
Copy link
Member

rjernst commented Sep 12, 2019

I'm ok with the keySet method as in this PR, but I don't think it needs to be public? The Settings class for a node is a representation of all settings across elasticsearch.yml and the keystore. This is an implementation detail only necessary to get correct behavior for this one method.

@probakowski
Copy link
Contributor Author

@rjernst you were right that there is option to reuse current methods, using reversed check from Setting.innerGetRaw, I think current version is less confusing as we don't open anything new

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

One more nit, then LGTM

public boolean exists(final Settings settings) {
return settings.keySet().contains(getKey());
SecureSettings secureSettings = settings.getSecureSettings();
return settings.keySet().contains(getKey()) && (secureSettings == null || !secureSettings.getSettingNames().contains(getKey()));
Copy link
Member

Choose a reason for hiding this comment

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

We prefer to use == false for negations because it is easier to visually spot than !

@probakowski
Copy link
Contributor Author

@elasticmachine test this please

@probakowski
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/2

@probakowski
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/bwc

@probakowski
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/default-distro

@probakowski
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/docs

@probakowski probakowski merged commit faf6ef8 into elastic:master Sep 16, 2019
@probakowski probakowski deleted the setting-exist branch September 16, 2019 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting.exists reflects secure settings but .get doesnt

4 participants