Skip to content

Refactor getRegistry: firstly get registry outside from lock#5484

Closed
maoyiz wants to merge 1 commit intoapache:masterfrom
maoyiz:refactor-getRegistry
Closed

Refactor getRegistry: firstly get registry outside from lock#5484
maoyiz wants to merge 1 commit intoapache:masterfrom
maoyiz:refactor-getRegistry

Conversation

@maoyiz
Copy link
Copy Markdown
Contributor

@maoyiz maoyiz commented Dec 15, 2019

What is the purpose of the change

we should get registry instance outside lock firstly, and if not null, return directly.

Brief changelog

AbstractRegistryFactory.java

Verifying this change

XXXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • 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.
  • Format the pull request title like [Dubbo-XXX] Fix UnknownException when host config not exist #XXX. 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.
  • 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.
  • Run mvn clean install -DskipTests=false & mvn clean test-compile failsafe:integration-test to make sure unit-test and integration-test pass.
  • If this contribution is large, please follow the Software Donation Guide.

@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #5484 into master will decrease coverage by 0.06%.
The diff coverage is 70.58%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #5484      +/-   ##
============================================
- Coverage     61.08%   61.01%   -0.07%     
+ Complexity      422      421       -1     
============================================
  Files           919      919              
  Lines         37502    37502              
  Branches       5444     5444              
============================================
- Hits          22909    22883      -26     
- Misses        12097    12124      +27     
+ Partials       2496     2495       -1
Impacted Files Coverage Δ Complexity Δ
...ubbo/registry/support/AbstractRegistryFactory.java 70.58% <70.58%> (ø) 0 <0> (ø) ⬇️
...che/dubbo/remoting/transport/mina/MinaChannel.java 43.42% <0%> (-10.53%) 16% <0%> (-1%)
.../remoting/transport/netty4/NettyServerHandler.java 59.09% <0%> (-9.1%) 0% <0%> (ø)
...ng/exchange/support/header/HeartbeatTimerTask.java 73.68% <0%> (-5.27%) 0% <0%> (ø)
.../org/apache/dubbo/remoting/ExecutionException.java 15.78% <0%> (-5.27%) 0% <0%> (ø)
.../remoting/transport/netty4/NettyClientHandler.java 59.32% <0%> (-5.09%) 0% <0%> (ø)
.../apache/dubbo/remoting/transport/AbstractPeer.java 58.69% <0%> (-4.35%) 0% <0%> (ø)
...pache/dubbo/registry/support/AbstractRegistry.java 77.15% <0%> (-3%) 0% <0%> (ø)
...exchange/support/header/HeaderExchangeHandler.java 61.94% <0%> (-2.66%) 0% <0%> (ø)
...rg/apache/dubbo/common/timer/HashedWheelTimer.java 63.1% <0%> (-0.35%) 0% <0%> (ø)
... and 3 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 839d2a6...5992484. Read the comment docs.

@htynkn htynkn added type/refactor type/need-triage Need maintainers to triage labels Dec 20, 2019
@maoyiz maoyiz requested a review from chickenlj December 29, 2019 14:36
@chickenlj chickenlj added this to the 2.7.6 milestone Dec 30, 2019
@CodingSinger
Copy link
Copy Markdown
Member

ping @zhaixiaoxiang

@chickenlj chickenlj self-assigned this Jan 3, 2020
.removeParameters(EXPORT_KEY, REFER_KEY)
.build();
String key = url.toServiceStringWithoutResolving();
Registry registry = REGISTRIES.get(key);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i think shouldn't move those code outside the lock-unlock block. it will cause invoke createRegistry multiple times in some cases.

if (registry == null) {
throw new IllegalStateException("Can not create registry " + url);
}
REGISTRIES.put(key, registry);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe using the java.util.concurrent.ConcurrentHashMap#computeIfAbsent is the better choice ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agree. Could you please take a look? @zhaixiaoxiang

if (registry == null) {
throw new IllegalStateException("Can not create registry " + url);
}
REGISTRIES.put(key, registry);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agree. Could you please take a look? @zhaixiaoxiang

@chickenlj
Copy link
Copy Markdown
Contributor

Closed.
Please format the file and re-submit, thanks.

@chickenlj chickenlj closed this Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/need-triage Need maintainers to triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants