[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-2784?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16018251#comment-16018251
 ] 

ASF GitHub Bot commented on ZOOKEEPER-2784:
-------------------------------------------

Github user asdf2014 commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/257#discussion_r117599887
  
    --- Diff: 
src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java ---
    @@ -310,8 +311,8 @@ public boolean initiateConnection(Socket sock, Long 
sid) {
          * possible long value to lose the challenge.
          *
          */
    -    public void receiveConnection(Socket sock) {
    -        Long sid = null, protocolVersion = null;
    +    public void receiveConnection(Socket sock) throws ConfigException {
    +        Long sid, protocolVersion;
    --- End diff --
    
    Yeah, actually it could be a problem. `Long == Long` will call 
`Long.valueof` method, and compare the address of Object. And the 
`Long.valueof` method will create a new `Long` Object when the value of `Long` 
Object more than 127. So, it could return the `false`.
    ```java
    /*
    127L == 127L: true
    128L == 128L: false
    128L equals 128L: true
    127 == 127: true
    128 == 128: true
     */
    public static void main(String... args) {
        Long l1 = 127L, l2 = 127L, l3 = 128L, l4 = 128L;
        System.out.println("127L == 127L: " + (l1 == l2));
        System.out.println("128L == 128L: " + (l3 == l4));
        System.out.println("128L equals 128L: " + (l3.equals(l4)));
        long ll1 = 127, ll2 = 127, ll3 = 128, ll4 = 128;
        System.out.println("127 == 127: " + (ll1 == ll2));
        System.out.println("128 == 128: " + (ll3 == ll4));
    }
    ```


> Add some limitations on code level for `SID` to avoid configuration problem
> ---------------------------------------------------------------------------
>
>                 Key: ZOOKEEPER-2784
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2784
>             Project: ZooKeeper
>          Issue Type: Improvement
>          Components: quorum
>    Affects Versions: 3.5.2
>            Reporter: Benedict Jin
>             Fix For: 3.6.0
>
>   Original Estimate: 168h
>  Remaining Estimate: 168h
>
> As so far, `QuorumCnxManager#receiveConnection` cannot find out the same 
> `SID` problem, then the Zookeeper cluster will start successfully. But the 
> cluster is not health, and it will throw some problem like `not 
> synchronized`. So, i thought we should add some limitations on code level for 
> `SID` to find those configuration problem more early.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to