yandrey321 commented on code in PR #11878:
URL: https://github.com/apache/ozone/pull/11878#discussion_r4462516681


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationConfigValidator.java:
##########
@@ -43,6 +50,23 @@ public class ReplicationConfigValidator {
 
   private Pattern compiledValidationPattern;
 
+  /**
+   * Returns a validator for the pattern configured in {@code conf}. {@code 
conf.getObject(...)} creates a validator
+   * by reflection and compiles its pattern on every call; this reuses the one 
built for the same pattern, and still
+   * reads the pattern from {@code conf} each time, so a changed configuration 
takes effect at once.
+   * The returned validator is shared, so it is not exposed outside this 
package.
+   */
+  static ReplicationConfigValidator get(ConfigurationSource conf) {
+    final String pattern = conf.get(ALLOWED_CONFIGS_KEY, 
ALLOWED_CONFIGS_DEFAULT);
+    ReplicationConfigValidator validator = cached;
+    if (validator == null || !Objects.equals(validator.validationPattern, 
pattern)) {
+      validator = new ReplicationConfigValidator();
+      validator.setValidationPattern(pattern);

Review Comment:
   Changing pattern when ozone is running should be very infrequent event, so 
replacing validator in place should be cheaper and safer than introducing 
synchronization and reusing the old object.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to