Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[master] Fix DubboConfigEarlyInitializationPostProcessor registered twice in Spring Framework #9397

Merged
merged 6 commits into from
Dec 15, 2021

Conversation

gitchenjh
Copy link
Contributor

@gitchenjh gitchenjh commented Dec 13, 2021

What is the purpose of the change

fix #9370

Brief changelog

fix DubboConfigEarlyInitializationPostProcessor counted as BeanPostProcess twice in PostProcessorRegistrationDelegate.registerBeanPostProcessors()

Verifying this change

before

image

DubboConfigEarlyInitializationPostProcessor in beanFactory.getBeanPostProcessors() and postProcessorNames
The beanProcessorTargetCount is 17
After registration the beanFactory.getBeanPostProcessors() should be 16

after

image
No more dubboConfigEarlyInitializationPostProcessor in postProcessorNames
The beanProcessorTargetCount is 16,
After registration the beanFactory.getBeanPostProcessors() should be 16

Checklist

  • Make sure there is a GitHub_issue 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.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7
  • 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 project.
  • Add some description to dubbo-website project if you are requesting to add a feature.
  • GitHub Actions works fine on your own branch.
  • If this contribution is large, please follow the Software Donation Guide.

…eanPostProcess twice in PostProcessorRegistrationDelegate.registerBeanPostProcessors()(#9370)
if (beanFactory != null) {
DubboConfigEarlyInitializationPostProcessor dceiPostProcessor =
DubboConfigEarlyInitializationPostProcessor.getSingleton(beanFactory);
// Register itself
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Register itself

change this comment

DubboConfigEarlyInitializationPostProcessor.getSingleton(beanFactory);
// Register itself
if (logger.isInfoEnabled()) {
logger.info("BeanFactory is about to be initialized, trying to resolve the Dubbo Config Beans early " +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this log message

if (beanFactory == null) { // try again if postProcessBeanDefinitionRegistry method does not effect.
this.beanFactory = unwrap(beanFactory);
initBeanFactory();
public static DubboConfigEarlyInitializationPostProcessor getSingleton(DefaultListableBeanFactory beanFactory) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The global instance of DubboConfigEarlyInitializationPostProcessor holds in DubboConfigEarlyRegistrationPostProcessor is better.
DubboConfigEarlyInitializationPostProcessor just a BeanPostProcessor , it should not care for how to create and be registered.

Copy link
Member

@kylixs kylixs Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the DubboConfigEarlyInitializationPostProcessor can be changed to a inner class of DubboConfigEarlyRegistrationPostProcessor, it's managed by DubboConfigEarlyRegistrationPostProcessor. Then the relationship is more clear and reduce confusion.

@kylixs
Copy link
Member

kylixs commented Dec 14, 2021

The root cause of the incorrect beanProcessorCount is that DubboConfigEarlyInitializationPostProcessor has been registered twice, once by manual registration and once by Spring automatic registration. A more elegant solution is to register only once, and there is no problem with registering in BeanDefinitionRegistryPostProcessor. It is best to explain its role more accurately in the javadoc.

@gitchenjh gitchenjh changed the title [master] Fix DubboConfigEarlyInitializationPostProcessor problem [master] Fix DubboConfigEarlyInitializationPostProcessor registered twice in Spring-Framework Dec 15, 2021
@codecov-commenter
Copy link

codecov-commenter commented Dec 15, 2021

Codecov Report

Merging #9397 (586e65b) into master (7cb6bff) will decrease coverage by 0.00%.
The diff coverage is 50.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #9397      +/-   ##
============================================
- Coverage     60.85%   60.85%   -0.01%     
+ Complexity      448      447       -1     
============================================
  Files          1100     1100              
  Lines         44507    44509       +2     
  Branches       6473     6475       +2     
============================================
  Hits          27086    27086              
+ Misses        14454    14452       -2     
- Partials       2967     2971       +4     
Impacted Files Coverage Δ
...fig/DubboConfigEarlyRegistrationPostProcessor.java 50.00% <50.00%> (ø)
...pache/dubbo/config/spring/util/DubboBeanUtils.java 54.54% <50.00%> (ø)
...in/java/org/apache/dubbo/common/utils/JVMUtil.java 81.13% <0.00%> (-11.33%) ⬇️
...g/apache/dubbo/remoting/p2p/support/FileGroup.java 41.50% <0.00%> (-9.44%) ⬇️
...rg/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java 70.53% <0.00%> (-3.58%) ⬇️
...port/identifier/BaseServiceMetadataIdentifier.java 57.14% <0.00%> (-3.58%) ⬇️
...mmon/serialize/kryo/utils/AbstractKryoFactory.java 75.43% <0.00%> (-3.51%) ⬇️
...he/dubbo/remoting/transport/netty/NettyServer.java 70.17% <0.00%> (-3.51%) ⬇️
...e/dubbo/remoting/transport/netty/NettyChannel.java 55.68% <0.00%> (-3.41%) ⬇️
...ava/org/apache/dubbo/config/ServiceConfigBase.java 57.83% <0.00%> (-1.21%) ⬇️
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7cb6bff...586e65b. Read the comment docs.

@gitchenjh gitchenjh changed the title [master] Fix DubboConfigEarlyInitializationPostProcessor registered twice in Spring-Framework [master] Fix DubboConfigEarlyInitializationPostProcessor registered twice in Spring Framework Dec 15, 2021
Copy link
Contributor

@chickenlj chickenlj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@chickenlj chickenlj added this to the 2.7.15 milestone Dec 15, 2021
@chickenlj chickenlj merged commit 9cfb1ae into apache:master Dec 15, 2021
Comment on lines +129 to +136
private boolean hasRegisteredCommonAnnotationBeanPostProcessor() {
for (BeanPostProcessor beanPostProcessor : beanFactory.getBeanPostProcessors()) {
if (CommonAnnotationBeanPostProcessor.class.equals(beanPostProcessor.getClass())) {
return true;
}
}
return false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to cache the result if has found CommonAnnotationBeanPostProcessor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to cache the result if has found CommonAnnotationBeanPostProcessor

Thanks for your reply. I can't cache the result all the time. Here is my reason:
There might be some BeanPostProcessors not instantiated before some Dubbo Config Bean instantiated (which will call this method),so the result of beanFactory.getBeanPostProcessors() may not be the same when this method is called.
But, it can be cached after CommonAnnotationBeanPostProcessor instantiated, I will submit another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new PR #9414

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants