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

Questionable code in __wt_try_readlock, __wt_try_writelock

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: WT2.7.0
    • Labels:
      None
    • # Replies:
      7
    • Last comment by Customer:
      true

      Description

      At src/os_posix/os_mtx_rw.c, line 84 (__wt_try_readlock) is this line:

      new = (pad << 48) + ((users + 1) << 32) + ((users + 1) << 16) + writers;

      When users == 64K-1, this code is intended to wrap around, with users set to 0. But this code does something unintended:

      new = (pad << 48) + (0x10000 << 32) + (0x10000 << 16) + writers;

      i.e.

      l->s.pad = 1; /* wrong, should be 0 */
      l->s.users = 1; /* wrong, should be 0 */
      l->s.readers = 0;
      l->s.writers = writers;

      This would be a big problem: in the 'ticket' algorithm, the users field is the next ticket number available. If another participant enters the system at this time and gets number 1, it will never be called because there is never any participant with number 0 that will increment writers to that number. Thus a wait forever for a lock that's actually available.

      All that said, it so happens that _wt_try_readlock is currently not used in WT. _wt_try_writelock has similar code, but the problem is benign since in that case, only the pad field is falsely incremented. I've confirmed this by asserting that pad == 0; it fails for a test case that opens a cursor 64K times.

        Issue Links

          Activity

          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'ddanderson', u'name': u'Don Anderson', u'email': u'dda@ddanderson.com'}

          Message: WT-2023: Don't allow increments of 16-bit values to overflow into other fields.
          Branch: develop
          https://github.com/wiredtiger/wiredtiger/commit/85c031c433849c716aeb1fd475497ba2cc22023b

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'ddanderson', u'name': u'Don Anderson', u'email': u'dda@ddanderson.com'} Message: WT-2023 : Don't allow increments of 16-bit values to overflow into other fields. Branch: develop https://github.com/wiredtiger/wiredtiger/commit/85c031c433849c716aeb1fd475497ba2cc22023b
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'ddanderson', u'name': u'Don Anderson', u'email': u'dda@ddanderson.com'}

          Message: WT-2023: The users field intentionally overflows into pad; comment that.
          Branch: develop
          https://github.com/wiredtiger/wiredtiger/commit/7fb1b9b751dd7a334f84924585f6046ff50b88a1

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'ddanderson', u'name': u'Don Anderson', u'email': u'dda@ddanderson.com'} Message: WT-2023 : The users field intentionally overflows into pad; comment that. Branch: develop https://github.com/wiredtiger/wiredtiger/commit/7fb1b9b751dd7a334f84924585f6046ff50b88a1
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'michaelcahill', u'name': u'Michael Cahill', u'email': u'michael.cahill@mongodb.com'}

          Message: Merge pull request #2099 from wiredtiger/mutex-overflow-cheap-test

          WT-2023: Avoid the CAS instruction in the trylock functions.
          Branch: develop
          https://github.com/wiredtiger/wiredtiger/commit/d7d2a98da7e435c5feb997e5fa01837234f4a32a

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'michaelcahill', u'name': u'Michael Cahill', u'email': u'michael.cahill@mongodb.com'} Message: Merge pull request #2099 from wiredtiger/mutex-overflow-cheap-test WT-2023 : Avoid the CAS instruction in the trylock functions. Branch: develop https://github.com/wiredtiger/wiredtiger/commit/d7d2a98da7e435c5feb997e5fa01837234f4a32a
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'michaelcahill', u'name': u'Michael Cahill', u'email': u'michael.cahill@mongodb.com'}

          Message: Merge pull request #2101 from wiredtiger/mutex-overflow-simplify

          WT-2023: Mutex overflow simplify
          Branch: develop
          https://github.com/wiredtiger/wiredtiger/commit/7d038763ccbcf94db3a08062e8db8dd5eb874c2a

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'michaelcahill', u'name': u'Michael Cahill', u'email': u'michael.cahill@mongodb.com'} Message: Merge pull request #2101 from wiredtiger/mutex-overflow-simplify WT-2023 : Mutex overflow simplify Branch: develop https://github.com/wiredtiger/wiredtiger/commit/7d038763ccbcf94db3a08062e8db8dd5eb874c2a
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'michaelcahill', u'name': u'Michael Cahill', u'email': u'michael.cahill@mongodb.com'}

          Message: WT-2023 Avoid bit shifts during read-write lock operations.
          Branch: develop
          https://github.com/wiredtiger/wiredtiger/commit/c1bcfe9d983f0b3b40549d719cf322e6500fab77

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'michaelcahill', u'name': u'Michael Cahill', u'email': u'michael.cahill@mongodb.com'} Message: WT-2023 Avoid bit shifts during read-write lock operations. Branch: develop https://github.com/wiredtiger/wiredtiger/commit/c1bcfe9d983f0b3b40549d719cf322e6500fab77
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'keithbostic', u'name': u'Keith Bostic', u'email': u'keith.bostic@mongodb.com'}

          Message: Merge pull request #2103 from wiredtiger/rwlock-noshift

          WT-2023 Avoid bit shifts during read-write lock operations.
          Branch: develop
          https://github.com/wiredtiger/wiredtiger/commit/81ffc2de72b31046c32ce4d8b2d2a809672e0c53

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'keithbostic', u'name': u'Keith Bostic', u'email': u'keith.bostic@mongodb.com'} Message: Merge pull request #2103 from wiredtiger/rwlock-noshift WT-2023 Avoid bit shifts during read-write lock operations. Branch: develop https://github.com/wiredtiger/wiredtiger/commit/81ffc2de72b31046c32ce4d8b2d2a809672e0c53
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'keithbostic', u'name': u'Keith Bostic', u'email': u'keith.bostic@mongodb.com'}

          Message: Merge pull request #2090 from wiredtiger/mutex-overflow

          WT-2023: Keep 16-bit values from overflowing into other fields.
          Branch: develop
          https://github.com/wiredtiger/wiredtiger/commit/53818779359c93f93a6499f9a04135684e110e28

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'keithbostic', u'name': u'Keith Bostic', u'email': u'keith.bostic@mongodb.com'} Message: Merge pull request #2090 from wiredtiger/mutex-overflow WT-2023 : Keep 16-bit values from overflowing into other fields. Branch: develop https://github.com/wiredtiger/wiredtiger/commit/53818779359c93f93a6499f9a04135684e110e28

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since reply:
                1 year, 34 weeks, 1 day ago
                Date of 1st Reply: