You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "adoroszlai (via GitHub)" <gi...@apache.org> on 2023/05/25 12:36:58 UTC

[GitHub] [ozone] adoroszlai opened a new pull request, #4774: HDDS-8668. Allow reconfiguration of annotated config object

adoroszlai opened a new pull request, #4774:
URL: https://github.com/apache/ozone/pull/4774

   ## What changes were proposed in this pull request?
   
    * allow `@Config` properties to be marked as `reconfigurable`
    * implement reconfiguration of annotated config object from `ConfigurationSource`
    * create base class `ReconfigurableConfig` to help with keeping track of reconfigurable properties and handling updates
   
   This is not tied into reconfiguration handling in OM/SCM/etc., will be done in follow-up.
   
   https://issues.apache.org/jira/browse/HDDS-8668
   
   ## How was this patch tested?
   
   Added unit tests.
   
   CI:
   https://github.com/adoroszlai/hadoop-ozone/actions/runs/5073256233


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] xichen01 commented on a diff in pull request #4774: HDDS-8668. Allow reconfiguration of annotated config object

Posted by "xichen01 (via GitHub)" <gi...@apache.org>.
xichen01 commented on code in PR #4774:
URL: https://github.com/apache/ozone/pull/4774#discussion_r1206455943


##########
hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationReflectionUtil.java:
##########
@@ -34,99 +36,101 @@ public final class ConfigurationReflectionUtil {
   private ConfigurationReflectionUtil() {
   }
 
+  public static <T> Map<String, Field> mapReconfigurableProperties(
+      Class<T> configurationClass) {
+    Optional<String> prefix = getPrefix(configurationClass);
+    Map<String, Field> props =
+        mapReconfigurableProperties(configurationClass, prefix);
+    Class<? super T> superClass = configurationClass.getSuperclass();
+    while (superClass != null) {
+      props.putAll(mapReconfigurableProperties(superClass, prefix));
+      superClass = superClass.getSuperclass();
+    }
+    return props;
+  }
+
+  private static <T> Map<String, Field> mapReconfigurableProperties(
+      Class<T> configurationClass, Optional<String> prefix) {
+    Map<String, Field> props = new HashMap<>();
+    for (Field field : configurationClass.getDeclaredFields()) {
+      if (field.isAnnotationPresent(Config.class)) {
+        Config configAnnotation = field.getAnnotation(Config.class);
+
+        if (configAnnotation.reconfigurable()) {
+          checkNotFinal(configurationClass, field);
+          props.put(getFullKey(prefix, configAnnotation), field);
+        }
+      }
+    }
+    return props;
+  }
+
   public static <T> void injectConfiguration(
       ConfigurationSource configuration,
       Class<T> configurationClass,
-      T configObject, String prefix) {
+      T configObject, String prefix, boolean reconfiguration) {
     injectConfigurationToObject(configuration, configurationClass, configObject,
-        prefix);
+        prefix, reconfiguration);
     Class<? super T> superClass = configurationClass.getSuperclass();
     while (superClass != null) {
       injectConfigurationToObject(configuration, superClass, configObject,
-          prefix);
+          prefix, reconfiguration);
       superClass = superClass.getSuperclass();
     }
   }
 
-  public static <T> void injectConfigurationToObject(ConfigurationSource from,
+  private static <T> void injectConfigurationToObject(ConfigurationSource from,
       Class<T> configurationClass,
       T configuration,
-      String prefix) {
+      String prefix,
+      boolean reconfiguration
+  ) {
     for (Field field : configurationClass.getDeclaredFields()) {
       if (field.isAnnotationPresent(Config.class)) {
-        if ((field.getModifiers() & Modifier.FINAL) != 0) {
-          throw new ConfigurationException(String.format(
-              "Trying to set final field %s#%s, probably indicates misplaced " +
-                  "@Config annotation",
-              configurationClass.getSimpleName(), field.getName()));
-        }
-
-        String fieldLocation =
-            configurationClass + "." + field.getName();
+        checkNotFinal(configurationClass, field);
 
         Config configAnnotation = field.getAnnotation(Config.class);
 
-        String key = prefix + "." + configAnnotation.key();
+        if (reconfiguration && !configAnnotation.reconfigurable()) {
+          continue;
+        }
 
+        String key = prefix + "." + configAnnotation.key();
         String defaultValue = configAnnotation.defaultValue();
+        String value = from.get(key, defaultValue);

Review Comment:
   If the `value` is equal with `defaultValue`, maybe we can skip `setField()` when reconfiguration.
   And we can output a LOG when the reconfiguration is successful.
   
   
   
   



##########
hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationReflectionUtil.java:
##########
@@ -34,99 +36,101 @@ public final class ConfigurationReflectionUtil {
   private ConfigurationReflectionUtil() {
   }
 
+  public static <T> Map<String, Field> mapReconfigurableProperties(
+      Class<T> configurationClass) {
+    Optional<String> prefix = getPrefix(configurationClass);
+    Map<String, Field> props =
+        mapReconfigurableProperties(configurationClass, prefix);
+    Class<? super T> superClass = configurationClass.getSuperclass();
+    while (superClass != null) {
+      props.putAll(mapReconfigurableProperties(superClass, prefix));
+      superClass = superClass.getSuperclass();
+    }
+    return props;
+  }
+
+  private static <T> Map<String, Field> mapReconfigurableProperties(
+      Class<T> configurationClass, Optional<String> prefix) {
+    Map<String, Field> props = new HashMap<>();
+    for (Field field : configurationClass.getDeclaredFields()) {
+      if (field.isAnnotationPresent(Config.class)) {
+        Config configAnnotation = field.getAnnotation(Config.class);
+
+        if (configAnnotation.reconfigurable()) {
+          checkNotFinal(configurationClass, field);
+          props.put(getFullKey(prefix, configAnnotation), field);
+        }
+      }
+    }
+    return props;
+  }
+
   public static <T> void injectConfiguration(
       ConfigurationSource configuration,
       Class<T> configurationClass,
-      T configObject, String prefix) {
+      T configObject, String prefix, boolean reconfiguration) {
     injectConfigurationToObject(configuration, configurationClass, configObject,
-        prefix);
+        prefix, reconfiguration);
     Class<? super T> superClass = configurationClass.getSuperclass();
     while (superClass != null) {
       injectConfigurationToObject(configuration, superClass, configObject,
-          prefix);
+          prefix, reconfiguration);
       superClass = superClass.getSuperclass();
     }
   }
 
-  public static <T> void injectConfigurationToObject(ConfigurationSource from,
+  private static <T> void injectConfigurationToObject(ConfigurationSource from,
       Class<T> configurationClass,
       T configuration,
-      String prefix) {
+      String prefix,
+      boolean reconfiguration
+  ) {
     for (Field field : configurationClass.getDeclaredFields()) {
       if (field.isAnnotationPresent(Config.class)) {
-        if ((field.getModifiers() & Modifier.FINAL) != 0) {
-          throw new ConfigurationException(String.format(
-              "Trying to set final field %s#%s, probably indicates misplaced " +
-                  "@Config annotation",
-              configurationClass.getSimpleName(), field.getName()));
-        }
-
-        String fieldLocation =
-            configurationClass + "." + field.getName();
+        checkNotFinal(configurationClass, field);
 
         Config configAnnotation = field.getAnnotation(Config.class);
 
-        String key = prefix + "." + configAnnotation.key();
+        if (reconfiguration && !configAnnotation.reconfigurable()) {
+          continue;
+        }
 
+        String key = prefix + "." + configAnnotation.key();
         String defaultValue = configAnnotation.defaultValue();
+        String value = from.get(key, defaultValue);
 
-        ConfigType type = configAnnotation.type();
+        setField(configurationClass, configuration, field, configAnnotation,

Review Comment:
   Is there a thread safety issue here? Reading the configuration may be in progress at any time while the program is running.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] xichen01 commented on pull request #4774: HDDS-8668. Allow reconfiguration of annotated config object

Posted by "xichen01 (via GitHub)" <gi...@apache.org>.
xichen01 commented on PR #4774:
URL: https://github.com/apache/ozone/pull/4774#issuecomment-1566465495

   @adoroszlai I have a curious question about the future code implementation.
   
   What is the relationship between configurations with the `@Config(reconfigurable = true)` annotation and configurations supported by the `reconfig` command?
   1. Are all configurations with the `@Config(reconfigurable = true)` annotation supported by the `reconfig` command
   2. Need to manually implemented which configurations are supported by the `reconfig` command.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai merged pull request #4774: HDDS-8668. Allow reconfiguration of annotated config object

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai merged PR #4774:
URL: https://github.com/apache/ozone/pull/4774


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai commented on pull request #4774: HDDS-8668. Allow reconfiguration of annotated config object

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #4774:
URL: https://github.com/apache/ozone/pull/4774#issuecomment-1566506318

   > What is the relationship between configurations with the `@Config(reconfigurable = true)` annotation and configurations supported by the `reconfig` command?
   
   Currently there is no relationship yet.  We'll need to register the config objects with the one that handles `reconfig` commands.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] xichen01 commented on a diff in pull request #4774: HDDS-8668. Allow reconfiguration of annotated config object

Posted by "xichen01 (via GitHub)" <gi...@apache.org>.
xichen01 commented on code in PR #4774:
URL: https://github.com/apache/ozone/pull/4774#discussion_r1208808525


##########
hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationReflectionUtil.java:
##########
@@ -34,99 +36,101 @@ public final class ConfigurationReflectionUtil {
   private ConfigurationReflectionUtil() {
   }
 
+  public static <T> Map<String, Field> mapReconfigurableProperties(
+      Class<T> configurationClass) {
+    Optional<String> prefix = getPrefix(configurationClass);
+    Map<String, Field> props =
+        mapReconfigurableProperties(configurationClass, prefix);
+    Class<? super T> superClass = configurationClass.getSuperclass();
+    while (superClass != null) {
+      props.putAll(mapReconfigurableProperties(superClass, prefix));
+      superClass = superClass.getSuperclass();
+    }
+    return props;
+  }
+
+  private static <T> Map<String, Field> mapReconfigurableProperties(
+      Class<T> configurationClass, Optional<String> prefix) {
+    Map<String, Field> props = new HashMap<>();
+    for (Field field : configurationClass.getDeclaredFields()) {
+      if (field.isAnnotationPresent(Config.class)) {
+        Config configAnnotation = field.getAnnotation(Config.class);
+
+        if (configAnnotation.reconfigurable()) {
+          checkNotFinal(configurationClass, field);
+          props.put(getFullKey(prefix, configAnnotation), field);
+        }
+      }
+    }
+    return props;
+  }
+
   public static <T> void injectConfiguration(
       ConfigurationSource configuration,
       Class<T> configurationClass,
-      T configObject, String prefix) {
+      T configObject, String prefix, boolean reconfiguration) {
     injectConfigurationToObject(configuration, configurationClass, configObject,
-        prefix);
+        prefix, reconfiguration);
     Class<? super T> superClass = configurationClass.getSuperclass();
     while (superClass != null) {
       injectConfigurationToObject(configuration, superClass, configObject,
-          prefix);
+          prefix, reconfiguration);
       superClass = superClass.getSuperclass();
     }
   }
 
-  public static <T> void injectConfigurationToObject(ConfigurationSource from,
+  private static <T> void injectConfigurationToObject(ConfigurationSource from,
       Class<T> configurationClass,
       T configuration,
-      String prefix) {
+      String prefix,
+      boolean reconfiguration
+  ) {
     for (Field field : configurationClass.getDeclaredFields()) {
       if (field.isAnnotationPresent(Config.class)) {
-        if ((field.getModifiers() & Modifier.FINAL) != 0) {
-          throw new ConfigurationException(String.format(
-              "Trying to set final field %s#%s, probably indicates misplaced " +
-                  "@Config annotation",
-              configurationClass.getSimpleName(), field.getName()));
-        }
-
-        String fieldLocation =
-            configurationClass + "." + field.getName();
+        checkNotFinal(configurationClass, field);
 
         Config configAnnotation = field.getAnnotation(Config.class);
 
-        String key = prefix + "." + configAnnotation.key();
+        if (reconfiguration && !configAnnotation.reconfigurable()) {
+          continue;
+        }
 
+        String key = prefix + "." + configAnnotation.key();
         String defaultValue = configAnnotation.defaultValue();
+        String value = from.get(key, defaultValue);
 
-        ConfigType type = configAnnotation.type();
+        setField(configurationClass, configuration, field, configAnnotation,

Review Comment:
   So it is possible that some synchronization operations may be required when implementing specific configuration updates.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai commented on pull request #4774: HDDS-8668. Allow reconfiguration of annotated config object

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #4774:
URL: https://github.com/apache/ozone/pull/4774#issuecomment-1563210937

   @whbing @xichen01 please review when you have some time


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai commented on a diff in pull request #4774: HDDS-8668. Allow reconfiguration of annotated config object

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #4774:
URL: https://github.com/apache/ozone/pull/4774#discussion_r1206703722


##########
hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationReflectionUtil.java:
##########
@@ -34,99 +36,101 @@ public final class ConfigurationReflectionUtil {
   private ConfigurationReflectionUtil() {
   }
 
+  public static <T> Map<String, Field> mapReconfigurableProperties(
+      Class<T> configurationClass) {
+    Optional<String> prefix = getPrefix(configurationClass);
+    Map<String, Field> props =
+        mapReconfigurableProperties(configurationClass, prefix);
+    Class<? super T> superClass = configurationClass.getSuperclass();
+    while (superClass != null) {
+      props.putAll(mapReconfigurableProperties(superClass, prefix));
+      superClass = superClass.getSuperclass();
+    }
+    return props;
+  }
+
+  private static <T> Map<String, Field> mapReconfigurableProperties(
+      Class<T> configurationClass, Optional<String> prefix) {
+    Map<String, Field> props = new HashMap<>();
+    for (Field field : configurationClass.getDeclaredFields()) {
+      if (field.isAnnotationPresent(Config.class)) {
+        Config configAnnotation = field.getAnnotation(Config.class);
+
+        if (configAnnotation.reconfigurable()) {
+          checkNotFinal(configurationClass, field);
+          props.put(getFullKey(prefix, configAnnotation), field);
+        }
+      }
+    }
+    return props;
+  }
+
   public static <T> void injectConfiguration(
       ConfigurationSource configuration,
       Class<T> configurationClass,
-      T configObject, String prefix) {
+      T configObject, String prefix, boolean reconfiguration) {
     injectConfigurationToObject(configuration, configurationClass, configObject,
-        prefix);
+        prefix, reconfiguration);
     Class<? super T> superClass = configurationClass.getSuperclass();
     while (superClass != null) {
       injectConfigurationToObject(configuration, superClass, configObject,
-          prefix);
+          prefix, reconfiguration);
       superClass = superClass.getSuperclass();
     }
   }
 
-  public static <T> void injectConfigurationToObject(ConfigurationSource from,
+  private static <T> void injectConfigurationToObject(ConfigurationSource from,
       Class<T> configurationClass,
       T configuration,
-      String prefix) {
+      String prefix,
+      boolean reconfiguration
+  ) {
     for (Field field : configurationClass.getDeclaredFields()) {
       if (field.isAnnotationPresent(Config.class)) {
-        if ((field.getModifiers() & Modifier.FINAL) != 0) {
-          throw new ConfigurationException(String.format(
-              "Trying to set final field %s#%s, probably indicates misplaced " +
-                  "@Config annotation",
-              configurationClass.getSimpleName(), field.getName()));
-        }
-
-        String fieldLocation =
-            configurationClass + "." + field.getName();
+        checkNotFinal(configurationClass, field);
 
         Config configAnnotation = field.getAnnotation(Config.class);
 
-        String key = prefix + "." + configAnnotation.key();
+        if (reconfiguration && !configAnnotation.reconfigurable()) {
+          continue;
+        }
 
+        String key = prefix + "." + configAnnotation.key();
         String defaultValue = configAnnotation.defaultValue();
+        String value = from.get(key, defaultValue);

Review Comment:
   The config object may have other value (e.g. if conf had non-default value previously), so we need to set it anyway.  We may skip setting it if the field's actual value is the same as the new value, but I don't think it's worth adding the equality check.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai commented on a diff in pull request #4774: HDDS-8668. Allow reconfiguration of annotated config object

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #4774:
URL: https://github.com/apache/ozone/pull/4774#discussion_r1206705931


##########
hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationReflectionUtil.java:
##########
@@ -34,99 +36,101 @@ public final class ConfigurationReflectionUtil {
   private ConfigurationReflectionUtil() {
   }
 
+  public static <T> Map<String, Field> mapReconfigurableProperties(
+      Class<T> configurationClass) {
+    Optional<String> prefix = getPrefix(configurationClass);
+    Map<String, Field> props =
+        mapReconfigurableProperties(configurationClass, prefix);
+    Class<? super T> superClass = configurationClass.getSuperclass();
+    while (superClass != null) {
+      props.putAll(mapReconfigurableProperties(superClass, prefix));
+      superClass = superClass.getSuperclass();
+    }
+    return props;
+  }
+
+  private static <T> Map<String, Field> mapReconfigurableProperties(
+      Class<T> configurationClass, Optional<String> prefix) {
+    Map<String, Field> props = new HashMap<>();
+    for (Field field : configurationClass.getDeclaredFields()) {
+      if (field.isAnnotationPresent(Config.class)) {
+        Config configAnnotation = field.getAnnotation(Config.class);
+
+        if (configAnnotation.reconfigurable()) {
+          checkNotFinal(configurationClass, field);
+          props.put(getFullKey(prefix, configAnnotation), field);
+        }
+      }
+    }
+    return props;
+  }
+
   public static <T> void injectConfiguration(
       ConfigurationSource configuration,
       Class<T> configurationClass,
-      T configObject, String prefix) {
+      T configObject, String prefix, boolean reconfiguration) {
     injectConfigurationToObject(configuration, configurationClass, configObject,
-        prefix);
+        prefix, reconfiguration);
     Class<? super T> superClass = configurationClass.getSuperclass();
     while (superClass != null) {
       injectConfigurationToObject(configuration, superClass, configObject,
-          prefix);
+          prefix, reconfiguration);
       superClass = superClass.getSuperclass();
     }
   }
 
-  public static <T> void injectConfigurationToObject(ConfigurationSource from,
+  private static <T> void injectConfigurationToObject(ConfigurationSource from,
       Class<T> configurationClass,
       T configuration,
-      String prefix) {
+      String prefix,
+      boolean reconfiguration
+  ) {
     for (Field field : configurationClass.getDeclaredFields()) {
       if (field.isAnnotationPresent(Config.class)) {
-        if ((field.getModifiers() & Modifier.FINAL) != 0) {
-          throw new ConfigurationException(String.format(
-              "Trying to set final field %s#%s, probably indicates misplaced " +
-                  "@Config annotation",
-              configurationClass.getSimpleName(), field.getName()));
-        }
-
-        String fieldLocation =
-            configurationClass + "." + field.getName();
+        checkNotFinal(configurationClass, field);
 
         Config configAnnotation = field.getAnnotation(Config.class);
 
-        String key = prefix + "." + configAnnotation.key();
+        if (reconfiguration && !configAnnotation.reconfigurable()) {
+          continue;
+        }
 
+        String key = prefix + "." + configAnnotation.key();
         String defaultValue = configAnnotation.defaultValue();
+        String value = from.get(key, defaultValue);
 
-        ConfigType type = configAnnotation.type();
+        setField(configurationClass, configuration, field, configAnnotation,

Review Comment:
   Correct, I think none of the type-safe config objects in Ozone are thread-safe, but it's not specific to this change.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] whbing commented on pull request #4774: HDDS-8668. Allow reconfiguration of annotated config object

Posted by "whbing (via GitHub)" <gi...@apache.org>.
whbing commented on PR #4774:
URL: https://github.com/apache/ozone/pull/4774#issuecomment-1565296698

   The code is elegant and generic !  LGTM +1


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai commented on pull request #4774: HDDS-8668. Allow reconfiguration of annotated config object

Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #4774:
URL: https://github.com/apache/ozone/pull/4774#issuecomment-1578013610

   Thanks @symious, @whbing, @xichen01 for the review.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] xichen01 commented on a diff in pull request #4774: HDDS-8668. Allow reconfiguration of annotated config object

Posted by "xichen01 (via GitHub)" <gi...@apache.org>.
xichen01 commented on code in PR #4774:
URL: https://github.com/apache/ozone/pull/4774#discussion_r1208807854


##########
hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationReflectionUtil.java:
##########
@@ -34,99 +36,101 @@ public final class ConfigurationReflectionUtil {
   private ConfigurationReflectionUtil() {
   }
 
+  public static <T> Map<String, Field> mapReconfigurableProperties(
+      Class<T> configurationClass) {
+    Optional<String> prefix = getPrefix(configurationClass);
+    Map<String, Field> props =
+        mapReconfigurableProperties(configurationClass, prefix);
+    Class<? super T> superClass = configurationClass.getSuperclass();
+    while (superClass != null) {
+      props.putAll(mapReconfigurableProperties(superClass, prefix));
+      superClass = superClass.getSuperclass();
+    }
+    return props;
+  }
+
+  private static <T> Map<String, Field> mapReconfigurableProperties(
+      Class<T> configurationClass, Optional<String> prefix) {
+    Map<String, Field> props = new HashMap<>();
+    for (Field field : configurationClass.getDeclaredFields()) {
+      if (field.isAnnotationPresent(Config.class)) {
+        Config configAnnotation = field.getAnnotation(Config.class);
+
+        if (configAnnotation.reconfigurable()) {
+          checkNotFinal(configurationClass, field);
+          props.put(getFullKey(prefix, configAnnotation), field);
+        }
+      }
+    }
+    return props;
+  }
+
   public static <T> void injectConfiguration(
       ConfigurationSource configuration,
       Class<T> configurationClass,
-      T configObject, String prefix) {
+      T configObject, String prefix, boolean reconfiguration) {
     injectConfigurationToObject(configuration, configurationClass, configObject,
-        prefix);
+        prefix, reconfiguration);
     Class<? super T> superClass = configurationClass.getSuperclass();
     while (superClass != null) {
       injectConfigurationToObject(configuration, superClass, configObject,
-          prefix);
+          prefix, reconfiguration);
       superClass = superClass.getSuperclass();
     }
   }
 
-  public static <T> void injectConfigurationToObject(ConfigurationSource from,
+  private static <T> void injectConfigurationToObject(ConfigurationSource from,
       Class<T> configurationClass,
       T configuration,
-      String prefix) {
+      String prefix,
+      boolean reconfiguration
+  ) {
     for (Field field : configurationClass.getDeclaredFields()) {
       if (field.isAnnotationPresent(Config.class)) {
-        if ((field.getModifiers() & Modifier.FINAL) != 0) {
-          throw new ConfigurationException(String.format(
-              "Trying to set final field %s#%s, probably indicates misplaced " +
-                  "@Config annotation",
-              configurationClass.getSimpleName(), field.getName()));
-        }
-
-        String fieldLocation =
-            configurationClass + "." + field.getName();
+        checkNotFinal(configurationClass, field);
 
         Config configAnnotation = field.getAnnotation(Config.class);
 
-        String key = prefix + "." + configAnnotation.key();
+        if (reconfiguration && !configAnnotation.reconfigurable()) {
+          continue;
+        }
 
+        String key = prefix + "." + configAnnotation.key();
         String defaultValue = configAnnotation.defaultValue();
+        String value = from.get(key, defaultValue);

Review Comment:
   OK, understood



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org