-
Notifications
You must be signed in to change notification settings - Fork 862
SOLR-17864: Provide backwards support for "<str name="hideStackTrace">${solr.hideStackTrace:false}</str>" #4893
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
Open
epugh
wants to merge
4
commits into
apache:main
Choose a base branch
from
epugh:SOLR-17864_part_diecinueve
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
11 changes: 11 additions & 0 deletions
11
changelog/unreleased/SOLR-17864-legacy-sysprop-fallback-in-config-substitution.yml
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,11 @@ | ||
| title: > | ||
| A solr.xml or solrconfig.xml property-substitution token (${...}) that still references a | ||
| legacy/deprecated system property name now falls back to the current property's value if that's | ||
| been set, instead of silently ignoring it. Previously, upgrading and setting only the new | ||
| property name had no effect unless the config file's own ${...} token was also updated by hand. | ||
| type: fixed | ||
| authors: | ||
| - name: Eric Pugh | ||
| links: | ||
| - name: SOLR-17864 | ||
| url: https://issues.apache.org/jira/browse/SOLR-17864 |
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
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
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
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
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
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
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
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 |
|---|---|---|
|
|
@@ -47,8 +47,14 @@ public class EnvUtils { | |
| /** Maps ENV keys to sys prop keys for special/custom mappings */ | ||
| private static final Map<String, String> CUSTOM_MAPPINGS = new HashMap<>(); | ||
|
|
||
| /** | ||
| * Maps a legacy/deprecated sys prop key (dot-separated form) to the current property it was | ||
| * replaced by, and whether the replacement is boolean-inverted relative to the legacy property. | ||
| */ | ||
| private record DeprecatedMapping(String currentName, boolean inverted) {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay/fine but merely for a boolean you could simply have a parallel set of inverted names. That's what I'd do. |
||
|
|
||
| /** Maps deprecated sys prop keys to current sys prop keys with special/custom mappings */ | ||
| private static final Map<String, String> DEPRECATED_MAPPINGS = new HashMap<>(); | ||
| private static final Map<String, DeprecatedMapping> DEPRECATED_MAPPINGS = new HashMap<>(); | ||
|
|
||
| private static final Map<String, String> camelCaseToDotsMap = new ConcurrentHashMap<>(); | ||
|
|
||
|
|
@@ -74,8 +80,14 @@ public class EnvUtils { | |
| for (String key : props.stringPropertyNames()) { | ||
| CUSTOM_MAPPINGS.put(key, props.getProperty(key)); | ||
| } | ||
| for (String key : deprecatedProps.stringPropertyNames()) { | ||
| DEPRECATED_MAPPINGS.put(camelCaseToDotSeparated(deprecatedProps.getProperty(key)), key); | ||
| for (String currentName : deprecatedProps.stringPropertyNames()) { | ||
| String legacyName = deprecatedProps.getProperty(currentName); | ||
| boolean inverted = legacyName.startsWith("!"); | ||
| if (inverted) { | ||
| legacyName = legacyName.substring(1); | ||
| } | ||
| DEPRECATED_MAPPINGS.put( | ||
| camelCaseToDotSeparated(legacyName), new DeprecatedMapping(currentName, inverted)); | ||
| } | ||
| init(false, System.getenv(), System.getProperties()); | ||
| } | ||
|
|
@@ -108,24 +120,68 @@ public static String getProperty(String key) { | |
| * @param defaultValue fallback value if property is not found | ||
| */ | ||
| public static String getProperty(String key, String defaultValue) { | ||
| String value = getPropertyWithCamelCaseFallback(key); | ||
| String value = resolvePropertyValue(key); | ||
| return value != null ? value : defaultValue; | ||
| } | ||
|
|
||
| /** | ||
| * Get a property from given key or an alias key converted from CamelCase to dot separated. | ||
| * Resolves {@code key} by trying, in order: the key as given; the key converted from CamelCase to | ||
| * dot-separated; and -- if {@code key} is itself a legacy/deprecated property name -- the current | ||
| * property it was replaced by. See {@link #resolveViaDeprecatedMapping} for why that last | ||
| * fallback is needed. | ||
| * | ||
| * @return property value or value of dot-separated alias key or null if not found | ||
| * @return the resolved value, or null if none of the above are found | ||
| */ | ||
| private static String getPropertyWithCamelCaseFallback(String key) { | ||
| private static String resolvePropertyValue(String key) { | ||
| String value = System.getProperty(key); | ||
| if (value != null) { | ||
| return value; | ||
| } else { | ||
| // Figure out if string is CamelCase and convert to dot separated | ||
| String altKey = camelCaseToDotSeparated(key); | ||
| return System.getProperty(altKey); | ||
| } | ||
| // Figure out if string is CamelCase and convert to dot separated | ||
| String altKey = camelCaseToDotSeparated(key); | ||
| value = System.getProperty(altKey); | ||
| if (value != null) { | ||
| return value; | ||
| } | ||
| return resolveViaDeprecatedMapping(key, altKey); | ||
| } | ||
|
|
||
| /** | ||
| * If {@code dotKey} is a known legacy/deprecated property name, returns the value of the current | ||
| * property it was replaced by (inverted, if the mapping is boolean-inverted), or null if that | ||
| * current property hasn't been set either. | ||
| * | ||
| * <p>This matters for config files (e.g. {@code solr.xml}) that still contain a {@code | ||
| * ${legacyName:default}} substitution token from before a property was renamed: without this, | ||
| * setting only the new property name would silently have no effect on that token, since nothing | ||
| * else ever rewrites the token's text. See SOLR-17864. | ||
| * | ||
| * @param key the property key as originally looked up (used only for the deprecation message) | ||
| * @param dotKey {@code key} converted to dot-separated form; this is what {@code | ||
| * DEPRECATED_MAPPINGS} is keyed by | ||
| */ | ||
| private static String resolveViaDeprecatedMapping(String key, String dotKey) { | ||
| DeprecatedMapping mapping = DEPRECATED_MAPPINGS.get(dotKey); | ||
| if (mapping == null) { | ||
| return null; | ||
| } | ||
| String newValue = System.getProperty(mapping.currentName()); | ||
|
epugh marked this conversation as resolved.
|
||
| if (newValue == null) { | ||
| return null; | ||
| } | ||
| DeprecationLog.log( | ||
| dotKey, | ||
| () -> | ||
| "A config file still references the deprecated system property " | ||
| + key | ||
| + "; it was replaced by " | ||
| + mapping.currentName() | ||
| + ". Support for the old property will be removed in a future version of Solr."); | ||
| return mapping.inverted() ? invertBooleanString(newValue) : newValue; | ||
| } | ||
|
|
||
| private static String invertBooleanString(String value) { | ||
| return String.valueOf(!Boolean.parseBoolean(value)); | ||
| } | ||
|
|
||
| private static String camelCaseToDotSeparated(String key) { | ||
|
|
@@ -218,26 +274,24 @@ static synchronized void init( | |
|
|
||
| for (String deprecatedKey : sysProperties.stringPropertyNames()) { | ||
| var dotKey = camelCaseToDotSeparated(deprecatedKey); | ||
| if (DEPRECATED_MAPPINGS.containsKey(dotKey) | ||
| || DEPRECATED_MAPPINGS.containsKey("!" + dotKey)) { | ||
| applyDeprecatedPropertyMapping(deprecatedKey, dotKey, sysProperties); | ||
| DeprecatedMapping mapping = DEPRECATED_MAPPINGS.get(dotKey); | ||
| if (mapping != null) { | ||
| applyDeprecatedPropertyMapping(deprecatedKey, mapping, sysProperties); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void applyDeprecatedPropertyMapping( | ||
| String deprecatedKey, String lookupKey, Properties sysProperties) { | ||
| var newPropName = | ||
| DEPRECATED_MAPPINGS.getOrDefault(lookupKey, DEPRECATED_MAPPINGS.get("!" + lookupKey)); | ||
| String deprecatedKey, DeprecatedMapping mapping, Properties sysProperties) { | ||
| var newValue = | ||
| DEPRECATED_MAPPINGS.containsKey(lookupKey) | ||
| ? sysProperties.getProperty(deprecatedKey) | ||
| : String.valueOf(!Boolean.parseBoolean(sysProperties.getProperty(deprecatedKey))); | ||
| mapping.inverted() | ||
| ? invertBooleanString(sysProperties.getProperty(deprecatedKey)) | ||
| : sysProperties.getProperty(deprecatedKey); | ||
| log.warn( | ||
| "Deprecated system property {} has been replaced by {}. Support for the old property will be removed in a future version of Solr.", | ||
| deprecatedKey, | ||
| newPropName); | ||
| setProperty(newPropName, newValue); | ||
| mapping.currentName()); | ||
| setProperty(mapping.currentName(), newValue); | ||
| } | ||
|
|
||
| protected static String envNameToSyspropName(String envName) { | ||
|
|
||
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
Oops, something went wrong.
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.
This first part is needless; surely putIfAbsent will handle this, right?
Is this an optimization? If it is, a comment should clearly say so. But I'm suspicious it's any faster than putIfAbsent; surely that one can bail fast. I looked at the code for it in ConcurrentHashMap and I think it's good.