Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-28913

[v3.2] BackgroundSync::consume() should check result of BlockingQueue::blockingPop() before decrementing server metrics

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.12
    • Component/s: Replication
    • Labels:
      None
    • Replication
    • ALL
    • 0

      In 3.2, BackgroundSync::consume may erroneously decrement the following server status metrics when BlockingQueue::blockingPop() returns an empty document:

      "repl.buffer.count"
      "repl.buffer.sizeBytes"

      https://github.com/mongodb/mongo/blob/f98bd7d1a376ab741024d21e20e4b1b48d9a0af6/src/mongo/db/repl/bgsync.cpp#L840

      bgsync.cpp
      void BackgroundSync::consume() {
          // this is just to get the op off the queue, it's been peeked at
          // and queued for application already
          BSONObj op = _buffer.blockingPop();
          bufferCountGauge.decrement(1);
          bufferSizeGauge.decrement(getSize(op));
      }
      

      https://github.com/mongodb/mongo/blob/f98bd7d1a376ab741024d21e20e4b1b48d9a0af6/src/mongo/util/queue.h#L171

      queue.h
          T blockingPop() {
              stdx::unique_lock<stdx::mutex> lk(_lock);
              _clearing = false;
              while (_queue.empty() && !_clearing)
                  _cvNoLongerEmpty.wait(lk);
              if (_clearing) {
                  return T{};
              }
      
              T t = _queue.front();
              _queue.pop();
              _currentSize -= _getSize(t);
              _cvNoLongerFull.notify_one();
      
              return t;
          }
      

            Assignee:
            backlog-server-repl [DO NOT USE] Backlog - Replication Team
            Reporter:
            benety.goh@mongodb.com Benety Goh
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: