summaryrefslogtreecommitdiff
path: root/src/mongo/db/exec
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2017-08-01 09:35:39 -0400
committerMathias Stearn <mathias@10gen.com>2017-08-16 16:28:02 -0400
commit40036f67d0c15e2cd319e82f8c6a1e691fb74806 (patch)
treefd9744b756fb092c47c1b3fbcd15e349fe0e270a /src/mongo/db/exec
parent53a9b329fbf1a6d8b620fee2cbb2ef1c27ddd3f3 (diff)
downloadmongo-40036f67d0c15e2cd319e82f8c6a1e691fb74806.tar.gz
SERVER-30580 No more status locations
Diffstat (limited to 'src/mongo/db/exec')
-rw-r--r--src/mongo/db/exec/update.cpp107
-rw-r--r--src/mongo/db/exec/update.h24
2 files changed, 50 insertions, 81 deletions
diff --git a/src/mongo/db/exec/update.cpp b/src/mongo/db/exec/update.cpp
index 42e2bb3bf8f..0788a621ee9 100644
--- a/src/mongo/db/exec/update.cpp
+++ b/src/mongo/db/exec/update.cpp
@@ -87,16 +87,12 @@ Status ensureIdFieldIsFirst(mb::Document* doc) {
return Status::OK();
}
-Status addObjectIDIdField(mb::Document* doc) {
+void addObjectIDIdField(mb::Document* doc) {
const auto idElem = doc->makeElementNewOID(idFieldName);
if (!idElem.ok())
- return {ErrorCodes::BadValue, "Could not create new ObjectId '_id' field.", 17268};
+ uasserted(17268, "Could not create new ObjectId '_id' field.");
- const auto s = doc->root().pushFront(idElem);
- if (!s.isOK())
- return s;
-
- return Status::OK();
+ uassertStatusOK(doc->root().pushFront(idElem));
}
/**
@@ -253,7 +249,7 @@ BSONObj UpdateStage::transformAndUpdate(const Snapshotted<BSONObj>& oldObj, Reco
if (status.code() == ErrorCodes::InvalidIdField) {
// Create ObjectId _id field if we are doing that
if (createIdField) {
- uassertStatusOK(addObjectIDIdField(&_doc));
+ addObjectIDIdField(&_doc);
}
} else {
uassertStatusOK(status);
@@ -324,16 +320,14 @@ BSONObj UpdateStage::transformAndUpdate(const Snapshotted<BSONObj>& oldObj, Reco
args.update = logObj;
args.criteria = idQuery;
args.fromMigrate = request->isFromMigration();
- StatusWith<RecordId> res = _collection->updateDocument(getOpCtx(),
- recordId,
- oldObj,
- newObj,
- true,
- driver->modsAffectIndices(),
- _params.opDebug,
- &args);
- uassertStatusOK(res.getStatus());
- newRecordId = res.getValue();
+ newRecordId = _collection->updateDocument(getOpCtx(),
+ recordId,
+ oldObj,
+ newObj,
+ true,
+ driver->modsAffectIndices(),
+ _params.opDebug,
+ &args);
}
}
@@ -362,15 +356,14 @@ BSONObj UpdateStage::transformAndUpdate(const Snapshotted<BSONObj>& oldObj, Reco
return newObj;
}
-Status UpdateStage::applyUpdateOpsForInsert(OperationContext* opCtx,
- const CanonicalQuery* cq,
- const BSONObj& query,
- UpdateDriver* driver,
- mutablebson::Document* doc,
- bool isInternalRequest,
- const NamespaceString& ns,
- UpdateStats* stats,
- BSONObj* out) {
+BSONObj UpdateStage::applyUpdateOpsForInsert(OperationContext* opCtx,
+ const CanonicalQuery* cq,
+ const BSONObj& query,
+ UpdateDriver* driver,
+ mutablebson::Document* doc,
+ bool isInternalRequest,
+ const NamespaceString& ns,
+ UpdateStats* stats) {
// Since this is an insert (no docs found and upsert:true), we will be logging it
// as an insert in the oplog. We don't need the driver's help to build the
// oplog record, then. We also set the context of the update driver to the INSERT_CONTEXT.
@@ -392,11 +385,7 @@ Status UpdateStage::applyUpdateOpsForInsert(OperationContext* opCtx,
BSONObj original;
if (cq) {
- Status status = driver->populateDocumentWithQueryFields(*cq, immutablePaths, *doc);
- if (!status.isOK()) {
- return status;
- }
-
+ uassertStatusOK(driver->populateDocumentWithQueryFields(*cq, immutablePaths, *doc));
if (driver->isDocReplacement())
stats->fastmodinsert = true;
original = doc->getObject();
@@ -416,17 +405,15 @@ Status UpdateStage::applyUpdateOpsForInsert(OperationContext* opCtx,
Status updateStatus =
driver->update(StringData(), original, doc, validateForStorage, immutablePaths);
if (!updateStatus.isOK()) {
- return Status(updateStatus.code(), updateStatus.reason(), 16836);
+ uasserted(16836, updateStatus.reason());
}
// Ensure _id exists and is first
auto idAndFirstStatus = ensureIdFieldIsFirst(doc);
if (idAndFirstStatus.code() == ErrorCodes::InvalidIdField) { // _id field is missing
- idAndFirstStatus = addObjectIDIdField(doc);
- }
-
- if (!idAndFirstStatus.isOK()) {
- return idAndFirstStatus;
+ addObjectIDIdField(doc);
+ } else {
+ uassertStatusOK(idAndFirstStatus);
}
// Validate that the object replacement or modifiers resulted in a document
@@ -441,13 +428,11 @@ Status UpdateStage::applyUpdateOpsForInsert(OperationContext* opCtx,
BSONObj newObj = doc->getObject();
if (newObj.objsize() > BSONObjMaxUserSize) {
- return Status(ErrorCodes::InvalidBSON,
- str::stream() << "Document to upsert is larger than " << BSONObjMaxUserSize,
- 17420);
+ uasserted(17420,
+ str::stream() << "Document to upsert is larger than " << BSONObjMaxUserSize);
}
- *out = newObj;
- return Status::OK();
+ return newObj;
}
void UpdateStage::doInsert() {
@@ -459,16 +444,14 @@ void UpdateStage::doInsert() {
// Reset the document we will be writing to.
_doc.reset();
- BSONObj newObj;
- uassertStatusOK(applyUpdateOpsForInsert(getOpCtx(),
- _params.canonicalQuery,
- request->getQuery(),
- _params.driver,
- &_doc,
- isInternalRequest,
- request->getNamespaceString(),
- &_specificStats,
- &newObj));
+ BSONObj newObj = applyUpdateOpsForInsert(getOpCtx(),
+ _params.canonicalQuery,
+ request->getQuery(),
+ _params.driver,
+ &_doc,
+ isInternalRequest,
+ request->getNamespaceString(),
+ &_specificStats);
_specificStats.objInserted = newObj;
@@ -722,7 +705,7 @@ PlanStage::StageState UpdateStage::doWork(WorkingSetID* out) {
return status;
}
-Status UpdateStage::restoreUpdateState() {
+void UpdateStage::doRestoreState() {
const UpdateRequest& request = *_params.request;
const NamespaceString& nsString(request.getNamespaceString());
@@ -731,9 +714,9 @@ Status UpdateStage::restoreUpdateState() {
!repl::getGlobalReplicationCoordinator()->canAcceptWritesFor(getOpCtx(), nsString);
if (userInitiatedWritesAndNotPrimary) {
- return Status(ErrorCodes::PrimarySteppedDown,
- str::stream() << "Demoted from primary while performing update on "
- << nsString.ns());
+ uasserted(ErrorCodes::PrimarySteppedDown,
+ str::stream() << "Demoted from primary while performing update on "
+ << nsString.ns());
}
if (request.getLifecycle()) {
@@ -741,19 +724,11 @@ Status UpdateStage::restoreUpdateState() {
lifecycle->setCollection(_collection);
if (!lifecycle->canContinue()) {
- return Status(ErrorCodes::IllegalOperation,
- "Update aborted due to invalid state transitions after yield.",
- 17270);
+ uasserted(17270, "Update aborted due to invalid state transitions after yield.");
}
_params.driver->refreshIndexKeys(lifecycle->getIndexKeys(getOpCtx()));
}
-
- return Status::OK();
-}
-
-void UpdateStage::doRestoreState() {
- uassertStatusOK(restoreUpdateState());
}
unique_ptr<PlanStageStats> UpdateStage::getStats() {
diff --git a/src/mongo/db/exec/update.h b/src/mongo/db/exec/update.h
index fa866f87606..f5dccd1c7e6 100644
--- a/src/mongo/db/exec/update.h
+++ b/src/mongo/db/exec/update.h
@@ -132,17 +132,16 @@ public:
*
* Fills out whether or not this is a fastmodinsert in 'stats'.
*
- * Returns the document to insert in *out.
+ * Returns the document to insert.
*/
- static Status applyUpdateOpsForInsert(OperationContext* opCtx,
- const CanonicalQuery* cq,
- const BSONObj& query,
- UpdateDriver* driver,
- mutablebson::Document* doc,
- bool isInternalRequest,
- const NamespaceString& ns,
- UpdateStats* stats,
- BSONObj* out);
+ static BSONObj applyUpdateOpsForInsert(OperationContext* opCtx,
+ const CanonicalQuery* cq,
+ const BSONObj& query,
+ UpdateDriver* driver,
+ mutablebson::Document* doc,
+ bool isInternalRequest,
+ const NamespaceString& ns,
+ UpdateStats* stats);
private:
/**
@@ -171,11 +170,6 @@ private:
bool needInsert();
/**
- * Helper for restoring the state of this update.
- */
- Status restoreUpdateState();
-
- /**
* Stores 'idToRetry' in '_idRetrying' so the update can be retried during the next call to
* work(). Always returns NEED_YIELD and sets 'out' to WorkingSet::INVALID_ID.
*/