From 16cf986b4b828f89f251c257ff812d02d77b8468 Mon Sep 17 00:00:00 2001 From: Kaloian Manassiev Date: Tue, 23 Feb 2016 12:57:10 -0500 Subject: SERVER-22783 Consolidate WriteConcernError parsing This change consolidates the checking for writeConcernError section to happen in the ShardRegistry instead of each command doing it separately. This makes WriteConcernFailed to be an actual error code of the command. Also cleans up the WCErrorDetail class by removing unnecessarly functionality. (cherry picked from commit e7c8e17220ef32befa8673bd776ba381b1911496) --- .../db/commands/write_commands/batch_executor.cpp | 13 ++--- src/mongo/db/exec/working_set_common.cpp | 3 +- .../s/catalog/replset/dist_lock_catalog_impl.cpp | 23 -------- .../replset/dist_lock_catalog_impl_test.cpp | 15 ++++-- src/mongo/s/client/shard_registry.cpp | 34 +++++++++++- src/mongo/s/client/shard_registry.h | 10 ++-- src/mongo/s/write_ops/batch_downconvert.cpp | 4 +- src/mongo/s/write_ops/batched_command_response.cpp | 12 ++--- src/mongo/s/write_ops/batched_command_response.h | 1 - .../s/write_ops/batched_command_response_test.cpp | 5 +- src/mongo/s/write_ops/wc_error_detail.cpp | 61 ++++++++++------------ src/mongo/s/write_ops/wc_error_detail.h | 38 ++++---------- src/mongo/s/write_ops/write_error_detail.cpp | 13 ++--- src/mongo/s/write_ops/write_error_detail.h | 15 +++--- src/mongo/scripting/mozjs/exception.cpp | 2 +- src/mongo/util/assert_util.cpp | 5 +- 16 files changed, 117 insertions(+), 137 deletions(-) diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp index 146bfd7e87f..e382f11d83d 100644 --- a/src/mongo/db/commands/write_commands/batch_executor.cpp +++ b/src/mongo/db/commands/write_commands/batch_executor.cpp @@ -119,13 +119,15 @@ private: std::unique_ptr _error; }; -WCErrorDetail* toWriteConcernError(const Status& wcStatus, const WriteConcernResult& wcResult) { - WCErrorDetail* wcError = new WCErrorDetail; +unique_ptr toWriteConcernError(const Status& wcStatus, + const WriteConcernResult& wcResult) { + auto wcError = stdx::make_unique(); wcError->setErrCode(wcStatus.code()); wcError->setErrMessage(wcStatus.reason()); - if (wcResult.wTimedOut) + if (wcResult.wTimedOut) { wcError->setErrInfo(BSON("wtimeout" << true)); + } return wcError; } @@ -326,21 +328,20 @@ void WriteBatchExecutor::executeBatch(const BatchedCommandRequest& request, // If something failed, we have already set the lastOp to be the last op to have succeeded // and written to the oplog. - unique_ptr wcError; { stdx::lock_guard lk(*_txn->getClient()); CurOp::get(_txn)->setMessage_inlock("waiting for write concern"); } + unique_ptr wcError; WriteConcernResult res; Status status = waitForWriteConcern(_txn, repl::ReplClientInfo::forClient(_txn->getClient()).getLastOp(), _txn->getWriteConcern(), &res); - if (!status.isOK()) { - wcError.reset(toWriteConcernError(status, res)); + wcError = std::move(toWriteConcernError(status, res)); } // diff --git a/src/mongo/db/exec/working_set_common.cpp b/src/mongo/db/exec/working_set_common.cpp index 745e8e8b4a5..db5ed4aa8ba 100644 --- a/src/mongo/db/exec/working_set_common.cpp +++ b/src/mongo/db/exec/working_set_common.cpp @@ -175,8 +175,7 @@ void WorkingSetCommon::getStatusMemberObject(const WorkingSet& ws, // static Status WorkingSetCommon::getMemberObjectStatus(const BSONObj& memberObj) { invariant(WorkingSetCommon::isValidStatusMemberObject(memberObj)); - return Status(static_cast(memberObj["code"].numberInt()), - memberObj["errmsg"]); + return Status(ErrorCodes::fromInt(memberObj["code"].numberInt()), memberObj["errmsg"]); } // static diff --git a/src/mongo/s/catalog/replset/dist_lock_catalog_impl.cpp b/src/mongo/s/catalog/replset/dist_lock_catalog_impl.cpp index 3664fdfcbc5..a617ef1a670 100644 --- a/src/mongo/s/catalog/replset/dist_lock_catalog_impl.cpp +++ b/src/mongo/s/catalog/replset/dist_lock_catalog_impl.cpp @@ -50,7 +50,6 @@ #include "mongo/s/write_ops/batched_command_request.h" #include "mongo/s/write_ops/batched_command_response.h" #include "mongo/s/write_ops/batched_update_request.h" -#include "mongo/s/write_ops/wc_error_detail.h" #include "mongo/util/time_support.h" namespace mongo { @@ -60,7 +59,6 @@ using std::vector; namespace { -const char kCmdResponseWriteConcernField[] = "writeConcernError"; const char kFindAndModifyResponseResultDocField[] = "value"; const char kLocalTimeField[] = "localTime"; const ReadPreferenceSetting kReadPref(ReadPreference::PrimaryOnly, TagSet()); @@ -84,26 +82,6 @@ StatusWith extractFindAndModifyNewObj(const BSONObj& responseObj) { return cmdStatus; } - BSONElement wcErrorElem; - auto wcErrStatus = - bsonExtractTypedField(responseObj, kCmdResponseWriteConcernField, Object, &wcErrorElem); - - if (wcErrStatus.isOK()) { - BSONObj wcErrObj(wcErrorElem.Obj()); - WCErrorDetail wcError; - - string wcErrorParseMsg; - if (!wcError.parseBSON(wcErrObj, &wcErrorParseMsg)) { - return Status(ErrorCodes::UnsupportedFormat, wcErrorParseMsg); - } - - return {ErrorCodes::WriteConcernFailed, wcError.getErrMessage()}; - } - - if (wcErrStatus != ErrorCodes::NoSuchKey) { - return wcErrStatus; - } - if (const auto& newDocElem = responseObj[kFindAndModifyResponseResultDocField]) { if (newDocElem.isNull()) { return {ErrorCodes::LockStateChangeFailed, @@ -347,7 +325,6 @@ Status DistLockCatalogImpl::unlockAll(OperationContext* txn, const std::string& auto response = _client->runCommandOnConfigWithRetries( txn, "config", cmdObj, ShardRegistry::kAllRetriableErrors); - if (!response.isOK()) { return response.getStatus(); } diff --git a/src/mongo/s/catalog/replset/dist_lock_catalog_impl_test.cpp b/src/mongo/s/catalog/replset/dist_lock_catalog_impl_test.cpp index 31bb64f4923..cf8ee77acd4 100644 --- a/src/mongo/s/catalog/replset/dist_lock_catalog_impl_test.cpp +++ b/src/mongo/s/catalog/replset/dist_lock_catalog_impl_test.cpp @@ -993,8 +993,7 @@ TEST_F(DistLockCatalogFixture, UnlockWriteConcernError) { ASSERT_FALSE(status.reason().empty()); }); - onCommand([](const RemoteCommandRequest& request) -> StatusWith { - return fromjson(R"({ + BSONObj writeConcernFailedResponse = fromjson(R"({ ok: 1, value: null, writeConcernError: { @@ -1002,7 +1001,17 @@ TEST_F(DistLockCatalogFixture, UnlockWriteConcernError) { errmsg: "waiting for replication timed out" } })"); - }); + + // The dist lock catalog calls into the ShardRegistry, which will retry 3 times for + // WriteConcernFailed errors + onCommand([&](const RemoteCommandRequest& request) + -> StatusWith { return writeConcernFailedResponse; }); + + onCommand([&](const RemoteCommandRequest& request) + -> StatusWith { return writeConcernFailedResponse; }); + + onCommand([&](const RemoteCommandRequest& request) + -> StatusWith { return writeConcernFailedResponse; }); future.timed_get(kFutureTimeout); } diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp index 6797ec27b55..a85ece2db3d 100644 --- a/src/mongo/s/client/shard_registry.cpp +++ b/src/mongo/s/client/shard_registry.cpp @@ -35,6 +35,7 @@ #include #include "mongo/bson/bsonobj.h" +#include "mongo/bson/util/bson_extract.h" #include "mongo/client/connection_string.h" #include "mongo/client/query_fetcher.h" #include "mongo/client/remote_command_targeter.h" @@ -53,6 +54,7 @@ #include "mongo/s/client/shard.h" #include "mongo/s/client/shard_connection.h" #include "mongo/s/grid.h" +#include "mongo/s/write_ops/wc_error_detail.h" #include "mongo/stdx/memory.h" #include "mongo/stdx/mutex.h" #include "mongo/util/log.h" @@ -74,6 +76,8 @@ using repl::OpTime; namespace { +const char kCmdResponseWriteConcernField[] = "writeConcernError"; + const Seconds kConfigCommandTimeout{30}; const int kOnErrorNumRetries = 3; const BSONObj kReplMetadata(BSON(rpc::kReplSetMetadataFieldName << 1)); @@ -119,6 +123,28 @@ BSONObj appendMaxTimeToCmdObj(long long maxTimeMicros, const BSONObj& cmdObj) { return updatedCmdBuilder.obj(); } +Status checkForWriteConcernError(const BSONObj& obj) { + BSONElement wcErrorElem; + Status status = bsonExtractTypedField(obj, kCmdResponseWriteConcernField, Object, &wcErrorElem); + if (status.isOK()) { + BSONObj wcErrObj(wcErrorElem.Obj()); + + WCErrorDetail wcError; + string wcErrorParseMsg; + if (!wcError.parseBSON(wcErrObj, &wcErrorParseMsg)) { + return Status(ErrorCodes::UnsupportedFormat, + str::stream() << "Failed to parse write concern section due to " + << wcErrorParseMsg); + } else { + return Status(ErrorCodes::WriteConcernFailed, wcError.toString()); + } + } else if (status == ErrorCodes::NoSuchKey) { + return Status::OK(); + } + + return status; +} + } // unnamed namespace const ShardRegistry::ErrorCodesSet ShardRegistry::kNotMasterErrors{ErrorCodes::NotMaster, @@ -755,9 +781,8 @@ StatusWith ShardRegistry::_runCommandWithMetadat // Block until the command is carried out executor->wait(callStatus.getValue()); - updateReplSetMonitor(targeter, host.getValue(), responseStatus.getStatus()); - if (!responseStatus.isOK()) { + updateReplSetMonitor(targeter, host.getValue(), responseStatus.getStatus()); return responseStatus.getStatus(); } @@ -770,6 +795,11 @@ StatusWith ShardRegistry::_runCommandWithMetadat return commandSpecificStatus; } + Status writeConcernStatus = checkForWriteConcernError(response.data); + if (!writeConcernStatus.isOK()) { + return writeConcernStatus; + } + CommandResponse cmdResponse; cmdResponse.response = response.data.getOwned(); cmdResponse.metadata = response.metadata.getOwned(); diff --git a/src/mongo/s/client/shard_registry.h b/src/mongo/s/client/shard_registry.h index dec0f770803..8965839d86c 100644 --- a/src/mongo/s/client/shard_registry.h +++ b/src/mongo/s/client/shard_registry.h @@ -303,9 +303,13 @@ public: using ErrorCodesSet = unordered_set; /** - * Runs commands against the config shard's primary. Retries if executing the command fails with - * one of the given error codes, or if executing the command succeeds but the server returned - * one of the codes. If executing the command fails with a different code we return that code. + * Runs a command against the config shard's primary and includes a set of errors on which to + * retry. Converts responses, which contain writeConcernError into WriteConcernFailed status. + * + * Retries if executing the command fails with one of the specified error codes, or if executing + * the command succeeds but the server returned one of the codes. If executing the command fails + * with a different code we return that code. + * * If executing the command succeeds and the command itself succeeds or fails with a code not in * the set, then we return the command response object. Thus the caller is responsible for * checking the command response object for any kind of command-specific failures other than diff --git a/src/mongo/s/write_ops/batch_downconvert.cpp b/src/mongo/s/write_ops/batch_downconvert.cpp index 38446241219..3531ec34193 100644 --- a/src/mongo/s/write_ops/batch_downconvert.cpp +++ b/src/mongo/s/write_ops/batch_downconvert.cpp @@ -92,8 +92,8 @@ Status extractGLEErrors(const BSONObj& gleResponse, GLEErrors* errors) { code == ErrorCodes::NotMaster || code == ErrorCodes::UnknownReplWriteConcern || code == ErrorCodes::WriteConcernFailed) { // Write concern errors that get returned as regular errors (result may not be ok: 1.0) - errors->wcError.reset(new WCErrorDetail); - errors->wcError->setErrCode(code); + errors->wcError.reset(new WCErrorDetail()); + errors->wcError->setErrCode(ErrorCodes::fromInt(code)); errors->wcError->setErrMessage(errMsg); } else if (!isOK) { // diff --git a/src/mongo/s/write_ops/batched_command_response.cpp b/src/mongo/s/write_ops/batched_command_response.cpp index 71afec87799..6f586da12c7 100644 --- a/src/mongo/s/write_ops/batched_command_response.cpp +++ b/src/mongo/s/write_ops/batched_command_response.cpp @@ -371,10 +371,6 @@ void BatchedCommandResponse::setErrMessage(StringData errMessage) { _isErrMessageSet = true; } -void BatchedCommandResponse::unsetErrMessage() { - _isErrMessageSet = false; -} - bool BatchedCommandResponse::isErrMessageSet() const { return _isErrMessageSet; } @@ -579,21 +575,19 @@ const WCErrorDetail* BatchedCommandResponse::getWriteConcernError() const { Status BatchedCommandResponse::toStatus() const { if (!getOk()) { - return Status(static_cast(getErrCode()), getErrMessage()); + return Status(ErrorCodes::fromInt(getErrCode()), getErrMessage()); } if (isErrDetailsSet()) { const WriteErrorDetail* errDetail = getErrDetails().front(); - return Status(static_cast(errDetail->getErrCode()), - errDetail->getErrMessage()); + return Status(ErrorCodes::fromInt(errDetail->getErrCode()), errDetail->getErrMessage()); } if (isWriteConcernErrorSet()) { const WCErrorDetail* errDetail = getWriteConcernError(); - return Status(static_cast(errDetail->getErrCode()), - errDetail->getErrMessage()); + return Status(ErrorCodes::fromInt(errDetail->getErrCode()), errDetail->getErrMessage()); } return Status::OK(); diff --git a/src/mongo/s/write_ops/batched_command_response.h b/src/mongo/s/write_ops/batched_command_response.h index bf2cb1c6f68..e59c2c3ea05 100644 --- a/src/mongo/s/write_ops/batched_command_response.h +++ b/src/mongo/s/write_ops/batched_command_response.h @@ -96,7 +96,6 @@ public: int getErrCode() const; void setErrMessage(StringData errMessage); - void unsetErrMessage(); bool isErrMessageSet() const; const std::string& getErrMessage() const; diff --git a/src/mongo/s/write_ops/batched_command_response_test.cpp b/src/mongo/s/write_ops/batched_command_response_test.cpp index 4f562078194..33d35526d77 100644 --- a/src/mongo/s/write_ops/batched_command_response_test.cpp +++ b/src/mongo/s/write_ops/batched_command_response_test.cpp @@ -50,9 +50,8 @@ TEST(BatchedCommandResponse, Basic) { << WriteErrorDetail::errInfo(BSON("more info" << 1)) << WriteErrorDetail::errMessage("index 1 failed too"))); - BSONObj writeConcernError(BSON(WCErrorDetail::errCode(8) - << WCErrorDetail::errInfo(BSON("a" << 1)) - << WCErrorDetail::errMessage("norepl"))); + BSONObj writeConcernError(BSON("code" << 8 << "errInfo" << BSON("a" << 1) << "errmsg" + << "norepl")); BSONObj origResponseObj = BSON(BatchedCommandResponse::ok(false) diff --git a/src/mongo/s/write_ops/wc_error_detail.cpp b/src/mongo/s/write_ops/wc_error_detail.cpp index 40474c819c7..33528c42525 100644 --- a/src/mongo/s/write_ops/wc_error_detail.cpp +++ b/src/mongo/s/write_ops/wc_error_detail.cpp @@ -26,6 +26,8 @@ * then also delete it in the license file. */ +#include "mongo/platform/basic.h" + #include "mongo/s/write_ops/wc_error_detail.h" #include "mongo/db/field_parser.h" @@ -35,26 +37,27 @@ namespace mongo { using std::string; -using mongoutils::str::stream; -const BSONField WCErrorDetail::errCode("code"); -const BSONField WCErrorDetail::errInfo("errInfo"); -const BSONField WCErrorDetail::errMessage("errmsg"); +namespace { + +const BSONField errCode("code"); +const BSONField errInfo("errInfo"); +const BSONField errMessage("errmsg"); + +} // namespace WCErrorDetail::WCErrorDetail() { clear(); } -WCErrorDetail::~WCErrorDetail() {} - -bool WCErrorDetail::isValid(std::string* errMsg) const { - std::string dummy; +bool WCErrorDetail::isValid(string* errMsg) const { + string dummy; if (errMsg == NULL) { errMsg = &dummy; } // All the mandatory fields must be present. if (!_isErrCodeSet) { - *errMsg = stream() << "missing " << errCode.name() << " field"; + *errMsg = str::stream() << "missing " << errCode.name() << " field"; return false; } @@ -79,15 +82,19 @@ BSONObj WCErrorDetail::toBSON() const { bool WCErrorDetail::parseBSON(const BSONObj& source, string* errMsg) { clear(); - std::string dummy; + string dummy; if (!errMsg) errMsg = &dummy; FieldParser::FieldState fieldState; - fieldState = FieldParser::extract(source, errCode, &_errCode, errMsg); + int errCodeValue; + fieldState = FieldParser::extract(source, errCode, &errCodeValue, errMsg); if (fieldState == FieldParser::FIELD_INVALID) return false; _isErrCodeSet = fieldState == FieldParser::FIELD_SET; + if (_isErrCodeSet) { + _errCode = ErrorCodes::fromInt(errCodeValue); + } fieldState = FieldParser::extract(source, errInfo, &_errInfo, errMsg); if (fieldState == FieldParser::FIELD_INVALID) @@ -103,7 +110,7 @@ bool WCErrorDetail::parseBSON(const BSONObj& source, string* errMsg) { } void WCErrorDetail::clear() { - _errCode = 0; + _errCode = ErrorCodes::OK; _isErrCodeSet = false; _errInfo = BSONObj(); @@ -126,24 +133,18 @@ void WCErrorDetail::cloneTo(WCErrorDetail* other) const { other->_isErrMessageSet = _isErrMessageSet; } -std::string WCErrorDetail::toString() const { - return "implement me"; +string WCErrorDetail::toString() const { + return str::stream() << (_isErrCodeSet ? ErrorCodes::errorString(_errCode) : "") + << ": " << (_isErrMessageSet ? _errMessage : "") + << ". Error details: " << (_isErrInfoSet ? _errInfo.toString() : ""); } -void WCErrorDetail::setErrCode(int errCode) { - _errCode = errCode; +void WCErrorDetail::setErrCode(ErrorCodes::Error code) { + _errCode = code; _isErrCodeSet = true; } -void WCErrorDetail::unsetErrCode() { - _isErrCodeSet = false; -} - -bool WCErrorDetail::isErrCodeSet() const { - return _isErrCodeSet; -} - -int WCErrorDetail::getErrCode() const { +ErrorCodes::Error WCErrorDetail::getErrCode() const { dassert(_isErrCodeSet); return _errCode; } @@ -153,10 +154,6 @@ void WCErrorDetail::setErrInfo(const BSONObj& errInfo) { _isErrInfoSet = true; } -void WCErrorDetail::unsetErrInfo() { - _isErrInfoSet = false; -} - bool WCErrorDetail::isErrInfoSet() const { return _isErrInfoSet; } @@ -171,15 +168,11 @@ void WCErrorDetail::setErrMessage(StringData errMessage) { _isErrMessageSet = true; } -void WCErrorDetail::unsetErrMessage() { - _isErrMessageSet = false; -} - bool WCErrorDetail::isErrMessageSet() const { return _isErrMessageSet; } -const std::string& WCErrorDetail::getErrMessage() const { +const string& WCErrorDetail::getErrMessage() const { dassert(_isErrMessageSet); return _errMessage; } diff --git a/src/mongo/s/write_ops/wc_error_detail.h b/src/mongo/s/write_ops/wc_error_detail.h index 6bf1a757997..05d07d2f090 100644 --- a/src/mongo/s/write_ops/wc_error_detail.h +++ b/src/mongo/s/write_ops/wc_error_detail.h @@ -29,11 +29,10 @@ #pragma once #include -#include +#include "mongo/base/error_codes.h" #include "mongo/base/string_data.h" #include "mongo/db/jsobj.h" -#include "mongo/s/bson_serializable.h" namespace mongo { @@ -41,24 +40,11 @@ namespace mongo { * This class represents the layout and content of the error that occurs while trying * to satisfy the write concern after executing the insert/update/delete runCommand. */ -class WCErrorDetail : public BSONSerializable { +class WCErrorDetail { MONGO_DISALLOW_COPYING(WCErrorDetail); public: - // - // schema declarations - // - - static const BSONField errCode; - static const BSONField errInfo; - static const BSONField errMessage; - - // - // construction / destruction - // - WCErrorDetail(); - virtual ~WCErrorDetail(); /** Copies all the fields present in 'this' to 'other'. */ void cloneTo(WCErrorDetail* other) const; @@ -67,28 +53,24 @@ public: // bson serializable interface implementation // - virtual bool isValid(std::string* errMsg) const; - virtual BSONObj toBSON() const; - virtual bool parseBSON(const BSONObj& source, std::string* errMsg); - virtual void clear(); - virtual std::string toString() const; + bool isValid(std::string* errMsg) const; + BSONObj toBSON() const; + bool parseBSON(const BSONObj& source, std::string* errMsg); + void clear(); + std::string toString() const; // // individual field accessors // - void setErrCode(int errCode); - void unsetErrCode(); - bool isErrCodeSet() const; - int getErrCode() const; + void setErrCode(ErrorCodes::Error code); + ErrorCodes::Error getErrCode() const; void setErrInfo(const BSONObj& errInfo); - void unsetErrInfo(); bool isErrInfoSet() const; const BSONObj& getErrInfo() const; void setErrMessage(StringData errMessage); - void unsetErrMessage(); bool isErrMessageSet() const; const std::string& getErrMessage() const; @@ -96,7 +78,7 @@ private: // Convention: (M)andatory, (O)ptional // (M) error code for the write concern error. - int _errCode; + ErrorCodes::Error _errCode; bool _isErrCodeSet; // (O) further details about the write concern error. diff --git a/src/mongo/s/write_ops/write_error_detail.cpp b/src/mongo/s/write_ops/write_error_detail.cpp index b374ff47638..cc2368154fe 100644 --- a/src/mongo/s/write_ops/write_error_detail.cpp +++ b/src/mongo/s/write_ops/write_error_detail.cpp @@ -26,6 +26,8 @@ * then also delete it in the license file. */ +#include "mongo/platform/basic.h" + #include "mongo/s/write_ops/write_error_detail.h" #include "mongo/db/field_parser.h" @@ -35,7 +37,6 @@ namespace mongo { using std::string; -using mongoutils::str::stream; const BSONField WriteErrorDetail::index("index"); const BSONField WriteErrorDetail::errCode("code"); const BSONField WriteErrorDetail::errInfo("errInfo"); @@ -45,8 +46,6 @@ WriteErrorDetail::WriteErrorDetail() { clear(); } -WriteErrorDetail::~WriteErrorDetail() {} - bool WriteErrorDetail::isValid(std::string* errMsg) const { std::string dummy; if (errMsg == NULL) { @@ -55,12 +54,12 @@ bool WriteErrorDetail::isValid(std::string* errMsg) const { // All the mandatory fields must be present. if (!_isIndexSet) { - *errMsg = stream() << "missing " << index.name() << " field"; + *errMsg = str::stream() << "missing " << index.name() << " field"; return false; } if (!_isErrCodeSet) { - *errMsg = stream() << "missing " << errCode.name() << " field"; + *errMsg = str::stream() << "missing " << errCode.name() << " field"; return false; } @@ -209,10 +208,6 @@ void WriteErrorDetail::setErrMessage(StringData errMessage) { _isErrMessageSet = true; } -void WriteErrorDetail::unsetErrMessage() { - _isErrMessageSet = false; -} - bool WriteErrorDetail::isErrMessageSet() const { return _isErrMessageSet; } diff --git a/src/mongo/s/write_ops/write_error_detail.h b/src/mongo/s/write_ops/write_error_detail.h index 9ac64a85b5d..9c431f02f57 100644 --- a/src/mongo/s/write_ops/write_error_detail.h +++ b/src/mongo/s/write_ops/write_error_detail.h @@ -33,7 +33,6 @@ #include "mongo/base/string_data.h" #include "mongo/db/jsobj.h" -#include "mongo/s/bson_serializable.h" namespace mongo { @@ -41,7 +40,7 @@ namespace mongo { * This class represents the layout and content of a insert/update/delete runCommand, * the response side. */ -class WriteErrorDetail : public BSONSerializable { +class WriteErrorDetail { MONGO_DISALLOW_COPYING(WriteErrorDetail); public: @@ -59,7 +58,6 @@ public: // WriteErrorDetail(); - virtual ~WriteErrorDetail(); /** Copies all the fields present in 'this' to 'other'. */ void cloneTo(WriteErrorDetail* other) const; @@ -68,11 +66,11 @@ public: // bson serializable interface implementation // - virtual bool isValid(std::string* errMsg) const; - virtual BSONObj toBSON() const; - virtual bool parseBSON(const BSONObj& source, std::string* errMsg); - virtual void clear(); - virtual std::string toString() const; + bool isValid(std::string* errMsg) const; + BSONObj toBSON() const; + bool parseBSON(const BSONObj& source, std::string* errMsg); + void clear(); + std::string toString() const; // // individual field accessors @@ -94,7 +92,6 @@ public: const BSONObj& getErrInfo() const; void setErrMessage(StringData errMessage); - void unsetErrMessage(); bool isErrMessageSet() const; const std::string& getErrMessage() const; diff --git a/src/mongo/scripting/mozjs/exception.cpp b/src/mongo/scripting/mozjs/exception.cpp index 5b813087ad2..dd67fc41379 100644 --- a/src/mongo/scripting/mozjs/exception.cpp +++ b/src/mongo/scripting/mozjs/exception.cpp @@ -116,7 +116,7 @@ Status JSErrorReportToStatus(JSContext* cx, if (report->errorNumber < JSErr_Limit) { error = ErrorCodes::JSInterpreterFailure; } else { - error = static_cast(report->errorNumber - JSErr_Limit); + error = ErrorCodes::fromInt(report->errorNumber - JSErr_Limit); } } diff --git a/src/mongo/util/assert_util.cpp b/src/mongo/util/assert_util.cpp index c460bfb410d..750ff88f308 100644 --- a/src/mongo/util/assert_util.cpp +++ b/src/mongo/util/assert_util.cpp @@ -90,9 +90,10 @@ void DBException::traceIfNeeded(const DBException& e) { } ErrorCodes::Error DBException::convertExceptionCode(int exCode) { - if (exCode == 0) + if (exCode == 0) { return ErrorCodes::UnknownError; - return static_cast(exCode); + } + return ErrorCodes::fromInt(exCode); } void ExceptionInfo::append(BSONObjBuilder& b, const char* m, const char* c) const { -- cgit v1.2.1