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

Investigate and clean up unused `ret` cases.

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Storage Engines
    • StorEng - Defined Pipeline

      This ticket collects some seemingly unused ret values that can't be automatically detected by compiler or standard static analysis.

      It's not required to do all of them within this ticket. If any of these cases takes more than 5-10 minutes to investigate, it should be split into a separate ticket.

      1. src/reconcile/rec_track.c:400
      2. src/txn/txn_ckpt.c:1363:46
      3. src/txn/txn_ckpt.c:1423:11
      4. src/txn/txn_ckpt.c:1488 - probably fine
      5. src/txn/txn_recover.c:1178 subsequent WT_ERR overwrites the error code.
      6. __wt_txn_rollback builds up the return code and returns it but it never alters its behavior if there's a failure.
      7. __curjoin_close builds up the return code and returns it but it never alters its behavior if there's a failure.
      8. src/include/btree_inline.h:2019 - probably fine
      9. src/meta/meta_turtle.c:441 should probably be "ignore".
      10. src/block_cache/block_cache.c:636 - this probably should be converted to "panic" or "ignore"
      11. src/utilities/util_main.c:345:5 ret can be overwritten later and ignored.
      12. These two get overwritten by subsequent WT_ERR:
        1. src/btree/bt_import.c:114:5
        2. src/btree/bt_import.c:115
      13. These two get overwritten just after and should be replaced with "ignore":
        1. src/log/log.c:2435
        2. src/log/log.c:2439

      For reference: this script is used for detection:

      #!/bin/bash
      
      perl -nE '
        # Read entire file
        do { local $/=undef; $_=<>; };
      
        # Iterate through all assignments to `ret` plus following 15 lines of code afterwards
        while (/\n.*\b(?:(?:ret\s+=\s+(?!\d|WT_))|WT_TRET|WT_WINCALL_RETRY)(?:.*\n){15}/g) {
      
          # Save match
          $x = $&;
      
          # Calculate current matched position
          my $pos = pos()-length($x);
      
          # Set the next position to search from
          pos() = $pos+1;
      
          # Calculate line and offset
          $line = 3+(()=substr($_,0,$pos)=~/\n/g);
          $off = $x =~ /^\n.*\bret = / ? ":".(length($&)-6) : "";
      
          # Skip if the assignment is within a conditional expression
          next if $x =~ /^\n.*\b(?:while|if|switch|for).*?\bret = /;
      
          # Cut the useful portion of code after assignment:
          # Either until the end of the current function of until the next assignment.
          ($m = $x) =~ s/^\n.*?\bret = //;
          $m =~ s/\n[}]\n.*$//s;
          $next_ret = $m =~ s/\bret = .*$//s;
      
          # Skip if `ret` is referenced or there is a goto to error handling.
          next if $m =~ /\b(?:ret|goto (?:err|done))\b/;
      
          # Skip if its a conditional branch and theres an assignment coming next - we will check the next one next.
          next if $next_ret && $m =~ /
              ^ [^{}]+
              (?:
                  (?:
                      (?: [}] \s+ )? \b else \b (?: \s+ [{] )?
                  ) | (?:
                       \b (?: case | default ) \b
                  )
              )
              [^{}]+ $
          /xs;
      
          # Output the line in the compiler format.
          say "$ARGV:$line$off:".($x =~ s/(?<=.)\n.*$//sr =~ s/^\n//r);
        }
      ' `find src -name \*.[ch]`
      

            Assignee:
            backlog-server-storage-engines [DO NOT USE] Backlog - Storage Engines Team
            Reporter:
            y.ershov@mongodb.com Yury Ershov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: