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

Should read global generation before reading the session count

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • 0
    • Joker - StorEng - 2023-10-17

         /*
           * No lock is required because the session array is fixed size, but it may contain inactive
           * entries. We must review any active session, so insert a read barrier after reading the active
           * session count. That way, no matter what sessions come or go, we'll check the slots for all of
           * the sessions that could have been active when we started our check.
           */
          WT_ORDERED_READ(session_cnt, conn->session_cnt);
          /*
           * We need to order the read of the connection generation before the read of the session
           * generation. If the session generation read is ordered before the connection generation read
           * it could read an earlier session generation value. This would then violate the acquisition
           * semantics and could result in us reading 0 for the session generation when it is non-zero.
           */
          WT_ORDERED_READ(oldest, conn->generations[which]);
      

      In __gen_oldest, we read the session count before the global generation. This may create a problem if we race with a thread opening a new session and getting a generation.

      Here's the sequence that it is wrong:

      1. thread A reads the session count
      2. thread B opens a session and increase the session count
      3. thread B enters a generation with global generation at 10
      4. thread C increases the global generation to 11
      5. thread A reads the global generation as 11
      6. thread A misses the session generation of thread B because it doesn't read its session at all.

      To fix this, we should ensure the global generation is read before we read the session count.

            Assignee:
            backlog-server-storage-engines [DO NOT USE] Backlog - Storage Engines Team
            Reporter:
            chenhao.qu@mongodb.com Chenhao Qu
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: