summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-09-18 17:17:31 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-09-19 14:36:38 -0400
commitaed4f47200abff44605fc39f078601ebb0c316c7 (patch)
tree3878b3d69096d9428f69a349a29c618842091147 /src
parent6350b1f9f11a8f4971f15859426a0c991be39205 (diff)
downloadmongo-aed4f47200abff44605fc39f078601ebb0c316c7.tar.gz
SERVER-26155 Use read concern 'local' for dist lock manager on the config server
Diffstat (limited to 'src')
-rw-r--r--src/mongo/s/catalog/replset/dist_lock_catalog_impl.cpp43
-rw-r--r--src/mongo/s/catalog/replset/dist_lock_catalog_impl.h14
-rw-r--r--src/mongo/s/catalog/replset/dist_lock_catalog_impl_test.cpp2
-rw-r--r--src/mongo/s/config_server_test_fixture.cpp2
-rw-r--r--src/mongo/s/sharding_initialization.cpp3
5 files changed, 39 insertions, 25 deletions
diff --git a/src/mongo/s/catalog/replset/dist_lock_catalog_impl.cpp b/src/mongo/s/catalog/replset/dist_lock_catalog_impl.cpp
index 376cd853954..5041cb119f0 100644
--- a/src/mongo/s/catalog/replset/dist_lock_catalog_impl.cpp
+++ b/src/mongo/s/catalog/replset/dist_lock_catalog_impl.cpp
@@ -62,8 +62,6 @@ namespace {
const char kFindAndModifyResponseResultDocField[] = "value";
const char kLocalTimeField[] = "localTime";
-const ReadPreferenceSetting kReadPref(ReadPreference::PrimaryOnly, TagSet());
-
/**
* Returns the resulting new object from the findAndModify response object.
* Returns LockStateChangeFailed if value field was null, which indicates that
@@ -129,15 +127,18 @@ StatusWith<OID> extractElectionId(const BSONObj& responseObj) {
} // unnamed namespace
-DistLockCatalogImpl::DistLockCatalogImpl(ShardRegistry* shardRegistry)
- : _client(shardRegistry), _lockPingNS(LockpingsType::ConfigNS), _locksNS(LocksType::ConfigNS) {}
+DistLockCatalogImpl::DistLockCatalogImpl(ShardRegistry* shardRegistry, bool isLocal)
+ : _client(shardRegistry),
+ _isLocal(isLocal),
+ _lockPingNS(LockpingsType::ConfigNS),
+ _locksNS(LocksType::ConfigNS) {}
DistLockCatalogImpl::~DistLockCatalogImpl() = default;
StatusWith<LockpingsType> DistLockCatalogImpl::getPing(OperationContext* txn,
StringData processID) {
- auto findResult = _findOnConfig(
- txn, kReadPref, _lockPingNS, BSON(LockpingsType::process() << processID), BSONObj(), 1);
+ auto findResult =
+ _findOnConfig(txn, _lockPingNS, BSON(LockpingsType::process() << processID), BSONObj(), 1);
if (!findResult.isOK()) {
return findResult.getStatus();
@@ -376,7 +377,7 @@ Status DistLockCatalogImpl::unlockAll(OperationContext* txn, const std::string&
StatusWith<DistLockCatalog::ServerInfo> DistLockCatalogImpl::getServerInfo(OperationContext* txn) {
auto resultStatus = _client->getConfigShard()->runCommandWithFixedRetryAttempts(
txn,
- kReadPref,
+ ReadPreferenceSetting{ReadPreference::PrimaryOnly},
"admin",
BSON("serverStatus" << 1),
Shard::kDefaultConfigCommandTimeout,
@@ -410,8 +411,8 @@ StatusWith<DistLockCatalog::ServerInfo> DistLockCatalogImpl::getServerInfo(Opera
StatusWith<LocksType> DistLockCatalogImpl::getLockByTS(OperationContext* txn,
const OID& lockSessionID) {
- auto findResult = _findOnConfig(
- txn, kReadPref, _locksNS, BSON(LocksType::lockID(lockSessionID)), BSONObj(), 1);
+ auto findResult =
+ _findOnConfig(txn, _locksNS, BSON(LocksType::lockID(lockSessionID)), BSONObj(), 1);
if (!findResult.isOK()) {
return findResult.getStatus();
@@ -436,8 +437,7 @@ StatusWith<LocksType> DistLockCatalogImpl::getLockByTS(OperationContext* txn,
}
StatusWith<LocksType> DistLockCatalogImpl::getLockByName(OperationContext* txn, StringData name) {
- auto findResult =
- _findOnConfig(txn, kReadPref, _locksNS, BSON(LocksType::name() << name), BSONObj(), 1);
+ auto findResult = _findOnConfig(txn, _locksNS, BSON(LocksType::name() << name), BSONObj(), 1);
if (!findResult.isOK()) {
return findResult.getStatus();
@@ -478,15 +478,20 @@ Status DistLockCatalogImpl::stopPing(OperationContext* txn, StringData processId
return findAndModifyStatus.getStatus();
}
-StatusWith<vector<BSONObj>> DistLockCatalogImpl::_findOnConfig(
- OperationContext* txn,
- const ReadPreferenceSetting& readPref,
- const NamespaceString& nss,
- const BSONObj& query,
- const BSONObj& sort,
- boost::optional<long long> limit) {
+StatusWith<vector<BSONObj>> DistLockCatalogImpl::_findOnConfig(OperationContext* txn,
+ const NamespaceString& nss,
+ const BSONObj& query,
+ const BSONObj& sort,
+ boost::optional<long long> limit) {
auto result = _client->getConfigShard()->exhaustiveFindOnConfig(
- txn, readPref, repl::ReadConcernLevel::kMajorityReadConcern, nss, query, sort, limit);
+ txn,
+ ReadPreferenceSetting{ReadPreference::PrimaryOnly},
+ (_isLocal ? repl::ReadConcernLevel::kLocalReadConcern
+ : repl::ReadConcernLevel::kMajorityReadConcern),
+ nss,
+ query,
+ sort,
+ limit);
if (!result.isOK()) {
return result.getStatus();
}
diff --git a/src/mongo/s/catalog/replset/dist_lock_catalog_impl.h b/src/mongo/s/catalog/replset/dist_lock_catalog_impl.h
index 6f26a3a1235..8903eb5b33a 100644
--- a/src/mongo/s/catalog/replset/dist_lock_catalog_impl.h
+++ b/src/mongo/s/catalog/replset/dist_lock_catalog_impl.h
@@ -48,7 +48,12 @@ struct ReadPreferenceSetting;
class DistLockCatalogImpl final : public DistLockCatalog {
public:
- DistLockCatalogImpl(ShardRegistry* shardRegistry);
+ /**
+ * Constructs a new dist lock catalog, specifying whether it is being used locally on the config
+ * server or remotely (from a shard or mongos). See the comment for the associated class
+ * variable for more information.
+ */
+ DistLockCatalogImpl(ShardRegistry* shardRegistry, bool isLocal);
virtual ~DistLockCatalogImpl();
@@ -95,13 +100,16 @@ private:
Status _unlock(OperationContext* txn, const FindAndModifyRequest& request);
StatusWith<std::vector<BSONObj>> _findOnConfig(OperationContext* txn,
- const ReadPreferenceSetting& readPref,
const NamespaceString& nss,
const BSONObj& query,
const BSONObj& sort,
boost::optional<long long> limit);
- ShardRegistry* _client;
+ ShardRegistry* const _client;
+
+ // Indicates whether this catalog manager is used as a local or remote instance. Controls the
+ // read concern level used for dist lock information lookup.
+ const bool _isLocal;
// These are not static to avoid initialization order fiasco.
const NamespaceString _lockPingNS;
diff --git a/src/mongo/s/catalog/replset/dist_lock_catalog_impl_test.cpp b/src/mongo/s/catalog/replset/dist_lock_catalog_impl_test.cpp
index 99a7d61de8d..1588b0d4c30 100644
--- a/src/mongo/s/catalog/replset/dist_lock_catalog_impl_test.cpp
+++ b/src/mongo/s/catalog/replset/dist_lock_catalog_impl_test.cpp
@@ -97,7 +97,7 @@ protected:
std::unique_ptr<DistLockCatalog> makeDistLockCatalog(ShardRegistry* shardRegistry) override {
invariant(shardRegistry);
- return stdx::make_unique<DistLockCatalogImpl>(shardRegistry);
+ return stdx::make_unique<DistLockCatalogImpl>(shardRegistry, false);
}
std::unique_ptr<DistLockManager> makeDistLockManager(
diff --git a/src/mongo/s/config_server_test_fixture.cpp b/src/mongo/s/config_server_test_fixture.cpp
index f648eb14721..40253df784e 100644
--- a/src/mongo/s/config_server_test_fixture.cpp
+++ b/src/mongo/s/config_server_test_fixture.cpp
@@ -108,7 +108,7 @@ void ConfigServerTestFixture::setUp() {
std::unique_ptr<DistLockCatalog> ConfigServerTestFixture::makeDistLockCatalog(
ShardRegistry* shardRegistry) {
invariant(shardRegistry);
- return stdx::make_unique<DistLockCatalogImpl>(shardRegistry);
+ return stdx::make_unique<DistLockCatalogImpl>(shardRegistry, false);
}
std::unique_ptr<DistLockManager> ConfigServerTestFixture::makeDistLockManager(
diff --git a/src/mongo/s/sharding_initialization.cpp b/src/mongo/s/sharding_initialization.cpp
index 0c46df7a3cd..5ae5edf9593 100644
--- a/src/mongo/s/sharding_initialization.cpp
+++ b/src/mongo/s/sharding_initialization.cpp
@@ -84,7 +84,8 @@ std::unique_ptr<ThreadPoolTaskExecutor> makeTaskExecutor(std::unique_ptr<Network
std::unique_ptr<ShardingCatalogClient> makeCatalogClient(ServiceContext* service,
ShardRegistry* shardRegistry,
StringData distLockProcessId) {
- auto distLockCatalog = stdx::make_unique<DistLockCatalogImpl>(shardRegistry);
+ auto distLockCatalog = stdx::make_unique<DistLockCatalogImpl>(
+ shardRegistry, serverGlobalParams.clusterRole == ClusterRole::ConfigServer);
auto distLockManager =
stdx::make_unique<ReplSetDistLockManager>(service,
distLockProcessId,