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

zookeeper recipes lock's c implement: function child_floor bug

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.4.8
    • Fix Version/s: None
    • Component/s: c client
    • Labels:
    • Environment:

      zookeeper cluster with multi servers(not standalone mode), and multi clients connect to different zookeeper server.

      Description

      1. start zookeeper cluster with multi servers
      2. multi clients connect to different zookeeper server at the same time
      3. clients use lock from zookeeper recipes lock's C implement.

      for example:
      Client A create a node like x-025373e3a9960050-0000000067
      and Client B create a node like x-015373e3a9960050-0000000068;
      A is a lock owner now, then kill A, as expect, B should become owner, but in fact B not.
      Because in zoo_lock.c, function zkr_lock_operation call child_floor to monitoring a pre node, but child_floor has bug, it caused B not check its prenode A.

      B function child_floor just simply strcmp "x-025373e3a9960050-0000000067" with own node "x-015373e3a9960050-0000000068",
      it should only strcmp "0000000067" with "0000000068", not include session info.
      besides, it is better that using binary search than travelling every node for looking for a pre node when there exists many nodes.
      fix:
      static char* child_floor(char **sorted_data, int len, char *element) {
      char* ret = NULL;

      int begin = 0;
      int end = len-1;
      int index = 0;

      while (begin <= end) {
      index = (begin+end)/2;
      int iCmpRet = strcmp(strrchr(sorted_data[index], '')+1, strrchr(element, '')+1);
      if (iCmpRet < 0)

      { begin = index + 1; }

      else {
      if (iCmpRet == 0) {
      if (index - 1 >= 0)

      { ret = sorted_data[index-1]; }

      break;
      }
      else

      { end = index - 1; }

      }
      }

      return ret;
      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              europelee europelee
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Time Tracking

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