diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/commands/list_databases.cpp | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/commands/list_databases.cpp')
-rw-r--r-- | src/mongo/db/commands/list_databases.cpp | 156 |
1 files changed, 79 insertions, 77 deletions
diff --git a/src/mongo/db/commands/list_databases.cpp b/src/mongo/db/commands/list_databases.cpp index 81779a83a76..886c035d076 100644 --- a/src/mongo/db/commands/list_databases.cpp +++ b/src/mongo/db/commands/list_databases.cpp @@ -38,85 +38,87 @@ namespace mongo { - using std::set; - using std::string; - using std::stringstream; - using std::vector; - - // XXX: remove and put into storage api - intmax_t dbSize( const string& database ); - - class CmdListDatabases : public Command { - public: - virtual bool slaveOk() const { - return false; - } - virtual bool slaveOverrideOk() const { - return true; - } - virtual bool adminOnly() const { - return true; - } - virtual bool isWriteCommandForConfigServer() const { return false; } - virtual void help( stringstream& help ) const { help << "list databases on this server"; } - virtual void addRequiredPrivileges(const std::string& dbname, - const BSONObj& cmdObj, - std::vector<Privilege>* out) { - ActionSet actions; - actions.addAction(ActionType::listDatabases); - out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); - } - - CmdListDatabases() : Command("listDatabases" , true ) {} - - bool run(OperationContext* txn, - const string& dbname, - BSONObj& jsobj, - int, - string& errmsg, - BSONObjBuilder& result) { - - vector< string > dbNames; - StorageEngine* storageEngine = getGlobalServiceContext()->getGlobalStorageEngine(); - storageEngine->listDatabases( &dbNames ); - - vector< BSONObj > dbInfos; - - set<string> seen; - intmax_t totalSize = 0; - for ( vector< string >::iterator i = dbNames.begin(); i != dbNames.end(); ++i ) { - const string& dbname = *i; - - BSONObjBuilder b; - b.append( "name", dbname ); - - { - ScopedTransaction transaction(txn, MODE_IS); - Lock::DBLock dbLock(txn->lockState(), dbname, MODE_IS); - - Database* db = dbHolder().get( txn, dbname ); - if ( !db ) - continue; - - const DatabaseCatalogEntry* entry = db->getDatabaseCatalogEntry(); - invariant( entry ); - - int64_t size = entry->sizeOnDisk( txn ); - b.append( "sizeOnDisk", static_cast<double>( size ) ); - totalSize += size; - - b.appendBool("empty", size == 0); - } - - dbInfos.push_back( b.obj() ); - - seen.insert( i->c_str() ); +using std::set; +using std::string; +using std::stringstream; +using std::vector; + +// XXX: remove and put into storage api +intmax_t dbSize(const string& database); + +class CmdListDatabases : public Command { +public: + virtual bool slaveOk() const { + return false; + } + virtual bool slaveOverrideOk() const { + return true; + } + virtual bool adminOnly() const { + return true; + } + virtual bool isWriteCommandForConfigServer() const { + return false; + } + virtual void help(stringstream& help) const { + help << "list databases on this server"; + } + virtual void addRequiredPrivileges(const std::string& dbname, + const BSONObj& cmdObj, + std::vector<Privilege>* out) { + ActionSet actions; + actions.addAction(ActionType::listDatabases); + out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); + } + + CmdListDatabases() : Command("listDatabases", true) {} + + bool run(OperationContext* txn, + const string& dbname, + BSONObj& jsobj, + int, + string& errmsg, + BSONObjBuilder& result) { + vector<string> dbNames; + StorageEngine* storageEngine = getGlobalServiceContext()->getGlobalStorageEngine(); + storageEngine->listDatabases(&dbNames); + + vector<BSONObj> dbInfos; + + set<string> seen; + intmax_t totalSize = 0; + for (vector<string>::iterator i = dbNames.begin(); i != dbNames.end(); ++i) { + const string& dbname = *i; + + BSONObjBuilder b; + b.append("name", dbname); + + { + ScopedTransaction transaction(txn, MODE_IS); + Lock::DBLock dbLock(txn->lockState(), dbname, MODE_IS); + + Database* db = dbHolder().get(txn, dbname); + if (!db) + continue; + + const DatabaseCatalogEntry* entry = db->getDatabaseCatalogEntry(); + invariant(entry); + + int64_t size = entry->sizeOnDisk(txn); + b.append("sizeOnDisk", static_cast<double>(size)); + totalSize += size; + + b.appendBool("empty", size == 0); } - result.append( "databases", dbInfos ); - result.append( "totalSize", double( totalSize ) ); - return true; + dbInfos.push_back(b.obj()); + + seen.insert(i->c_str()); } - } cmdListDatabases; + result.append("databases", dbInfos); + result.append("totalSize", double(totalSize)); + return true; + } +} cmdListDatabases; } |