diff options
author | Randolph Tan <randolph@10gen.com> | 2015-08-07 15:15:18 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2015-08-11 12:08:52 -0400 |
commit | 248aea0dad9f9a3d46cb37547a546b0c9fe7e135 (patch) | |
tree | 1ff09899731c586f52ab1b20bbf044e7ecab5b20 /src/mongo/s/catalog/dist_lock_catalog_impl.cpp | |
parent | 8117ecc138e9f87ade5a475a2695d1e39f474d8c (diff) | |
download | mongo-248aea0dad9f9a3d46cb37547a546b0c9fe7e135.tar.gz |
SERVER-19390 Make config server queries do read committed
Diffstat (limited to 'src/mongo/s/catalog/dist_lock_catalog_impl.cpp')
-rw-r--r-- | src/mongo/s/catalog/dist_lock_catalog_impl.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/mongo/s/catalog/dist_lock_catalog_impl.cpp b/src/mongo/s/catalog/dist_lock_catalog_impl.cpp index 6f02a4aba32..fbfe5e0d34e 100644 --- a/src/mongo/s/catalog/dist_lock_catalog_impl.cpp +++ b/src/mongo/s/catalog/dist_lock_catalog_impl.cpp @@ -39,7 +39,9 @@ #include "mongo/client/remote_command_targeter.h" #include "mongo/db/lasterror.h" #include "mongo/db/query/find_and_modify_request.h" +#include "mongo/db/repl/read_concern_args.h" #include "mongo/rpc/get_status_from_command_result.h" +#include "mongo/rpc/metadata.h" #include "mongo/rpc/metadata/sharding_metadata.h" #include "mongo/s/catalog/type_lockpings.h" #include "mongo/s/catalog/type_locks.h" @@ -50,12 +52,14 @@ namespace mongo { using std::string; +using std::vector; namespace { const char kCmdResponseWriteConcernField[] = "writeConcernError"; const char kFindAndModifyResponseResultDocField[] = "value"; const char kLocalTimeField[] = "localTime"; +const BSONObj kReplMetadata = BSON(rpc::kReplicationMetadataFieldName << 1); const ReadPreferenceSetting kReadPref(ReadPreference::PrimaryOnly, TagSet()); /** @@ -163,11 +167,11 @@ StatusWith<LockpingsType> DistLockCatalogImpl::getPing(StringData processID) { return targetStatus.getStatus(); } - auto findResult = _client->exhaustiveFind(targetStatus.getValue(), - _lockPingNS, - BSON(LockpingsType::process() << processID), - BSONObj(), - 1); + auto findResult = _findOnConfig(targetStatus.getValue(), + _lockPingNS, + BSON(LockpingsType::process() << processID), + BSONObj(), + 1); if (!findResult.isOK()) { return findResult.getStatus(); @@ -382,7 +386,7 @@ StatusWith<LocksType> DistLockCatalogImpl::getLockByTS(const OID& lockSessionID) return targetStatus.getStatus(); } - auto findResult = _client->exhaustiveFind( + auto findResult = _findOnConfig( targetStatus.getValue(), _locksNS, BSON(LocksType::lockID(lockSessionID)), BSONObj(), 1); if (!findResult.isOK()) { @@ -414,7 +418,7 @@ StatusWith<LocksType> DistLockCatalogImpl::getLockByName(StringData name) { return targetStatus.getStatus(); } - auto findResult = _client->exhaustiveFind( + auto findResult = _findOnConfig( targetStatus.getValue(), _locksNS, BSON(LocksType::name() << name), BSONObj(), 1); if (!findResult.isOK()) { @@ -457,4 +461,20 @@ Status DistLockCatalogImpl::stopPing(StringData processId) { return findAndModifyStatus.getStatus(); } +StatusWith<vector<BSONObj>> DistLockCatalogImpl::_findOnConfig(const HostAndPort& host, + const NamespaceString& nss, + const BSONObj& query, + const BSONObj& sort, + boost::optional<long long> limit) { + repl::ReadConcernArgs readConcern(boost::none, repl::ReadConcernLevel::kMajorityReadConcern); + auto result = + _client->exhaustiveFind(host, nss, query, sort, limit, readConcern, kReplMetadata); + + if (!result.isOK()) { + return result.getStatus(); + } + + return result.getValue().docs; +} + } // namespace mongo |