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

KVStorageEngine::listDatabases() omits databases that exist but have no collections

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Won't Fix
    • None
    • None
    • Storage
    • None
    • v4.0, v3.6
    • Storage NYC 2018-12-31

    Description

      KVStorageEngine::listDatabases() will skip databases that don't have any collections:

      kv_storage_engine.cpp

      370
      void KVStorageEngine::listDatabases(std::vector<std::string>* out) const {
      371
          stdx::lock_guard<stdx::mutex> lk(_dbsLock);
      372
          for (DBMap::const_iterator it = _dbs.begin(); it != _dbs.end(); ++it) {
      373
              if (it->second->isEmpty())
      374
                  continue;
      375
              out->push_back(it->first);
      376
          }
      377
      }
      

      I'm unsure of why this is, but there is a legitimate use case for listing empty databases. Consider the following sequence of user operations – the user is misled into thinking the database "bloop" doesn't exist because it is totally omitted from the listDatabases output even though the database does, in fact, exist:

      > use bloop
      switched to db bloop
      > db.coll.insert({x: 1});
      WriteResult({ "nInserted" : 1 })
      > show dbs
      admin   0.000GB
      bloop   0.000GB
      config  0.000GB
      local   0.000GB
      > assert(db.coll.drop());
      true
      > show dbs
      admin   0.000GB
      config  0.000GB
      local   0.000GB
      > use BLOOP
      switched to db BLOOP
      > db.coll.insert({x: 1})
      WriteResult({
              "nInserted" : 0,
              "writeError" : {
                      "code" : 13297,
                      "errmsg" : "db already exists with different case already have: [bloop] trying to create [BLOOP]"
              }
      })
      

      Attachments

        Issue Links

          Activity

            People

              gregory.wlodarek@mongodb.com Gregory Wlodarek
              kyle.suarez@mongodb.com Kyle Suarez
              Votes:
              1 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: