diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-10-09 12:02:07 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-10-13 09:43:40 -0400 |
commit | 25b498934fea1c93ae82823ee13cff0866ed6007 (patch) | |
tree | 9dd86577760e216f444aca7a089bf002040dcb35 /src | |
parent | 4877c6b197438495d9fdd88317d4b79d565014c6 (diff) | |
download | mongo-25b498934fea1c93ae82823ee13cff0866ed6007.tar.gz |
SERVER-20646 Get rid of CommonErrorCodes
Replace all usages with the standard ErrorCodes enumeration.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/base/error_codes.err | 10 | ||||
-rw-r--r-- | src/mongo/client/dbclient_rs.cpp | 6 | ||||
-rw-r--r-- | src/mongo/client/parallel.cpp | 4 | ||||
-rw-r--r-- | src/mongo/client/syncclusterconnection.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/dbcommands.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/instance.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator.h | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/s/migration_impl.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/client/shard_registry.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_find_and_modify_cmd.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/s_only.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/stale_exception.h | 20 | ||||
-rw-r--r-- | src/mongo/util/assert_util.h | 14 |
14 files changed, 36 insertions, 50 deletions
diff --git a/src/mongo/base/error_codes.err b/src/mongo/base/error_codes.err index adb7a372f05..7044584ab00 100644 --- a/src/mongo/base/error_codes.err +++ b/src/mongo/base/error_codes.err @@ -152,7 +152,7 @@ error_code("NoConfigMaster", 149) # Non-sequential error codes (for compatibility only) error_code("RecvStaleConfig", 9996) -error_code("NotMaster", 10107) #this comes from assert_util.h +error_code("NotMaster", 10107) error_code("CannotGrowDocumentInCappedNamespace", 10003) error_code("DuplicateKey", 11000) error_code("InterruptedAtShutdown", 11600) @@ -161,13 +161,13 @@ error_code("OutOfDiskSpace", 14031 ) error_code("KeyTooLong", 17280); error_code("BackgroundOperationInProgressForDatabase", 12586); error_code("BackgroundOperationInProgressForNamespace", 12587); -error_code("NotMasterOrSecondaryCode", 13436); -error_code("NotMasterNoSlaveOkCode", 13435); +error_code("NotMasterOrSecondary", 13436); +error_code("NotMasterNoSlaveOk", 13435); error_code("ShardKeyTooBig", 13334); error_code("SendStaleConfig", 13388); error_code("DatabaseDifferCase", 13297); -error_code("PrepareConfigsFailedCode", 13104); +error_code("PrepareConfigsFailed", 13104); error_class("NetworkError", ["HostUnreachable", "HostNotFound", "NetworkTimeout"]) error_class("Interruption", ["Interrupted", "InterruptedAtShutdown", "ExceededTimeLimit"]) -error_class("NotMasterError", ["NotMaster", "NotMasterNoSlaveOkCode"]) +error_class("NotMasterError", ["NotMaster", "NotMasterNoSlaveOk"]) diff --git a/src/mongo/client/dbclient_rs.cpp b/src/mongo/client/dbclient_rs.cpp index 4eaf980b610..6d3e6d2973e 100644 --- a/src/mongo/client/dbclient_rs.cpp +++ b/src/mongo/client/dbclient_rs.cpp @@ -629,7 +629,7 @@ unique_ptr<DBClientCursor> DBClientReplicaSet::checkSlaveQueryResult( // If the error code here ever changes, we need to change this code also BSONElement code = error["code"]; - if (code.isNumber() && code.Int() == NotMasterOrSecondaryCode /* not master or secondary */) { + if (code.isNumber() && code.Int() == ErrorCodes::NotMasterOrSecondary) { isntSecondary(); throw DBException(str::stream() << "slave " << _lastSlaveOkHost.toString() << " is no longer secondary", @@ -847,7 +847,7 @@ void DBClientReplicaSet::checkResponse(const char* data, if (nReturned == -1 /* no result, maybe network problem */ || (hasErrField(dataObj) && !dataObj["code"].eoo() && - dataObj["code"].Int() == NotMasterOrSecondaryCode)) { + dataObj["code"].Int() == ErrorCodes::NotMasterOrSecondary)) { if (_lazyState._lastClient == _lastSlaveOkConn.get()) { isntSecondary(); } else if (_lazyState._lastClient == _master.get()) { @@ -871,7 +871,7 @@ void DBClientReplicaSet::checkResponse(const char* data, if (nReturned == -1 /* no result, maybe network problem */ || (hasErrField(dataObj) && !dataObj["code"].eoo() && - dataObj["code"].Int() == NotMasterNoSlaveOkCode)) { + dataObj["code"].Int() == ErrorCodes::NotMasterNoSlaveOk)) { if (_lazyState._lastClient == _master.get()) { isntMaster(); } diff --git a/src/mongo/client/parallel.cpp b/src/mongo/client/parallel.cpp index 7977bd45250..8d5d72d7c4b 100644 --- a/src/mongo/client/parallel.cpp +++ b/src/mongo/client/parallel.cpp @@ -82,7 +82,7 @@ string ParallelSortClusteredCursor::getNS() { /** * Throws a RecvStaleConfigException wrapping the stale error document in this cursor when the - * ShardConfigStale flag is set or a command returns a SendStaleConfigCode error code. + * ShardConfigStale flag is set or a command returns a ErrorCodes::SendStaleConfig error code. */ void throwCursorStale(DBClientCursor* cursor) { verify(cursor); @@ -99,7 +99,7 @@ void throwCursorStale(DBClientCursor* cursor) { // flag on the cursor. // TODO: Standardize stale config reporting. BSONObj res = cursor->peekFirst(); - if (res.hasField("code") && res["code"].Number() == SendStaleConfigCode) { + if (res.hasField("code") && res["code"].Number() == ErrorCodes::SendStaleConfig) { throw RecvStaleConfigException("command returned a stale config error", res); } } diff --git a/src/mongo/client/syncclusterconnection.cpp b/src/mongo/client/syncclusterconnection.cpp index 1340bb65822..37d9b631684 100644 --- a/src/mongo/client/syncclusterconnection.cpp +++ b/src/mongo/client/syncclusterconnection.cpp @@ -41,8 +41,6 @@ #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/util/log.h" -// error codes 8000-8009 - namespace mongo { using std::unique_ptr; @@ -285,7 +283,7 @@ BSONObj SyncClusterConnection::findOne(const string& ns, if (lockType > 0) { // write $cmd string errmsg; if (!prepare(errmsg)) - throw UserException(PrepareConfigsFailedCode, + throw UserException(ErrorCodes::PrepareConfigsFailed, (string) "SyncClusterConnection::findOne prepare failed: " + errmsg); diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp index 6dc9a14e1d7..d5df85345d6 100644 --- a/src/mongo/db/dbcommands.cpp +++ b/src/mongo/db/dbcommands.cpp @@ -1219,7 +1219,7 @@ void Command::execCommand(OperationContext* txn, // This logic is clearer if we don't have to invert it. if (!canRunHere && command->slaveOverrideOk()) { - uasserted(ErrorCodes::NotMasterNoSlaveOkCode, "not master and slaveOk=false"); + uasserted(ErrorCodes::NotMasterNoSlaveOk, "not master and slaveOk=false"); } uassert(ErrorCodes::NotMaster, "not master", canRunHere); @@ -1228,7 +1228,7 @@ void Command::execCommand(OperationContext* txn, replCoord->getReplicationMode() == repl::ReplicationCoordinator::modeReplSet && !replCoord->canAcceptWritesForDatabase(dbname) && !replCoord->getMemberState().secondary()) { - uasserted(ErrorCodes::NotMasterOrSecondaryCode, "node is recovering"); + uasserted(ErrorCodes::NotMasterOrSecondary, "node is recovering"); } } diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp index 55f8e72a6cf..183912d6187 100644 --- a/src/mongo/db/instance.cpp +++ b/src/mongo/db/instance.cpp @@ -179,7 +179,7 @@ void generateLegacyQueryErrorResponse(const AssertionException* exception, << " ntoreturn:" << queryMessage.ntoreturn; } - const SendStaleConfigException* scex = (exception->getCode() == SendStaleConfigCode) + const SendStaleConfigException* scex = (exception->getCode() == ErrorCodes::SendStaleConfig) ? static_cast<const SendStaleConfigException*>(exception) : NULL; diff --git a/src/mongo/db/repl/replication_coordinator.h b/src/mongo/db/repl/replication_coordinator.h index 03ea6a907a4..fda5d177abf 100644 --- a/src/mongo/db/repl/replication_coordinator.h +++ b/src/mongo/db/repl/replication_coordinator.h @@ -542,7 +542,7 @@ public: * Returns Status::OK() if all updates are processed correctly, NodeNotFound * if any updating node cannot be found in the config, InvalidReplicaSetConfig if the * "configVersion" sent in any of the updates doesn't match our config version, or - * NotMasterOrSecondaryCode if we are in state REMOVED or otherwise don't have a valid + * NotMasterOrSecondary if we are in state REMOVED or otherwise don't have a valid * replica set config. * If a non-OK status is returned, it is unspecified whether none or some of the updates * were applied. diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index c9b1f6203d3..dc2cb75c7d5 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -931,7 +931,7 @@ Status ReplicationCoordinatorImpl::_setLastOptime_inlock(const UpdatePositionArg long long* configVersion) { if (_selfIndex == -1) { // Ignore updates when we're in state REMOVED - return Status(ErrorCodes::NotMasterOrSecondaryCode, + return Status(ErrorCodes::NotMasterOrSecondary, "Received replSetUpdatePosition command but we are in state REMOVED"); } invariant(getReplicationMode() == modeReplSet); @@ -1479,7 +1479,7 @@ Status ReplicationCoordinatorImpl::checkCanServeReadsFor(OperationContext* txn, const NamespaceString& ns, bool slaveOk) { if (_memberState.rollback() && ns.isOplog()) { - return Status(ErrorCodes::NotMasterOrSecondaryCode, + return Status(ErrorCodes::NotMasterOrSecondary, "cannot read from oplog collection while in rollback"); } if (txn->getClient()->isInDirectClient()) { @@ -1495,10 +1495,10 @@ Status ReplicationCoordinatorImpl::checkCanServeReadsFor(OperationContext* txn, if (_canServeNonLocalReads.loadRelaxed()) { return Status::OK(); } - return Status(ErrorCodes::NotMasterOrSecondaryCode, + return Status(ErrorCodes::NotMasterOrSecondary, "not master or secondary; cannot currently read from this replSet member"); } - return Status(ErrorCodes::NotMasterNoSlaveOkCode, "not master and slaveOk=false"); + return Status(ErrorCodes::NotMasterNoSlaveOk, "not master and slaveOk=false"); } bool ReplicationCoordinatorImpl::isInPrimaryOrSecondaryState() const { diff --git a/src/mongo/db/s/migration_impl.cpp b/src/mongo/db/s/migration_impl.cpp index c84cffd98a2..b04a4d02679 100644 --- a/src/mongo/db/s/migration_impl.cpp +++ b/src/mongo/db/s/migration_impl.cpp @@ -441,7 +441,7 @@ Status ChunkMoveOperationState::commitMigration(OperationContext* txn) { // For testing migration failures if (MONGO_FAIL_POINT(failMigrationConfigWritePrepare)) { throw DBException("mock migration failure before config write", - PrepareConfigsFailedCode); + ErrorCodes::PrepareConfigsFailed); } applyOpsStatus = @@ -456,7 +456,7 @@ Status ChunkMoveOperationState::commitMigration(OperationContext* txn) { applyOpsStatus = ex.toStatus(); } - if (applyOpsStatus == ErrorCodes::PrepareConfigsFailedCode) { + if (applyOpsStatus == ErrorCodes::PrepareConfigsFailed) { // In the process of issuing the migrate commit, the SyncClusterConnection checks that // the config servers are reachable. If they are not, we are sure that the applyOps // command was not sent to any of the configs, so we can safely back out of the diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp index ba8fdd94be2..3d0c7725184 100644 --- a/src/mongo/s/client/shard_registry.cpp +++ b/src/mongo/s/client/shard_registry.cpp @@ -563,7 +563,7 @@ StatusWith<ShardRegistry::CommandResponse> ShardRegistry::_runCommandWithNotMast Status commandStatus = getStatusFromCommandResult(response.getValue().response); if (ErrorCodes::NotMaster == commandStatus || - ErrorCodes::NotMasterNoSlaveOkCode == commandStatus) { + ErrorCodes::NotMasterNoSlaveOk == commandStatus) { if (i == kNotMasterNumRetries - 1) { // If we're out of retries don't bother sleeping, just return. return commandStatus; diff --git a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp index dee89e63c05..4288b29620c 100644 --- a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp +++ b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp @@ -220,8 +220,8 @@ private: bool ok = conn->runCommand(conf->name(), cmdObj, res); conn.done(); - // RecvStaleConfigCode is the code for RecvStaleConfigException. - if (!ok && res.getIntField("code") == RecvStaleConfigCode) { + // ErrorCodes::RecvStaleConfig is the code for RecvStaleConfigException. + if (!ok && res.getIntField("code") == ErrorCodes::RecvStaleConfig) { // Command code traps this exception and re-runs throw RecvStaleConfigException("FindAndModify", res); } diff --git a/src/mongo/s/s_only.cpp b/src/mongo/s/s_only.cpp index d62107a76d5..277d653cbde 100644 --- a/src/mongo/s/s_only.cpp +++ b/src/mongo/s/s_only.cpp @@ -130,7 +130,7 @@ void Command::execCommandClientBasic(OperationContext* txn, const int code = e.getCode(); // Codes for StaleConfigException - if (code == RecvStaleConfigCode || code == SendStaleConfigCode) { + if (code == ErrorCodes::RecvStaleConfig || code == ErrorCodes::SendStaleConfig) { throw; } diff --git a/src/mongo/s/stale_exception.h b/src/mongo/s/stale_exception.h index 227fced8698..c9d3827572d 100644 --- a/src/mongo/s/stale_exception.h +++ b/src/mongo/s/stale_exception.h @@ -47,11 +47,11 @@ public: int code, ChunkVersion received, ChunkVersion wanted) - : AssertionException(stream() << raw << " ( ns : " << ns - << ", received : " << received.toString() - << ", wanted : " << wanted.toString() << ", " - << (code == SendStaleConfigCode ? "send" : "recv") << " )", - code), + : AssertionException( + stream() << raw << " ( ns : " << ns << ", received : " << received.toString() + << ", wanted : " << wanted.toString() << ", " + << (code == ErrorCodes::SendStaleConfig ? "send" : "recv") << " )", + code), _ns(ns), _received(received), _wanted(wanted) {} @@ -64,7 +64,7 @@ public: : std::string("<unknown>")) << ", received : " << ChunkVersion::fromBSON(error, "vReceived").toString() << ", wanted : " << ChunkVersion::fromBSON(error, "vWanted").toString() - << ", " << (code == SendStaleConfigCode ? "send" : "recv") << " )", + << ", " << (code == ErrorCodes::SendStaleConfig ? "send" : "recv") << " )", code), // For legacy reasons, we may not always get a namespace here _ns(error["ns"].type() == String ? error["ns"].String() : ""), @@ -138,10 +138,10 @@ public: const std::string& raw, ChunkVersion received, ChunkVersion wanted) - : StaleConfigException(ns, raw, SendStaleConfigCode, received, wanted) {} + : StaleConfigException(ns, raw, ErrorCodes::SendStaleConfig, received, wanted) {} SendStaleConfigException(const std::string& raw, const BSONObj& error) - : StaleConfigException(raw, SendStaleConfigCode, error) {} + : StaleConfigException(raw, ErrorCodes::SendStaleConfig, error) {} }; class RecvStaleConfigException : public StaleConfigException { @@ -150,10 +150,10 @@ public: const std::string& raw, ChunkVersion received, ChunkVersion wanted) - : StaleConfigException(ns, raw, RecvStaleConfigCode, received, wanted) {} + : StaleConfigException(ns, raw, ErrorCodes::RecvStaleConfig, received, wanted) {} RecvStaleConfigException(const std::string& raw, const BSONObj& error) - : StaleConfigException(raw, RecvStaleConfigCode, error) {} + : StaleConfigException(raw, ErrorCodes::RecvStaleConfig, error) {} }; } // namespace mongo diff --git a/src/mongo/util/assert_util.h b/src/mongo/util/assert_util.h index e3f67296266..c32e770b0e4 100644 --- a/src/mongo/util/assert_util.h +++ b/src/mongo/util/assert_util.h @@ -1,6 +1,4 @@ -// assert_util.h - -/* Copyright 2009 10gen Inc. +/** Copyright 2009 10gen Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, @@ -46,16 +44,6 @@ namespace mongo { -enum CommonErrorCodes { - OkCode = 0, - SendStaleConfigCode = 13388, // uassert( 13388 ) - RecvStaleConfigCode = 9996, // uassert( 9996 ) - PrepareConfigsFailedCode = 13104, // uassert( 13104 ) - NotMasterOrSecondaryCode = 13436, // uassert( 13436 ) - NotMasterNoSlaveOkCode = 13435, // uassert( 13435 ) - NotMaster = 10107, // uassert( 10107 ) -}; - class AssertionCount { public: AssertionCount(); |