summaryrefslogtreecommitdiff
path: root/src/mongo/s/commands/cluster_remove_shard_cmd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/commands/cluster_remove_shard_cmd.cpp')
-rw-r--r--src/mongo/s/commands/cluster_remove_shard_cmd.cpp162
1 files changed, 78 insertions, 84 deletions
diff --git a/src/mongo/s/commands/cluster_remove_shard_cmd.cpp b/src/mongo/s/commands/cluster_remove_shard_cmd.cpp
index e936e926d3b..14aeaf6bf42 100644
--- a/src/mongo/s/commands/cluster_remove_shard_cmd.cpp
+++ b/src/mongo/s/commands/cluster_remove_shard_cmd.cpp
@@ -45,90 +45,84 @@
namespace mongo {
- using std::string;
- using std::vector;
+using std::string;
+using std::vector;
namespace {
- class RemoveShardCmd : public Command {
- public:
- RemoveShardCmd() : Command("removeShard", false, "removeshard") { }
-
- virtual bool slaveOk() const {
- return true;
- }
-
- virtual bool adminOnly() const {
- return true;
- }
-
- virtual bool isWriteCommandForConfigServer() const {
- return false;
- }
-
- virtual void help(std::stringstream& help) const {
- help << "remove a shard from the system.";
+class RemoveShardCmd : public Command {
+public:
+ RemoveShardCmd() : Command("removeShard", false, "removeshard") {}
+
+ virtual bool slaveOk() const {
+ return true;
+ }
+
+ virtual bool adminOnly() const {
+ return true;
+ }
+
+ virtual bool isWriteCommandForConfigServer() const {
+ return false;
+ }
+
+ virtual void help(std::stringstream& help) const {
+ help << "remove a shard from the system.";
+ }
+
+ virtual void addRequiredPrivileges(const std::string& dbname,
+ const BSONObj& cmdObj,
+ std::vector<Privilege>* out) {
+ ActionSet actions;
+ actions.addAction(ActionType::removeShard);
+ out->push_back(Privilege(ResourcePattern::forClusterResource(), actions));
+ }
+
+ virtual bool run(OperationContext* txn,
+ const std::string& dbname,
+ BSONObj& cmdObj,
+ int options,
+ std::string& errmsg,
+ BSONObjBuilder& result) {
+ const string target = cmdObj.firstElement().valuestrsafe();
+
+ const auto s = grid.shardRegistry()->getShard(target);
+ if (!s) {
+ string msg(str::stream() << "Could not drop shard '" << target
+ << "' because it does not exist");
+ log() << msg;
+ return appendCommandStatus(result, Status(ErrorCodes::ShardNotFound, msg));
}
- virtual void addRequiredPrivileges(const std::string& dbname,
- const BSONObj& cmdObj,
- std::vector<Privilege>* out) {
-
- ActionSet actions;
- actions.addAction(ActionType::removeShard);
- out->push_back(Privilege(ResourcePattern::forClusterResource(), actions));
+ StatusWith<ShardDrainingStatus> removeShardResult =
+ grid.catalogManager()->removeShard(txn, s->getId());
+ if (!removeShardResult.isOK()) {
+ return appendCommandStatus(result, removeShardResult.getStatus());
}
- virtual bool run(OperationContext* txn,
- const std::string& dbname,
- BSONObj& cmdObj,
- int options,
- std::string& errmsg,
- BSONObjBuilder& result) {
-
- const string target = cmdObj.firstElement().valuestrsafe();
-
- const auto s = grid.shardRegistry()->getShard(target);
- if (!s) {
- string msg(str::stream() <<
- "Could not drop shard '" << target <<
- "' because it does not exist");
- log() << msg;
- return appendCommandStatus(result,
- Status(ErrorCodes::ShardNotFound, msg));
- }
-
- StatusWith<ShardDrainingStatus> removeShardResult =
- grid.catalogManager()->removeShard(txn, s->getId());
- if (!removeShardResult.isOK()) {
- return appendCommandStatus(result, removeShardResult.getStatus());
- }
-
- vector<string> databases;
- grid.catalogManager()->getDatabasesForShard(s->getId(), &databases);
-
- // Get BSONObj containing:
- // 1) note about moving or dropping databases in a shard
- // 2) list of databases (excluding 'local' database) that need to be moved
- BSONObj dbInfo;
- {
- BSONObjBuilder dbInfoBuilder;
- dbInfoBuilder.append("note",
- "you need to drop or movePrimary these databases");
- BSONArrayBuilder dbs(dbInfoBuilder.subarrayStart("dbsToMove"));
- for (vector<string>::const_iterator it = databases.begin();
- it != databases.end();
- it++) {
- if (*it != "local") {
- dbs.append(*it);
- }
+ vector<string> databases;
+ grid.catalogManager()->getDatabasesForShard(s->getId(), &databases);
+
+ // Get BSONObj containing:
+ // 1) note about moving or dropping databases in a shard
+ // 2) list of databases (excluding 'local' database) that need to be moved
+ BSONObj dbInfo;
+ {
+ BSONObjBuilder dbInfoBuilder;
+ dbInfoBuilder.append("note", "you need to drop or movePrimary these databases");
+ BSONArrayBuilder dbs(dbInfoBuilder.subarrayStart("dbsToMove"));
+ for (vector<string>::const_iterator it = databases.begin(); it != databases.end();
+ it++) {
+ if (*it != "local") {
+ dbs.append(*it);
}
- dbs.doneFast();
- dbInfo = dbInfoBuilder.obj();
}
+ dbs.doneFast();
+ dbInfo = dbInfoBuilder.obj();
+ }
- // TODO: Standardize/Seperate how we append to the result object
- switch (removeShardResult.getValue()) {
+ // TODO: Standardize/Seperate how we append to the result object
+ switch (removeShardResult.getValue()) {
case ShardDrainingStatus::STARTED:
result.append("msg", "draining started successfully");
result.append("state", "started");
@@ -137,10 +131,10 @@ namespace {
break;
case ShardDrainingStatus::ONGOING: {
vector<ChunkType> chunks;
- Status status = grid.catalogManager()->getChunks(
- Query(BSON(ChunkType::shard(s->getId()))),
- 0, // return all
- &chunks);
+ Status status =
+ grid.catalogManager()->getChunks(Query(BSON(ChunkType::shard(s->getId()))),
+ 0, // return all
+ &chunks);
if (!status.isOK()) {
return appendCommandStatus(result, status);
}
@@ -161,12 +155,12 @@ namespace {
result.append("msg", "removeshard completed successfully");
result.append("state", "completed");
result.append("shard", s->getId());
- }
-
- return true;
}
- } removeShardCmd;
+ return true;
+ }
+
+} removeShardCmd;
-} // namespace
-} // namespace mongo
+} // namespace
+} // namespace mongo