summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorHaley Connelly <haley.connelly@mongodb.com>2020-08-12 18:58:21 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-08-17 19:13:31 +0000
commite2cb34fa34829370153fe207950f8c74dea45826 (patch)
treee0967657072075024596b3d3ea22763b31ef9552 /src/mongo/db
parent56b83070a83b2bf134a54063b27c2b48b22dd852 (diff)
downloadmongo-e2cb34fa34829370153fe207950f8c74dea45826.tar.gz
SERVER-49915 Disable document validation for <database>.system.resharding.* namespaces
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/catalog/collection_impl.cpp13
-rw-r--r--src/mongo/db/catalog/create_collection_test.cpp25
2 files changed, 38 insertions, 0 deletions
diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp
index ebeb5af4c3b..30520fe8a54 100644
--- a/src/mongo/db/catalog/collection_impl.cpp
+++ b/src/mongo/db/catalog/collection_impl.cpp
@@ -206,6 +206,12 @@ Status checkValidatorCanBeUsedOnNs(const BSONObj& validator,
if (validator.isEmpty())
return Status::OK();
+ if (nss.isTemporaryReshardingCollection()) {
+ // In resharding, if the user's original collection has a validator, then the temporary
+ // resharding collection is created with it as well.
+ return Status::OK();
+ }
+
if (nss.isSystem() && !nss.isDropPendingNamespace()) {
return {ErrorCodes::InvalidOptions,
str::stream() << "Document validators not allowed on system collection " << nss
@@ -384,6 +390,13 @@ Status CollectionImpl::checkValidation(OperationContext* opCtx, const BSONObj& d
if (documentValidationDisabled(opCtx))
return Status::OK();
+ if (ns().isTemporaryReshardingCollection()) {
+ // In resharding, the donor shard primary is responsible for performing document validation
+ // and the recipient should not perform validation on documents inserted into the temporary
+ // resharding collection.
+ return Status::OK();
+ }
+
if (validatorMatchExpr->matchesBSON(document))
return Status::OK();
diff --git a/src/mongo/db/catalog/create_collection_test.cpp b/src/mongo/db/catalog/create_collection_test.cpp
index ea9bc5c02a5..cef79c84a45 100644
--- a/src/mongo/db/catalog/create_collection_test.cpp
+++ b/src/mongo/db/catalog/create_collection_test.cpp
@@ -271,4 +271,29 @@ TEST_F(CreateCollectionTest, ValidationOptions) {
validateValidator("{$expr: {$_internalJsEmit: {eval: 'function() {}', this: {}}}}", 4660801);
validateValidator("{$where: 'this.a == this.b'}", static_cast<int>(ErrorCodes::BadValue));
}
+
+// Tests that validator validation is disabled when inserting a document into a
+// <database>.system.resharding.* collection. The primary donor is responsible for validating
+// documents before they are inserted into the recipient's temporary resharding collection.
+TEST_F(CreateCollectionTest, ValidationDisabledForTemporaryReshardingCollection) {
+ NamespaceString reshardingNss("myDb", "system.resharding.yay");
+ auto opCtx = makeOpCtx();
+
+ Lock::GlobalLock lk(opCtx.get(), MODE_X); // Satisfy low-level locking invariants.
+ BSONObj createCmdObj = BSON("create" << reshardingNss.coll() << "validator" << BSON("a" << 5));
+ ASSERT_OK(createCollection(opCtx.get(), reshardingNss.db().toString(), createCmdObj));
+ ASSERT_TRUE(collectionExists(opCtx.get(), reshardingNss));
+
+ AutoGetCollection agc(opCtx.get(), reshardingNss, MODE_X);
+ Collection* collection = agc.getCollection();
+
+ WriteUnitOfWork wuow(opCtx.get());
+ // Ensure a document that violates validator criteria can be inserted into the temporary
+ // resharding collection.
+ auto insertObj = fromjson("{'_id':2, a:1}");
+ auto status =
+ collection->insertDocument(opCtx.get(), InsertStatement(insertObj), nullptr, false);
+ ASSERT_OK(status);
+}
+
} // namespace