Uploaded image for project: 'WiredTiger'
  1. WiredTiger
  2. WT-10584

Add missing read barriers in __cursor_skip_prev

    • 3
    • 2023-02-23 "Stoney Baloney"
    • v6.3, v6.2, v6.0, v5.0, v4.4, v4.2

      I was reading the code in __cursor_skip_prev and believe we are missing some read barriers there:

          /*
           * Find the first node up the search stack that does not move.
           *
           * The depth of the current item must be at least this level, since we
           * see it in that many levels of the stack.
           *
           * !!! Watch these loops carefully: they all rely on the value of i,
           * and the exit conditions to end up with the right values are
           * non-trivial.
           */
          ins = NULL; /* -Wconditional-uninitialized */
          for (i = 0; i < WT_SKIP_MAXDEPTH - 1; i++)
              if ((ins = PREV_INS(cbt, i + 1)) != current)
                  break;
      
          /*
           * Find a starting point for the new search. That is either at the non-moving node if we found a
           * valid node, or the beginning of the next list down that is not the current node.
           *
           * Since it is the beginning of a list, and we know the current node is has a skip depth at
           * least this high, any node we find must sort before the current node.
           */
          if (ins == NULL || ins == current)
              for (; i >= 0; i--) {
                  cbt->ins_stack[i] = NULL;
                  cbt->next_stack[i] = NULL;
                  ins = cbt->ins_head->head[i];
                  if (ins != NULL && ins != current)
                      break;
              }
      

      Here the compiler may choose to reread the ins variable.

             else { /* Drop down a level */
                  cbt->ins_stack[i] = &ins->next[i];
                  cbt->next_stack[i] = ins->next[i];
                  --i;
              }
      

      We may read stale data here.

            Assignee:
            chenhao.qu@mongodb.com Chenhao Qu
            Reporter:
            chenhao.qu@mongodb.com Chenhao Qu
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: