diff options
author | Mathias Stearn <mathias@10gen.com> | 2018-04-24 16:58:23 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2018-05-08 14:57:37 -0400 |
commit | 589af3820b00ed0b7ac26a84cfeed6554ab191f3 (patch) | |
tree | bb393adad8b1ca4f6f0e23c035141e829e3eeee6 /src/mongo/db/commands | |
parent | 98f28d452b9b330d6c1696d6d8207b582a5870fc (diff) | |
download | mongo-589af3820b00ed0b7ac26a84cfeed6554ab191f3.tar.gz |
SERVER-34628 Prep for removing appendCommandStatus
* Added appendCommandStatusNoThrow matching the current aCS behavior
* Make appendCommandStatus call uassertStatusOK then aCS on success
* Make the few places that need to not throw call aCSNT
A following commit will completely remove appendCommandStatus. It is split out
because that commit is fairly huge.
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r-- | src/mongo/db/commands/apply_ops_cmd.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/commands/create_indexes.cpp | 16 | ||||
-rw-r--r-- | src/mongo/db/commands/do_txn_cmd.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/commands/get_last_error.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/commands/user_management_commands.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/commands/validate.cpp | 4 |
6 files changed, 16 insertions, 20 deletions
diff --git a/src/mongo/db/commands/apply_ops_cmd.cpp b/src/mongo/db/commands/apply_ops_cmd.cpp index 976a85bcec8..d78414e95ea 100644 --- a/src/mongo/db/commands/apply_ops_cmd.cpp +++ b/src/mongo/db/commands/apply_ops_cmd.cpp @@ -267,7 +267,7 @@ public: << repl::ApplyOps::kOplogApplicationModeFieldName)); } - auto applyOpsStatus = CommandHelpers::appendCommandStatus( + auto applyOpsStatus = CommandHelpers::appendCommandStatusNoThrow( result, repl::applyOps(opCtx, dbname, cmdObj, oplogApplicationMode, &result)); return applyOpsStatus; diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index bf1edf90884..0e08effe965 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -369,19 +369,15 @@ public: // that day, to avoid data corruption due to lack of index cleanup. opCtx->recoveryUnit()->abandonSnapshot(); dbLock.relockWithMode(MODE_X); - if (!repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, ns)) { - return CommandHelpers::appendCommandStatus( - result, - Status(ErrorCodes::NotMaster, - str::stream() - << "Not primary while creating background indexes in " - << ns.ns() - << ": cleaning up index build failure due to " - << e.toString())); - } } catch (...) { std::terminate(); } + uassert(ErrorCodes::NotMaster, + str::stream() << "Not primary while creating background indexes in " + << ns.ns() + << ": cleaning up index build failure due to " + << e.toString(), + repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, ns)); } throw; } diff --git a/src/mongo/db/commands/do_txn_cmd.cpp b/src/mongo/db/commands/do_txn_cmd.cpp index d0dd99ec645..15183f8524c 100644 --- a/src/mongo/db/commands/do_txn_cmd.cpp +++ b/src/mongo/db/commands/do_txn_cmd.cpp @@ -159,8 +159,8 @@ public: // was acknowledged. To fix this, we should wait for replication of the node’s last applied // OpTime if the last write operation was a no-op write. - auto doTxnStatus = - CommandHelpers::appendCommandStatus(result, doTxn(opCtx, dbname, cmdObj, &result)); + auto doTxnStatus = CommandHelpers::appendCommandStatusNoThrow( + result, doTxn(opCtx, dbname, cmdObj, &result)); return doTxnStatus; } diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp index 7d8b277e798..2cb45c3b445 100644 --- a/src/mongo/db/commands/get_last_error.cpp +++ b/src/mongo/db/commands/get_last_error.cpp @@ -177,7 +177,7 @@ public: Status status = bsonExtractOpTimeField(cmdObj, "wOpTime", &lastOpTime); if (!status.isOK()) { result.append("badGLE", cmdObj); - return CommandHelpers::appendCommandStatus(result, status); + return CommandHelpers::appendCommandStatusNoThrow(result, status); } } else { return CommandHelpers::appendCommandStatus( @@ -195,7 +195,7 @@ public: FieldParser::extract(cmdObj, wElectionIdField, &electionId, &errmsg); if (!extracted) { result.append("badGLE", cmdObj); - CommandHelpers::appendCommandStatus(result, false, errmsg); + CommandHelpers::appendSimpleCommandStatus(result, false, errmsg); return false; } @@ -242,7 +242,7 @@ public: if (!status.isOK()) { result.append("badGLE", writeConcernDoc); - return CommandHelpers::appendCommandStatus(result, status); + return CommandHelpers::appendCommandStatusNoThrow(result, status); } // Don't wait for replication if there was an error reported - this matches 2.4 behavior @@ -298,7 +298,7 @@ public: return true; } - return CommandHelpers::appendCommandStatus(result, status); + return CommandHelpers::appendCommandStatusNoThrow(result, status); } } cmdGetLastError; diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp index fd3519d4871..1fb2582eee5 100644 --- a/src/mongo/db/commands/user_management_commands.cpp +++ b/src/mongo/db/commands/user_management_commands.cpp @@ -1463,7 +1463,7 @@ public: return CommandHelpers::appendCommandStatus(result, status); } - CommandHelpers::appendCommandStatus(responseBuilder, Status::OK()); + CommandHelpers::appendSimpleCommandStatus(responseBuilder, true); auto swResponse = CursorResponse::parseFromBSON(responseBuilder.obj()); if (!swResponse.isOK()) { return CommandHelpers::appendCommandStatus(result, swResponse.getStatus()); diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp index b6fd8a4b9e2..c98c02d629d 100644 --- a/src/mongo/db/commands/validate.cpp +++ b/src/mongo/db/commands/validate.cpp @@ -176,7 +176,7 @@ public: opCtx->waitForConditionOrInterrupt(_validationNotifier, lock); } } catch (AssertionException& e) { - CommandHelpers::appendCommandStatus( + CommandHelpers::appendCommandStatusNoThrow( result, {ErrorCodes::CommandFailed, str::stream() << "Exception during validation: " << e.toString()}); @@ -196,7 +196,7 @@ public: Status status = collection->validate(opCtx, level, background, std::move(collLk), &results, &result); if (!status.isOK()) { - return CommandHelpers::appendCommandStatus(result, status); + return CommandHelpers::appendCommandStatusNoThrow(result, status); } CollectionCatalogEntry* catalogEntry = collection->getCatalogEntry(); |