Uploaded image for project: 'ZooKeeper'
  1. ZooKeeper
  2. ZOOKEEPER-4372

Zookeeper lock recipe doesn't parse negative sequence numbers correctly

    XMLWordPrintableJSON

Details

    Description

      According to the Zookeeper docs ZNode sequence numbers will rollover to -2147483648 after reaching 2147483647 (I've also confirmed this is the case in practice):

      https://zookeeper.apache.org/doc/r3.7.0/zookeeperProgrammers.html#Sequence+Nodes+–+Unique+Naming

       

      When this rollover happens the negative symbol is incorrectly stripped off the sequence number in ZNodeName due to this code searching for the last index of "-", thus the sequence number parsed is always the absolute value:
      https://github.com/apache/zookeeper/blob/1e74a3395a9c3c4d67093f9a073bffb5a176916c/zookeeper-recipes/zookeeper-recipes-lock/src/main/java/org/apache/zookeeper/recipes/lock/ZNodeName.java#L54

       

      This results in any subsequently created sequence numbers being considered the "lowest" due to the absolute value decrementing until reaching 0. It also looks like there is no test to check parsing of negative sequence numbers.

       

      For context, this same issue arose in the unofficial Golang client recipe and there is a proposed fix there: https://github.com/go-zookeeper/zk/pull/65

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              colinmcintosh Colin McIntosh
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1.5h
                  1.5h