summaryrefslogtreecommitdiff
path: root/src/mongo/db/introspect.cpp
diff options
context:
space:
mode:
authorDianna Hohensee <dianna.hohensee@mongodb.com>2020-05-12 16:24:24 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-05-14 15:16:35 +0000
commit40c0fa9c0a3cf5d3d2ee16fe301c262946ececa8 (patch)
treefc06911ef6feadd7cdb1921935be60743b32ee0a /src/mongo/db/introspect.cpp
parent055265b725be5a3b1554f8d1f3bd86316cb75cfb (diff)
downloadmongo-40c0fa9c0a3cf5d3d2ee16fe301c262946ececa8.tar.gz
SERVER-47931 Retry WriteConflictExceptions when creating a *.system.profile collection
Diffstat (limited to 'src/mongo/db/introspect.cpp')
-rw-r--r--src/mongo/db/introspect.cpp49
1 files changed, 28 insertions, 21 deletions
diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp
index 3efdcf57c3f..a67929ff9b4 100644
--- a/src/mongo/db/introspect.cpp
+++ b/src/mongo/db/introspect.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/auth/user_set.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/client.h"
+#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/curop.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/jsobj.h"
@@ -184,32 +185,38 @@ Status createProfileCollection(OperationContext* opCtx, Database* db) {
invariant(!opCtx->shouldParticipateInFlowControl());
const auto dbProfilingNS = NamespaceString(db->name(), "system.profile");
- Collection* const collection =
- CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, dbProfilingNS);
- if (collection) {
- if (!collection->isCapped()) {
- return Status(ErrorCodes::NamespaceExists,
- str::stream() << dbProfilingNS << " exists but isn't capped");
- }
- return Status::OK();
- }
+ // Checking the collection exists must also be done in the WCE retry loop. Only retrying
+ // collection creation would endlessly throw errors because the collection exists: must check
+ // and see the collection exists in order to break free.
+ return writeConflictRetry(opCtx, "createProfileCollection", dbProfilingNS.ns(), [&] {
+ Collection* const collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, 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
- LOGV2(20701,
- "Creating profile collection: {dbProfilingNS}",
- "dbProfilingNS"_attr = dbProfilingNS);
+ return Status::OK();
+ }
+
+ // system.profile namespace doesn't exist; create it
+ LOGV2(20701,
+ "Creating profile collection: {dbProfilingNS}",
+ "dbProfilingNS"_attr = dbProfilingNS);
- CollectionOptions collectionOptions;
- collectionOptions.capped = true;
- collectionOptions.cappedSize = 1024 * 1024;
+ CollectionOptions collectionOptions;
+ collectionOptions.capped = true;
+ collectionOptions.cappedSize = 1024 * 1024;
- WriteUnitOfWork wunit(opCtx);
- repl::UnreplicatedWritesBlock uwb(opCtx);
- invariant(db->createCollection(opCtx, dbProfilingNS, collectionOptions));
- wunit.commit();
+ WriteUnitOfWork wunit(opCtx);
+ repl::UnreplicatedWritesBlock uwb(opCtx);
+ invariant(db->createCollection(opCtx, dbProfilingNS, collectionOptions));
+ wunit.commit();
- return Status::OK();
+ return Status::OK();
+ });
}
} // namespace mongo