Qomolang opened a new pull request #9603:
URL: https://github.com/apache/dubbo/pull/9603


   ## What is the purpose of the change
   the setting in application such as "dubbo.application.qosEnable" is useless, 
you must set "dubbo.application.qos-enable" to enable QoS, But they are 
supposed to be be equivalent
   
   ## Brief changelog
   i may not be able to express the bug and my action ​explictly in English, so 
i would like to use Chinese then.
   现状:
   目前只有这一个属性(qosEnable qos-enable)不一致,因为目前只有这个属性是kebab-case的默认property
   如果日后新加默认kebab-case的属性,也会导致用户配置失效
   
   本pr:
   兼容kebab-case与camelCase配置;
   保证用户配置不会被默认配置覆盖;
   
   
   ## Verifying this change
   
   原因:
   错误发生流程:
   precondition: dubbo通过反射进行环境变量值绑定,而在绑定过程中做匹配的都是kebab-case的值
   
   0. 假设我在property文件中设置了dubbo.application.qosEnable = true(待会我们会看到这个设置如何无效化的)
   1. 
dubbo自己实现了一个spring的EnvironmentPostProcessor,名字是DubboDefaultPropertiesEnvironmentPostProcessor。这个类会设置一些默认配置,包括dubbo.application.qos-enable=false。
   2. 
这个类在spring环境初始化过程中的执行优先级被设置为最低,于是它会在spring加载完其余所有环境变量后执行(此时,我们的environmentMap中,已经有<dubbo.application.qosEnable
 , 
true>),在设置完默认值后,它会执行addOrReplace方法,应该只有没有用户配置才加默认配置。但是问题来了:”dubbo.application.qosEnable“
 != "dubbo.application.qos-enable" 即使我们设置了qosEnable,默认值还是加成功了!
   3. 
在最后的绑定值前,ConfigurationUtils.getSubProperties会把environmentMap中qosEnable这种小驼峰格式的值(<dubbo.application.qosEnable
 , true>)转化为kebab-case(<dubbo.application.qos-nable , 
true>),再插回到environmentMap里。
   4. 插入方法是putIfAbsent,但是我们的默认值<dubbo.application.qos-enable, 
false>已经在map里了!插入失败!我们后面使用的其实是默认值 false
   
   修改方法:
   在默认配置添加完后进行额外处理,将所有kebab-case的默认配置转为camelCase,比如qos相关的默认配置将转化为qosEnable 。
   
   正确性:
   如果用户采用kebab-case的配置,则默认配置将被静默(就和现在用户配置被静默的原理一样,不过只是默认配置不生效)
   
如果用户采用camelCase的配置,则DubboDefaultPropertiesEnvironmentPostProcessor时,默认配置不会成功添加,因为已经有用户默认配置
   
   <!-- Follow this checklist to help us incorporate your contribution quickly 
and easily: -->
   
   ## Checklist
   - [x] Make sure there is a 
[GitHub_issue](https://github.com/apache/dubbo/issues) field for the change 
(usually before you start working on it). Trivial changes like typos do not 
require a GitHub issue. Your pull request should address just this issue, 
without pulling in other changes - one PR resolves one issue.
   - [x] Each commit in the pull request should have a meaningful subject line 
and body.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7
   - [x] Write necessary unit-test to verify your logic correction, more mock a 
little better when cross module dependency exist. If the new feature or 
significant change is committed, please remember to add sample in [dubbo 
samples](https://github.com/apache/dubbo-samples) project.
   - [x] Add some description to 
[dubbo-website](https://github.com/apache/dubbo-website) project if you are 
requesting to add a feature.
   - [x] GitHub Actions works fine on your own branch.
   - [x] If this contribution is large, please follow the [Software Donation 
Guide](https://github.com/apache/dubbo/wiki/Software-donation-guide).


-- 
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