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

ZOOKEEPER-4743: Increase data version once more when going back to -1 from Integer.MIN_VALUE

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 3.10.0
    • None

    Description

      DataVersion is a 32-bit signed integer. When dataVersion exceeds Integer.MAX, an overflow problem will occur.
      According to my own understanding, overflow itself is not a big problem. The core of dataVersion is to describe the causal order. Two different values ​​can be used to determine the happened-before relationship between the two.
      Then even if an overflow occurs, except for the scenario where Integer.MAX is larger than Integer.MAX+1, compared with any value in other scenarios and the value + 1, the latter is always larger than the former. As described above for the role of dataVersion, if it continues to increase after overflow, the role will still take effect.

      It is also worth nothing that zookeeper has special processing for dataVersion=-1. When expectedVersion==and currentVersion==-1, the dataVersion equality check is skipped, which violates the semantics of CAS updates. As shown in the following code block

          private static int checkAndIncVersion(int currentVersion, int expectedVersion, String path) throws KeeperException.BadVersionException {
              if (expectedVersion != -1 && expectedVersion != currentVersion) {
                  throw new KeeperException.BadVersionException(path);
              }
              return currentVersion + 1;
          }
      

      I propose that when the current dataVersion is -2, update dataVersion to 0 to skip the case of -1(Inspired by Tison,). This will avoid breaking the semantics of CAS updates.

      Attachments

        Issue Links

          Activity

            People

              tison Zili Chen
              zhaohaidao HaiyuanZhao
              Votes:
              1 Vote for this issue
              Watchers:
              4 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 - 1h 50m
                  1h 50m