summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2017-07-11 11:10:01 -0400
committerGeert Bosch <geert@mongodb.com>2017-07-11 16:02:10 -0400
commit48b88e8345b109889650b7dd510df916a94550df (patch)
treebc48d483bbc0afb612b0bb2f56ff8de0aa07fa97 /src
parent461d91da21c205a6a17476011c38fd4da246f592 (diff)
downloadmongo-48b88e8345b109889650b7dd510df916a94550df.tar.gz
SERVER-30087 convertToCapped should not yield locks before renaming
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/catalog/capped_utils.cpp66
1 files changed, 32 insertions, 34 deletions
diff --git a/src/mongo/db/catalog/capped_utils.cpp b/src/mongo/db/catalog/capped_utils.cpp
index f986367deb7..3db41392e06 100644
--- a/src/mongo/db/catalog/capped_utils.cpp
+++ b/src/mongo/db/catalog/capped_utils.cpp
@@ -248,46 +248,44 @@ mongo::Status mongo::convertToCapped(OperationContext* opCtx,
const std::string shortTmpName = str::stream() << "tmp.convertToCapped." << shortSource;
const NamespaceString longTmpName(dbname, shortTmpName);
- {
- AutoGetDb autoDb(opCtx, collectionName.db(), MODE_X);
+ AutoGetDb autoDb(opCtx, collectionName.db(), MODE_X);
- bool userInitiatedWritesAndNotPrimary = opCtx->writesAreReplicated() &&
- !repl::getGlobalReplicationCoordinator()->canAcceptWritesFor(opCtx, collectionName);
+ bool userInitiatedWritesAndNotPrimary = opCtx->writesAreReplicated() &&
+ !repl::getGlobalReplicationCoordinator()->canAcceptWritesFor(opCtx, collectionName);
- if (userInitiatedWritesAndNotPrimary) {
- return Status(ErrorCodes::NotMaster,
- str::stream() << "Not primary while converting " << collectionName.ns()
- << " to a capped collection");
- }
+ if (userInitiatedWritesAndNotPrimary) {
+ return Status(ErrorCodes::NotMaster,
+ str::stream() << "Not primary while converting " << collectionName.ns()
+ << " to a capped collection");
+ }
- Database* const db = autoDb.getDb();
- if (!db) {
- return Status(ErrorCodes::NamespaceNotFound,
- str::stream() << "database " << dbname << " not found");
- }
+ Database* const db = autoDb.getDb();
+ if (!db) {
+ return Status(ErrorCodes::NamespaceNotFound,
+ str::stream() << "database " << dbname << " not found");
+ }
- BackgroundOperation::assertNoBgOpInProgForDb(dbname);
-
- // If the temporary collection already exists due to an earlier aborted attempt, delete it.
- if (db->getCollection(opCtx, longTmpName)) {
- BSONObjBuilder unusedResult;
- Status status =
- dropCollection(opCtx,
- longTmpName,
- unusedResult,
- repl::OpTime(),
- DropCollectionSystemCollectionMode::kAllowSystemCollectionDrops);
- if (!status.isOK())
- return status;
- }
+ BackgroundOperation::assertNoBgOpInProgForDb(dbname);
+
+ // If the temporary collection already exists due to an earlier aborted attempt, delete it.
+ if (db->getCollection(opCtx, longTmpName)) {
+ BSONObjBuilder unusedResult;
+ Status status =
+ dropCollection(opCtx,
+ longTmpName,
+ unusedResult,
+ repl::OpTime(),
+ DropCollectionSystemCollectionMode::kAllowSystemCollectionDrops);
+ if (!status.isOK())
+ return status;
+ }
- {
- Status status = cloneCollectionAsCapped(
- opCtx, db, shortSource.toString(), shortTmpName, size, true);
+ {
+ Status status =
+ cloneCollectionAsCapped(opCtx, db, shortSource.toString(), shortTmpName, size, true);
- if (!status.isOK())
- return status;
- }
+ if (!status.isOK())
+ return status;
}
return renameCollection(