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

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

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Storage
    • Labels:
      None
    • v4.0, v3.6
    • Storage NYC 2018-12-31

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

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

      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]"
              }
      })
      

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

              Created:
              Updated:
              Resolved: