summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/database_impl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/catalog/database_impl.cpp')
-rw-r--r--src/mongo/db/catalog/database_impl.cpp104
1 files changed, 72 insertions, 32 deletions
diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp
index 78ce8314d82..f9872364a89 100644
--- a/src/mongo/db/catalog/database_impl.cpp
+++ b/src/mongo/db/catalog/database_impl.cpp
@@ -73,6 +73,7 @@
#include "mongo/db/storage/storage_options.h"
#include "mongo/db/system_index.h"
#include "mongo/db/views/view_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/random.h"
#include "mongo/s/cannot_implicitly_create_collection_info.h"
#include "mongo/util/assert_util.h"
@@ -138,7 +139,7 @@ void DatabaseImpl::init(OperationContext* const opCtx) const {
Status status = validateDBName(_name);
if (!status.isOK()) {
- warning() << "tried to open invalid db: " << _name;
+ LOGV2_WARNING(20325, "tried to open invalid db: {name}", "name"_attr = _name);
uasserted(10028, status.toString());
}
@@ -159,9 +160,12 @@ void DatabaseImpl::init(OperationContext* const opCtx) const {
auto views = ViewCatalog::get(this);
Status reloadStatus = views->reload(opCtx, ViewCatalogLookupBehavior::kValidateDurableViews);
if (!reloadStatus.isOK()) {
- warning() << "Unable to parse views: " << redact(reloadStatus)
- << "; remove any invalid views from the " << _viewsName
- << " collection to restore server functionality." << startupWarningsLog;
+ LOGV2_WARNING_OPTIONS(20326,
+ {logv2::LogTag::kStartupWarnings},
+ "Unable to parse views: {reloadStatus}; remove any invalid views "
+ "from the {viewsName} collection to restore server functionality.",
+ "reloadStatus"_attr = redact(reloadStatus),
+ "viewsName"_attr = _viewsName);
}
}
@@ -173,13 +177,17 @@ void DatabaseImpl::clearTmpCollections(OperationContext* opCtx) const {
WriteUnitOfWork wuow(opCtx);
Status status = dropCollection(opCtx, collection->ns(), {});
if (!status.isOK()) {
- warning() << "could not drop temp collection '" << collection->ns()
- << "': " << redact(status);
+ LOGV2_WARNING(20327,
+ "could not drop temp collection '{collection_ns}': {status}",
+ "collection_ns"_attr = collection->ns(),
+ "status"_attr = redact(status));
}
wuow.commit();
} catch (const WriteConflictException&) {
- warning() << "could not drop temp collection '" << collection->ns()
- << "' due to WriteConflictException";
+ LOGV2_WARNING(
+ 20328,
+ "could not drop temp collection '{collection_ns}' due to WriteConflictException",
+ "collection_ns"_attr = collection->ns());
opCtx->recoveryUnit()->abandonSnapshot();
}
return true;
@@ -289,8 +297,10 @@ void DatabaseImpl::getStats(OperationContext* opCtx, BSONObjBuilder* output, dou
} else {
output->appendNumber("fsUsedSize", -1);
output->appendNumber("fsTotalSize", -1);
- log() << "Failed to query filesystem disk stats (code: " << ec.value()
- << "): " << ec.message();
+ LOGV2(20312,
+ "Failed to query filesystem disk stats (code: {ec_value}): {ec_message}",
+ "ec_value"_attr = ec.value(),
+ "ec_message"_attr = ec.message());
}
}
}
@@ -340,7 +350,7 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx,
repl::OpTime dropOpTime) const {
invariant(opCtx->lockState()->isCollectionLockedForMode(nss, MODE_X));
- LOG(1) << "dropCollection: " << nss;
+ LOGV2_DEBUG(20313, 1, "dropCollection: {nss}", "nss"_attr = nss);
// A valid 'dropOpTime' is not allowed when writes are replicated.
if (!dropOpTime.isNull() && opCtx->writesAreReplicated()) {
@@ -393,9 +403,13 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx,
_dropCollectionIndexes(opCtx, nss, collection);
auto commitTimestamp = opCtx->recoveryUnit()->getCommitTimestamp();
- log() << "dropCollection: " << nss << " (" << uuid
- << ") - storage engine will take ownership of drop-pending collection with optime "
- << dropOpTime << " and commit timestamp " << commitTimestamp;
+ LOGV2(20314,
+ "dropCollection: {nss} ({uuid}) - storage engine will take ownership of drop-pending "
+ "collection with optime {dropOpTime} and commit timestamp {commitTimestamp}",
+ "nss"_attr = nss,
+ "uuid"_attr = uuid,
+ "dropOpTime"_attr = dropOpTime,
+ "commitTimestamp"_attr = commitTimestamp);
if (dropOpTime.isNull()) {
// Log oplog entry for collection drop and remove the UUID.
dropOpTime = opObserver->onDropCollection(
@@ -434,9 +448,13 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx,
// Rename collection using drop-pending namespace generated from drop optime.
auto dpns = nss.makeDropPendingNamespace(dropOpTime);
const bool stayTemp = true;
- log() << "dropCollection: " << nss << " (" << uuid
- << ") - renaming to drop-pending collection: " << dpns << " with drop optime "
- << dropOpTime;
+ LOGV2(20315,
+ "dropCollection: {nss} ({uuid}) - renaming to drop-pending collection: {dpns} with drop "
+ "optime {dropOpTime}",
+ "nss"_attr = nss,
+ "uuid"_attr = uuid,
+ "dpns"_attr = dpns,
+ "dropOpTime"_attr = dropOpTime);
{
Lock::CollectionLock collLk(opCtx, dpns, MODE_X);
fassert(40464, renameCollection(opCtx, nss, dpns, stayTemp));
@@ -453,19 +471,22 @@ void DatabaseImpl::_dropCollectionIndexes(OperationContext* opCtx,
const NamespaceString& nss,
Collection* collection) const {
invariant(_name == nss.db());
- LOG(1) << "dropCollection: " << nss << " - dropAllIndexes start";
+ LOGV2_DEBUG(20316, 1, "dropCollection: {nss} - dropAllIndexes start", "nss"_attr = nss);
collection->getIndexCatalog()->dropAllIndexes(opCtx, true);
invariant(DurableCatalog::get(opCtx)->getTotalIndexCount(opCtx, collection->getCatalogId()) ==
0);
- LOG(1) << "dropCollection: " << nss << " - dropAllIndexes done";
+ LOGV2_DEBUG(20317, 1, "dropCollection: {nss} - dropAllIndexes done", "nss"_attr = nss);
}
Status DatabaseImpl::_finishDropCollection(OperationContext* opCtx,
const NamespaceString& nss,
Collection* collection) const {
UUID uuid = collection->uuid();
- log() << "Finishing collection drop for " << nss << " (" << uuid << ").";
+ LOGV2(20318,
+ "Finishing collection drop for {nss} ({uuid}).",
+ "nss"_attr = nss,
+ "uuid"_attr = uuid);
auto status = DurableCatalog::get(opCtx)->dropCollection(opCtx, collection->getCatalogId());
if (!status.isOK())
@@ -514,8 +535,11 @@ Status DatabaseImpl::renameCollection(OperationContext* opCtx,
<< toNss);
}
- log() << "renameCollection: renaming collection " << collToRename->uuid() << " from " << fromNss
- << " to " << toNss;
+ LOGV2(20319,
+ "renameCollection: renaming collection {collToRename_uuid} from {fromNss} to {toNss}",
+ "collToRename_uuid"_attr = collToRename->uuid(),
+ "fromNss"_attr = fromNss,
+ "toNss"_attr = toNss);
Top::get(opCtx->getServiceContext()).collectionDropped(fromNss);
@@ -623,7 +647,7 @@ Collection* DatabaseImpl::createCollection(OperationContext* opCtx,
if (!canAcceptWrites) {
std::string msg = str::stream()
<< "Attempted to create a new collection " << nss << " without a UUID";
- severe() << msg;
+ LOGV2_FATAL(20329, "{msg}", "msg"_attr = msg);
uasserted(ErrorCodes::InvalidOptions, msg);
} else {
optionsWithUUID.uuid.emplace(CollectionUUID::gen());
@@ -658,8 +682,13 @@ Collection* DatabaseImpl::createCollection(OperationContext* opCtx,
_checkCanCreateCollection(opCtx, nss, optionsWithUUID);
audit::logCreateCollection(&cc(), nss.ns());
- log() << "createCollection: " << nss << " with " << (generatedUUID ? "generated" : "provided")
- << " UUID: " << optionsWithUUID.uuid.get() << " and options: " << options.toBSON();
+ LOGV2(20320,
+ "createCollection: {nss} with {generatedUUID_generated_provided} UUID: "
+ "{optionsWithUUID_uuid_get} and options: {options}",
+ "nss"_attr = nss,
+ "generatedUUID_generated_provided"_attr = (generatedUUID ? "generated" : "provided"),
+ "optionsWithUUID_uuid_get"_attr = optionsWithUUID.uuid.get(),
+ "options"_attr = options.toBSON());
// Create Collection object
auto storageEngine = opCtx->getServiceContext()->getStorageEngine();
@@ -781,7 +810,10 @@ void DatabaseImpl::checkForIdIndexesAndDropPendingCollections(OperationContext*
CollectionCatalog::get(opCtx).getAllCollectionNamesFromDb(opCtx, _name)) {
if (nss.isDropPendingNamespace()) {
auto dropOpTime = fassert(40459, nss.getDropPendingNamespaceOpTime());
- log() << "Found drop-pending namespace " << nss << " with drop optime " << dropOpTime;
+ LOGV2(20321,
+ "Found drop-pending namespace {nss} with drop optime {dropOpTime}",
+ "nss"_attr = nss,
+ "dropOpTime"_attr = dropOpTime);
repl::DropPendingCollectionReaper::get(opCtx)->addDropPendingNamespace(
opCtx, dropOpTime, nss);
}
@@ -796,11 +828,15 @@ void DatabaseImpl::checkForIdIndexesAndDropPendingCollections(OperationContext*
if (coll->getIndexCatalog()->findIdIndex(opCtx))
continue;
- log() << "WARNING: the collection '" << nss << "' lacks a unique index on _id."
- << " This index is needed for replication to function properly" << startupWarningsLog;
- log() << "\t To fix this, you need to create a unique index on _id."
- << " See http://dochub.mongodb.org/core/build-replica-set-indexes"
- << startupWarningsLog;
+ LOGV2_OPTIONS(20322,
+ {logv2::LogTag::kStartupWarnings},
+ "WARNING: the collection '{nss}' lacks a unique index on _id. This index is "
+ "needed for replication to function properly",
+ "nss"_attr = nss);
+ LOGV2_OPTIONS(20323,
+ {logv2::LogTag::kStartupWarnings},
+ "\t To fix this, you need to create a unique index on _id. See "
+ "http://dochub.mongodb.org/core/build-replica-set-indexes");
}
}
@@ -809,7 +845,11 @@ Status DatabaseImpl::userCreateNS(OperationContext* opCtx,
CollectionOptions collectionOptions,
bool createDefaultIndexes,
const BSONObj& idIndex) const {
- LOG(1) << "create collection " << nss << ' ' << collectionOptions.toBSON();
+ LOGV2_DEBUG(20324,
+ 1,
+ "create collection {nss} {collectionOptions}",
+ "nss"_attr = nss,
+ "collectionOptions"_attr = collectionOptions.toBSON());
if (!NamespaceString::validCollectionComponent(nss.ns()))
return Status(ErrorCodes::InvalidNamespace, str::stream() << "invalid ns: " << nss);