summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2020-12-09 22:54:38 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-12-10 17:27:33 +0000
commitd1f0d546f21ff900d3a0b083006bf6a4b61657a8 (patch)
tree32a419076660ed9e5bb2847559ed327c07ea83a0
parent6dd2aee6bd51adcba6c34520b28d956379bf0a3d (diff)
downloadmongo-d1f0d546f21ff900d3a0b083006bf6a4b61657a8.tar.gz
SERVER-51333 setFeatureCompatibilityVersion fails when downgrading from FCV 4.4 to FCV 4.2 with long collection names present
-rw-r--r--jstests/multiVersion/long_collection_names.js33
-rw-r--r--src/mongo/db/commands/set_feature_compatibility_version_command.cpp21
2 files changed, 30 insertions, 24 deletions
diff --git a/jstests/multiVersion/long_collection_names.js b/jstests/multiVersion/long_collection_names.js
index d72b56b3dcf..b4e81634dc6 100644
--- a/jstests/multiVersion/long_collection_names.js
+++ b/jstests/multiVersion/long_collection_names.js
@@ -67,44 +67,29 @@ conn = MongoRunner.runMongod(restartOpts42);
assert.eq(null, conn, 'mongod was able to start with version ' + tojson(restartOpts42));
/**
- * Restart with the 4.4 binary to set the FCV to 4.2.
+ * Cannot downgrade to FCV 4.2 on a 4.4 binary when long collection names are present.
*/
let restartOpts44 = Object.extend(mongodOptions44, {restart: true});
conn = MongoRunner.runMongod(restartOpts44);
assert.neq(null, conn, 'mongod was unable to start with version ' + tojson(restartOpts44));
testDb = conn.getDB(dbName);
-assert.commandWorked(testDb.adminCommand({setFeatureCompatibilityVersion: lastStableFCV}));
-MongoRunner.stopMongod(conn);
+assert.commandFailedWithCode(testDb.adminCommand({setFeatureCompatibilityVersion: lastStableFCV}),
+ ErrorCodes.InvalidNamespace);
/**
- * Restart with the 4.2 binary while in FCV 4.2 with long collection names present. This shouldn't
- * crash the server.
+ * FCV can be set to 4.2 after removing the long collection name. However, we cannot create any new
+ * collections with long names in FCV 4.2.
*/
-conn = MongoRunner.runMongod(restartOpts42);
-assert.neq(null, conn, 'mongod was unable to start with version ' + tojson(restartOpts42));
-
testDb = conn.getDB(dbName);
+assert.eq(true, testDb.getCollection(longCollName).drop());
-// Ensure we have the proper collections.
-let collNames = testDb.getCollectionNames();
-
-assert.eq(true, collNames.includes(shortCollName));
-assert.eq(true, collNames.includes(longCollName));
-
-MongoRunner.stopMongod(conn);
-
-/**
- * Restart with the 4.4 binary while in FCV 4.2. We shouldn't be able to create any collections with
- * long names.
- */
-conn = MongoRunner.runMongod(restartOpts44);
-assert.neq(null, conn, 'mongod was unable to start with version ' + tojson(restartOpts44));
-
-testDb = conn.getDB(dbName);
+assert.commandWorked(testDb.adminCommand({setFeatureCompatibilityVersion: lastStableFCV}));
// Creating a long collection name on a 4.4 binary with FCV 4.2 should fail.
assert.commandFailedWithCode(testDb.createCollection('c'.repeat(8192)), 4862100);
+assert.commandFailedWithCode(testDb.createCollection(longCollName),
+ ErrorCodes.IncompatibleServerVersion);
// Running rename within the same database or across two databases should fail for long collection
// names.
diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
index 50815f25fa4..a4e63703057 100644
--- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
+++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/catalog/coll_mod.h"
+#include "mongo/db/catalog/collection_catalog_helper.h"
#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/commands.h"
@@ -349,6 +350,26 @@ public:
numIndexBuilds == 0U);
}
+ // Cannot downgrade to FCV 4.2 when long collection names are present.
+ const std::vector<std::string> dbNames = CollectionCatalog::get(opCtx).getAllDbNames();
+ for (const auto& dbName : dbNames) {
+ Lock::DBLock dbLock(opCtx, dbName, MODE_IS);
+ catalog::forEachCollectionFromDb(
+ opCtx, dbName, MODE_IS, [&](const Collection* collection) {
+ const auto collNss = collection->ns();
+ uassert(ErrorCodes::InvalidNamespace,
+ str::stream()
+ << "Cannot downgrade the cluster when there are long "
+ << "collection names present. FCV 4.2 limit: "
+ << NamespaceString::MaxNSCollectionLenFCV42
+ << ". Found: " << collNss
+ << ", but there may be more. Rename or drop the collection",
+ collNss.size() <= NamespaceString::MaxNSCollectionLenFCV42);
+ return true;
+ });
+ }
+
+
FeatureCompatibilityVersion::setTargetDowngrade(opCtx);
// Safe reconfig introduces a new "term" field in the config document. If the user tries