You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by "kezhuw (via GitHub)" <gi...@apache.org> on 2025/08/20 16:29:52 UTC

[PR] ZOOKEEPER-4966: Decouple `ZKConfig` from `QuorumPeerConfig.ConfigException` [zookeeper]

kezhuw opened a new pull request, #2306:
URL: https://github.com/apache/zookeeper/pull/2306

   `ZKConfig` is client accessible, it should avoid accessing server side `QuorumPeerConfig`.
   
   Changes:
   1. Introduce `org.apache.zookeeper.common.ConfigException` for `ZKConfig(String configPath)`.
   2. Make `QuorumPeerConfig.ConfigException` a subclass of above.
   3. Throw `QuorumPeerConfig.ConfigException` if possible.
   
   Given above changes, this pr maintain abi compatibility with old releases.
   
   **Breaking change**: `ZKConfig(String configPath)` throws `org.apache.zookeeper.common.ConfigException` now but not `QuorumPeerConfig.ConfigException`, so developers have to fix it to compile.


-- 
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: notifications-unsubscribe@zookeeper.apache.org

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


Re: [PR] ZOOKEEPER-4966: Decouple `ZKConfig` from `QuorumPeerConfig.ConfigException` [zookeeper]

Posted by "anmolnar (via GitHub)" <gi...@apache.org>.
anmolnar commented on PR #2306:
URL: https://github.com/apache/zookeeper/pull/2306#issuecomment-3648884421

   @kezhuw Did you see my comments?


-- 
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: notifications-unsubscribe@zookeeper.apache.org

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


Re: [PR] ZOOKEEPER-4966: Decouple `ZKConfig` from `QuorumPeerConfig.ConfigException` [zookeeper]

Posted by "kezhuw (via GitHub)" <gi...@apache.org>.
kezhuw commented on code in PR #2306:
URL: https://github.com/apache/zookeeper/pull/2306#discussion_r2617051194


##########
zookeeper-server/src/main/java/org/apache/zookeeper/common/ZKConfig.java:
##########
@@ -215,16 +215,39 @@ public void setProperty(String key, String value) {
      *
      * @param configPath path to Configuration file.
      */
-    @SuppressWarnings("deprecation")
     public void addConfiguration(Path configPath) throws ConfigException {
-        addConfiguration(configPath.toFile());
+        Path absoluteConfigPath = configPath.toAbsolutePath();
+        LOG.info("Reading configuration from: {}", absoluteConfigPath);
+        try {
+            File configFile = (new VerifyingFileFactory.Builder(LOG).warnForRelativePath()
+                                                               .failForNonExistingPath()
+                                                               .build()).validate(configPath.toFile());
+            Properties cfg = new Properties();
+            try (FileInputStream in = new FileInputStream(configFile)) {
+                cfg.load(in);
+            }
+            parseProperties(cfg);
+        } catch (IOException | IllegalArgumentException e) {
+            LOG.error("Error while configuration from: {}", absoluteConfigPath, e);
+            String msg = "Error while processing " + absoluteConfigPath;
+            try {
+                Class<?> clazz = Class.forName("org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException");

Review Comment:
   The decoupling is known to break something. This pr tried to break compilation while keeping runtime compatibility.
   
   > we could just get rid of it.
   
   I think it is viable given that the runtime error(a.k.a. `NoClassDefFoundError`) is so noticable. I would like to update this pr to this direction. I think we can upgrade ZOOKEEPER-4970 to deprecate `QuorumPeerConfig.ConfigException` also.



-- 
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: notifications-unsubscribe@zookeeper.apache.org

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


Re: [PR] ZOOKEEPER-4966: Decouple `ZKConfig` from `QuorumPeerConfig.ConfigException` [zookeeper]

Posted by "anmolnar (via GitHub)" <gi...@apache.org>.
anmolnar commented on code in PR #2306:
URL: https://github.com/apache/zookeeper/pull/2306#discussion_r2587195150


##########
zookeeper-server/src/main/java/org/apache/zookeeper/common/ZKConfig.java:
##########
@@ -215,16 +215,39 @@ public void setProperty(String key, String value) {
      *
      * @param configPath path to Configuration file.
      */
-    @SuppressWarnings("deprecation")
     public void addConfiguration(Path configPath) throws ConfigException {
-        addConfiguration(configPath.toFile());
+        Path absoluteConfigPath = configPath.toAbsolutePath();
+        LOG.info("Reading configuration from: {}", absoluteConfigPath);
+        try {
+            File configFile = (new VerifyingFileFactory.Builder(LOG).warnForRelativePath()
+                                                               .failForNonExistingPath()
+                                                               .build()).validate(configPath.toFile());
+            Properties cfg = new Properties();
+            try (FileInputStream in = new FileInputStream(configFile)) {
+                cfg.load(in);
+            }
+            parseProperties(cfg);
+        } catch (IOException | IllegalArgumentException e) {
+            LOG.error("Error while configuration from: {}", absoluteConfigPath, e);
+            String msg = "Error while processing " + absoluteConfigPath;
+            try {
+                Class<?> clazz = Class.forName("org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException");

Review Comment:
   Why don't we throw only `ConfigException` here?
   The `QuorumPeerConfig.ConfigExcpetion` signature has already been deprecated, so we could just get rid of it.



-- 
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: notifications-unsubscribe@zookeeper.apache.org

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


Re: [PR] ZOOKEEPER-4966: Decouple `ZKConfig` from `QuorumPeerConfig.ConfigException` [zookeeper]

Posted by "anmolnar (via GitHub)" <gi...@apache.org>.
anmolnar commented on code in PR #2306:
URL: https://github.com/apache/zookeeper/pull/2306#discussion_r2587196446


##########
zookeeper-server/src/main/java/org/apache/zookeeper/common/ZKConfig.java:
##########
@@ -215,16 +215,39 @@ public void setProperty(String key, String value) {
      *
      * @param configPath path to Configuration file.
      */
-    @SuppressWarnings("deprecation")
     public void addConfiguration(Path configPath) throws ConfigException {
-        addConfiguration(configPath.toFile());
+        Path absoluteConfigPath = configPath.toAbsolutePath();
+        LOG.info("Reading configuration from: {}", absoluteConfigPath);
+        try {
+            File configFile = (new VerifyingFileFactory.Builder(LOG).warnForRelativePath()
+                                                               .failForNonExistingPath()
+                                                               .build()).validate(configPath.toFile());
+            Properties cfg = new Properties();
+            try (FileInputStream in = new FileInputStream(configFile)) {
+                cfg.load(in);
+            }
+            parseProperties(cfg);
+        } catch (IOException | IllegalArgumentException e) {
+            LOG.error("Error while configuration from: {}", absoluteConfigPath, e);
+            String msg = "Error while processing " + absoluteConfigPath;
+            try {
+                Class<?> clazz = Class.forName("org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException");

Review Comment:
   This patch is needed only on the master branch anyways.



-- 
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: notifications-unsubscribe@zookeeper.apache.org

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


Re: [PR] ZOOKEEPER-4966: Decouple `ZKConfig` from `QuorumPeerConfig.ConfigException` [zookeeper]

Posted by "kezhuw (via GitHub)" <gi...@apache.org>.
kezhuw commented on PR #2306:
URL: https://github.com/apache/zookeeper/pull/2306#issuecomment-3207134766

   The breaking change is source code level so it won't break runtime code. We could also make `org.apache.zookeeper.common.ConfigException` as an unchecked exception, but that could break runtime expectation as it could be catched as `RuntimeException`. I would prefer to break in source code leve but not runtime.
   
   Give this pr and #2305, I could split `zookeeper-client` from `zookeeper-server` by moving classes mostly, though, the package hierarcy does not look good.


-- 
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: notifications-unsubscribe@zookeeper.apache.org

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


Re: [PR] ZOOKEEPER-4966: Decouple `ZKConfig` from `QuorumPeerConfig.ConfigException` [zookeeper]

Posted by "anmolnar (via GitHub)" <gi...@apache.org>.
anmolnar commented on code in PR #2306:
URL: https://github.com/apache/zookeeper/pull/2306#discussion_r2587184810


##########
zookeeper-server/src/main/java/org/apache/zookeeper/common/ZKConfig.java:
##########
@@ -215,16 +215,39 @@ public void setProperty(String key, String value) {
      *
      * @param configPath path to Configuration file.
      */
-    @SuppressWarnings("deprecation")
     public void addConfiguration(Path configPath) throws ConfigException {
-        addConfiguration(configPath.toFile());
+        Path absoluteConfigPath = configPath.toAbsolutePath();
+        LOG.info("Reading configuration from: {}", absoluteConfigPath);
+        try {
+            File configFile = (new VerifyingFileFactory.Builder(LOG).warnForRelativePath()
+                                                               .failForNonExistingPath()
+                                                               .build()).validate(configPath.toFile());
+            Properties cfg = new Properties();
+            try (FileInputStream in = new FileInputStream(configFile)) {
+                cfg.load(in);
+            }
+            parseProperties(cfg);
+        } catch (IOException | IllegalArgumentException e) {
+            LOG.error("Error while configuration from: {}", absoluteConfigPath, e);
+            String msg = "Error while processing " + absoluteConfigPath;
+            try {
+                Class<?> clazz = Class.forName("org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException");

Review Comment:
   Omg. Are you sure we cannot avoid reflection here?



-- 
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: notifications-unsubscribe@zookeeper.apache.org

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


Re: [PR] ZOOKEEPER-4966: Decouple `ZKConfig` from `QuorumPeerConfig.ConfigException` [zookeeper]

Posted by "kezhuw (via GitHub)" <gi...@apache.org>.
kezhuw commented on code in PR #2306:
URL: https://github.com/apache/zookeeper/pull/2306#discussion_r2617073978


##########
zookeeper-server/src/main/java/org/apache/zookeeper/common/ZKConfig.java:
##########
@@ -215,16 +215,39 @@ public void setProperty(String key, String value) {
      *
      * @param configPath path to Configuration file.
      */
-    @SuppressWarnings("deprecation")
     public void addConfiguration(Path configPath) throws ConfigException {
-        addConfiguration(configPath.toFile());
+        Path absoluteConfigPath = configPath.toAbsolutePath();
+        LOG.info("Reading configuration from: {}", absoluteConfigPath);
+        try {
+            File configFile = (new VerifyingFileFactory.Builder(LOG).warnForRelativePath()
+                                                               .failForNonExistingPath()
+                                                               .build()).validate(configPath.toFile());
+            Properties cfg = new Properties();
+            try (FileInputStream in = new FileInputStream(configFile)) {
+                cfg.load(in);
+            }
+            parseProperties(cfg);
+        } catch (IOException | IllegalArgumentException e) {
+            LOG.error("Error while configuration from: {}", absoluteConfigPath, e);
+            String msg = "Error while processing " + absoluteConfigPath;
+            try {
+                Class<?> clazz = Class.forName("org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException");

Review Comment:
   > I think we can upgrade [ZOOKEEPER-4970](https://issues.apache.org/jira/browse/ZOOKEEPER-4970) to deprecate `QuorumPeerConfig.ConfigException` also.
   
   Previously(#2309), only references to `QuorumPeerConfig.ConfigException` from client package are deprecated but not the exception.



-- 
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: notifications-unsubscribe@zookeeper.apache.org

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


Re: [PR] ZOOKEEPER-4966: Decouple `ZKConfig` from `QuorumPeerConfig.ConfigException` [zookeeper]

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


-- 
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: notifications-unsubscribe@zookeeper.apache.org

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