summaryrefslogtreecommitdiff
path: root/src/mongo/util
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2017-06-15 00:20:33 -0400
committerGeert Bosch <geert@mongodb.com>2017-06-23 15:11:09 -0400
commita69ae445303fc4821c6745866b3902623a385c1c (patch)
tree177cab03d8078defe675fd0dff15349cc32401c0 /src/mongo/util
parent3bb0f6030b5609002049ea2156e97fe4c6c05d5d (diff)
downloadmongo-a69ae445303fc4821c6745866b3902623a385c1c.tar.gz
SERVER-27992 Use UUIDs for replication
Diffstat (limited to 'src/mongo/util')
-rw-r--r--src/mongo/util/SConscript39
-rw-r--r--src/mongo/util/namespace_uuid_cache.cpp63
-rw-r--r--src/mongo/util/namespace_uuid_cache.h85
-rw-r--r--src/mongo/util/namespace_uuid_cache_test.cpp61
-rw-r--r--src/mongo/util/uuid.cpp4
-rw-r--r--src/mongo/util/uuid.h15
-rw-r--r--src/mongo/util/uuid_catalog.cpp83
-rw-r--r--src/mongo/util/uuid_catalog.h85
-rw-r--r--src/mongo/util/uuid_catalog_test.cpp97
9 files changed, 14 insertions, 518 deletions
diff --git a/src/mongo/util/SConscript b/src/mongo/util/SConscript
index 2bb79104f3c..604743801c4 100644
--- a/src/mongo/util/SConscript
+++ b/src/mongo/util/SConscript
@@ -101,26 +101,9 @@ env.Library(
target='uuid',
source=[
'uuid.cpp',
- 'namespace_uuid_cache.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
- '$BUILD_DIR/mongo/db/catalog/collection',
- '$BUILD_DIR/mongo/util/decorable',
- '$BUILD_DIR/third_party/murmurhash3/murmurhash3',
- ],
-)
-
-env.Library(
- target='uuid_catalog',
- source=[
- 'uuid_catalog.cpp'
- ],
- LIBDEPS=[
- 'uuid',
- '$BUILD_DIR/mongo/base',
- '$BUILD_DIR/mongo/db/catalog/collection',
- '$BUILD_DIR/mongo/db/namespace_string',
'$BUILD_DIR/mongo/util/decorable',
'$BUILD_DIR/third_party/murmurhash3/murmurhash3',
],
@@ -137,28 +120,6 @@ env.CppUnitTest(
],
)
-env.CppUnitTest(
- target='namespace_uuid_cache_test',
- source=[
- 'namespace_uuid_cache_test.cpp'
- ],
- LIBDEPS=[
- 'uuid',
- ],
-)
-
-env.CppUnitTest(
- target='uuid_catalog_test',
- source=[
- 'uuid_catalog_test.cpp',
- ],
- LIBDEPS=[
- 'uuid_catalog',
- 'uuid',
- '$BUILD_DIR/mongo/db/service_context',
- ]
- )
-
env.Library(
target='summation',
source=[
diff --git a/src/mongo/util/namespace_uuid_cache.cpp b/src/mongo/util/namespace_uuid_cache.cpp
deleted file mode 100644
index 59e40b73166..00000000000
--- a/src/mongo/util/namespace_uuid_cache.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * Copyright (C) 2017 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#include "namespace_uuid_cache.h"
-
-#include "mongo/util/assert_util.h"
-
-namespace mongo {
-
-const OperationContext::Decoration<NamespaceUUIDCache> NamespaceUUIDCache::get =
- OperationContext::declareDecoration<NamespaceUUIDCache>();
-
-void NamespaceUUIDCache::ensureNamespaceInCache(const NamespaceString& nss, CollectionUUID uuid) {
- StringData ns(nss.ns());
- CollectionUUIDMap::const_iterator it = _cache.find(ns);
- if (it == _cache.end()) {
- // Add ns, uuid pair to the cache if it does not yet exist.
- invariant(_cache.try_emplace(ns, uuid).second == true);
- } else {
- // If ns exists in the cache, make sure it does not correspond to another uuid.
- uassert(40418,
- "Cannot continue operation on namespace " + ns + ": it now resolves " +
- uuid.toString() + " instead of " + it->second.toString(),
- it->second == uuid);
- }
-}
-void NamespaceUUIDCache::onDropCollection(const NamespaceString& nss) {
- _evictNamespace(nss);
-}
-
-void NamespaceUUIDCache::onRenameCollection(const NamespaceString& nss) {
- _evictNamespace(nss);
-}
-
-void NamespaceUUIDCache::_evictNamespace(const NamespaceString& nss) {
- invariant(_cache.erase(nss.ns()) <= 1);
-}
-} // namespace mongo
diff --git a/src/mongo/util/namespace_uuid_cache.h b/src/mongo/util/namespace_uuid_cache.h
deleted file mode 100644
index 10f4bd75206..00000000000
--- a/src/mongo/util/namespace_uuid_cache.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * Copyright (C) 2017 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-#include "mongo/base/disallow_copying.h"
-#include "mongo/db/catalog/collection_options.h"
-#include "mongo/db/operation_context.h"
-#include "mongo/util/string_map.h"
-#include "mongo/util/uuid.h"
-
-namespace mongo {
-
-/**
- * This class comprises the NamespaceString to UUID cache that prevents given namespaces
- * from resolving to multiple UUIDs.
- */
-using CollectionUUID = UUID;
-
-class NamespaceUUIDCache {
- MONGO_DISALLOW_COPYING(NamespaceUUIDCache);
-
-public:
- static const OperationContext::Decoration<NamespaceUUIDCache> get;
- NamespaceUUIDCache() = default;
-
- /**
- * This function adds the pair nss.ns(), uuid to the namespace uuid cache
- * if it does not yet exist. If nss.ns() already exists in the cache with
- * a different uuid, a UserException is thrown, so we can guarantee that
- * an operation will always resolve the same name to the same collection,
- * even in presence of drops and renames.
- */
- void ensureNamespaceInCache(const NamespaceString& nss, CollectionUUID uuid);
-
- /**
- * This function removes the entry for nss.ns() from the namespace uuid
- * cache. Does nothing if the entry doesn't exist. It is called via the
- * op observer when a collection is dropped.
- */
- void onDropCollection(const NamespaceString& nss);
-
- /**
- * This function removes the entry for nss.ns() from the namespace uuid
- * cache. Does nothing if the entry doesn't exist. It is called via the
- * op observer when a collection is renamed.
- */
- void onRenameCollection(const NamespaceString& nss);
-
-private:
- /**
- * This function removes the entry for nss.ns() from the namespace uuid
- * cache. Does nothing if the entry doesn't exist.
- */
- void _evictNamespace(const NamespaceString& nss);
- using CollectionUUIDMap = StringMap<CollectionUUID>;
- CollectionUUIDMap _cache;
-};
-
-} // namespace mongo
diff --git a/src/mongo/util/namespace_uuid_cache_test.cpp b/src/mongo/util/namespace_uuid_cache_test.cpp
deleted file mode 100644
index 7834dcb4968..00000000000
--- a/src/mongo/util/namespace_uuid_cache_test.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * Copyright (C) 2017 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#include "mongo/util/namespace_uuid_cache.h"
-
-#include "mongo/unittest/unittest.h"
-
-using namespace mongo;
-
-namespace {
-
-TEST(NamespaceUUIDCache, ensureNamespaceInCache) {
- NamespaceUUIDCache cache;
- CollectionUUID uuid = CollectionUUID::gen();
- CollectionUUID uuidConflict = CollectionUUID::gen();
- NamespaceString nss("test", "test_collection_ns");
- // Add nss, uuid to cache.
- cache.ensureNamespaceInCache(nss, uuid);
- // Do nothing if we query for existing nss, uuid pairing.
- cache.ensureNamespaceInCache(nss, uuid);
- // Uassert if we query for existing nss and uuid that does not match.
- ASSERT_THROWS(cache.ensureNamespaceInCache(nss, uuidConflict), UserException);
-}
-
-TEST(NamespaceUUIDCache, onDropCollection) {
- NamespaceUUIDCache cache;
- CollectionUUID uuid = CollectionUUID::gen();
- CollectionUUID newUuid = CollectionUUID::gen();
- NamespaceString nss("test", "test_collection_ns");
- cache.ensureNamespaceInCache(nss, uuid);
- cache.onDropCollection(nss);
- // Add nss to the cache with a different uuid. This should not throw since
- // we evicted the previous entry from the cache.
- cache.ensureNamespaceInCache(nss, newUuid);
-}
-} // namespace
diff --git a/src/mongo/util/uuid.cpp b/src/mongo/util/uuid.cpp
index 3c041e64010..fdd0798abb1 100644
--- a/src/mongo/util/uuid.cpp
+++ b/src/mongo/util/uuid.cpp
@@ -91,6 +91,10 @@ bool UUID::isUUIDString(const std::string& s) {
return std::regex_match(s, uuidRegex);
}
+bool UUID::isRFC4122v4() const {
+ return (_uuid[6] & ~0x0f) == 0x40 && (_uuid[8] & ~0x3f) == 0x80; // See RFC 4122, section 4.4.
+}
+
UUID UUID::gen() {
int64_t randomWords[2];
diff --git a/src/mongo/util/uuid.h b/src/mongo/util/uuid.h
index 9e1caa88b6c..0049fe9b665 100644
--- a/src/mongo/util/uuid.h
+++ b/src/mongo/util/uuid.h
@@ -64,7 +64,7 @@ public:
static constexpr int kNumBytes = sizeof(UUIDStorage);
/**
- * Generate a new random v4 UUID per RFC 4122.
+ * Generates a new random v4 UUID per RFC 4122.
*/
static UUID gen();
@@ -81,7 +81,7 @@ public:
static StatusWith<UUID> parse(BSONElement from);
/**
- * Parse a BSON document of the form { uuid: BinData(4, "...") }.
+ * Parses a BSON document of the form { uuid: BinData(4, "...") }.
*
* For IDL.
*/
@@ -107,17 +107,17 @@ public:
}
/**
- * Append to builder as BinData(4, "...") element with the given name.
+ * Appends to builder as BinData(4, "...") element with the given name.
*/
void appendToBuilder(BSONObjBuilder* builder, StringData name) const;
/**
- * Return a BSON object of the form { uuid: BinData(4, "...") }.
+ * Returns a BSON object of the form { uuid: BinData(4, "...") }.
*/
BSONObj toBSON() const;
/**
- * Return a string representation of this UUID, in hexadecimal,
+ * Returns a string representation of this UUID, in hexadecimal,
* as per RFC 4122:
*
* 4 Octets - 2 Octets - 2 Octets - 2 Octets - 6 Octets
@@ -133,6 +133,11 @@ public:
}
/**
+ * Returns true only if the UUID is the RFC 4122 variant, v4 (random).
+ */
+ bool isRFC4122v4() const;
+
+ /**
* Custom hasher so UUIDs can be used in unordered data structures.
*
* ex: std::unordered_set<UUID, UUID::Hash> uuidSet;
diff --git a/src/mongo/util/uuid_catalog.cpp b/src/mongo/util/uuid_catalog.cpp
deleted file mode 100644
index a73b1288b7a..00000000000
--- a/src/mongo/util/uuid_catalog.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
- * Copyright (C) 2017 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kStorage
-
-#include "mongo/platform/basic.h"
-
-#include "uuid_catalog.h"
-
-#include "mongo/db/storage/recovery_unit.h"
-#include "mongo/util/log.h"
-#include "mongo/util/uuid.h"
-
-namespace mongo {
-
-const ServiceContext::Decoration<UUIDCatalog> UUIDCatalog::get =
- ServiceContext::declareDecoration<UUIDCatalog>();
-
-void UUIDCatalog::onCreateCollection(OperationContext* opCtx,
- Collection* coll,
- CollectionUUID uuid) {
- _registerUUIDCatalogEntry(uuid, coll);
- opCtx->recoveryUnit()->onRollback([this, uuid] { _removeUUIDCatalogEntry(uuid); });
-}
-
-Collection* UUIDCatalog::lookupCollectionByUUID(CollectionUUID uuid) const {
- stdx::lock_guard<stdx::mutex> lock(_catalogLock);
- auto foundIt = _catalog.find(uuid);
- return foundIt == _catalog.end() ? nullptr : foundIt->second;
-}
-
-NamespaceString UUIDCatalog::lookupNSSByUUID(CollectionUUID uuid) const {
- stdx::lock_guard<stdx::mutex> lock(_catalogLock);
- auto foundIt = _catalog.find(uuid);
- return foundIt == _catalog.end() ? NamespaceString() : foundIt->second->ns();
-}
-
-void UUIDCatalog::onDropCollection(OperationContext* opCtx, CollectionUUID uuid) {
- Collection* foundCol = _removeUUIDCatalogEntry(uuid);
- opCtx->recoveryUnit()->onRollback(
- [this, foundCol, uuid] { _registerUUIDCatalogEntry(uuid, foundCol); });
-}
-
-void UUIDCatalog::_registerUUIDCatalogEntry(CollectionUUID uuid, Collection* coll) {
- stdx::lock_guard<stdx::mutex> lock(_catalogLock);
- if (coll) {
- std::pair<CollectionUUID, Collection*> entry = std::make_pair(uuid, coll);
- LOG(2) << "registering collection " << coll->ns() << " as having UUID " << uuid.toString();
- invariant(_catalog.insert(entry).second);
- }
-}
-
-Collection* UUIDCatalog::_removeUUIDCatalogEntry(CollectionUUID uuid) {
- stdx::lock_guard<stdx::mutex> lock(_catalogLock);
- Collection* foundCol = _catalog[uuid];
- invariant(_catalog.erase(uuid) <= 1);
- return foundCol;
-}
-} // namespace mongo
diff --git a/src/mongo/util/uuid_catalog.h b/src/mongo/util/uuid_catalog.h
deleted file mode 100644
index 6f532745ba7..00000000000
--- a/src/mongo/util/uuid_catalog.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * Copyright (C) 2017 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-#include <unordered_map>
-
-#include "mongo/base/disallow_copying.h"
-#include "mongo/db/catalog/collection.h"
-#include "mongo/db/service_context.h"
-#include "mongo/util/uuid.h"
-
-namespace mongo {
-
-/**
- * This class comprises a UUID to collection catalog, allowing for efficient
- * collection lookup by UUID.
- */
-using CollectionUUID = UUID;
-
-class UUIDCatalog {
- MONGO_DISALLOW_COPYING(UUIDCatalog);
-
-public:
- static const ServiceContext::Decoration<UUIDCatalog> get;
- UUIDCatalog() = default;
-
- /* This function inserts the entry for uuid, coll into the UUID
- * Collection. It is called by the op observer when a collection
- * is created.
- */
- void onCreateCollection(OperationContext* opCtx, Collection* coll, CollectionUUID uuid);
-
- /* This function gets the Collection* pointer that corresponds to
- * CollectionUUID uuid. The required locks should be obtained prior
- * to calling this function, or else the found Collection pointer
- * might no longer be valid when the call returns.
- */
- Collection* lookupCollectionByUUID(CollectionUUID uuid) 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.
- */
- NamespaceString lookupNSSByUUID(CollectionUUID uuid) const;
-
- /* This function removes the entry for uuid from the UUID catalog. It
- * is called by the op observer when a collection is dropped.
- */
- void onDropCollection(OperationContext* opCtx, CollectionUUID uuid);
-
-private:
- mutable mongo::stdx::mutex _catalogLock;
- mongo::stdx::unordered_map<CollectionUUID, Collection*, CollectionUUID::Hash> _catalog;
-
- void _registerUUIDCatalogEntry(CollectionUUID uuid, Collection* coll);
- Collection* _removeUUIDCatalogEntry(CollectionUUID uuid);
-};
-
-} // namespace mongo
diff --git a/src/mongo/util/uuid_catalog_test.cpp b/src/mongo/util/uuid_catalog_test.cpp
deleted file mode 100644
index 65720343f45..00000000000
--- a/src/mongo/util/uuid_catalog_test.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- * Copyright (C) 2017 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#include "mongo/util/uuid_catalog.h"
-
-#include "mongo/db/catalog/collection_mock.h"
-#include "mongo/db/operation_context_noop.h"
-#include "mongo/unittest/unittest.h"
-
-using namespace mongo;
-
-/**
- * A test fixture that creates a UUID Catalog and Collection* pointer to store in it.
- */
-class UUIDCatalogTest : public unittest::Test {
-public:
- UUIDCatalogTest()
- : uuid(CollectionUUID::gen()),
- nss("testdb", "testcol"),
- col(stdx::make_unique<CollectionMock>(nss)) {
- // Register dummy collection in catalog.
- catalog.onCreateCollection(&opCtx, &col, uuid);
- }
-
-protected:
- UUIDCatalog catalog;
- OperationContextNoop opCtx;
- CollectionUUID uuid;
- NamespaceString nss;
- Collection col;
-};
-
-namespace {
-
-TEST_F(UUIDCatalogTest, onCreateCollection) {
- ASSERT(catalog.lookupCollectionByUUID(uuid) == &col);
-}
-
-TEST_F(UUIDCatalogTest, lookupCollectionByUUID) {
- // Ensure the string value of the NamespaceString of the obtained Collection is equal to
- // nss.ns().
- ASSERT_EQUALS(catalog.lookupCollectionByUUID(uuid)->ns().ns(), nss.ns());
- // Ensure lookups of unknown UUIDs result in null pointers.
- ASSERT(catalog.lookupCollectionByUUID(CollectionUUID::gen()) == nullptr);
-}
-
-TEST_F(UUIDCatalogTest, lookupNSSByUUID) {
- // Ensure the string value of the obtained NamespaceString is equal to nss.ns().
- ASSERT_EQUALS(catalog.lookupNSSByUUID(uuid).ns(), nss.ns());
- // Ensure namespace lookups of unknown UUIDs result in empty NamespaceStrings.
- ASSERT_EQUALS(catalog.lookupNSSByUUID(CollectionUUID::gen()).ns(), NamespaceString().ns());
-}
-
-TEST_F(UUIDCatalogTest, insertAfterLookup) {
- auto newUUID = CollectionUUID::gen();
- NamespaceString newNss(nss.db(), "newcol");
- Collection newCol(stdx::make_unique<CollectionMock>(newNss));
-
- // 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());
- catalog.onCreateCollection(&opCtx, &newCol, newUUID);
- ASSERT_EQUALS(catalog.lookupCollectionByUUID(newUUID), &newCol);
- ASSERT_EQUALS(catalog.lookupNSSByUUID(uuid), nss);
-}
-
-TEST_F(UUIDCatalogTest, onDropCollection) {
- catalog.onDropCollection(&opCtx, uuid);
- // Ensure the lookup returns a null pointer upon removing the uuid entry.
- ASSERT(catalog.lookupCollectionByUUID(uuid) == nullptr);
-}
-} // namespace