summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLingzhi Deng <lingzhi.deng@mongodb.com>2020-09-25 16:21:24 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-28 14:24:19 +0000
commit04c7ef38b5b7123de2910420dbc1918437a690fe (patch)
treeed20bc5b824bde2d04c3bb5c9c7ebea635a9f80f
parent56729130a2bf0d39463160162d684c1e21018966 (diff)
downloadmongo-04c7ef38b5b7123de2910420dbc1918437a690fe.tar.gz
SERVER-51154: Generate a new collection UUID for import
-rw-r--r--src/mongo/db/storage/durable_catalog_impl.cpp11
-rw-r--r--src/mongo/db/storage/kv/durable_catalog_test.cpp25
2 files changed, 20 insertions, 16 deletions
diff --git a/src/mongo/db/storage/durable_catalog_impl.cpp b/src/mongo/db/storage/durable_catalog_impl.cpp
index b5b35933a07..89ff840882d 100644
--- a/src/mongo/db/storage/durable_catalog_impl.cpp
+++ b/src/mongo/db/storage/durable_catalog_impl.cpp
@@ -913,13 +913,20 @@ StatusWith<DurableCatalog::ImportResult> DurableCatalogImpl::importCollection(
const BSONElement mdElement = metadata["md"];
uassert(ErrorCodes::BadValue, "Malformed catalog metadata", mdElement.isABSONObj());
md.parse(mdElement.Obj());
- uassert(ErrorCodes::BadValue, "Attempted to import collection without UUID", md.options.uuid);
uassert(ErrorCodes::BadValue,
"Attemped to import collection without idxIdent",
metadata.hasField("idxIdent"));
- StatusWith<Entry> swEntry = _importEntry(opCtx, nss, metadata);
+ // Generate a new UUID for the collection.
+ md.options.uuid = CollectionUUID::gen();
+ BSONObjBuilder catalogEntry;
+ // Generate a new "md" field after setting the new UUID.
+ catalogEntry.append("md", md.toBSON());
+ // Append the rest of the metadata.
+ catalogEntry.appendElementsUnique(metadata);
+
+ StatusWith<Entry> swEntry = _importEntry(opCtx, nss, catalogEntry.obj());
if (!swEntry.isOK())
return swEntry.getStatus();
Entry& entry = swEntry.getValue();
diff --git a/src/mongo/db/storage/kv/durable_catalog_test.cpp b/src/mongo/db/storage/kv/durable_catalog_test.cpp
index 1bbc54bb659..bc0e0a11f58 100644
--- a/src/mongo/db/storage/kv/durable_catalog_test.cpp
+++ b/src/mongo/db/storage/kv/durable_catalog_test.cpp
@@ -473,7 +473,6 @@ TEST_F(DurableCatalogTest, ImportCollection) {
md.ns = nss.ns();
- CollectionOptions options;
CollectionOptions optionsWithUUID;
optionsWithUUID.uuid = UUID::gen();
md.options = optionsWithUUID;
@@ -509,18 +508,10 @@ TEST_F(DurableCatalogTest, ImportCollection) {
AssertionException,
ErrorCodes::BadValue);
- // Import should fail with missing UUID from collection options.
- md.options = options;
- ASSERT_THROWS_CODE(importCollectionTest(nss,
- BSON("md" << md.toBSON() << "idxIdent" << idxIdentObj
- << "ns" << nss.ns() << "ident" << ident)),
- AssertionException,
- ErrorCodes::BadValue);
-
// Import should success with validate inputs.
- const auto validMetaData =
- BSON("md" << mdObj << "idxIdent" << idxIdentObj << "ns" << nss.ns() << "ident" << ident);
- auto swImportResult = importCollectionTest(nss, validMetaData);
+ auto swImportResult = importCollectionTest(
+ nss,
+ BSON("md" << mdObj << "idxIdent" << idxIdentObj << "ns" << nss.ns() << "ident" << ident));
ASSERT_OK(swImportResult.getStatus());
DurableCatalog::ImportResult importResult = std::move(swImportResult.getValue());
@@ -530,9 +521,15 @@ TEST_F(DurableCatalogTest, ImportCollection) {
ASSERT_EQ(entry.ident, ident);
ASSERT_EQ(getCatalog()->getIndexIdent(operationContext(), importResult.catalogId, "_id_"),
idxIdent);
+
+ // Test that a collection UUID is generated for import.
+ ASSERT_NE(optionsWithUUID.uuid.get(), importResult.uuid);
+ // Substitute in the generated UUID and check that the rest of fields in the catalog entry
+ // match.
+ md.options.uuid = importResult.uuid;
ASSERT_BSONOBJ_EQ(getCatalog()->getCatalogEntry(operationContext(), importResult.catalogId),
- validMetaData);
- ASSERT_EQ(optionsWithUUID.uuid.get(), importResult.uuid);
+ BSON("md" << md.toBSON() << "idxIdent" << idxIdentObj << "ns" << nss.ns()
+ << "ident" << ident));
}
} // namespace