summaryrefslogtreecommitdiff
path: root/src/mongo/s/config.cpp
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2016-08-09 14:17:06 -0400
committerRandolph Tan <randolph@10gen.com>2016-08-19 02:06:00 -0400
commit0b165e8a2b756c5c5fa8746df049f7b3253ec294 (patch)
tree81d09d07a43c1bd872952c26325e8e0d3397f82e /src/mongo/s/config.cpp
parentbc8096859cdd734012d76e4e192f427ac94e48d7 (diff)
downloadmongo-0b165e8a2b756c5c5fa8746df049f7b3253ec294.tar.gz
SERVER-22175 DBConfig needs to lock mutex whenever accessing _primaryId or _shardingEnabled
Diffstat (limited to 'src/mongo/s/config.cpp')
-rw-r--r--src/mongo/s/config.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/mongo/s/config.cpp b/src/mongo/s/config.cpp
index 2fec7afa466..a4064b0246f 100644
--- a/src/mongo/s/config.cpp
+++ b/src/mongo/s/config.cpp
@@ -155,13 +155,6 @@ bool DBConfig::isSharded(const string& ns) {
return i->second.isSharded();
}
-const ShardId& DBConfig::getShardId(OperationContext* txn, const string& ns) {
- uassert(28679, "ns can't be sharded", !isSharded(ns));
-
- uassert(10178, "no primary!", grid.shardRegistry()->getShard(txn, _primaryId));
- return _primaryId;
-}
-
void DBConfig::invalidateNs(const std::string& ns) {
stdx::lock_guard<stdx::mutex> lk(_lock);
@@ -185,14 +178,14 @@ void DBConfig::enableSharding(OperationContext* txn) {
}
bool DBConfig::removeSharding(OperationContext* txn, const string& ns) {
+ stdx::lock_guard<stdx::mutex> lk(_lock);
+
if (!_shardingEnabled) {
warning() << "could not remove sharding for collection " << ns
<< ", sharding not enabled for db";
return false;
}
- stdx::lock_guard<stdx::mutex> lk(_lock);
-
CollectionInfoMap::iterator i = _collections.find(ns);
if (i == _collections.end())
@@ -680,7 +673,7 @@ void DBConfig::getAllShardIds(set<ShardId>* shardIds) {
dassert(shardIds);
stdx::lock_guard<stdx::mutex> lk(_lock);
- shardIds->insert(getPrimaryId());
+ shardIds->insert(_primaryId);
for (CollectionInfoMap::const_iterator it(_collections.begin()), end(_collections.end());
it != end;
++it) {
@@ -700,6 +693,16 @@ void DBConfig::getAllShardedCollections(set<string>& namespaces) {
}
}
+bool DBConfig::isShardingEnabled() {
+ stdx::lock_guard<stdx::mutex> lk(_lock);
+ return _shardingEnabled;
+}
+
+ShardId DBConfig::getPrimaryId() {
+ stdx::lock_guard<stdx::mutex> lk(_lock);
+ return _primaryId;
+}
+
/* --- ConfigServer ---- */
void ConfigServer::replicaSetChangeShardRegistryUpdateHook(const string& setName,