diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-12-05 13:47:54 -0500 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-12-06 09:04:36 -0500 |
commit | d5be73dbe4d28211994746dc1f5b47fb840ccdbd (patch) | |
tree | 4a27750cfaad68c90671bc14ef83759e0e607a47 /src/mongo/db/s/cleanup_orphaned_cmd.cpp | |
parent | a18859168f73428522d4338fee982329d9d431ed (diff) | |
download | mongo-d5be73dbe4d28211994746dc1f5b47fb840ccdbd.tar.gz |
SERVER-31056 Remove the KeyRange type from non-test code
Diffstat (limited to 'src/mongo/db/s/cleanup_orphaned_cmd.cpp')
-rw-r--r-- | src/mongo/db/s/cleanup_orphaned_cmd.cpp | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/src/mongo/db/s/cleanup_orphaned_cmd.cpp b/src/mongo/db/s/cleanup_orphaned_cmd.cpp index 5ab210ec520..69e7b311b79 100644 --- a/src/mongo/db/s/cleanup_orphaned_cmd.cpp +++ b/src/mongo/db/s/cleanup_orphaned_cmd.cpp @@ -30,6 +30,7 @@ #include "mongo/platform/basic.h" +#include <boost/optional.hpp> #include <string> #include <vector> @@ -52,13 +53,7 @@ #include "mongo/s/migration_secondary_throttle_options.h" #include "mongo/util/log.h" -#include <boost/optional.hpp> - namespace mongo { - -using std::string; -using str::stream; - namespace { enum CleanupResult { CleanupResult_Done, CleanupResult_Continue, CleanupResult_Error }; @@ -78,22 +73,20 @@ CleanupResult cleanupOrphanedData(OperationContext* opCtx, const BSONObj& startingFromKeyConst, const WriteConcernOptions& secondaryThrottle, BSONObj* stoppedAtKey, - string* errMsg) { - + std::string* errMsg) { BSONObj startingFromKey = startingFromKeyConst; boost::optional<ChunkRange> targetRange; CollectionShardingState::CleanupNotification notifn; - OID epoch; + { AutoGetCollection autoColl(opCtx, ns, MODE_IX); - auto css = CollectionShardingState::get(opCtx, ns.toString()); + const auto css = CollectionShardingState::get(opCtx, ns.toString()); auto metadata = css->getMetadata(); if (!metadata) { log() << "skipping orphaned data cleanup for " << ns.toString() << ", collection is not sharded"; return CleanupResult_Done; } - epoch = metadata->getCollVersion().epoch(); BSONObj keyPattern = metadata->getKeyPattern(); if (!startingFromKey.isEmpty()) { @@ -109,18 +102,16 @@ CleanupResult cleanupOrphanedData(OperationContext* opCtx, startingFromKey = metadata->getMinKey(); } - boost::optional<KeyRange> orphanRange = css->getNextOrphanRange(startingFromKey); - if (!orphanRange) { + targetRange = css->getNextOrphanRange(startingFromKey); + if (!targetRange) { LOG(1) << "cleanupOrphaned requested for " << ns.toString() << " starting from " << redact(startingFromKey) << ", no orphan ranges remain"; return CleanupResult_Done; } - orphanRange->ns = ns.ns(); - *stoppedAtKey = orphanRange->maxKey; - targetRange.emplace( - ChunkRange(orphanRange->minKey.getOwned(), orphanRange->maxKey.getOwned())); + *stoppedAtKey = targetRange->getMax(); + notifn = css->cleanUpRange(*targetRange, CollectionShardingState::kNow); } @@ -130,13 +121,17 @@ CleanupResult cleanupOrphanedData(OperationContext* opCtx, LOG(1) << "cleanupOrphaned requested for " << ns.toString() << " starting from " << redact(startingFromKey) << ", removing next orphan range " << redact(targetRange->toString()) << "; waiting..."; + Status result = notifn.waitStatus(opCtx); + LOG(1) << "Finished waiting for last " << ns.toString() << " orphan range cleanup"; + if (!result.isOK()) { log() << redact(result.reason()); *errMsg = result.reason(); return CleanupResult_Error; } + return CleanupResult_Continue; } @@ -172,16 +167,17 @@ class CleanupOrphanedCommand : public ErrmsgCommandDeprecated { public: CleanupOrphanedCommand() : ErrmsgCommandDeprecated("cleanupOrphaned") {} - virtual bool slaveOk() const { + bool slaveOk() const override { return false; } - virtual bool adminOnly() const { + + bool adminOnly() const override { return true; } - virtual Status checkAuthForCommand(Client* client, - const std::string& dbname, - const BSONObj& cmdObj) { + Status checkAuthForCommand(Client* client, + const std::string& dbname, + const BSONObj& cmdObj) override { if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( ResourcePattern::forClusterResource(), ActionType::cleanupOrphaned)) { return Status(ErrorCodes::Unauthorized, "Not authorized for cleanupOrphaned command."); @@ -189,23 +185,23 @@ public: return Status::OK(); } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { + bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } // Input - static BSONField<string> nsField; + static BSONField<std::string> nsField; static BSONField<BSONObj> startingFromKeyField; // Output static BSONField<BSONObj> stoppedAtKeyField; bool errmsgRun(OperationContext* opCtx, - string const& db, + std::string const& db, const BSONObj& cmdObj, - string& errmsg, - BSONObjBuilder& result) { - string ns; + std::string& errmsg, + BSONObjBuilder& result) override { + std::string ns; if (!FieldParser::extract(cmdObj, nsField, &ns, &errmsg)) { return false; } @@ -255,7 +251,7 @@ public: } cleanupOrphanedCmd; -BSONField<string> CleanupOrphanedCommand::nsField("cleanupOrphaned"); +BSONField<std::string> CleanupOrphanedCommand::nsField("cleanupOrphaned"); BSONField<BSONObj> CleanupOrphanedCommand::startingFromKeyField("startingFromKey"); BSONField<BSONObj> CleanupOrphanedCommand::stoppedAtKeyField("stoppedAtKey"); |