summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjannaerin <golden.janna@gmail.com>2018-03-01 11:33:36 -0500
committerjannaerin <golden.janna@gmail.com>2018-03-06 15:47:13 -0500
commit5da505eb1c4f81cbaa22860fd2a9453f10e81a62 (patch)
tree32160f637fe6340b5e85b61ae7679bcea722388a
parent1365c273c4b1aab22f70750963a910332a0db992 (diff)
downloadmongo-5da505eb1c4f81cbaa22860fd2a9453f10e81a62.tar.gz
SERVER-33516 Make _configsvrCreateCollection take the db distlock to prevent conncurrent movePrimary
-rw-r--r--jstests/concurrency/fsm_workloads/view_catalog.js13
-rw-r--r--jstests/concurrency/fsm_workloads/view_catalog_cycle_with_drop.js13
-rw-r--r--src/mongo/db/s/config/configsvr_create_collection_command.cpp14
3 files changed, 35 insertions, 5 deletions
diff --git a/jstests/concurrency/fsm_workloads/view_catalog.js b/jstests/concurrency/fsm_workloads/view_catalog.js
index 31ed0072bb3..ebb44905bf4 100644
--- a/jstests/concurrency/fsm_workloads/view_catalog.js
+++ b/jstests/concurrency/fsm_workloads/view_catalog.js
@@ -79,9 +79,18 @@ var $config = (function() {
dropCollections(db, pattern);
}
+ // This test performs createCollection concurrently from many threads, and createCollection on a
+ // sharded cluster takes a distributed lock. Since a distributed lock is acquired by repeatedly
+ // attempting to grab the lock every half second for 20 seconds (a max of 40 attempts), it's
+ // possible that some thread will be starved by the other threads and fail to grab the lock
+ // after 40 attempts. To reduce the likelihood of this, we choose threadCount and iterations so
+ // that threadCount * iterations < 40.
+ // The threadCount and iterations can be increased once PM-697 ("Remove all usages of
+ // distributed lock") is complete.
+
return {
- threadCount: 10,
- iterations: 100,
+ threadCount: 5,
+ iterations: 5,
data: data,
states: states,
transitions: transitions,
diff --git a/jstests/concurrency/fsm_workloads/view_catalog_cycle_with_drop.js b/jstests/concurrency/fsm_workloads/view_catalog_cycle_with_drop.js
index f5d82b98fb6..9768ec7dee5 100644
--- a/jstests/concurrency/fsm_workloads/view_catalog_cycle_with_drop.js
+++ b/jstests/concurrency/fsm_workloads/view_catalog_cycle_with_drop.js
@@ -97,9 +97,18 @@ var $config = (function() {
dropCollections(db, pattern);
}
+ // This test performs createCollection concurrently from many threads, and createCollection on a
+ // sharded cluster takes a distributed lock. Since a distributed lock is acquired by repeatedly
+ // attempting to grab the lock every half second for 20 seconds (a max of 40 attempts), it's
+ // possible that some thread will be starved by the other threads and fail to grab the lock
+ // after 40 attempts. To reduce the likelihood of this, we choose threadCount and iterations so
+ // that threadCount * iterations < 40.
+ // The threadCount and iterations can be increased once PM-697 ("Remove all usages of
+ // distributed lock") is complete.
+
return {
- threadCount: 10,
- iterations: 100,
+ threadCount: 5,
+ iterations: 5,
data: data,
states: states,
startState: 'readFromView',
diff --git a/src/mongo/db/s/config/configsvr_create_collection_command.cpp b/src/mongo/db/s/config/configsvr_create_collection_command.cpp
index 7eba3758208..8745aeff00a 100644
--- a/src/mongo/db/s/config/configsvr_create_collection_command.cpp
+++ b/src/mongo/db/s/config/configsvr_create_collection_command.cpp
@@ -88,8 +88,12 @@ public:
return Status::OK();
}
+ std::string parseNs(const std::string& dbname, const BSONObj& cmdObj) const override {
+ return CommandHelpers::parseNsFullyQualified(dbname, cmdObj);
+ }
+
bool run(OperationContext* opCtx,
- const std::string& dbname,
+ const std::string& dbname_unused,
const BSONObj& cmdObj,
BSONObjBuilder& result) override {
@@ -113,6 +117,14 @@ public:
uassertStatusOK(options.parse(*requestOptions));
}
+ auto const catalogClient = Grid::get(opCtx)->catalogClient();
+ const NamespaceString nss(parseNs(dbname_unused, cmdObj));
+
+ auto dbDistLock = uassertStatusOK(catalogClient->getDistLockManager()->lock(
+ opCtx, nss.db(), "createCollection", DistLockManager::kDefaultLockTimeout));
+ auto collDistLock = uassertStatusOK(catalogClient->getDistLockManager()->lock(
+ opCtx, nss.ns(), "createCollection", DistLockManager::kDefaultLockTimeout));
+
ShardingCatalogManager::get(opCtx)->createCollection(opCtx, createCmd.getNs(), options);
return true;