summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2019-05-06 13:27:10 -0400
committerGregory Wlodarek <gregory.wlodarek@mongodb.com>2019-05-07 07:58:41 -0400
commit28de51de6adb41ce4cdb678812d37b726ff3a3f9 (patch)
treee4c0aa58ebf68ed9a097eb129a54a3f7d29c220d /src/mongo/db
parent400e0500147836ba11ab611bdac2675d65cb7b48 (diff)
downloadmongo-28de51de6adb41ce4cdb678812d37b726ff3a3f9.tar.gz
SERVER-40964 Change lookupNSSByUUID to return boost::optional<NamespaceString> instead of NamespaceString
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/catalog/create_collection.cpp16
-rw-r--r--src/mongo/db/catalog/create_collection_test.cpp5
-rw-r--r--src/mongo/db/catalog/database_test.cpp7
-rw-r--r--src/mongo/db/catalog/rename_collection.cpp28
-rw-r--r--src/mongo/db/catalog/rename_collection_test.cpp20
-rw-r--r--src/mongo/db/catalog/uuid_catalog.cpp11
-rw-r--r--src/mongo/db/catalog/uuid_catalog.h8
-rw-r--r--src/mongo/db/catalog/uuid_catalog_helper.cpp9
-rw-r--r--src/mongo/db/catalog/uuid_catalog_test.cpp24
-rw-r--r--src/mongo/db/catalog_raii.cpp8
-rw-r--r--src/mongo/db/commands/oplog_application_checks.cpp7
-rw-r--r--src/mongo/db/index_builds_coordinator.cpp38
-rw-r--r--src/mongo/db/repl/do_txn.cpp20
-rw-r--r--src/mongo/db/repl/oplog.cpp9
-rw-r--r--src/mongo/db/repl/rollback_impl.cpp23
-rw-r--r--src/mongo/db/repl/rs_rollback.cpp97
-rw-r--r--src/mongo/db/repl/sync_tail.cpp4
17 files changed, 177 insertions, 157 deletions
diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp
index 75c2dc37ecd..d2ecd5bed28 100644
--- a/src/mongo/db/catalog/create_collection.cpp
+++ b/src/mongo/db/catalog/create_collection.cpp
@@ -226,16 +226,16 @@ Status createCollectionForApplyOps(OperationContext* opCtx,
const auto currentName = catalog.lookupNSSByUUID(uuid);
auto serviceContext = opCtx->getServiceContext();
auto opObserver = serviceContext->getOpObserver();
- if (currentName == newCollName)
+ if (currentName && *currentName == newCollName)
return Result(Status::OK());
- if (currentName.isDropPendingNamespace()) {
+ if (currentName && currentName->isDropPendingNamespace()) {
log() << "CMD: create " << newCollName
<< " - existing collection with conflicting UUID " << uuid
- << " is in a drop-pending state: " << currentName;
+ << " is in a drop-pending state: " << *currentName;
return Result(Status(ErrorCodes::NamespaceExists,
str::stream() << "existing collection "
- << currentName.toString()
+ << currentName->toString()
<< " with conflicting UUID "
<< uuid.toString()
<< " is in a drop-pending state."));
@@ -280,14 +280,16 @@ Status createCollectionForApplyOps(OperationContext* opCtx,
// If the collection with the requested UUID already exists, but with a different
// name, just rename it to 'newCollName'.
if (catalog.lookupCollectionByUUID(uuid)) {
+ invariant(currentName);
uassert(40655,
str::stream() << "Invalid name " << newCollName << " for UUID " << uuid,
- currentName.db() == newCollName.db());
- Status status = db->renameCollection(opCtx, currentName, newCollName, stayTemp);
+ currentName->db() == newCollName.db());
+ Status status =
+ db->renameCollection(opCtx, *currentName, newCollName, stayTemp);
if (!status.isOK())
return Result(status);
opObserver->onRenameCollection(opCtx,
- currentName,
+ *currentName,
newCollName,
uuid,
/*dropTargetUUID*/ {},
diff --git a/src/mongo/db/catalog/create_collection_test.cpp b/src/mongo/db/catalog/create_collection_test.cpp
index f69fc41db17..2d2061c1e98 100644
--- a/src/mongo/db/catalog/create_collection_test.cpp
+++ b/src/mongo/db/catalog/create_collection_test.cpp
@@ -188,9 +188,10 @@ TEST_F(CreateCollectionTest,
// Check that old collection that was renamed out of the way still exists.
auto& uuidCatalog = UUIDCatalog::get(opCtx.get());
auto renamedCollectionNss = uuidCatalog.lookupNSSByUUID(existingCollectionUuid);
- ASSERT_TRUE(collectionExists(opCtx.get(), renamedCollectionNss))
+ ASSERT(renamedCollectionNss);
+ ASSERT_TRUE(collectionExists(opCtx.get(), *renamedCollectionNss))
<< "old renamed collection with UUID " << existingCollectionUuid
- << " missing: " << renamedCollectionNss;
+ << " missing: " << *renamedCollectionNss;
}
TEST_F(CreateCollectionTest,
diff --git a/src/mongo/db/catalog/database_test.cpp b/src/mongo/db/catalog/database_test.cpp
index 337a56d0a96..fdf80e6b1f8 100644
--- a/src/mongo/db/catalog/database_test.cpp
+++ b/src/mongo/db/catalog/database_test.cpp
@@ -29,6 +29,7 @@
#include "mongo/platform/basic.h"
+#include <boost/optional/optional_io.hpp>
#include <pcrecpp.h>
#include "mongo/bson/util/builder.h"
@@ -352,13 +353,13 @@ TEST_F(DatabaseTest, RenameCollectionPreservesUuidOfSourceCollectionAndUpdatesUu
auto fromUuid = UUID::gen();
auto&& uuidCatalog = UUIDCatalog::get(opCtx);
- ASSERT_EQUALS(NamespaceString(), uuidCatalog.lookupNSSByUUID(fromUuid));
+ ASSERT_EQUALS(boost::none, uuidCatalog.lookupNSSByUUID(fromUuid));
WriteUnitOfWork wuow(opCtx);
CollectionOptions fromCollectionOptions;
fromCollectionOptions.uuid = fromUuid;
ASSERT_TRUE(db->createCollection(opCtx, fromNss, fromCollectionOptions));
- ASSERT_EQUALS(fromNss, uuidCatalog.lookupNSSByUUID(fromUuid));
+ ASSERT_EQUALS(fromNss, *uuidCatalog.lookupNSSByUUID(fromUuid));
auto stayTemp = false;
ASSERT_OK(db->renameCollection(opCtx, fromNss, toNss, stayTemp));
@@ -374,7 +375,7 @@ TEST_F(DatabaseTest, RenameCollectionPreservesUuidOfSourceCollectionAndUpdatesUu
ASSERT_TRUE(toUuid);
ASSERT_EQUALS(fromUuid, *toUuid);
- ASSERT_EQUALS(toNss, uuidCatalog.lookupNSSByUUID(*toUuid));
+ ASSERT_EQUALS(toNss, *uuidCatalog.lookupNSSByUUID(*toUuid));
wuow.commit();
});
diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp
index ec3c7a3ce52..3f8f82c35cc 100644
--- a/src/mongo/db/catalog/rename_collection.cpp
+++ b/src/mongo/db/catalog/rename_collection.cpp
@@ -65,7 +65,7 @@ namespace {
MONGO_FAIL_POINT_DEFINE(writeConfilctInRenameCollCopyToTmp);
-NamespaceString getNamespaceFromUUID(OperationContext* opCtx, const UUID& uuid) {
+boost::optional<NamespaceString> getNamespaceFromUUID(OperationContext* opCtx, const UUID& uuid) {
return UUIDCatalog::get(opCtx).lookupNSSByUUID(uuid);
}
@@ -397,7 +397,6 @@ Status renameCollectionWithinDBForApplyOps(OperationContext* opCtx,
return Status::OK();
}
if (uuidToDrop && uuidToDrop != targetColl->uuid()) {
- auto dropTargetNssFromUUID = getNamespaceFromUUID(opCtx, uuidToDrop.get());
// We need to rename the targetColl to a temporary name.
auto status = renameTargetCollectionToTmp(
opCtx, source, sourceColl->uuid().get(), db, target, targetColl->uuid().get());
@@ -413,9 +412,9 @@ Status renameCollectionWithinDBForApplyOps(OperationContext* opCtx,
if (!targetColl && uuidToDrop) {
invariant(options.dropTarget);
auto collToDropBasedOnUUID = getNamespaceFromUUID(opCtx, uuidToDrop.get());
- if (!collToDropBasedOnUUID.isEmpty() && !collToDropBasedOnUUID.isDropPendingNamespace()) {
- invariant(collToDropBasedOnUUID.db() == target.db());
- targetColl = db->getCollection(opCtx, collToDropBasedOnUUID);
+ if (collToDropBasedOnUUID && !collToDropBasedOnUUID->isDropPendingNamespace()) {
+ invariant(collToDropBasedOnUUID->db() == target.db());
+ targetColl = db->getCollection(opCtx, *collToDropBasedOnUUID);
}
}
@@ -764,8 +763,8 @@ Status renameCollectionForApplyOps(OperationContext* opCtx,
if (!ui.eoo()) {
uuidToRename = uassertStatusOK(UUID::parse(ui));
auto nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(uuidToRename.get());
- if (!nss.isEmpty())
- sourceNss = nss;
+ if (nss)
+ sourceNss = *nss;
}
RenameCollectionOptions options;
@@ -797,7 +796,7 @@ Status renameCollectionForApplyOps(OperationContext* opCtx,
.getCollection();
if (sourceNss.isDropPendingNamespace() || sourceColl == nullptr) {
- NamespaceString dropTargetNss;
+ boost::optional<NamespaceString> dropTargetNss;
if (options.dropTarget)
dropTargetNss = targetNss;
@@ -806,10 +805,10 @@ Status renameCollectionForApplyOps(OperationContext* opCtx,
dropTargetNss = getNamespaceFromUUID(opCtx, uuidToDrop.get());
// Downgrade renameCollection to dropCollection.
- if (!dropTargetNss.isEmpty()) {
+ if (dropTargetNss) {
BSONObjBuilder unusedResult;
return dropCollection(opCtx,
- dropTargetNss,
+ *dropTargetNss,
unusedResult,
renameOpTime,
DropCollectionSystemCollectionMode::kAllowSystemCollectionDrops);
@@ -838,17 +837,18 @@ Status renameCollectionForRollback(OperationContext* opCtx,
const UUID& uuid) {
// If the UUID we're targeting already exists, rename from there no matter what.
auto source = getNamespaceFromUUID(opCtx, uuid);
- invariant(source.db() == target.db(),
+ invariant(source);
+ invariant(source->db() == target.db(),
str::stream() << "renameCollectionForRollback: source and target namespaces must "
"have the same database. source: "
- << source
+ << *source
<< ". target: "
<< target);
- log() << "renameCollectionForRollback: rename " << source << " (" << uuid << ") to " << target
+ log() << "renameCollectionForRollback: rename " << *source << " (" << uuid << ") to " << target
<< ".";
- return renameCollectionWithinDB(opCtx, source, target, {});
+ return renameCollectionWithinDB(opCtx, *source, target, {});
}
} // namespace mongo
diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp
index 4cc2be1a0dd..96b8fc46890 100644
--- a/src/mongo/db/catalog/rename_collection_test.cpp
+++ b/src/mongo/db/catalog/rename_collection_test.cpp
@@ -653,9 +653,9 @@ TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsDropTargetByUUIDTargetEx
ASSERT_TRUE(_collectionExists(_opCtx.get(), collB));
// The original B should exist too, but with a temporary name
const auto& tmpB = UUIDCatalog::get(_opCtx.get()).lookupNSSByUUID(collBUUID);
- ASSERT_FALSE(tmpB.isEmpty());
- ASSERT_TRUE(tmpB.coll().startsWith("tmp"));
- ASSERT_TRUE(tmpB != collB);
+ ASSERT(tmpB);
+ ASSERT_TRUE(tmpB->coll().startsWith("tmp"));
+ ASSERT_TRUE(*tmpB != collB);
}
TEST_F(RenameCollectionTest,
@@ -686,10 +686,10 @@ TEST_F(RenameCollectionTest,
ASSERT_TRUE(_collectionExists(_opCtx.get(), collB));
// The original B should exist too, but with a temporary name
const auto& tmpB = UUIDCatalog::get(_opCtx.get()).lookupNSSByUUID(collBUUID);
- ASSERT_FALSE(tmpB.isEmpty());
- ASSERT_TRUE(tmpB != collB);
- ASSERT_TRUE(tmpB.coll().startsWith("tmp"));
- ASSERT_TRUE(_isTempCollection(_opCtx.get(), tmpB));
+ ASSERT(tmpB);
+ ASSERT_TRUE(*tmpB != collB);
+ ASSERT_TRUE(tmpB->coll().startsWith("tmp"));
+ ASSERT_TRUE(_isTempCollection(_opCtx.get(), *tmpB));
}
TEST_F(RenameCollectionTest,
@@ -712,9 +712,9 @@ TEST_F(RenameCollectionTest,
ASSERT_TRUE(_collectionExists(_opCtx.get(), collB));
// The original B should exist too, but with a temporary name
const auto& tmpB = UUIDCatalog::get(_opCtx.get()).lookupNSSByUUID(collBUUID);
- ASSERT_FALSE(tmpB.isEmpty());
- ASSERT_TRUE(tmpB != collB);
- ASSERT_TRUE(tmpB.coll().startsWith("tmp"));
+ ASSERT(tmpB);
+ ASSERT_TRUE(*tmpB != collB);
+ ASSERT_TRUE(tmpB->coll().startsWith("tmp"));
}
TEST_F(RenameCollectionTest,
diff --git a/src/mongo/db/catalog/uuid_catalog.cpp b/src/mongo/db/catalog/uuid_catalog.cpp
index 0c69ca017f8..f8edcc77a77 100644
--- a/src/mongo/db/catalog/uuid_catalog.cpp
+++ b/src/mongo/db/catalog/uuid_catalog.cpp
@@ -305,11 +305,14 @@ CollectionCatalogEntry* UUIDCatalog::lookupCollectionCatalogEntryByNamespace(
return it == _collections.end() ? nullptr : it->second->collectionCatalogEntry.get();
}
-NamespaceString UUIDCatalog::lookupNSSByUUID(CollectionUUID uuid) const {
+boost::optional<NamespaceString> UUIDCatalog::lookupNSSByUUID(CollectionUUID uuid) const {
stdx::lock_guard<stdx::mutex> lock(_catalogLock);
auto foundIt = _catalog.find(uuid);
- if (foundIt != _catalog.end())
- return foundIt->second.collectionCatalogEntry->ns();
+ if (foundIt != _catalog.end()) {
+ NamespaceString ns = foundIt->second.collectionCatalogEntry->ns();
+ invariant(!ns.isEmpty());
+ return ns;
+ }
// Only in the case that the catalog is closed and a UUID is currently unknown, resolve it
// using the pre-close state. This ensures that any tasks reloading the catalog can see their
@@ -319,7 +322,7 @@ NamespaceString UUIDCatalog::lookupNSSByUUID(CollectionUUID uuid) const {
if (shadowIt != _shadowCatalog->end())
return shadowIt->second;
}
- return NamespaceString();
+ return boost::none;
}
boost::optional<CollectionUUID> UUIDCatalog::lookupUUIDByNSS(const NamespaceString& nss) const {
diff --git a/src/mongo/db/catalog/uuid_catalog.h b/src/mongo/db/catalog/uuid_catalog.h
index 1cd68110dab..33d36b34780 100644
--- a/src/mongo/db/catalog/uuid_catalog.h
+++ b/src/mongo/db/catalog/uuid_catalog.h
@@ -204,11 +204,11 @@ public:
const NamespaceString& nss) const;
/**
- * This function gets the NamespaceString from the Collection* pointer that
- * corresponds to CollectionUUID uuid. If there is no such pointer, an empty
- * NamespaceString is returned. See onCloseCatalog/onOpenCatalog for more info.
+ * This function gets the NamespaceString from the collection catalog entry that
+ * corresponds to CollectionUUID uuid. If no collection exists with the uuid, return
+ * boost::none. See onCloseCatalog/onOpenCatalog for more info.
*/
- NamespaceString lookupNSSByUUID(CollectionUUID uuid) const;
+ boost::optional<NamespaceString> lookupNSSByUUID(CollectionUUID uuid) const;
/**
* Returns the UUID if `nss` exists in UUIDCatalog. The time complexity of
diff --git a/src/mongo/db/catalog/uuid_catalog_helper.cpp b/src/mongo/db/catalog/uuid_catalog_helper.cpp
index 49f79e15007..5bbc2bf6618 100644
--- a/src/mongo/db/catalog/uuid_catalog_helper.cpp
+++ b/src/mongo/db/catalog/uuid_catalog_helper.cpp
@@ -47,17 +47,16 @@ void forEachCollectionFromDb(
auto uuid = collectionIt.uuid().get();
auto nss = uuidCatalog.lookupNSSByUUID(uuid);
- // If the NamespaceString we resolve by the 'uuid' is empty, the collection was dropped
- // and we should move onto the next one.
- if (nss.isEmpty()) {
+ // If the NamespaceString can't be resolved from the uuid, then the collection was dropped.
+ if (!nss) {
continue;
}
- Lock::CollectionLock clk(opCtx, nss, collLockMode);
+ Lock::CollectionLock clk(opCtx, *nss, collLockMode);
auto collection = uuidCatalog.lookupCollectionByUUID(uuid);
auto catalogEntry = uuidCatalog.lookupCollectionCatalogEntryByUUID(uuid);
- if (!collection || !catalogEntry || catalogEntry->ns() != nss)
+ if (!collection || !catalogEntry || catalogEntry->ns() != *nss)
continue;
if (!callback(collection, catalogEntry))
diff --git a/src/mongo/db/catalog/uuid_catalog_test.cpp b/src/mongo/db/catalog/uuid_catalog_test.cpp
index 888d12f5dad..34542ae9e91 100644
--- a/src/mongo/db/catalog/uuid_catalog_test.cpp
+++ b/src/mongo/db/catalog/uuid_catalog_test.cpp
@@ -535,9 +535,9 @@ TEST_F(UUIDCatalogTest, LookupCollectionByUUID) {
TEST_F(UUIDCatalogTest, LookupNSSByUUID) {
// Ensure the string value of the obtained NamespaceString is equal to nss.ns().
- ASSERT_EQUALS(catalog.lookupNSSByUUID(colUUID).ns(), nss.ns());
+ ASSERT_EQUALS(catalog.lookupNSSByUUID(colUUID)->ns(), nss.ns());
// Ensure namespace lookups of unknown UUIDs result in empty NamespaceStrings.
- ASSERT_EQUALS(catalog.lookupNSSByUUID(CollectionUUID::gen()).ns(), NamespaceString().ns());
+ ASSERT_EQUALS(catalog.lookupNSSByUUID(CollectionUUID::gen()), boost::none);
}
TEST_F(UUIDCatalogTest, InsertAfterLookup) {
@@ -549,11 +549,11 @@ TEST_F(UUIDCatalogTest, InsertAfterLookup) {
// Ensure that looking up non-existing UUIDs doesn't affect later registration of those UUIDs.
ASSERT(catalog.lookupCollectionByUUID(newUUID) == nullptr);
- ASSERT(catalog.lookupNSSByUUID(newUUID) == NamespaceString());
+ ASSERT_EQUALS(catalog.lookupNSSByUUID(newUUID), boost::none);
catalog.registerCatalogEntry(newUUID, std::move(newCatalogEntry));
catalog.onCreateCollection(&opCtx, std::move(newCollUnique), newUUID);
ASSERT_EQUALS(catalog.lookupCollectionByUUID(newUUID), newCol);
- ASSERT_EQUALS(catalog.lookupNSSByUUID(colUUID), nss);
+ ASSERT_EQUALS(*catalog.lookupNSSByUUID(colUUID), nss);
}
TEST_F(UUIDCatalogTest, OnDropCollection) {
@@ -583,9 +583,9 @@ TEST_F(UUIDCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsOldNSSIfDropped) {
catalog.onDropCollection(&opCtx, colUUID);
catalog.deregisterCatalogEntry(colUUID);
ASSERT(catalog.lookupCollectionByUUID(colUUID) == nullptr);
- ASSERT_EQUALS(catalog.lookupNSSByUUID(colUUID), nss);
+ ASSERT_EQUALS(*catalog.lookupNSSByUUID(colUUID), nss);
catalog.onOpenCatalog(&opCtx);
- ASSERT_EQUALS(catalog.lookupNSSByUUID(colUUID), NamespaceString());
+ ASSERT_EQUALS(catalog.lookupNSSByUUID(colUUID), boost::none);
}
TEST_F(UUIDCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsNewlyCreatedNSS) {
@@ -598,16 +598,16 @@ TEST_F(UUIDCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsNewlyCreatedNSS) {
// Ensure that looking up non-existing UUIDs doesn't affect later registration of those UUIDs.
catalog.onCloseCatalog(&opCtx);
ASSERT(catalog.lookupCollectionByUUID(newUUID) == nullptr);
- ASSERT(catalog.lookupNSSByUUID(newUUID) == NamespaceString());
+ ASSERT_EQUALS(catalog.lookupNSSByUUID(newUUID), boost::none);
catalog.registerCatalogEntry(newUUID, std::move(newCatalogEntry));
catalog.onCreateCollection(&opCtx, std::move(newCollUnique), newUUID);
ASSERT_EQUALS(catalog.lookupCollectionByUUID(newUUID), newCol);
- ASSERT_EQUALS(catalog.lookupNSSByUUID(colUUID), nss);
+ ASSERT_EQUALS(*catalog.lookupNSSByUUID(colUUID), nss);
// Ensure that collection still exists after opening the catalog again.
catalog.onOpenCatalog(&opCtx);
ASSERT_EQUALS(catalog.lookupCollectionByUUID(newUUID), newCol);
- ASSERT_EQUALS(catalog.lookupNSSByUUID(colUUID), nss);
+ ASSERT_EQUALS(*catalog.lookupNSSByUUID(colUUID), nss);
}
TEST_F(UUIDCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsFreshestNSS) {
@@ -620,16 +620,16 @@ TEST_F(UUIDCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsFreshestNSS) {
catalog.onDropCollection(&opCtx, colUUID);
catalog.deregisterCatalogEntry(colUUID);
ASSERT(catalog.lookupCollectionByUUID(colUUID) == nullptr);
- ASSERT_EQUALS(catalog.lookupNSSByUUID(colUUID), nss);
+ ASSERT_EQUALS(*catalog.lookupNSSByUUID(colUUID), nss);
catalog.registerCatalogEntry(colUUID, std::move(newCatalogEntry));
catalog.onCreateCollection(&opCtx, std::move(newCollUnique), colUUID);
ASSERT_EQUALS(catalog.lookupCollectionByUUID(colUUID), newCol);
- ASSERT_EQUALS(catalog.lookupNSSByUUID(colUUID), newNss);
+ ASSERT_EQUALS(*catalog.lookupNSSByUUID(colUUID), newNss);
// Ensure that collection still exists after opening the catalog again.
catalog.onOpenCatalog(&opCtx);
ASSERT_EQUALS(catalog.lookupCollectionByUUID(colUUID), newCol);
- ASSERT_EQUALS(catalog.lookupNSSByUUID(colUUID), newNss);
+ ASSERT_EQUALS(*catalog.lookupNSSByUUID(colUUID), newNss);
}
DEATH_TEST_F(UUIDCatalogResourceTest, AddInvalidResourceType, "invariant") {
diff --git a/src/mongo/db/catalog_raii.cpp b/src/mongo/db/catalog_raii.cpp
index f4b010e647b..5222dcf1843 100644
--- a/src/mongo/db/catalog_raii.cpp
+++ b/src/mongo/db/catalog_raii.cpp
@@ -162,15 +162,15 @@ NamespaceString AutoGetCollection::resolveNamespaceStringOrUUID(OperationContext
uassert(ErrorCodes::NamespaceNotFound,
str::stream() << "Unable to resolve " << nsOrUUID.toString(),
- resolvedNss.isValid());
+ resolvedNss && resolvedNss->isValid());
uassert(ErrorCodes::NamespaceNotFound,
str::stream() << "UUID " << nsOrUUID.toString() << " specified in " << nsOrUUID.dbname()
<< " resolved to a collection in a different database: "
- << resolvedNss.toString(),
- resolvedNss.db() == nsOrUUID.dbname());
+ << *resolvedNss,
+ resolvedNss->db() == nsOrUUID.dbname());
- return resolvedNss;
+ return *resolvedNss;
}
AutoGetOrCreateDb::AutoGetOrCreateDb(OperationContext* opCtx,
diff --git a/src/mongo/db/commands/oplog_application_checks.cpp b/src/mongo/db/commands/oplog_application_checks.cpp
index 08a2d78dbbd..cb29312ef84 100644
--- a/src/mongo/db/commands/oplog_application_checks.cpp
+++ b/src/mongo/db/commands/oplog_application_checks.cpp
@@ -66,9 +66,10 @@ Status OplogApplicationChecks::checkOperationAuthorization(OperationContext* opC
if (oplogEntry.hasField("ui"_sd)) {
// ns by UUID overrides the ns specified if they are different.
auto& uuidCatalog = UUIDCatalog::get(opCtx);
- NamespaceString uuidCollNS = uuidCatalog.lookupNSSByUUID(getUUIDFromOplogEntry(oplogEntry));
- if (!uuidCollNS.isEmpty() && uuidCollNS != ns)
- ns = uuidCollNS;
+ boost::optional<NamespaceString> uuidCollNS =
+ uuidCatalog.lookupNSSByUUID(getUUIDFromOplogEntry(oplogEntry));
+ if (uuidCollNS && *uuidCollNS != ns)
+ ns = *uuidCollNS;
}
BSONElement oElem = oplogEntry["o"];
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp
index 6a236e4d244..e2f7372b381 100644
--- a/src/mongo/db/index_builds_coordinator.cpp
+++ b/src/mongo/db/index_builds_coordinator.cpp
@@ -547,25 +547,26 @@ IndexBuildsCoordinator::_registerAndSetUpIndexBuild(
IndexBuildProtocol protocol,
boost::optional<CommitQuorumOptions> commitQuorum) {
auto nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(collectionUUID);
- if (nss.isEmpty()) {
+ if (!nss) {
return Status(ErrorCodes::NamespaceNotFound,
str::stream() << "Cannot create index on collection '" << collectionUUID
<< "' because the collection no longer exists.");
}
- auto dbName = nss.db().toString();
+
+ auto dbName = nss->db().toString();
AutoGetDb autoDb(opCtx, dbName, MODE_X);
if (!autoDb.getDb()) {
return Status(ErrorCodes::NamespaceNotFound,
- str::stream() << "Failed to create index(es) on collection '" << nss
+ str::stream() << "Failed to create index(es) on collection '" << *nss
<< "' because the collection no longer exists");
}
- auto collection = autoDb.getDb()->getCollection(opCtx, nss);
+ auto collection = autoDb.getDb()->getCollection(opCtx, *nss);
if (!collection) {
// The collection does not exist. We will not build an index.
return Status(ErrorCodes::NamespaceNotFound,
- str::stream() << "Failed to create index(es) on collection '" << nss
+ str::stream() << "Failed to create index(es) on collection '" << *nss
<< "' because the collection no longer exists");
}
@@ -586,7 +587,7 @@ IndexBuildsCoordinator::_registerAndSetUpIndexBuild(
std::vector<BSONObj> filteredSpecs;
try {
- filteredSpecs = _addDefaultsAndFilterExistingIndexes(opCtx, collection, nss, specs);
+ filteredSpecs = _addDefaultsAndFilterExistingIndexes(opCtx, collection, *nss, specs);
} catch (const DBException& ex) {
return ex.toStatus();
}
@@ -640,7 +641,7 @@ IndexBuildsCoordinator::_registerAndSetUpIndexBuild(
opCtx->getServiceContext()->getOpObserver()->onStartIndexBuild(
opCtx,
- nss,
+ *nss,
replIndexBuildState->collectionUUID,
replIndexBuildState->buildUUID,
filteredSpecs,
@@ -654,7 +655,7 @@ IndexBuildsCoordinator::_registerAndSetUpIndexBuild(
IndexBuildsManager::SetupOptions options;
options.indexConstraints =
- repl::ReplicationCoordinator::get(opCtx)->shouldRelaxIndexConstraints(opCtx, nss)
+ repl::ReplicationCoordinator::get(opCtx)->shouldRelaxIndexConstraints(opCtx, *nss)
? IndexBuildsManager::IndexConstraints::kRelax
: IndexBuildsManager::IndexConstraints::kEnforce;
status = _indexBuildsManager.setUpIndexBuild(
@@ -740,18 +741,19 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx,
// 'status' should always be set to something else before this function exits.
Status status{ErrorCodes::InternalError,
"Uninitialized status value in IndexBuildsCoordinator"};
- NamespaceString nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(replState->collectionUUID);
+ boost::optional<NamespaceString> nss =
+ UUIDCatalog::get(opCtx).lookupNSSByUUID(replState->collectionUUID);
- invariant(!nss.isEmpty(),
+ invariant(nss,
str::stream() << "Collection '" << replState->collectionUUID
<< "' should exist because an index build is in progress.");
// Set up the thread's currentOp information to display createIndexes cmd information.
- _updateCurOpOpDescription(opCtx, nss, replState->indexSpecs);
+ _updateCurOpOpDescription(opCtx, *nss, replState->indexSpecs);
// Do not use AutoGetOrCreateDb because we may relock the database in mode IX.
boost::optional<Lock::DBLock> dbLock;
- dbLock.emplace(opCtx, nss.db(), MODE_X);
+ dbLock.emplace(opCtx, nss->db(), MODE_X);
// Allow the strong lock acquisition above to be interrupted, but from this point forward do
// not allow locks or re-locks to be interrupted.
@@ -759,7 +761,7 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx,
auto collection = UUIDCatalog::get(opCtx).lookupCollectionByUUID(replState->collectionUUID);
invariant(collection,
- str::stream() << "Collection " << nss
+ str::stream() << "Collection " << *nss
<< " should exist because an index build is in progress.");
auto replCoord = repl::ReplicationCoordinator::get(opCtx);
@@ -776,9 +778,9 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx,
// accordingly (checkForInterrupt() will throw an exception while
// checkForInterruptNoAssert() returns an error Status).
opCtx->runWithoutInterruptionExceptAtGlobalShutdown(
- [&, this] { _buildIndex(opCtx, collection, nss, replState, &*dbLock); });
+ [&, this] { _buildIndex(opCtx, collection, *nss, replState, &*dbLock); });
} else {
- _buildIndex(opCtx, collection, nss, replState, &*dbLock);
+ _buildIndex(opCtx, collection, *nss, replState, &*dbLock);
}
replState->stats.numIndexesAfter = _getNumIndexesTotal(opCtx, collection);
status = Status::OK();
@@ -790,7 +792,7 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx,
// yielding.
if (!opCtx->lockState()->isDbLockedForMode(replState->dbName, MODE_X)) {
dbLock.reset(); // Might still have the Global lock, so be sure to clear it out first here.
- dbLock.emplace(opCtx, nss.db(), MODE_X);
+ dbLock.emplace(opCtx, nss->db(), MODE_X);
}
if (replSetAndNotPrimary && status == ErrorCodes::InterruptedAtShutdown) {
@@ -818,7 +820,7 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx,
_indexBuildsManager.tearDownIndexBuild(opCtx, collection, replState->buildUUID);
if (!status.isOK()) {
- logFailure(status, nss, replState);
+ logFailure(status, *nss, replState);
// Failed index builds should abort secondary oplog application.
if (replSetAndNotPrimary) {
@@ -832,7 +834,7 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx,
MONGO_UNREACHABLE;
}
- log() << "Index build completed successfully: " << replState->buildUUID << ": " << nss << " ( "
+ log() << "Index build completed successfully: " << replState->buildUUID << ": " << *nss << " ( "
<< replState->collectionUUID << " ). Index specs built: " << replState->indexSpecs.size()
<< ". Indexes in catalog before build: " << replState->stats.numIndexesBefore
<< ". Indexes in catalog after build: " << replState->stats.numIndexesAfter;
diff --git a/src/mongo/db/repl/do_txn.cpp b/src/mongo/db/repl/do_txn.cpp
index 3fb6f97f4e4..109df753fc6 100644
--- a/src/mongo/db/repl/do_txn.cpp
+++ b/src/mongo/db/repl/do_txn.cpp
@@ -112,21 +112,21 @@ Status _doTxn(OperationContext* opCtx,
BSONElement e = i.next();
const BSONObj& opObj = e.Obj();
- NamespaceString nss(opObj["ns"].String());
+ boost::optional<NamespaceString> nss = NamespaceString(opObj["ns"].String());
// Need to check this here, or OldClientContext may fail an invariant.
- if (!nss.isValid())
- return {ErrorCodes::InvalidNamespace, "invalid ns: " + nss.ns()};
+ if (!nss->isValid())
+ return {ErrorCodes::InvalidNamespace, "invalid ns: " + nss->ns()};
Status status(ErrorCodes::InternalError, "");
- AutoGetDb autoDb(opCtx, nss.db(), MODE_IX);
+ AutoGetDb autoDb(opCtx, nss->db(), MODE_IX);
auto db = autoDb.getDb();
if (!db) {
uasserted(ErrorCodes::NamespaceNotFound,
str::stream() << "cannot apply insert, delete, or update operation on a "
"non-existent namespace "
- << nss.ns()
+ << nss->ns()
<< ": "
<< mongo::redact(opObj));
}
@@ -138,24 +138,24 @@ Status _doTxn(OperationContext* opCtx,
nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(uuidStatus.getValue());
uassert(ErrorCodes::NamespaceNotFound,
str::stream() << "cannot find collection uuid " << uuidStatus.getValue(),
- !nss.isEmpty());
+ nss);
}
- Lock::CollectionLock collLock(opCtx, nss, MODE_IX);
- auto collection = db->getCollection(opCtx, nss);
+ Lock::CollectionLock collLock(opCtx, *nss, MODE_IX);
+ auto collection = db->getCollection(opCtx, *nss);
// When processing an update on a non-existent collection, applyOperation_inlock()
// returns UpdateOperationFailed on updates and allows the collection to be
// implicitly created on upserts. We detect both cases here and fail early with
// NamespaceNotFound.
// Additionally for inserts, we fail early on non-existent collections.
- if (!collection && ViewCatalog::get(db)->lookup(opCtx, nss.ns())) {
+ if (!collection && ViewCatalog::get(db)->lookup(opCtx, nss->ns())) {
uasserted(ErrorCodes::CommandNotSupportedOnView,
str::stream() << "doTxn not supported on a view: " << redact(opObj));
}
if (!collection) {
uasserted(ErrorCodes::NamespaceNotFound,
str::stream() << "cannot apply operation on a non-existent namespace "
- << nss.ns()
+ << nss->ns()
<< " with doTxn: "
<< redact(opObj));
}
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index 1a7e90075e0..9aa26b0bfc6 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -801,8 +801,8 @@ std::pair<OptionalCollectionUUID, NamespaceString> parseCollModUUIDAndNss(Operat
str::stream() << "Failed to apply operation due to missing collection (" << uuid
<< "): "
<< redact(cmd.toString()),
- !nsByUUID.isEmpty());
- return std::pair<OptionalCollectionUUID, NamespaceString>(uuid, nsByUUID);
+ nsByUUID);
+ return std::pair<OptionalCollectionUUID, NamespaceString>(uuid, *nsByUUID);
}
NamespaceString parseUUID(OperationContext* opCtx, const BSONElement& ui) {
@@ -811,9 +811,8 @@ NamespaceString parseUUID(OperationContext* opCtx, const BSONElement& ui) {
auto uuid = statusWithUUID.getValue();
auto& catalog = UUIDCatalog::get(opCtx);
auto nss = catalog.lookupNSSByUUID(uuid);
- uassert(
- ErrorCodes::NamespaceNotFound, "No namespace with UUID " + uuid.toString(), !nss.isEmpty());
- return nss;
+ uassert(ErrorCodes::NamespaceNotFound, "No namespace with UUID " + uuid.toString(), nss);
+ return *nss;
}
NamespaceString parseUUIDorNs(OperationContext* opCtx,
diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp
index dd3cb7fcfc0..678c63cd56e 100644
--- a/src/mongo/db/repl/rollback_impl.cpp
+++ b/src/mongo/db/repl/rollback_impl.cpp
@@ -592,7 +592,7 @@ Status RollbackImpl::_findRecordStoreCounts(OperationContext* opCtx) {
// Drop-pending collections are not visible to rollback via the catalog when they are
// managed by the storage engine. See StorageEngine::supportsPendingDrops().
- if (nss.isEmpty()) {
+ if (!nss) {
invariant(storageEngine->supportsPendingDrops(),
str::stream() << "The collection with UUID " << uuid
<< " is unexpectedly missing in the UUIDCatalog");
@@ -611,7 +611,7 @@ Status RollbackImpl::_findRecordStoreCounts(OperationContext* opCtx) {
"collection count during rollback.");
oldCount = static_cast<StorageInterface::CollectionCount>(dropPendingInfo.count);
} else {
- auto countSW = _storageInterface->getCollectionCount(opCtx, nss);
+ auto countSW = _storageInterface->getCollectionCount(opCtx, *nss);
if (!countSW.isOK()) {
return countSW.getStatus();
}
@@ -619,7 +619,8 @@ Status RollbackImpl::_findRecordStoreCounts(OperationContext* opCtx) {
}
if (oldCount > static_cast<uint64_t>(std::numeric_limits<long long>::max())) {
- warning() << "Count for " << nss.ns() << " (" << uuid.toString() << ") was " << oldCount
+ warning() << "Count for " << nss->ns() << " (" << uuid.toString() << ") was "
+ << oldCount
<< " which is larger than the maximum int64_t value. Not attempting to fix "
"count during rollback.";
continue;
@@ -629,7 +630,7 @@ Status RollbackImpl::_findRecordStoreCounts(OperationContext* opCtx) {
auto newCount = oldCountSigned + countDiff;
if (newCount < 0) {
- warning() << "Attempted to set count for " << nss.ns() << " (" << uuid.toString()
+ warning() << "Attempted to set count for " << nss->ns() << " (" << uuid.toString()
<< ") to " << newCount
<< " but set it to 0 instead. This is likely due to the count previously "
"becoming inconsistent from an unclean shutdown or a rollback that could "
@@ -637,7 +638,7 @@ Status RollbackImpl::_findRecordStoreCounts(OperationContext* opCtx) {
<< oldCount << ". Count change: " << countDiff;
newCount = 0;
}
- LOG(2) << "Record count of " << nss.ns() << " (" << uuid.toString()
+ LOG(2) << "Record count of " << nss->ns() << " (" << uuid.toString()
<< ") before rollback is " << oldCount << ". Setting it to " << newCount
<< ", due to change of " << countDiff;
_newCounts[uuid] = newCount;
@@ -1013,25 +1014,25 @@ Status RollbackImpl::_writeRollbackFiles(OperationContext* opCtx) {
// Drop-pending collections are not visible to rollback via the catalog when they are
// managed by the storage engine. See StorageEngine::supportsPendingDrops().
- if (nss.isEmpty() && storageEngine->supportsPendingDrops()) {
+ if (!nss && storageEngine->supportsPendingDrops()) {
log() << "The collection with UUID " << uuid
<< " is missing in the UUIDCatalog. This could be due to a dropped collection. "
- "Not writing rollback file for namespace "
- << nss.ns() << " with uuid " << uuid;
+ "Not writing rollback file for uuid "
+ << uuid;
continue;
}
- invariant(!nss.isEmpty(),
+ invariant(nss,
str::stream() << "The collection with UUID " << uuid
<< " is unexpectedly missing in the UUIDCatalog");
if (_isInShutdown()) {
- log() << "Rollback shutting down; not writing rollback file for namespace " << nss.ns()
+ log() << "Rollback shutting down; not writing rollback file for namespace " << nss->ns()
<< " with uuid " << uuid;
continue;
}
- _writeRollbackFileForNamespace(opCtx, uuid, nss, entry.second);
+ _writeRollbackFileForNamespace(opCtx, uuid, *nss, entry.second);
}
// TODO (SERVER-40614): This interrupt point should be removed.
diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp
index 4d90bba29cc..1ae1cae9a82 100644
--- a/src/mongo/db/repl/rs_rollback.cpp
+++ b/src/mongo/db/repl/rs_rollback.cpp
@@ -710,8 +710,9 @@ void dropIndex(OperationContext* opCtx,
*/
void rollbackCreateIndexes(OperationContext* opCtx, UUID uuid, std::set<std::string> indexNames) {
- NamespaceString nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(uuid);
- Lock::DBLock dbLock(opCtx, nss.db(), MODE_X);
+ boost::optional<NamespaceString> nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(uuid);
+ invariant(nss);
+ Lock::DBLock dbLock(opCtx, nss->db(), MODE_X);
Collection* collection = UUIDCatalog::get(opCtx).lookupCollectionByUUID(uuid);
// If we cannot find the collection, we skip over dropping the index.
@@ -732,12 +733,12 @@ void rollbackCreateIndexes(OperationContext* opCtx, UUID uuid, std::set<std::str
for (auto itIndex = indexNames.begin(); itIndex != indexNames.end(); itIndex++) {
const string& indexName = *itIndex;
- log() << "Dropping index in rollback for collection: " << nss << ", UUID: " << uuid
+ log() << "Dropping index in rollback for collection: " << *nss << ", UUID: " << uuid
<< ", index: " << indexName;
- dropIndex(opCtx, indexCatalog, indexName, nss);
+ dropIndex(opCtx, indexCatalog, indexName, *nss);
- LOG(1) << "Dropped index in rollback for collection: " << nss << ", UUID: " << uuid
+ LOG(1) << "Dropped index in rollback for collection: " << *nss << ", UUID: " << uuid
<< ", index: " << indexName;
}
}
@@ -750,8 +751,9 @@ void rollbackDropIndexes(OperationContext* opCtx,
UUID uuid,
std::map<std::string, BSONObj> indexNames) {
- NamespaceString nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(uuid);
- Lock::DBLock dbLock(opCtx, nss.db(), MODE_X);
+ boost::optional<NamespaceString> nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(uuid);
+ invariant(nss);
+ Lock::DBLock dbLock(opCtx, nss->db(), MODE_X);
Collection* collection = UUIDCatalog::get(opCtx).lookupCollectionByUUID(uuid);
// If we cannot find the collection, we skip over dropping the index.
if (!collection) {
@@ -768,17 +770,17 @@ void rollbackDropIndexes(OperationContext* opCtx,
// renameCollection command has occurred, changing the namespace of the
// collection from what it initially was during the creation of this index.
BSONObjBuilder updatedNss;
- updatedNss.append("ns", nss.ns());
+ updatedNss.append("ns", nss->ns());
BSONObj updatedNssObj = updatedNss.obj();
indexSpec = indexSpec.addField(updatedNssObj.firstElement());
- log() << "Creating index in rollback for collection: " << nss << ", UUID: " << uuid
+ log() << "Creating index in rollback for collection: " << *nss << ", UUID: " << uuid
<< ", index: " << indexName;
- createIndexForApplyOps(opCtx, indexSpec, nss, {}, OplogApplication::Mode::kRecovering);
+ createIndexForApplyOps(opCtx, indexSpec, *nss, {}, OplogApplication::Mode::kRecovering);
- LOG(1) << "Created index in rollback for collection: " << nss << ", UUID: " << uuid
+ LOG(1) << "Created index in rollback for collection: " << *nss << ", UUID: " << uuid
<< ", index: " << indexName;
}
}
@@ -1049,18 +1051,23 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
invariant(!doc._id.eoo()); // This is checked when we insert to the set.
UUID uuid = doc.uuid;
- NamespaceString nss = catalog.lookupNSSByUUID(uuid);
+ boost::optional<NamespaceString> nss = catalog.lookupNSSByUUID(uuid);
try {
- LOG(2) << "Refetching document, collection: " << nss << ", UUID: " << uuid << ", "
- << redact(doc._id);
+ if (nss) {
+ LOG(2) << "Refetching document, collection: " << *nss << ", UUID: " << uuid << ", "
+ << redact(doc._id);
+ } else {
+ LOG(2) << "Refetching document, UUID: " << uuid << ", " << redact(doc._id);
+ }
// TODO : Slow. Lots of round trips.
numFetched++;
BSONObj good;
NamespaceString resNss;
- std::tie(good, resNss) =
- rollbackSource.findOneByUUID(nss.db().toString(), uuid, doc._id.wrap());
+
+ std::string dbName = nss ? nss->db().toString() : "";
+ std::tie(good, resNss) = rollbackSource.findOneByUUID(dbName, uuid, doc._id.wrap());
// To prevent inconsistencies in the transactions collection, rollback fails if the UUID
// of the collection is different on the sync source than on the node rolling back,
@@ -1159,20 +1166,20 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
invariant(!fixUpInfo.collectionsToRename.count(uuid));
invariant(!fixUpInfo.collectionsToResyncMetadata.count(uuid));
- NamespaceString nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(uuid);
+ boost::optional<NamespaceString> nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(uuid);
// Do not attempt to acquire the database lock with an empty namespace. We should survive
// an attempt to drop a non-existent collection.
- if (nss.isEmpty()) {
+ if (!nss) {
log() << "This collection does not exist, UUID: " << uuid;
} else {
- log() << "Dropping collection: " << nss << ", UUID: " << uuid;
- AutoGetDb dbLock(opCtx, nss.db(), MODE_X);
+ log() << "Dropping collection: " << *nss << ", UUID: " << uuid;
+ AutoGetDb dbLock(opCtx, nss->db(), MODE_X);
Database* db = dbLock.getDb();
if (db) {
Collection* collection = UUIDCatalog::get(opCtx).lookupCollectionByUUID(uuid);
- dropCollection(opCtx, nss, collection, db);
- LOG(1) << "Dropped collection: " << nss << ", UUID: " << uuid;
+ dropCollection(opCtx, *nss, collection, db);
+ LOG(1) << "Dropped collection: " << *nss << ", UUID: " << uuid;
}
}
}
@@ -1217,14 +1224,15 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
// occurs and then the collection is dropped. If we do not first re-create the
// collection, we will not be able to retrieve the collection's catalog entries.
for (auto uuid : fixUpInfo.collectionsToResyncMetadata) {
- NamespaceString nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(uuid);
+ boost::optional<NamespaceString> nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(uuid);
+ invariant(nss);
- log() << "Resyncing collection metadata for collection: " << nss << ", UUID: " << uuid;
+ log() << "Resyncing collection metadata for collection: " << *nss << ", UUID: " << uuid;
- Lock::DBLock dbLock(opCtx, nss.db(), MODE_X);
+ Lock::DBLock dbLock(opCtx, nss->db(), MODE_X);
auto databaseHolder = DatabaseHolder::get(opCtx);
- auto db = databaseHolder->openDb(opCtx, nss.db().toString());
+ auto db = databaseHolder->openDb(opCtx, nss->db().toString());
invariant(db);
Collection* collection = UUIDCatalog::get(opCtx).lookupCollectionByUUID(uuid);
@@ -1232,7 +1240,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
auto cce = collection->getCatalogEntry();
- auto infoResult = rollbackSource.getCollectionInfoByUUID(nss.db().toString(), uuid);
+ auto infoResult = rollbackSource.getCollectionInfoByUUID(nss->db().toString(), uuid);
if (!infoResult.isOK()) {
// The collection was dropped by the sync source so we can't correctly change it
@@ -1240,8 +1248,8 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
// is rolled back upstream and we restart, we expect to still have the
// collection.
- log() << nss.ns() << " not found on remote host, so we do not roll back collmod "
- "operation. Instead, we will drop the collection soon.";
+ log() << nss->ns() << " not found on remote host, so we do not roll back collmod "
+ "operation. Instead, we will drop the collection soon.";
continue;
}
@@ -1287,7 +1295,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
opCtx, options.validator, options.validationLevel, options.validationAction);
if (!validatorStatus.isOK()) {
throw RSFatalException(
- str::stream() << "Failed to update validator for " << nss.toString() << " ("
+ str::stream() << "Failed to update validator for " << nss->toString() << " ("
<< uuid
<< ") with "
<< redact(info)
@@ -1297,7 +1305,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
wuow.commit();
- LOG(1) << "Resynced collection metadata for collection: " << nss << ", UUID: " << uuid
+ LOG(1) << "Resynced collection metadata for collection: " << *nss << ", UUID: " << uuid
<< ", with: " << redact(info)
<< ", to: " << redact(cce->getCollectionOptions(opCtx).toBSON());
}
@@ -1334,12 +1342,15 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
unique_ptr<RemoveSaver> removeSaver;
invariant(!fixUpInfo.collectionsToDrop.count(uuid));
- NamespaceString nss = catalog.lookupNSSByUUID(uuid);
+ boost::optional<NamespaceString> nss = catalog.lookupNSSByUUID(uuid);
+ if (!nss) {
+ nss = NamespaceString();
+ }
if (RollbackImpl::shouldCreateDataFiles()) {
- removeSaver = std::make_unique<RemoveSaver>("rollback", "", nss.ns());
+ removeSaver = std::make_unique<RemoveSaver>("rollback", "", nss->ns());
log() << "Preparing to write deleted documents to a rollback file for collection "
- << nss << " with uuid " << uuid.toString() << " to "
+ << *nss << " with uuid " << uuid.toString() << " to "
<< removeSaver->file().generic_string();
}
@@ -1374,16 +1385,16 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
if (found) {
auto status = removeSaver->goingToDelete(obj);
if (!status.isOK()) {
- severe() << "Rollback cannot write document in namespace " << nss.ns()
+ severe() << "Rollback cannot write document in namespace " << nss->ns()
<< " to archive file: " << redact(status);
throw RSFatalException(str::stream()
<< "Rollback cannot write document in namespace "
- << nss.ns()
+ << nss->ns()
<< " to archive file.");
}
} else {
error() << "Rollback cannot find object: " << pattern << " in namespace "
- << nss.ns();
+ << nss->ns();
}
}
@@ -1409,7 +1420,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
const auto findOneStart = clock->now();
RecordId loc = Helpers::findOne(opCtx, collection, pattern, false);
if (clock->now() - findOneStart > Milliseconds(200))
- warning() << "Roll back slow no _id index for " << nss.ns()
+ warning() << "Roll back slow no _id index for " << nss->ns()
<< " perhaps?";
// Would be faster but requires index:
// RecordId loc = Helpers::findById(nsd, pattern);
@@ -1444,7 +1455,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
// eventually.
warning() << "Ignoring failure to roll back change to capped "
- << "collection " << nss.ns() << " with _id "
+ << "collection " << nss->ns() << " with _id "
<< redact(idAndDoc.first._id.toString(
/*includeFieldName*/ false))
<< ": " << redact(e);
@@ -1452,7 +1463,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
} else {
deleteObjects(opCtx,
collection,
- nss,
+ *nss,
pattern,
true, // justOne
true); // god
@@ -1465,7 +1476,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
// TODO faster...
updates++;
- UpdateRequest request(nss);
+ UpdateRequest request(*nss);
request.setQuery(pattern);
request.setUpdateModification(idAndDoc.second);
@@ -1475,8 +1486,8 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
update(opCtx, ctx.db(), request);
}
} catch (const DBException& e) {
- log() << "Exception in rollback ns:" << nss.ns() << ' ' << pattern.toString() << ' '
- << redact(e) << " ndeletes:" << deletes;
+ log() << "Exception in rollback ns:" << nss->ns() << ' ' << pattern.toString()
+ << ' ' << redact(e) << " ndeletes:" << deletes;
throw;
}
}
diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp
index b902ecb6af5..ed9ebf77454 100644
--- a/src/mongo/db/repl/sync_tail.cpp
+++ b/src/mongo/db/repl/sync_tail.cpp
@@ -223,8 +223,8 @@ NamespaceString parseUUIDOrNs(OperationContext* opCtx, const OplogEntry& oplogEn
auto nss = catalog.lookupNSSByUUID(uuid);
uassert(ErrorCodes::NamespaceNotFound,
str::stream() << "No namespace with UUID " << uuid.toString(),
- !nss.isEmpty());
- return nss;
+ nss);
+ return *nss;
}
NamespaceStringOrUUID getNsOrUUID(const NamespaceString& nss, const BSONObj& op) {