[SERVER-35283] KVStorageEngine::listDatabases() omits databases that exist but have no collections Created: 30/May/18  Updated: 04/Aug/19  Resolved: 31/Dec/18

Status: Closed
Project: Core Server
Component/s: Storage
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Kyle Suarez Assignee: Gregory Wlodarek
Resolution: Won't Fix Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
depends on SERVER-33272 The DatabaseHolder::close() function ... Closed
Related
Backport Requested:
v4.0, v3.6
Sprint: Storage NYC 2018-12-31
Participants:
Case:

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



 Comments   
Comment by Gregory Wlodarek [ 31/Dec/18 ]

This won't be an issue once SERVER-33272 is finished. Databases are ephemeral, once they are empty, they have to be removed.

Generated at Thu Feb 08 04:39:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.