Skip to content

Commit

Permalink
SERVER-28049 Apply name-only filters before locking in listDatabases
Browse files Browse the repository at this point in the history
  • Loading branch information
GeertBosch committed Feb 20, 2017
1 parent fff6d49 commit ef5a80f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/mongo/db/commands/list_databases.cpp
Expand Up @@ -43,6 +43,7 @@
namespace mongo {
namespace {
static const StringData kFilterField{"filter"};
static const StringData kNameField{"name"};
static const StringData kNameOnlyField{"nameOnly"};
} // namespace

Expand Down Expand Up @@ -120,6 +121,7 @@ class CmdListDatabases : public Command {

vector<BSONObj> dbInfos;

bool filterNameOnly = filter && filter->isLeaf() && filter->path() == kNameField;
intmax_t totalSize = 0;
for (vector<string>::iterator i = dbNames.begin(); i != dbNames.end(); ++i) {
const string& dbname = *i;
Expand All @@ -129,6 +131,10 @@ class CmdListDatabases : public Command {

int64_t size = 0;
if (!nameOnly) {
// Filtering on name only should not require taking locks on filtered-out names.
if (filterNameOnly && !filter->matchesBSON(b.asTempObj()))
continue;

ScopedTransaction transaction(txn, MODE_IS);
Lock::DBLock dbLock(txn->lockState(), dbname, MODE_IS);

Expand Down

0 comments on commit ef5a80f

Please sign in to comment.