Uploaded image for project: 'ZooKeeper'
  1. ZooKeeper
  2. ZOOKEEPER-1970 Fix Findbugs Warnings
  3. ZOOKEEPER-1972

Fix invalid volatile long/int increment (++)

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.5.0
    • 3.5.0
    • None
    • None
    • Reviewed
    • Awesome! thanks Hongchao! Committed to trunk

    Description

      The findbugs complains about incrementing a volatile variable in AuthFastLeaderElection and FastLeaderElection:

      volatile long logicalclock; /* Election instance */
      ...
      logicalclock++;
      

      Actually this is a bug. It should use AtomicLong here instead of volatile.

      Leader.java and QuorumPeer.java and LearnerHandler.java:

      volatile int tick;
      

      I don't think it needs volatile here. The tick is incremented only in Leader.java:

        synchronized (this) {
                ...
                          if (!tickSkip) {
                              self.tick++;
                          }
        }
      

      and it's protected by the synchronized statement. I just remove volatile keyword.

      Attachments

        1. ZOOKEEPER-1972.patch.4
          15 kB
          Patrick D. Hunt
        2. ZOOKEEPER-1972.patch.3
          16 kB
          Hongchao Deng
        3. ZOOKEEPER-1972.patch.2
          16 kB
          Hongchao Deng
        4. ZOOKEEPER-1972.patch
          13 kB
          Hongchao Deng

        Activity

          People

            hdeng Hongchao Deng
            hdeng Hongchao Deng
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: