Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Dubbo-3625] Add constant 'MIN_PATH_ARRAY_LENGTH' #3680

Closed
wants to merge 2 commits into from

Conversation

John-Smile
Copy link
Contributor

@John-Smile John-Smile commented Mar 16, 2019

Fixes #3625

What is the purpose of the change

Remove magic number 5 in line 70 of org.apache.dubbo.configcenter.support.zookeeper.CacheListener#childEvent.

Brief changelog

Add constant 'MIN_PATH_ARRAY_LENGTH'

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 integration-test in test module.
  • 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.

if (done != null) {
done.signal();
}
done.signalAll();
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, this change is irrelevant. And is addressed in #3681 . Please rebase with the master and send the pull request again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK,I will send the pull request again.

@codecov-io
Copy link

Codecov Report

Merging #3680 into master will decrease coverage by 0.13%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #3680      +/-   ##
============================================
- Coverage     63.44%   63.31%   -0.14%     
  Complexity       71       71              
============================================
  Files           703      703              
  Lines         31000    31050      +50     
  Branches       5024     5039      +15     
============================================
- Hits          19669    19659      -10     
- Misses         9066     9122      +56     
- Partials       2265     2269       +4
Impacted Files Coverage Δ Complexity Δ
...dubbo/remoting/exchange/support/DefaultFuture.java 71.42% <100%> (-4.25%) 0 <0> (ø)
.../configcenter/support/zookeeper/CacheListener.java 63.15% <100%> (+0.99%) 0 <0> (ø) ⬇️
.../apache/dubbo/remoting/transport/AbstractPeer.java 60.86% <0%> (-10.87%) 0% <0%> (ø)
...mmon/threadpool/support/AbortPolicyWithReport.java 83.33% <0%> (-5.56%) 0% <0%> (ø)
...ng/exchange/support/header/HeartbeatTimerTask.java 73.68% <0%> (-5.27%) 0% <0%> (ø)
...bo/rpc/cluster/support/FailbackClusterInvoker.java 67.21% <0%> (-3.28%) 0% <0%> (ø)
...a/org/apache/dubbo/registry/etcd/EtcdRegistry.java 0% <0%> (ø) 0% <0%> (ø) ⬇️
...pache/dubbo/remoting/transport/AbstractServer.java 47.91% <0%> (+1.04%) 0% <0%> (ø) ⬇️
...ache/dubbo/remoting/p2p/support/AbstractGroup.java 56.81% <0%> (+11.36%) 0% <0%> (ø) ⬇️

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 b2bfbc7...8eb47c3. Read the comment docs.

@@ -89,7 +89,8 @@ public void dataChanged(String path, Object value, EventType eventType) {
// TODO We limit the notification of config changes to a specific path level, for example
// /dubbo/config/service/configurators, other config changes not in this level will not get notified,
// say /dubbo/config/dubbo.properties
if (path.split("/").length >= 5) {
final int MIN_PATH_ARRAY_LENGTH = 5;
Copy link
Contributor

Choose a reason for hiding this comment

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

It is better to make it static.

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 is better to be local, because it is only used in one method.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, it is not. As a local constant, it will be allocated every time the method is invoked. I don't think it should be local.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I make an experiment.

public class Test {
    private static final int CLZ_FIELD = 65535;
    public static void main(String[] args) {
        final int localVariable = 65536;
        System.out.println(localVariable);
        System.out.println(CLZ_FIELD);
    }
}

After decompilation, I got

public static void main(java.lang.String[]);
  Code:
     0: ldc           #2                  // int 65536
     2: istore_1
     3: getstatic     #3                  // Field java/lang/System.out:Ljava/io/PrintStream;
     6: ldc           #2                  // int 65536
     8: invokevirtual #4                  // Method java/io/PrintStream.println:(I)V
    11: getstatic     #3                  // Field java/lang/System.out:Ljava/io/PrintStream;
    14: ldc           #6                  // int 65535
    16: invokevirtual #4                  // Method java/io/PrintStream.println:(I)V
    19: return

Every time the local constant need one more step ('0: ldc #2') and one more stack space than static constant.
So you are right, I will make it static.

@John-Smile John-Smile closed this Mar 24, 2019
@John-Smile John-Smile deleted the dev_fix_magic_number branch March 24, 2019 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Magic number in CacheListener
4 participants