summaryrefslogtreecommitdiff
path: root/src/mongo/db/introspect.cpp
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2015-06-20 00:22:50 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2015-06-20 10:56:02 -0400
commit9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch)
tree3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/introspect.cpp
parent01965cf52bce6976637ecb8f4a622aeb05ab256a (diff)
downloadmongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/introspect.cpp')
-rw-r--r--src/mongo/db/introspect.cpp215
1 files changed, 103 insertions, 112 deletions
diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp
index b0788ad9d55..8a6cca1dabb 100644
--- a/src/mongo/db/introspect.cpp
+++ b/src/mongo/db/introspect.cpp
@@ -46,153 +46,144 @@
namespace mongo {
- using std::unique_ptr;
- using std::endl;
- using std::string;
+using std::unique_ptr;
+using std::endl;
+using std::string;
namespace {
- void _appendUserInfo(const CurOp& c,
- BSONObjBuilder& builder,
- AuthorizationSession* authSession) {
- UserNameIterator nameIter = authSession->getAuthenticatedUserNames();
+void _appendUserInfo(const CurOp& c, BSONObjBuilder& builder, AuthorizationSession* authSession) {
+ UserNameIterator nameIter = authSession->getAuthenticatedUserNames();
- UserName bestUser;
- if (nameIter.more())
- bestUser = *nameIter;
+ UserName bestUser;
+ if (nameIter.more())
+ bestUser = *nameIter;
- std::string opdb( nsToDatabase( c.getNS() ) );
+ std::string opdb(nsToDatabase(c.getNS()));
- BSONArrayBuilder allUsers(builder.subarrayStart("allUsers"));
- for ( ; nameIter.more(); nameIter.next()) {
- BSONObjBuilder nextUser(allUsers.subobjStart());
- nextUser.append(AuthorizationManager::USER_NAME_FIELD_NAME, nameIter->getUser());
- nextUser.append(AuthorizationManager::USER_DB_FIELD_NAME, nameIter->getDB());
- nextUser.doneFast();
+ BSONArrayBuilder allUsers(builder.subarrayStart("allUsers"));
+ for (; nameIter.more(); nameIter.next()) {
+ BSONObjBuilder nextUser(allUsers.subobjStart());
+ nextUser.append(AuthorizationManager::USER_NAME_FIELD_NAME, nameIter->getUser());
+ nextUser.append(AuthorizationManager::USER_DB_FIELD_NAME, nameIter->getDB());
+ nextUser.doneFast();
- if (nameIter->getDB() == opdb) {
- bestUser = *nameIter;
- }
+ if (nameIter->getDB() == opdb) {
+ bestUser = *nameIter;
}
- allUsers.doneFast();
-
- builder.append("user", bestUser.getUser().empty() ? "" : bestUser.getFullName());
-
}
+ allUsers.doneFast();
-} // namespace
+ builder.append("user", bestUser.getUser().empty() ? "" : bestUser.getFullName());
+}
+} // namespace
- void profile(OperationContext* txn, int op) {
- // Initialize with 1kb at start in order to avoid realloc later
- BufBuilder profileBufBuilder(1024);
- BSONObjBuilder b(profileBufBuilder);
+void profile(OperationContext* txn, int op) {
+ // Initialize with 1kb at start in order to avoid realloc later
+ BufBuilder profileBufBuilder(1024);
- {
- Locker::LockerInfo lockerInfo;
- txn->lockState()->getLockerInfo(&lockerInfo);
- CurOp::get(txn)->debug().append(*CurOp::get(txn), lockerInfo.stats, b);
- }
+ BSONObjBuilder b(profileBufBuilder);
- b.appendDate("ts", jsTime());
- b.append("client", txn->getClient()->clientAddress());
+ {
+ Locker::LockerInfo lockerInfo;
+ txn->lockState()->getLockerInfo(&lockerInfo);
+ CurOp::get(txn)->debug().append(*CurOp::get(txn), lockerInfo.stats, b);
+ }
- AuthorizationSession * authSession = AuthorizationSession::get(txn->getClient());
- _appendUserInfo(*CurOp::get(txn), b, authSession);
+ b.appendDate("ts", jsTime());
+ b.append("client", txn->getClient()->clientAddress());
- const BSONObj p = b.done();
+ AuthorizationSession* authSession = AuthorizationSession::get(txn->getClient());
+ _appendUserInfo(*CurOp::get(txn), b, authSession);
- const bool wasLocked = txn->lockState()->isLocked();
+ const BSONObj p = b.done();
- const string dbName(nsToDatabase(CurOp::get(txn)->getNS()));
+ const bool wasLocked = txn->lockState()->isLocked();
- try {
- bool acquireDbXLock = false;
- while (true) {
- ScopedTransaction scopedXact(txn, MODE_IX);
+ const string dbName(nsToDatabase(CurOp::get(txn)->getNS()));
- std::unique_ptr<AutoGetDb> autoGetDb;
- if (acquireDbXLock) {
- autoGetDb.reset(new AutoGetDb(txn, dbName, MODE_X));
- if (autoGetDb->getDb()) {
- createProfileCollection(txn, autoGetDb->getDb());
- }
- }
- else {
- autoGetDb.reset(new AutoGetDb(txn, dbName, MODE_IX));
- }
+ try {
+ bool acquireDbXLock = false;
+ while (true) {
+ ScopedTransaction scopedXact(txn, MODE_IX);
- Database* const db = autoGetDb->getDb();
- if (!db) {
- // Database disappeared
- log() << "note: not profiling because db went away for "
- << CurOp::get(txn)->getNS();
- break;
+ std::unique_ptr<AutoGetDb> autoGetDb;
+ if (acquireDbXLock) {
+ autoGetDb.reset(new AutoGetDb(txn, dbName, MODE_X));
+ if (autoGetDb->getDb()) {
+ createProfileCollection(txn, autoGetDb->getDb());
}
+ } else {
+ autoGetDb.reset(new AutoGetDb(txn, dbName, MODE_IX));
+ }
- Lock::CollectionLock collLock(txn->lockState(), db->getProfilingNS(), MODE_IX);
-
- Collection* const coll = db->getCollection(db->getProfilingNS());
- if (coll) {
- WriteUnitOfWork wuow(txn);
- coll->insertDocument(txn, p, false);
- wuow.commit();
+ Database* const db = autoGetDb->getDb();
+ if (!db) {
+ // Database disappeared
+ log() << "note: not profiling because db went away for "
+ << CurOp::get(txn)->getNS();
+ break;
+ }
- break;
- }
- else if (!acquireDbXLock &&
- (!wasLocked || txn->lockState()->isDbLockedForMode(dbName, MODE_X))) {
- // Try to create the collection only if we are not under lock, in order to
- // avoid deadlocks due to lock conversion. This would only be hit if someone
- // deletes the profiler collection after setting profile level.
- acquireDbXLock = true;
- }
- else {
- // Cannot write the profile information
- break;
- }
+ Lock::CollectionLock collLock(txn->lockState(), db->getProfilingNS(), MODE_IX);
+
+ Collection* const coll = db->getCollection(db->getProfilingNS());
+ if (coll) {
+ WriteUnitOfWork wuow(txn);
+ coll->insertDocument(txn, p, false);
+ wuow.commit();
+
+ break;
+ } else if (!acquireDbXLock &&
+ (!wasLocked || txn->lockState()->isDbLockedForMode(dbName, MODE_X))) {
+ // Try to create the collection only if we are not under lock, in order to
+ // avoid deadlocks due to lock conversion. This would only be hit if someone
+ // deletes the profiler collection after setting profile level.
+ acquireDbXLock = true;
+ } else {
+ // Cannot write the profile information
+ break;
}
}
- catch (const AssertionException& assertionEx) {
- warning() << "Caught Assertion while trying to profile "
- << opToString(op)
- << " against " << CurOp::get(txn)->getNS()
- << ": " << assertionEx.toString() << endl;
- }
+ } catch (const AssertionException& assertionEx) {
+ warning() << "Caught Assertion while trying to profile " << opToString(op) << " against "
+ << CurOp::get(txn)->getNS() << ": " << assertionEx.toString() << endl;
}
+}
- Status createProfileCollection(OperationContext* txn, Database *db) {
- invariant(txn->lockState()->isDbLockedForMode(db->name(), MODE_X));
-
- const std::string dbProfilingNS(db->getProfilingNS());
+Status createProfileCollection(OperationContext* txn, Database* db) {
+ invariant(txn->lockState()->isDbLockedForMode(db->name(), MODE_X));
- Collection* const collection = db->getCollection(dbProfilingNS);
- if (collection) {
- if (!collection->isCapped()) {
- return Status(ErrorCodes::NamespaceExists,
- str::stream() << dbProfilingNS << " exists but isn't capped");
- }
+ const std::string dbProfilingNS(db->getProfilingNS());
- return Status::OK();
+ Collection* const collection = db->getCollection(dbProfilingNS);
+ if (collection) {
+ if (!collection->isCapped()) {
+ return Status(ErrorCodes::NamespaceExists,
+ str::stream() << dbProfilingNS << " exists but isn't capped");
}
- // system.profile namespace doesn't exist; create it
- log() << "Creating profile collection: " << dbProfilingNS << endl;
+ return Status::OK();
+ }
- CollectionOptions collectionOptions;
- collectionOptions.capped = true;
- collectionOptions.cappedSize = 1024 * 1024;
+ // system.profile namespace doesn't exist; create it
+ log() << "Creating profile collection: " << dbProfilingNS << endl;
- WriteUnitOfWork wunit(txn);
- bool shouldReplicateWrites = txn->writesAreReplicated();
- txn->setReplicatedWrites(false);
- ON_BLOCK_EXIT(&OperationContext::setReplicatedWrites, txn, shouldReplicateWrites);
- invariant(db->createCollection(txn, dbProfilingNS, collectionOptions));
- wunit.commit();
+ CollectionOptions collectionOptions;
+ collectionOptions.capped = true;
+ collectionOptions.cappedSize = 1024 * 1024;
- return Status::OK();
- }
+ WriteUnitOfWork wunit(txn);
+ bool shouldReplicateWrites = txn->writesAreReplicated();
+ txn->setReplicatedWrites(false);
+ ON_BLOCK_EXIT(&OperationContext::setReplicatedWrites, txn, shouldReplicateWrites);
+ invariant(db->createCollection(txn, dbProfilingNS, collectionOptions));
+ wunit.commit();
+
+ return Status::OK();
+}
-} // namespace mongo
+} // namespace mongo