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

Do not run aggregation for orphans against oplog.rs for collstats

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.0.1, 6.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • ALL
    • v6.0
    • Sharding EMEA 2022-06-13

      After SERVER-64163, under the debugger, on a non-shard server, I see that we run
      `BalancerStatsRegistry::get(opCtx)->getCollNumOrphanDocsFromDiskIfNeeded()`

      which throws an exception because this code (src/mongo/db/s/balancer_stats_registry.cpp)
      ```
      long long BalancerStatsRegistry::getCollNumOrphanDocs(const UUID& collectionUUID) const {
      if (!_isInitialized())
      uasserted(ErrorCodes::NotYetInitialized, "BalancerStatsRegistry is not initialized");
      ```
      always throws and then we run an aggregation.

      Since this code runs in FTDC, I want to avoid expensive operations like aggregations in FTDC since they may stall (I realize this may not be that the aggregation may have been here for a long time). In this case, we should not gather balancer stats for oplog.rs since it is the local database and I believe local is not sharded database.

      Discovered because I was debugging mongod and catching all C++ exceptions.

      Stack

      (lldb) bt
      * thread #20, name = 'ftdc', stop reason = breakpoint 4.1
        * frame #0: 0x00007ffff717d6c0 libstdc++.so.6`__cxa_throw
          frame #1: 0x0000555565a6a254 mongod`mongo::error_details::throwExceptionForStatus(status=Status(NotYetInitialized, "BalancerStatsRegistry is not initialized")) at error_codes.cpp:2596:13
          frame #2: 0x0000555565b898f5 mongod`mongo::uassertedWithLocation(status=Status(NotYetInitialized, "BalancerStatsRegistry is not initialized"), file="src/mongo/db/s/balancer_stats_registry.cpp", line=186) at assert_util.cpp:274:5
          frame #3: 0x00005555626cb45a mongod`mongo::BalancerStatsRegistry::getCollNumOrphanDocs(this=0x00007fffe2c64120) const::$_9::operator()() const at balancer_stats_registry.cpp:186:9
          frame #4: 0x00005555626cb2d3 mongod`mongo::BalancerStatsRegistry::getCollNumOrphanDocs(this=0x00007ffff52e6bb8, collectionUUID=705e0c35-12cc-4292-a52f-1093c3113662) const at balancer_stats_registry.cpp:186:9
          frame #5: 0x00005555626cb4c0 mongod`mongo::BalancerStatsRegistry::getCollNumOrphanDocsFromDiskIfNeeded(this=0x00007ffff52e6bb8, opCtx=0x00007fffc76d9460, collectionUUID=705e0c35-12cc-4292-a52f-1093c3113662) const at balancer_stats_registry.cpp:199:16
          frame #6: 0x000055556234972f mongod`mongo::appendCollectionStorageStats(opCtx=0x00007fffc76d9460, nss="local.oplog.rs", storageStatsSpec=0x00007fffe2c65e70, result=0x00007fffe2c66020) at storage_stats.cpp:121:48
          frame #7: 0x00005555615a913d mongod`mongo::(anonymous namespace)::CollectionStats::errmsgRun(this=0x0000555566241670, opCtx=0x00007fffc76d9460, dbname="local", jsobj={
          "collStats": "oplog.rs",
          "waitForLock": false,
          "numericOnly": true,
          "$db": "local"
      }, errmsg="", result=0x00007fffe2c66020) at dbcommands.cpp:503:25
          frame #8: 0x00005555634f0c85 mongod`mongo::ErrmsgCommandDeprecated::run(this=0x0000555566241670, opCtx=0x00007fffc76d9460, db="local", cmdObj={
          "collStats": "oplog.rs",
          "waitForLock": false,
          "numericOnly": true,
          "$db": "local"
      }, result=0x00007fffe2c66020) at commands.cpp:1056:15
          frame #9: 0x000055555fa0ebfb mongod`mongo::BasicCommand::runWithReplyBuilder(this=0x0000555566241670, opCtx=0x00007fffc76d9460, db="local", cmdObj={
          "collStats": "oplog.rs",
          "waitForLock": false,
          "numericOnly": true,
          "$db": "local"
      }, replyBuilder=0x00007fffe2c66318) at commands.h:968:16
          frame #10: 0x00005555634fbd2a mongod`mongo::BasicCommandWithReplyBuilderInterface::Invocation::run(this=0x00007fffcb625880, opCtx=0x00007fffc76d9460, result=0x00007fffe2c66318) at commands.cpp:909:29
          frame #11: 0x00005555634e8df3 mongod`mongo::CommandHelpers::runCommandDirectly(opCtx=0x00007fffc76d9460, request=0x00007ffff5128368) at commands.cpp:170:21
          frame #12: 0x00005555601140ba mongod`mongo::FTDCSimpleInternalCommandCollector::collect(this=0x00007ffff5128340, opCtx=0x00007fffc76d9460, builder=0x00007fffe2c665b8) at ftdc_server.cpp:184:19
          frame #13: 0x000055556016bb56 mongod`mongo::FTDCCollectorCollection::collect(this=0x00007fffe5208768, client=0x00007fffe4664020) at collector.cpp:93:20
          frame #14: 0x0000555560171c8c mongod`mongo::FTDCController::doLoop(this=0x00007fffe5208620) at controller.cpp:251:54
          frame #15: 0x0000555560172898 mongod`mongo::FTDCController::start(this=0x00007ffff506f390)::$_0::operator()() const at controller.cpp:147:37
          frame #16: 0x000055556017286d mongod`void std::__invoke_impl<void, mongo::FTDCController::start()::$_0>((null)=__invoke_other @ 0x00007fffe2c66878, __f=0x00007ffff506f390)::$_0&&) at invoke.h:61:14
          frame #17: 0x000055556017283d mongod`std::__invoke_result<mongo::FTDCController::start()::$_0>::type std::__invoke<mongo::FTDCController::start(__fn=0x00007ffff506f390)::$_0>(mongo::FTDCController::start()::$_0&&) at invoke.h:96:14
          frame #18: 0x0000555560172801 mongod`decltype(__f=0x00007ffff506f390, __t=0x00007ffff506f398, (null)=std::index_sequence<> @ 0x00007fffe2c668c8) std::__apply_impl<mongo::FTDCController::start()::$_0, std::tuple<> >(mongo::FTDCController::start()::$_0&&, std::tuple<>&&, std::integer_sequence<unsigned long>) at tuple:1852:14
      

            Assignee:
            pierlauro.sciarelli@mongodb.com Pierlauro Sciarelli
            Reporter:
            mark.benvenuto@mongodb.com Mark Benvenuto
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: