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

Simplify txn id allocation path atomic usage

    • Storage Engines
    • 2
    • 2024-08-06 - Withholding Tax

      Since a very old commit we've had this code in the __wt_txn_id_alloc function:

              id = __wt_atomic_addv64(&txn_global->current, 1) - 1;

      The comment above the code reads:

      so we want post-increment semantics. Our atomic add primitive does pre-increment, so adjust the result here. 

      It seems like at the time the fetch_add primitive did not exist in WiredTiger. Which means we can simplify this line of code to:

             id = __wt_atomic_fetch_addv64(&txn_global->current, 1); 

      This will return the value pre-increment, and be the correct way of doing what the code aims to atomically.

      Scope:

      • Replace both occurrences with fetch_add.
      • Run stress testing on the change.

       

            Assignee:
            andrew.morton@mongodb.com Andrew Morton
            Reporter:
            luke.pearson@mongodb.com Luke Pearson
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: