This is an automated email from the ASF dual-hosted git repository.
xyuanlu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git
The following commit(s) were added to refs/heads/master by this push:
new ee7a8b834 Only build property key path on construction (#3040)
ee7a8b834 is described below
commit ee7a8b8349ce837cfbe9129bdee1bb8ec9dc55f1
Author: Grant Paláu Spencer <[email protected]>
AuthorDate: Wed May 21 09:16:35 2025 -0700
Only build property key path on construction (#3040)
Changes PropertyKey so that it only builds the path once when it is
instantiated. PropertyKey.getPath() previously would rebuild the path on every
call. This could cause a performance hit as it was performing a regex match
each time. getPath now returns the path that was constructed when the
PropertyKey object is first instantiated
---
.../src/main/java/org/apache/helix/PropertyKey.java | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/helix-core/src/main/java/org/apache/helix/PropertyKey.java
b/helix-core/src/main/java/org/apache/helix/PropertyKey.java
index eb5d5c1d4..1037c94e2 100644
--- a/helix-core/src/main/java/org/apache/helix/PropertyKey.java
+++ b/helix-core/src/main/java/org/apache/helix/PropertyKey.java
@@ -86,6 +86,7 @@ public class PropertyKey {
public PropertyType _type;
private final String[] _params;
Class<? extends HelixProperty> _typeClazz;
+ private String _path;
// if type is CONFIGS, set configScope; otherwise null
ConfigScopeProperty _configScope;
@@ -110,15 +111,18 @@ public class PropertyKey {
*/
public PropertyKey(PropertyType type, ConfigScopeProperty configScope,
Class<? extends HelixProperty> typeClazz, String... params) {
- _type = type;
if (params == null || params.length == 0 ||
Arrays.asList(params).contains(null)) {
throw new IllegalArgumentException("params cannot be null");
}
+ _type = type;
_params = params;
_typeClazz = typeClazz;
-
_configScope = configScope;
+ _path = PropertyPathBuilder.getPath(_type, _params[0],
Arrays.copyOfRange(_params, 1, _params.length));
+ if (_path == null) {
+ LOG.error("Invalid property key with type: {} subKeys: {}", _type,
Arrays.toString(_params));
+ }
}
@Override
@@ -165,13 +169,7 @@ public class PropertyKey {
* @return absolute path to the property
*/
public String getPath() {
- String clusterName = _params[0];
- String[] subKeys = Arrays.copyOfRange(_params, 1, _params.length);
- String path = PropertyPathBuilder.getPath(_type, clusterName, subKeys);
- if (path == null) {
- LOG.error("Invalid property key with type:" + _type + "subKeys:" +
Arrays.toString(_params));
- }
- return path;
+ return _path;
}
/**