diff options
author | Randolph Tan <randolph@10gen.com> | 2015-06-24 13:39:35 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2015-06-25 15:42:26 -0400 |
commit | 72bfa63d73733520512c450e259ac64fea321ce4 (patch) | |
tree | 4417d1d973462c9201c2e65a9e497ac1f6fbba33 /src/mongo/s/catalog/dist_lock_catalog_impl.cpp | |
parent | 240596e01525374c6d6c0dabc44c107e2c0b900d (diff) | |
download | mongo-72bfa63d73733520512c450e259ac64fea321ce4.tar.gz |
SERVER-18589 Implement getPing, getLockByTS, getLockByName
Diffstat (limited to 'src/mongo/s/catalog/dist_lock_catalog_impl.cpp')
-rw-r--r-- | src/mongo/s/catalog/dist_lock_catalog_impl.cpp | 92 |
1 files changed, 88 insertions, 4 deletions
diff --git a/src/mongo/s/catalog/dist_lock_catalog_impl.cpp b/src/mongo/s/catalog/dist_lock_catalog_impl.cpp index 89f1dee7f99..40c8479c786 100644 --- a/src/mongo/s/catalog/dist_lock_catalog_impl.cpp +++ b/src/mongo/s/catalog/dist_lock_catalog_impl.cpp @@ -152,7 +152,37 @@ DistLockCatalogImpl::DistLockCatalogImpl(RemoteCommandTargeter* targeter, DistLockCatalogImpl::~DistLockCatalogImpl() = default; StatusWith<LockpingsType> DistLockCatalogImpl::getPing(StringData processID) { - invariant(false); // TODO + auto targetStatus = _targeter->findHost(kReadPref); + + if (!targetStatus.isOK()) { + return targetStatus.getStatus(); + } + + auto findResult = _client->exhaustiveFind(targetStatus.getValue(), + _lockPingNS, + BSON(LockpingsType::process() << processID), + BSONObj(), + 1); + + if (!findResult.isOK()) { + return findResult.getStatus(); + } + + const auto& findResultSet = findResult.getValue(); + + if (findResultSet.empty()) { + return {ErrorCodes::NoMatchingDocument, + str::stream() << "ping entry for " << processID << " not found"}; + } + + LockpingsType pingDoc; + + string errMsg; + if (!pingDoc.parseBSON(findResultSet.front(), &errMsg)) { + return {ErrorCodes::FailedToParse, errMsg}; + } + + return pingDoc; } Status DistLockCatalogImpl::ping(StringData processID, Date_t ping) { @@ -164,7 +194,7 @@ Status DistLockCatalogImpl::ping(StringData processID, Date_t ping) { auto request = FindAndModifyRequest::makeUpdate(_lockPingNS, - BSON(LockpingsType::process(processID.toString())), + BSON(LockpingsType::process() << processID), BSON("$set" << BSON(LockpingsType::ping(ping)))); request.setUpsert(true); request.setWriteConcern(_writeConcern); @@ -379,11 +409,65 @@ StatusWith<DistLockCatalog::ServerInfo> DistLockCatalogImpl::getServerInfo() { } StatusWith<LocksType> DistLockCatalogImpl::getLockByTS(const OID& lockSessionID) { - invariant(false); // TODO + auto targetStatus = _targeter->findHost(kReadPref); + + if (!targetStatus.isOK()) { + return targetStatus.getStatus(); + } + + auto findResult = _client->exhaustiveFind( + targetStatus.getValue(), _locksNS, BSON(LocksType::lockID(lockSessionID)), BSONObj(), 1); + + if (!findResult.isOK()) { + return findResult.getStatus(); + } + + const auto& findResultSet = findResult.getValue(); + + if (findResultSet.empty()) { + return {ErrorCodes::LockNotFound, + str::stream() << "lock with ts " << lockSessionID << " not found"}; + } + + LocksType lockDoc; + + string errMsg; + if (!lockDoc.parseBSON(findResultSet.front(), &errMsg)) { + return {ErrorCodes::FailedToParse, errMsg}; + } + + return lockDoc; } StatusWith<LocksType> DistLockCatalogImpl::getLockByName(StringData name) { - invariant(false); // TODO + auto targetStatus = _targeter->findHost(kReadPref); + + if (!targetStatus.isOK()) { + return targetStatus.getStatus(); + } + + auto findResult = _client->exhaustiveFind( + targetStatus.getValue(), _locksNS, BSON(LocksType::name() << name), BSONObj(), 1); + + if (!findResult.isOK()) { + return findResult.getStatus(); + } + + const auto& findResultSet = findResult.getValue(); + + if (findResultSet.empty()) { + return {ErrorCodes::LockNotFound, + str::stream() << "lock with name " << name << " not found"}; + } + + LocksType lockDoc; + + string errMsg; + if (!lockDoc.parseBSON(findResultSet.front(), &errMsg)) { + return {ErrorCodes::FailedToParse, errMsg}; + } + + return lockDoc; } Status DistLockCatalogImpl::stopPing(StringData processId) { |