diff options
author | clang-format-7.0.1 <adam.martin@10gen.com> | 2019-07-26 18:20:35 -0400 |
---|---|---|
committer | ADAM David Alan Martin <adam.martin@10gen.com> | 2019-07-27 11:02:23 -0400 |
commit | 134a4083953270e8a11430395357fb70a29047ad (patch) | |
tree | dd428e1230e31d92b20b393dfdc17ffe7fa79cb6 /src/mongo/client | |
parent | 1e46b5049003f427047e723ea5fab15b5a9253ca (diff) | |
download | mongo-134a4083953270e8a11430395357fb70a29047ad.tar.gz |
SERVER-41772 Apply clang-format 7.0.1 to the codebase
Diffstat (limited to 'src/mongo/client')
29 files changed, 411 insertions, 801 deletions
diff --git a/src/mongo/client/authenticate.cpp b/src/mongo/client/authenticate.cpp index 52055262b78..f035312e4f7 100644 --- a/src/mongo/client/authenticate.cpp +++ b/src/mongo/client/authenticate.cpp @@ -119,8 +119,7 @@ StatusWith<OpMsgRequest> createX509AuthCmd(const BSONObj& params, StringData cli return OpMsgRequest::fromDBAndBody(db.getValue(), BSON("authenticate" << 1 << "mechanism" << "MONGODB-X509" - << "user" - << username)); + << "user" << username)); } // Use the MONGODB-X509 protocol to authenticate as "username." The certificate details @@ -241,14 +240,11 @@ BSONObj getInternalAuthParams(size_t idx, const std::string& mechanism) { internalSecurity.user->getName().getUser().toString(), password); } - return BSON(saslCommandMechanismFieldName << mechanism << saslCommandUserDBFieldName - << internalSecurity.user->getName().getDB() - << saslCommandUserFieldName - << internalSecurity.user->getName().getUser() - << saslCommandPasswordFieldName - << password - << saslCommandDigestPasswordFieldName - << false); + return BSON(saslCommandMechanismFieldName + << mechanism << saslCommandUserDBFieldName + << internalSecurity.user->getName().getDB() << saslCommandUserFieldName + << internalSecurity.user->getName().getUser() << saslCommandPasswordFieldName + << password << saslCommandDigestPasswordFieldName << false); } Future<std::string> negotiateSaslMechanism(RunCommandHook runCommand, @@ -313,14 +309,10 @@ BSONObj buildAuthParams(StringData dbname, StringData username, StringData passwordText, bool digestPassword) { - return BSON(saslCommandMechanismFieldName << "SCRAM-SHA-1" << saslCommandUserDBFieldName - << dbname - << saslCommandUserFieldName - << username - << saslCommandPasswordFieldName - << passwordText - << saslCommandDigestPasswordFieldName - << digestPassword); + return BSON(saslCommandMechanismFieldName + << "SCRAM-SHA-1" << saslCommandUserDBFieldName << dbname << saslCommandUserFieldName + << username << saslCommandPasswordFieldName << passwordText + << saslCommandDigestPasswordFieldName << digestPassword); } StringData getSaslCommandUserDBFieldName() { diff --git a/src/mongo/client/authenticate_test.cpp b/src/mongo/client/authenticate_test.cpp index c7d477b36c0..c72f6ddba04 100644 --- a/src/mongo/client/authenticate_test.cpp +++ b/src/mongo/client/authenticate_test.cpp @@ -127,11 +127,7 @@ public: << "MONGODB-CR" << "db" << "admin" - << "user" - << _username - << "pwd" - << _password - << "digest" + << "user" << _username << "pwd" << _password << "digest" << "true"); } @@ -141,8 +137,7 @@ public: pushRequest("$external", BSON("authenticate" << 1 << "mechanism" << "MONGODB-X509" - << "user" - << _username)); + << "user" << _username)); // 2. Client receives 'ok' pushResponse(BSON("ok" << 1)); @@ -152,8 +147,7 @@ public: << "MONGODB-X509" << "db" << "$external" - << "user" - << _username); + << "user" << _username); } diff --git a/src/mongo/client/connection_string_connect.cpp b/src/mongo/client/connection_string_connect.cpp index 81e3bdaef4f..14b3f8f08ff 100644 --- a/src/mongo/client/connection_string_connect.cpp +++ b/src/mongo/client/connection_string_connect.cpp @@ -110,4 +110,4 @@ std::unique_ptr<DBClientBase> ConnectionString::connect(StringData applicationNa MONGO_UNREACHABLE; } -} // namepspace mongo +} // namespace mongo diff --git a/src/mongo/client/constants.h b/src/mongo/client/constants.h index c96076c84ef..5f282e0da7f 100644 --- a/src/mongo/client/constants.h +++ b/src/mongo/client/constants.h @@ -49,4 +49,4 @@ enum ResultFlagType { */ ResultFlag_AwaitCapable = 8 }; -} +} // namespace mongo diff --git a/src/mongo/client/cyrus_sasl_client_session.cpp b/src/mongo/client/cyrus_sasl_client_session.cpp index e6ddd6e3a7f..85c8c575ca1 100644 --- a/src/mongo/client/cyrus_sasl_client_session.cpp +++ b/src/mongo/client/cyrus_sasl_client_session.cpp @@ -147,8 +147,7 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(CyrusSaslClientContext, if (result != SASL_OK) { return Status(ErrorCodes::UnknownError, str::stream() << "Could not initialize sasl client components (" - << sasl_errstring(result, nullptr, nullptr) - << ")"); + << sasl_errstring(result, nullptr, nullptr) << ")"); } SaslClientSession::create = createCyrusSaslClientSession; @@ -311,4 +310,4 @@ Status CyrusSaslClientSession::step(StringData inputData, std::string* outputDat return Status(ErrorCodes::ProtocolError, sasl_errdetail(_saslConnection)); } } -} // namespace +} // namespace mongo diff --git a/src/mongo/client/dbclient_base.cpp b/src/mongo/client/dbclient_base.cpp index 3c896123850..893c4e0fab7 100644 --- a/src/mongo/client/dbclient_base.cpp +++ b/src/mongo/client/dbclient_base.cpp @@ -73,11 +73,11 @@ namespace mongo { -using std::unique_ptr; using std::endl; using std::list; using std::string; using std::stringstream; +using std::unique_ptr; using std::vector; using executor::RemoteCommandRequest; @@ -221,23 +221,16 @@ std::pair<rpc::UniqueReply, DBClientBase*> DBClientBase::runCommandWithTarget( // more helpful error message. Note that call() can itself throw a socket exception. uassert(ErrorCodes::HostUnreachable, str::stream() << "network error while attempting to run " - << "command '" - << request.getCommandName() - << "' " - << "on host '" - << host - << "' ", + << "command '" << request.getCommandName() << "' " + << "on host '" << host << "' ", call(requestMsg, replyMsg, false, &host)); auto commandReply = parseCommandReplyMessage(host, replyMsg); uassert(ErrorCodes::RPCProtocolNegotiationFailed, str::stream() << "Mismatched RPC protocols - request was '" - << networkOpToString(requestMsg.operation()) - << "' '" - << " but reply was '" - << networkOpToString(replyMsg.operation()) - << "' ", + << networkOpToString(requestMsg.operation()) << "' '" + << " but reply was '" << networkOpToString(replyMsg.operation()) << "' ", rpc::protocolForMessage(requestMsg) == commandReply->getProtocol()); return {std::move(commandReply), this}; @@ -314,8 +307,7 @@ bool DBClientBase::runPseudoCommand(StringData db, if (status == ErrorCodes::CommandResultSchemaViolation) { msgasserted(28624, str::stream() << "Received bad " << realCommandName - << " response from server: " - << info); + << " response from server: " << info); } else if (status == ErrorCodes::CommandNotFound) { NamespaceString pseudoCommandNss(db, pseudoCommandCol); // if this throws we just let it escape as that's how runCommand works. @@ -614,10 +606,7 @@ void DBClientBase::findN(vector<BSONObj>& out, uassert(10276, str::stream() << "DBClientBase::findN: transport error: " << getServerAddress() - << " ns: " - << ns - << " query: " - << query.toString(), + << " ns: " << ns << " query: " << query.toString(), c.get()); if (c->hasResultFlag(ResultFlag_ShardConfigStale)) { diff --git a/src/mongo/client/dbclient_base.h b/src/mongo/client/dbclient_base.h index a7cdfc43c3b..d4d5bc315e0 100644 --- a/src/mongo/client/dbclient_base.h +++ b/src/mongo/client/dbclient_base.h @@ -123,7 +123,7 @@ public: /** query N objects from the database into an array. makes sense mostly when you want a small * number of results. if a huge number, use query() and iterate the cursor. - */ + */ void findN(std::vector<BSONObj>& out, const std::string& ns, Query query, @@ -293,9 +293,9 @@ public: int options = 0); /** - * Authenticates to another cluster member using appropriate authentication data. - * @return true if the authentication was successful - */ + * Authenticates to another cluster member using appropriate authentication data. + * @return true if the authentication was successful + */ virtual Status authenticateInternalUser(); /** diff --git a/src/mongo/client/dbclient_connection.cpp b/src/mongo/client/dbclient_connection.cpp index 8477a5edae9..bc65eb35938 100644 --- a/src/mongo/client/dbclient_connection.cpp +++ b/src/mongo/client/dbclient_connection.cpp @@ -80,10 +80,10 @@ namespace mongo { -using std::unique_ptr; using std::endl; using std::map; using std::string; +using std::unique_ptr; MONGO_FAIL_POINT_DEFINE(dbClientConnectionDisableChecksum); @@ -109,8 +109,8 @@ private: }; /** -* Initializes the wire version of conn, and returns the isMaster reply. -*/ + * Initializes the wire version of conn, and returns the isMaster reply. + */ executor::RemoteCommandResponse initWireVersion(DBClientConnection* conn, StringData applicationName, const MongoURI& uri, @@ -327,8 +327,7 @@ Status DBClientConnection::connectSocketOnly(const HostAndPort& serverAddress) { if (!sws.isOK()) { return Status(ErrorCodes::HostUnreachable, str::stream() << "couldn't connect to server " << _serverAddress.toString() - << ", connection attempt failed: " - << sws.getStatus()); + << ", connection attempt failed: " << sws.getStatus()); } { @@ -622,9 +621,7 @@ bool DBClientConnection::call(Message& toSend, if (assertOk) uasserted(10278, str::stream() << "dbclient error communicating with server " - << getServerAddress() - << ": " - << redact(errStatus)); + << getServerAddress() << ": " << redact(errStatus)); return false; }; @@ -672,7 +669,7 @@ void DBClientConnection::checkResponse(const std::vector<BSONObj>& batch, string* host) { /* check for errors. the only one we really care about at * this stage is "not master" - */ + */ *retry = false; *host = _serverAddress.toString(); @@ -701,8 +698,7 @@ void DBClientConnection::handleNotMasterResponse(const BSONObj& replyBody, monitor->failedHost(_serverAddress, {ErrorCodes::NotMaster, str::stream() << "got not master from: " << _serverAddress - << " of repl set: " - << _parentReplSetName}); + << " of repl set: " << _parentReplSetName}); } _markFailed(kSetFlag); diff --git a/src/mongo/client/dbclient_cursor.cpp b/src/mongo/client/dbclient_cursor.cpp index 16be475d4b0..a49267ad152 100644 --- a/src/mongo/client/dbclient_cursor.cpp +++ b/src/mongo/client/dbclient_cursor.cpp @@ -60,9 +60,9 @@ namespace mongo { -using std::unique_ptr; using std::endl; using std::string; +using std::unique_ptr; using std::vector; namespace { @@ -256,7 +256,7 @@ void DBClientCursor::requestMore() { invariant(_scopedHost.size()); DBClientBase::withConnection_do_not_use(_scopedHost, [&](DBClientBase* conn) { - ON_BLOCK_EXIT([&, origClient = _client ] { _client = origClient; }); + ON_BLOCK_EXIT([&, origClient = _client] { _client = origClient; }); _client = conn; doRequestMore(); }); diff --git a/src/mongo/client/dbclient_cursor_test.cpp b/src/mongo/client/dbclient_cursor_test.cpp index 292ce2c8bb5..234c68ce4af 100644 --- a/src/mongo/client/dbclient_cursor_test.cpp +++ b/src/mongo/client/dbclient_cursor_test.cpp @@ -27,8 +27,8 @@ * it in the license file. */ -#include "mongo/client/dbclient_cursor.h" #include "mongo/client/dbclient_connection.h" +#include "mongo/client/dbclient_cursor.h" #include "mongo/db/query/cursor_response.h" #include "mongo/unittest/unittest.h" #include "mongo/util/assert_util.h" diff --git a/src/mongo/client/dbclient_rs.cpp b/src/mongo/client/dbclient_rs.cpp index b7e2044f93c..978cef3182e 100644 --- a/src/mongo/client/dbclient_rs.cpp +++ b/src/mongo/client/dbclient_rs.cpp @@ -49,12 +49,12 @@ namespace mongo { -using std::shared_ptr; -using std::unique_ptr; using std::endl; using std::map; using std::set; +using std::shared_ptr; using std::string; +using std::unique_ptr; using std::vector; namespace { @@ -314,9 +314,9 @@ DBClientConnection* DBClientReplicaSet::checkMaster() { } if (newConn == nullptr || !errmsg.empty()) { - const std::string message = str::stream() << "can't connect to new replica set master [" - << _masterHost.toString() << "]" - << (errmsg.empty() ? "" : ", err: ") << errmsg; + const std::string message = str::stream() + << "can't connect to new replica set master [" << _masterHost.toString() << "]" + << (errmsg.empty() ? "" : ", err: ") << errmsg; monitor->failedHost(_masterHost, {ErrorCodes::Error(40659), message}); uasserted(ErrorCodes::FailedToSatisfyReadPreference, message); } @@ -537,9 +537,9 @@ unique_ptr<DBClientCursor> DBClientReplicaSet::query(const NamespaceStringOrUUID << _getMonitor()->getName() << ", read pref is " << readPref->toString() << " (primary : " << (_master.get() != nullptr ? _master->getServerAddress() : "[not cached]") - << ", lastTagged : " << (_lastSlaveOkConn.get() != nullptr - ? _lastSlaveOkConn->getServerAddress() - : "[not cached]") + << ", lastTagged : " + << (_lastSlaveOkConn.get() != nullptr ? _lastSlaveOkConn->getServerAddress() + : "[not cached]") << ")" << endl; string lastNodeErrMsg; @@ -589,9 +589,9 @@ BSONObj DBClientReplicaSet::findOne(const string& ns, << _getMonitor()->getName() << ", read pref is " << readPref->toString() << " (primary : " << (_master.get() != nullptr ? _master->getServerAddress() : "[not cached]") - << ", lastTagged : " << (_lastSlaveOkConn.get() != nullptr - ? _lastSlaveOkConn->getServerAddress() - : "[not cached]") + << ", lastTagged : " + << (_lastSlaveOkConn.get() != nullptr ? _lastSlaveOkConn->getServerAddress() + : "[not cached]") << ")" << endl; string lastNodeErrMsg; @@ -719,7 +719,7 @@ DBClientConnection* DBClientReplicaSet::selectNodeUsingTags( return _master.get(); } - auto dtor = [host = _lastSlaveOkHost.toString()](DBClientConnection * ptr) { + auto dtor = [host = _lastSlaveOkHost.toString()](DBClientConnection* ptr) { globalConnPool.release(host, ptr); }; @@ -768,9 +768,9 @@ void DBClientReplicaSet::say(Message& toSend, bool isRetry, string* actualServer << _getMonitor()->getName() << ", read pref is " << readPref->toString() << " (primary : " << (_master.get() != nullptr ? _master->getServerAddress() : "[not cached]") - << ", lastTagged : " << (_lastSlaveOkConn.get() != nullptr - ? _lastSlaveOkConn->getServerAddress() - : "[not cached]") + << ", lastTagged : " + << (_lastSlaveOkConn.get() != nullptr ? _lastSlaveOkConn->getServerAddress() + : "[not cached]") << ")" << endl; string lastNodeErrMsg; @@ -882,8 +882,9 @@ void DBClientReplicaSet::checkResponse(const std::vector<BSONObj>& batch, // query could potentially go to a secondary, so see if this is an error (or empty) and // retry if we're not past our retry limit. - if (networkError || (hasErrField(dataObj) && !dataObj["code"].eoo() && - dataObj["code"].Int() == ErrorCodes::NotMasterOrSecondary)) { + if (networkError || + (hasErrField(dataObj) && !dataObj["code"].eoo() && + dataObj["code"].Int() == ErrorCodes::NotMasterOrSecondary)) { if (_lazyState._lastClient == _lastSlaveOkConn.get()) { isntSecondary(); } else if (_lazyState._lastClient == _master.get()) { @@ -905,8 +906,9 @@ void DBClientReplicaSet::checkResponse(const std::vector<BSONObj>& batch, } else if (_lazyState._lastOp == dbQuery) { // if query could not potentially go to a secondary, just mark the master as bad - if (networkError || (hasErrField(dataObj) && !dataObj["code"].eoo() && - dataObj["code"].Int() == ErrorCodes::NotMasterNoSlaveOk)) { + if (networkError || + (hasErrField(dataObj) && !dataObj["code"].eoo() && + dataObj["code"].Int() == ErrorCodes::NotMasterNoSlaveOk)) { if (_lazyState._lastClient == _master.get()) { isntMaster(); } @@ -957,8 +959,7 @@ std::pair<rpc::UniqueReply, DBClientBase*> DBClientReplicaSet::runCommandWithTar uasserted(ErrorCodes::HostNotFound, str::stream() << "Could not satisfy $readPreference of '" << readPref.toString() - << "' while attempting to run command " - << request.getCommandName()); + << "' while attempting to run command " << request.getCommandName()); } std::pair<rpc::UniqueReply, std::shared_ptr<DBClientBase>> DBClientReplicaSet::runCommandWithTarget( @@ -999,9 +1000,9 @@ bool DBClientReplicaSet::call(Message& toSend, << _getMonitor()->getName() << ", read pref is " << readPref->toString() << " (primary : " << (_master.get() != nullptr ? _master->getServerAddress() : "[not cached]") - << ", lastTagged : " << (_lastSlaveOkConn.get() != nullptr - ? _lastSlaveOkConn->getServerAddress() - : "[not cached]") + << ", lastTagged : " + << (_lastSlaveOkConn.get() != nullptr ? _lastSlaveOkConn->getServerAddress() + : "[not cached]") << ")" << endl; for (size_t retry = 0; retry < MAX_RETRY; retry++) { diff --git a/src/mongo/client/dbclient_rs.h b/src/mongo/client/dbclient_rs.h index 92e2a93acb0..1ab59966676 100644 --- a/src/mongo/client/dbclient_rs.h +++ b/src/mongo/client/dbclient_rs.h @@ -57,8 +57,8 @@ typedef std::shared_ptr<ReplicaSetMonitor> ReplicaSetMonitorPtr; class DBClientReplicaSet : public DBClientBase { public: using DBClientBase::query; - using DBClientBase::update; using DBClientBase::remove; + using DBClientBase::update; /** Call connect() after constructing. autoReconnect is always on for DBClientReplicaSet * connections. */ @@ -244,7 +244,7 @@ public: protected: /** Authorize. Authorizes all nodes as needed - */ + */ void _auth(const BSONObj& params) override; private: @@ -353,4 +353,4 @@ protected: } _lazyState; }; -} +} // namespace mongo diff --git a/src/mongo/client/fetcher.cpp b/src/mongo/client/fetcher.cpp index 8e707c0ce02..8843227ded5 100644 --- a/src/mongo/client/fetcher.cpp +++ b/src/mongo/client/fetcher.cpp @@ -75,13 +75,12 @@ Status parseCursorResponse(const BSONObj& obj, if (cursorElement.eoo()) { return Status(ErrorCodes::FailedToParse, str::stream() << "cursor response must contain '" << kCursorFieldName - << "' field: " - << obj); + << "' field: " << obj); } if (!cursorElement.isABSONObj()) { - return Status( - ErrorCodes::FailedToParse, - str::stream() << "'" << kCursorFieldName << "' field must be an object: " << obj); + return Status(ErrorCodes::FailedToParse, + str::stream() + << "'" << kCursorFieldName << "' field must be an object: " << obj); } BSONObj cursorObj = cursorElement.Obj(); @@ -89,17 +88,13 @@ Status parseCursorResponse(const BSONObj& obj, if (cursorIdElement.eoo()) { return Status(ErrorCodes::FailedToParse, str::stream() << "cursor response must contain '" << kCursorFieldName << "." - << kCursorIdFieldName - << "' field: " - << obj); + << kCursorIdFieldName << "' field: " << obj); } if (cursorIdElement.type() != mongo::NumberLong) { return Status(ErrorCodes::FailedToParse, str::stream() << "'" << kCursorFieldName << "." << kCursorIdFieldName << "' field must be a 'long' but was a '" - << typeName(cursorIdElement.type()) - << "': " - << obj); + << typeName(cursorIdElement.type()) << "': " << obj); } batchData->cursorId = cursorIdElement.numberLong(); @@ -107,25 +102,19 @@ Status parseCursorResponse(const BSONObj& obj, if (namespaceElement.eoo()) { return Status(ErrorCodes::FailedToParse, str::stream() << "cursor response must contain " - << "'" - << kCursorFieldName - << "." - << kNamespaceFieldName - << "' field: " - << obj); + << "'" << kCursorFieldName << "." << kNamespaceFieldName + << "' field: " << obj); } if (namespaceElement.type() != mongo::String) { return Status(ErrorCodes::FailedToParse, str::stream() << "'" << kCursorFieldName << "." << kNamespaceFieldName - << "' field must be a string: " - << obj); + << "' field must be a string: " << obj); } const NamespaceString tempNss(namespaceElement.valueStringData()); if (!tempNss.isValid()) { return Status(ErrorCodes::BadValue, str::stream() << "'" << kCursorFieldName << "." << kNamespaceFieldName - << "' contains an invalid namespace: " - << obj); + << "' contains an invalid namespace: " << obj); } batchData->nss = tempNss; @@ -133,27 +122,20 @@ Status parseCursorResponse(const BSONObj& obj, if (batchElement.eoo()) { return Status(ErrorCodes::FailedToParse, str::stream() << "cursor response must contain '" << kCursorFieldName << "." - << batchFieldName - << "' field: " - << obj); + << batchFieldName << "' field: " << obj); } if (!batchElement.isABSONObj()) { return Status(ErrorCodes::FailedToParse, str::stream() << "'" << kCursorFieldName << "." << batchFieldName - << "' field must be an array: " - << obj); + << "' field must be an array: " << obj); } BSONObj batchObj = batchElement.Obj(); for (auto itemElement : batchObj) { if (!itemElement.isABSONObj()) { return Status(ErrorCodes::FailedToParse, str::stream() << "found non-object " << itemElement << " in " - << "'" - << kCursorFieldName - << "." - << batchFieldName - << "' field: " - << obj); + << "'" << kCursorFieldName << "." << batchFieldName + << "' field: " << obj); } batchData->documents.push_back(itemElement.Obj()); } diff --git a/src/mongo/client/fetcher_test.cpp b/src/mongo/client/fetcher_test.cpp index 19713755b11..f0fa26cf7b3 100644 --- a/src/mongo/client/fetcher_test.cpp +++ b/src/mongo/client/fetcher_test.cpp @@ -405,8 +405,7 @@ TEST_F(FetcherTest, FindCommandFailed2) { ASSERT_OK(fetcher->schedule()); processNetworkResponse(BSON("ok" << 0 << "errmsg" << "bad hint" - << "code" - << int(ErrorCodes::BadValue)), + << "code" << int(ErrorCodes::BadValue)), ReadyQueueState::kEmpty, FetcherState::kInactive); ASSERT_EQUALS(ErrorCodes::BadValue, status.code()); @@ -432,10 +431,8 @@ TEST_F(FetcherTest, CursorIdFieldMissing) { ASSERT_OK(fetcher->schedule()); processNetworkResponse(BSON("cursor" << BSON("ns" << "db.coll" - << "firstBatch" - << BSONArray()) - << "ok" - << 1), + << "firstBatch" << BSONArray()) + << "ok" << 1), ReadyQueueState::kEmpty, FetcherState::kInactive); ASSERT_EQUALS(ErrorCodes::FailedToParse, status.code()); @@ -446,10 +443,8 @@ TEST_F(FetcherTest, CursorIdNotLongNumber) { ASSERT_OK(fetcher->schedule()); processNetworkResponse(BSON("cursor" << BSON("id" << 123.1 << "ns" << "db.coll" - << "firstBatch" - << BSONArray()) - << "ok" - << 1), + << "firstBatch" << BSONArray()) + << "ok" << 1), ReadyQueueState::kEmpty, FetcherState::kInactive); ASSERT_EQUALS(ErrorCodes::FailedToParse, status.code()); @@ -469,11 +464,11 @@ TEST_F(FetcherTest, NamespaceFieldMissing) { TEST_F(FetcherTest, NamespaceNotAString) { ASSERT_OK(fetcher->schedule()); - processNetworkResponse( - BSON("cursor" << BSON("id" << 123LL << "ns" << 123 << "firstBatch" << BSONArray()) << "ok" - << 1), - ReadyQueueState::kEmpty, - FetcherState::kInactive); + processNetworkResponse(BSON("cursor" + << BSON("id" << 123LL << "ns" << 123 << "firstBatch" << BSONArray()) + << "ok" << 1), + ReadyQueueState::kEmpty, + FetcherState::kInactive); ASSERT_EQUALS(ErrorCodes::FailedToParse, status.code()); ASSERT_STRING_CONTAINS(status.reason(), "'cursor.ns' field must be a string"); } @@ -482,10 +477,8 @@ TEST_F(FetcherTest, NamespaceEmpty) { ASSERT_OK(fetcher->schedule()); processNetworkResponse(BSON("cursor" << BSON("id" << 123LL << "ns" << "" - << "firstBatch" - << BSONArray()) - << "ok" - << 1), + << "firstBatch" << BSONArray()) + << "ok" << 1), ReadyQueueState::kEmpty, FetcherState::kInactive); ASSERT_EQUALS(ErrorCodes::BadValue, status.code()); @@ -496,10 +489,8 @@ TEST_F(FetcherTest, NamespaceMissingCollectionName) { ASSERT_OK(fetcher->schedule()); processNetworkResponse(BSON("cursor" << BSON("id" << 123LL << "ns" << "db." - << "firstBatch" - << BSONArray()) - << "ok" - << 1), + << "firstBatch" << BSONArray()) + << "ok" << 1), ReadyQueueState::kEmpty, FetcherState::kInactive); ASSERT_EQUALS(ErrorCodes::BadValue, status.code()); @@ -510,8 +501,7 @@ TEST_F(FetcherTest, FirstBatchFieldMissing) { ASSERT_OK(fetcher->schedule()); processNetworkResponse(BSON("cursor" << BSON("id" << 0LL << "ns" << "db.coll") - << "ok" - << 1), + << "ok" << 1), ReadyQueueState::kEmpty, FetcherState::kInactive); ASSERT_EQUALS(ErrorCodes::FailedToParse, status.code()); @@ -522,10 +512,8 @@ TEST_F(FetcherTest, FirstBatchNotAnArray) { ASSERT_OK(fetcher->schedule()); processNetworkResponse(BSON("cursor" << BSON("id" << 0LL << "ns" << "db.coll" - << "firstBatch" - << 123) - << "ok" - << 1), + << "firstBatch" << 123) + << "ok" << 1), ReadyQueueState::kEmpty, FetcherState::kInactive); ASSERT_EQUALS(ErrorCodes::FailedToParse, status.code()); @@ -536,10 +524,8 @@ TEST_F(FetcherTest, FirstBatchArrayContainsNonObject) { ASSERT_OK(fetcher->schedule()); processNetworkResponse(BSON("cursor" << BSON("id" << 0LL << "ns" << "db.coll" - << "firstBatch" - << BSON_ARRAY(8)) - << "ok" - << 1), + << "firstBatch" << BSON_ARRAY(8)) + << "ok" << 1), ReadyQueueState::kEmpty, FetcherState::kInactive); ASSERT_EQUALS(ErrorCodes::FailedToParse, status.code()); @@ -551,10 +537,8 @@ TEST_F(FetcherTest, FirstBatchEmptyArray) { ASSERT_OK(fetcher->schedule()); processNetworkResponse(BSON("cursor" << BSON("id" << 0LL << "ns" << "db.coll" - << "firstBatch" - << BSONArray()) - << "ok" - << 1), + << "firstBatch" << BSONArray()) + << "ok" << 1), ReadyQueueState::kEmpty, FetcherState::kInactive); ASSERT_OK(status); @@ -568,10 +552,8 @@ TEST_F(FetcherTest, FetchOneDocument) { const BSONObj doc = BSON("_id" << 1); processNetworkResponse(BSON("cursor" << BSON("id" << 0LL << "ns" << "db.coll" - << "firstBatch" - << BSON_ARRAY(doc)) - << "ok" - << 1), + << "firstBatch" << BSON_ARRAY(doc)) + << "ok" << 1), ReadyQueueState::kEmpty, FetcherState::kInactive); ASSERT_OK(status); @@ -596,10 +578,8 @@ TEST_F(FetcherTest, SetNextActionToContinueWhenNextBatchIsNotAvailable) { }; processNetworkResponse(BSON("cursor" << BSON("id" << 0LL << "ns" << "db.coll" - << "firstBatch" - << BSON_ARRAY(doc)) - << "ok" - << 1), + << "firstBatch" << BSON_ARRAY(doc)) + << "ok" << 1), ReadyQueueState::kEmpty, FetcherState::kInactive); ASSERT_OK(status); @@ -629,10 +609,8 @@ TEST_F(FetcherTest, FetchMultipleBatches) { processNetworkResponse(BSON("cursor" << BSON("id" << 1LL << "ns" << "db.coll" - << "firstBatch" - << BSON_ARRAY(doc)) - << "ok" - << 1), + << "firstBatch" << BSON_ARRAY(doc)) + << "ok" << 1), Milliseconds(100), ReadyQueueState::kHasReadyRequests, FetcherState::kActive); @@ -650,10 +628,8 @@ TEST_F(FetcherTest, FetchMultipleBatches) { processNetworkResponse(BSON("cursor" << BSON("id" << 1LL << "ns" << "db.coll" - << "nextBatch" - << BSON_ARRAY(doc2)) - << "ok" - << 1), + << "nextBatch" << BSON_ARRAY(doc2)) + << "ok" << 1), Milliseconds(200), ReadyQueueState::kHasReadyRequests, FetcherState::kActive); @@ -671,10 +647,8 @@ TEST_F(FetcherTest, FetchMultipleBatches) { processNetworkResponse(BSON("cursor" << BSON("id" << 0LL << "ns" << "db.coll" - << "nextBatch" - << BSON_ARRAY(doc3)) - << "ok" - << 1), + << "nextBatch" << BSON_ARRAY(doc3)) + << "ok" << 1), Milliseconds(300), ReadyQueueState::kEmpty, FetcherState::kInactive); @@ -698,10 +672,8 @@ TEST_F(FetcherTest, ScheduleGetMoreAndCancel) { processNetworkResponse(BSON("cursor" << BSON("id" << 1LL << "ns" << "db.coll" - << "firstBatch" - << BSON_ARRAY(doc)) - << "ok" - << 1), + << "firstBatch" << BSON_ARRAY(doc)) + << "ok" << 1), ReadyQueueState::kHasReadyRequests, FetcherState::kActive); @@ -715,10 +687,8 @@ TEST_F(FetcherTest, ScheduleGetMoreAndCancel) { const BSONObj doc2 = BSON("_id" << 2); processNetworkResponse(BSON("cursor" << BSON("id" << 1LL << "ns" << "db.coll" - << "nextBatch" - << BSON_ARRAY(doc2)) - << "ok" - << 1), + << "nextBatch" << BSON_ARRAY(doc2)) + << "ok" << 1), ReadyQueueState::kHasReadyRequests, FetcherState::kActive); @@ -761,10 +731,8 @@ TEST_F(FetcherTest, CancelDuringCallbackPutsFetcherInShutdown) { const BSONObj doc = BSON("_id" << 1); processNetworkResponse(BSON("cursor" << BSON("id" << 1LL << "ns" << "db.coll" - << "firstBatch" - << BSON_ARRAY(doc)) - << "ok" - << 1), + << "firstBatch" << BSON_ARRAY(doc)) + << "ok" << 1), ReadyQueueState::kHasReadyRequests, FetcherState::kInactive); @@ -782,10 +750,8 @@ TEST_F(FetcherTest, ScheduleGetMoreButShutdown) { processNetworkResponse(BSON("cursor" << BSON("id" << 1LL << "ns" << "db.coll" - << "firstBatch" - << BSON_ARRAY(doc)) - << "ok" - << 1), + << "firstBatch" << BSON_ARRAY(doc)) + << "ok" << 1), ReadyQueueState::kHasReadyRequests, FetcherState::kActive); @@ -800,10 +766,8 @@ TEST_F(FetcherTest, ScheduleGetMoreButShutdown) { processNetworkResponse(BSON("cursor" << BSON("id" << 1LL << "ns" << "db.coll" - << "nextBatch" - << BSON_ARRAY(doc2)) - << "ok" - << 1), + << "nextBatch" << BSON_ARRAY(doc2)) + << "ok" << 1), ReadyQueueState::kHasReadyRequests, FetcherState::kActive); @@ -839,10 +803,8 @@ TEST_F(FetcherTest, EmptyGetMoreRequestAfterFirstBatchMakesFetcherInactiveAndKil processNetworkResponse(BSON("cursor" << BSON("id" << 1LL << "ns" << "db.coll" - << "firstBatch" - << BSON_ARRAY(doc)) - << "ok" - << 1), + << "firstBatch" << BSON_ARRAY(doc)) + << "ok" << 1), ReadyQueueState::kHasReadyRequests, FetcherState::kInactive); @@ -896,10 +858,8 @@ TEST_F(FetcherTest, UpdateNextActionAfterSecondBatch) { processNetworkResponse(BSON("cursor" << BSON("id" << 1LL << "ns" << "db.coll" - << "firstBatch" - << BSON_ARRAY(doc)) - << "ok" - << 1), + << "firstBatch" << BSON_ARRAY(doc)) + << "ok" << 1), ReadyQueueState::kHasReadyRequests, FetcherState::kActive); @@ -916,10 +876,8 @@ TEST_F(FetcherTest, UpdateNextActionAfterSecondBatch) { processNetworkResponse(BSON("cursor" << BSON("id" << 1LL << "ns" << "db.coll" - << "nextBatch" - << BSON_ARRAY(doc2)) - << "ok" - << 1), + << "nextBatch" << BSON_ARRAY(doc2)) + << "ok" << 1), ReadyQueueState::kHasReadyRequests, FetcherState::kInactive); @@ -993,10 +951,8 @@ TEST_F(FetcherTest, ShutdownDuringSecondBatch) { processNetworkResponse(BSON("cursor" << BSON("id" << 1LL << "ns" << "db.coll" - << "firstBatch" - << BSON_ARRAY(doc)) - << "ok" - << 1), + << "firstBatch" << BSON_ARRAY(doc)) + << "ok" << 1), ReadyQueueState::kHasReadyRequests, FetcherState::kActive); @@ -1016,10 +972,8 @@ TEST_F(FetcherTest, ShutdownDuringSecondBatch) { processNetworkResponse(BSON("cursor" << BSON("id" << 1LL << "ns" << "db.coll" - << "nextBatch" - << BSON_ARRAY(doc2)) - << "ok" - << 1), + << "nextBatch" << BSON_ARRAY(doc2)) + << "ok" << 1), ReadyQueueState::kEmpty, FetcherState::kInactive); @@ -1059,10 +1013,8 @@ TEST_F(FetcherTest, FetcherAppliesRetryPolicyToFirstCommandButNotToGetMoreReques processNetworkResponse(rs, ReadyQueueState::kHasReadyRequests, FetcherState::kActive); processNetworkResponse(BSON("cursor" << BSON("id" << 1LL << "ns" << "db.coll" - << "firstBatch" - << BSON_ARRAY(doc)) - << "ok" - << 1), + << "firstBatch" << BSON_ARRAY(doc)) + << "ok" << 1), ReadyQueueState::kHasReadyRequests, FetcherState::kActive); ASSERT_OK(status); @@ -1110,10 +1062,8 @@ TEST_F(FetcherTest, FetcherResetsInternalFinishCallbackFunctionPointerAfterLastC processNetworkResponse(BSON("cursor" << BSON("id" << 0LL << "ns" << "db.coll" - << "firstBatch" - << BSONArray()) - << "ok" - << 1), + << "firstBatch" << BSONArray()) + << "ok" << 1), ReadyQueueState::kEmpty, FetcherState::kInactive); diff --git a/src/mongo/client/mongo_uri.cpp b/src/mongo/client/mongo_uri.cpp index e11f9b0a06f..433c33c8e61 100644 --- a/src/mongo/client/mongo_uri.cpp +++ b/src/mongo/client/mongo_uri.cpp @@ -169,8 +169,7 @@ MongoURI::OptionsMap parseOptions(StringData options, StringData url) { if (opt.empty()) { uasserted(ErrorCodes::FailedToParse, str::stream() - << "Missing a key/value pair in the options for mongodb:// URL: " - << url); + << "Missing a key/value pair in the options for mongodb:// URL: " << url); } const auto kvPair = partitionForward(opt, '='); @@ -190,8 +189,7 @@ MongoURI::OptionsMap parseOptions(StringData options, StringData url) { if (valRaw.empty()) { uasserted(ErrorCodes::FailedToParse, str::stream() << "Missing value for key '" << keyRaw - << "' in the options for mongodb:// URL: " - << url); + << "' in the options for mongodb:// URL: " << url); } const auto val = uassertStatusOKWithContext( uriDecode(valRaw), @@ -259,8 +257,7 @@ URIParts::URIParts(StringData uri) { if (schemeEnd == std::string::npos) { uasserted(ErrorCodes::FailedToParse, str::stream() << "URI must begin with " << kURIPrefix << " or " << kURISRVPrefix - << ": " - << uri); + << ": " << uri); } const auto uriWithoutPrefix = uri.substr(schemeEnd + 3); scheme = uri.substr(0, schemeEnd); @@ -380,10 +377,10 @@ MongoURI MongoURI::parseImpl(const std::string& url) { } if ((host.find('/') != std::string::npos) && !StringData(host).endsWith(".sock")) { - uasserted( - ErrorCodes::FailedToParse, - str::stream() << "'" << host << "' in '" << url - << "' appears to be a unix socket, but does not end in '.sock'"); + uasserted(ErrorCodes::FailedToParse, + str::stream() + << "'" << host << "' in '" << url + << "' appears to be a unix socket, but does not end in '.sock'"); } servers.push_back(uassertStatusOK(HostAndPort::parse(host))); diff --git a/src/mongo/client/mongo_uri_test.cpp b/src/mongo/client/mongo_uri_test.cpp index 729d04d8d83..6aa3e4fc5b3 100644 --- a/src/mongo/client/mongo_uri_test.cpp +++ b/src/mongo/client/mongo_uri_test.cpp @@ -828,7 +828,8 @@ TEST(MongoURI, srvRecordTest) { {"localhost.sub.test.build.10gen.cc", 27017}, }, { - {"ssl", "true"}, {"replicaSet", "repl0"}, + {"ssl", "true"}, + {"replicaSet", "repl0"}, }, success}, @@ -842,7 +843,8 @@ TEST(MongoURI, srvRecordTest) { {"localhost.sub.test.build.10gen.cc", 27017}, }, { - {"ssl", "true"}, {"replicaSet", "repl0"}, + {"ssl", "true"}, + {"replicaSet", "repl0"}, }, success}, @@ -988,19 +990,19 @@ TEST(MongoURI, srvRecordTest) { for (const auto& test : tests) { auto rs = MongoURI::parse(test.uri); if (test.expectation == failure) { - ASSERT_FALSE(rs.getStatus().isOK()) << "Failing URI: " << test.uri - << " data on line: " << test.lineNumber; + ASSERT_FALSE(rs.getStatus().isOK()) + << "Failing URI: " << test.uri << " data on line: " << test.lineNumber; continue; } ASSERT_OK(rs.getStatus()) << "Failed on URI: " << test.uri << " data on line: " << test.lineNumber; auto rv = rs.getValue(); - ASSERT_EQ(rv.getUser(), test.user) << "Failed on URI: " << test.uri - << " data on line: " << test.lineNumber; - ASSERT_EQ(rv.getPassword(), test.password) << "Failed on URI: " << test.uri - << " data on line : " << test.lineNumber; - ASSERT_EQ(rv.getDatabase(), test.database) << "Failed on URI: " << test.uri - << " data on line : " << test.lineNumber; + ASSERT_EQ(rv.getUser(), test.user) + << "Failed on URI: " << test.uri << " data on line: " << test.lineNumber; + ASSERT_EQ(rv.getPassword(), test.password) + << "Failed on URI: " << test.uri << " data on line : " << test.lineNumber; + ASSERT_EQ(rv.getDatabase(), test.database) + << "Failed on URI: " << test.uri << " data on line : " << test.lineNumber; compareOptions(test.lineNumber, test.uri, rv.getOptions(), test.options); std::vector<HostAndPort> hosts(begin(rv.getServers()), end(rv.getServers())); @@ -1009,9 +1011,9 @@ TEST(MongoURI, srvRecordTest) { std::sort(begin(expectedHosts), end(expectedHosts)); for (std::size_t i = 0; i < std::min(hosts.size(), expectedHosts.size()); ++i) { - ASSERT_EQ(hosts[i], expectedHosts[i]) << "Failed on URI: " << test.uri - << " at host number" << i - << " data on line: " << test.lineNumber; + ASSERT_EQ(hosts[i], expectedHosts[i]) + << "Failed on URI: " << test.uri << " at host number" << i + << " data on line: " << test.lineNumber; } ASSERT_TRUE(hosts.size() == expectedHosts.size()) << "Failed on URI: " << test.uri << " Found " << hosts.size() << " hosts, expected " diff --git a/src/mongo/client/native_sasl_client_session.cpp b/src/mongo/client/native_sasl_client_session.cpp index b7f51fa0f68..3fa871bda5d 100644 --- a/src/mongo/client/native_sasl_client_session.cpp +++ b/src/mongo/client/native_sasl_client_session.cpp @@ -98,4 +98,4 @@ Status NativeSaslClientSession::step(StringData inputData, std::string* outputDa } return status.getStatus(); } -} // namespace +} // namespace mongo diff --git a/src/mongo/client/query_spec.h b/src/mongo/client/query_spec.h index c115f50cd70..534a841842f 100644 --- a/src/mongo/client/query_spec.h +++ b/src/mongo/client/query_spec.h @@ -116,11 +116,7 @@ public: std::string toString() const { return str::stream() << "QSpec " << BSON("ns" << _ns << "n2skip" << _ntoskip << "n2return" << _ntoreturn - << "options" - << _options - << "query" - << _query - << "fields" + << "options" << _options << "query" << _query << "fields" << _fields); } }; diff --git a/src/mongo/client/read_preference.cpp b/src/mongo/client/read_preference.cpp index 4391db7c388..b71825ad395 100644 --- a/src/mongo/client/read_preference.cpp +++ b/src/mongo/client/read_preference.cpp @@ -86,16 +86,9 @@ StatusWith<ReadPreference> parseReadPreferenceMode(StringData prefStr) { } return Status(ErrorCodes::FailedToParse, str::stream() << "Could not parse $readPreference mode '" << prefStr - << "'. Only the modes '" - << kPrimaryOnly - << "', '" - << kPrimaryPreferred - << "', '" - << kSecondaryOnly - << "', '" - << kSecondaryPreferred - << "', and '" - << kNearest + << "'. Only the modes '" << kPrimaryOnly << "', '" + << kPrimaryPreferred << "', '" << kSecondaryOnly << "', '" + << kSecondaryPreferred << "', and '" << kNearest << "' are supported."); } @@ -206,8 +199,8 @@ StatusWith<ReadPreferenceSetting> ReadPreferenceSetting::fromInnerBSON(const BSO if (maxStalenessSecondsValue && maxStalenessSecondsValue < 0) { return Status(ErrorCodes::BadValue, - str::stream() << kMaxStalenessSecondsFieldName - << " must be a non-negative integer"); + str::stream() + << kMaxStalenessSecondsFieldName << " must be a non-negative integer"); } if (maxStalenessSecondsValue && maxStalenessSecondsValue >= Seconds::max().count()) { @@ -218,9 +211,9 @@ StatusWith<ReadPreferenceSetting> ReadPreferenceSetting::fromInnerBSON(const BSO if (maxStalenessSecondsValue && maxStalenessSecondsValue < kMinimalMaxStalenessValue.count()) { return Status(ErrorCodes::MaxStalenessOutOfRange, - str::stream() << kMaxStalenessSecondsFieldName - << " value can not be less than " - << kMinimalMaxStalenessValue.count()); + str::stream() + << kMaxStalenessSecondsFieldName << " value can not be less than " + << kMinimalMaxStalenessValue.count()); } if ((mode == ReadPreference::PrimaryOnly) && maxStalenessSecondsValue) { @@ -236,9 +229,7 @@ StatusWith<ReadPreferenceSetting> ReadPreferenceSetting::fromInnerBSON(const BSO if (elem.type() != mongo::Object) { return Status(ErrorCodes::TypeMismatch, str::stream() << "$readPreference has incorrect type: expected " - << mongo::Object - << " but got " - << elem.type()); + << mongo::Object << " but got " << elem.type()); } return fromInnerBSON(elem.Obj()); } diff --git a/src/mongo/client/read_preference_test.cpp b/src/mongo/client/read_preference_test.cpp index f3a0dc78941..92bc2516be0 100644 --- a/src/mongo/client/read_preference_test.cpp +++ b/src/mongo/client/read_preference_test.cpp @@ -55,8 +55,7 @@ TEST(ReadPreferenceSetting, ParseValid) { // that the tags are parsed as the empty TagSet. checkParse(BSON("mode" << "primary" - << "tags" - << BSON_ARRAY(BSONObj())), + << "tags" << BSON_ARRAY(BSONObj())), ReadPreferenceSetting(ReadPreference::PrimaryOnly, TagSet::primaryOnly())); checkParse(BSON("mode" @@ -69,14 +68,12 @@ TEST(ReadPreferenceSetting, ParseValid) { << "ny"))))); checkParse(BSON("mode" << "secondary" - << "maxStalenessSeconds" - << kMinMaxStaleness.count()), + << "maxStalenessSeconds" << kMinMaxStaleness.count()), ReadPreferenceSetting(ReadPreference::SecondaryOnly, kMinMaxStaleness)); checkParse(BSON("mode" << "secondary" - << "maxStalenessSeconds" - << 0), + << "maxStalenessSeconds" << 0), ReadPreferenceSetting(ReadPreference::SecondaryOnly, Seconds(0))); checkParse(BSON("mode" @@ -84,8 +81,7 @@ TEST(ReadPreferenceSetting, ParseValid) { << "tags" << BSON_ARRAY(BSON("dc" << "ny")) - << "maxStalenessSeconds" - << kMinMaxStaleness.count()), + << "maxStalenessSeconds" << kMinMaxStaleness.count()), ReadPreferenceSetting(ReadPreference::SecondaryOnly, TagSet(BSON_ARRAY(BSON("dc" << "ny"))), @@ -149,8 +145,7 @@ TEST(ReadPreferenceSetting, ParseInvalid) { // maxStalenessSeconds is negative checkParseFails(BSON("mode" << "secondary" - << "maxStalenessSeconds" - << -1)); + << "maxStalenessSeconds" << -1)); // maxStalenessSeconds is NaN checkParseFails(BSON("mode" @@ -161,8 +156,7 @@ TEST(ReadPreferenceSetting, ParseInvalid) { // maxStalenessSeconds and primary checkParseFails(BSON("mode" << "primary" - << "maxStalenessSeconds" - << kMinMaxStaleness.count())); + << "maxStalenessSeconds" << kMinMaxStaleness.count())); // maxStalenessSeconds is less than min checkParseFailsWithError(BSON("mode" @@ -174,13 +168,11 @@ TEST(ReadPreferenceSetting, ParseInvalid) { // maxStalenessSeconds is greater than max checkParseFails(BSON("mode" << "secondary" - << "maxStalenessSeconds" - << Seconds::max().count())); + << "maxStalenessSeconds" << Seconds::max().count())); checkParseContainerFailsWithError(BSON("$query" << BSON("pang" << "pong") - << "$readPreference" - << 2), + << "$readPreference" << 2), ErrorCodes::TypeMismatch); } diff --git a/src/mongo/client/remote_command_retry_scheduler_test.cpp b/src/mongo/client/remote_command_retry_scheduler_test.cpp index 6a543bc76f7..7940be98674 100644 --- a/src/mongo/client/remote_command_retry_scheduler_test.cpp +++ b/src/mongo/client/remote_command_retry_scheduler_test.cpp @@ -401,8 +401,7 @@ TEST_F(RemoteCommandRetrySchedulerTest, SchedulerIgnoresEmbeddedErrorInSuccessfu // wire protocol. ResponseStatus response(BSON("ok" << 0 << "code" << int(ErrorCodes::FailedToParse) << "errmsg" << "injected error" - << "z" - << 456), + << "z" << 456), Milliseconds(100)); processNetworkResponse(response); diff --git a/src/mongo/client/replica_set_monitor.cpp b/src/mongo/client/replica_set_monitor.cpp index aacbfe4aea3..37dee8b0766 100644 --- a/src/mongo/client/replica_set_monitor.cpp +++ b/src/mongo/client/replica_set_monitor.cpp @@ -57,9 +57,9 @@ namespace mongo { -using std::shared_ptr; using std::numeric_limits; using std::set; +using std::shared_ptr; using std::string; using std::vector; @@ -254,7 +254,7 @@ void ReplicaSetMonitor::SetState::rescheduleRefresh(SchedulingStrategy strategy) nextScanTime = possibleNextScanTime; LOG(1) << "Next replica set scan scheduled for " << nextScanTime; auto swHandle = executor->scheduleWorkAt( - nextScanTime, [ this, anchor = shared_from_this() ](const CallbackArgs& cbArgs) { + nextScanTime, [this, anchor = shared_from_this()](const CallbackArgs& cbArgs) { if (!cbArgs.status.isOK()) return; @@ -529,7 +529,7 @@ void Refresher::scheduleNetworkRequests() { // ensure that the call to isMaster is scheduled at most every 500ms auto swHandle = _set->executor->scheduleWorkAt( node->nextPossibleIsMasterCall, - [ *this, host = ns.host ](const CallbackArgs& cbArgs) mutable { + [*this, host = ns.host](const CallbackArgs& cbArgs) mutable { if (!cbArgs.status.isOK()) { return; } @@ -584,7 +584,7 @@ void Refresher::scheduleIsMaster(const HostAndPort& host) { _set->executor ->scheduleRemoteCommand( std::move(request), - [ copy = *this, host, timer = Timer() ]( + [copy = *this, host, timer = Timer()]( const executor::TaskExecutor::RemoteCommandCallbackArgs& result) mutable { stdx::lock_guard lk(copy._set->mutex); // Ignore the reply and return if we are no longer the current scan. This might @@ -732,8 +732,7 @@ void Refresher::receivedIsMaster(const HostAndPort& from, failedHost(from, {ErrorCodes::InconsistentReplicaSetNames, str::stream() << "Target replica set name " << reply.setName - << " does not match the monitored set name " - << _set->name}); + << " does not match the monitored set name " << _set->name}); return; } @@ -811,12 +810,11 @@ Status Refresher::receivedIsMasterFromMaster(const HostAndPort& from, const IsMa // Reject if config version is older. This is for backwards compatibility with nodes in pv0 // since they don't have the same ordering with pv1 electionId. if (reply.configVersion < _set->configVersion) { - return {ErrorCodes::NotMaster, - str::stream() << "Node " << from - << " believes it is primary, but its config version " - << reply.configVersion - << " is older than the most recent config version " - << _set->configVersion}; + return { + ErrorCodes::NotMaster, + str::stream() << "Node " << from << " believes it is primary, but its config version " + << reply.configVersion << " is older than the most recent config version " + << _set->configVersion}; } if (reply.electionId.isSet()) { @@ -825,12 +823,11 @@ Status Refresher::receivedIsMasterFromMaster(const HostAndPort& from, const IsMa // because configVersion needs to be incremented whenever the protocol version is changed. if (reply.configVersion == _set->configVersion && _set->maxElectionId.isSet() && _set->maxElectionId.compare(reply.electionId) > 0) { - return {ErrorCodes::NotMaster, - str::stream() << "Node " << from - << " believes it is primary, but its election id " - << reply.electionId - << " is older than the most recent election id " - << _set->maxElectionId}; + return { + ErrorCodes::NotMaster, + str::stream() << "Node " << from << " believes it is primary, but its election id " + << reply.electionId << " is older than the most recent election id " + << _set->maxElectionId}; } _set->maxElectionId = reply.electionId; @@ -1320,9 +1317,7 @@ void SetState::notify(bool finishedScan) { Status SetState::makeUnsatisfedReadPrefError(const ReadPreferenceSetting& criteria) const { return Status(ErrorCodes::FailedToSatisfyReadPreference, str::stream() << "Could not find host matching read preference " - << criteria.toString() - << " for set " - << name); + << criteria.toString() << " for set " << name); } void SetState::init() { @@ -1415,4 +1410,4 @@ void ScanState::retryAllTriedHosts(PseudoRandom& rand) { std::shuffle(hostsToScan.begin(), hostsToScan.end(), rand.urbg()); triedHosts = waitingFor; } -} +} // namespace mongo diff --git a/src/mongo/client/replica_set_monitor_internal_test.cpp b/src/mongo/client/replica_set_monitor_internal_test.cpp index b796dff516c..1a90deed113 100644 --- a/src/mongo/client/replica_set_monitor_internal_test.cpp +++ b/src/mongo/client/replica_set_monitor_internal_test.cpp @@ -367,22 +367,10 @@ TEST_F(IsMasterReplyTest, IsMasterReplyRSNotInitiated) { BSONObj ismaster = BSON( "ismaster" << false << "secondary" << false << "info" << "can't get local.system.replset config from self or any seed (EMPTYCONFIG)" - << "isreplicaset" - << true - << "maxBsonObjectSize" - << 16777216 - << "maxMessageSizeBytes" - << 48000000 - << "maxWriteBatchSize" - << 1000 - << "localTime" - << mongo::jsTime() - << "maxWireVersion" - << 2 - << "minWireVersion" - << 0 - << "ok" - << 1); + << "isreplicaset" << true << "maxBsonObjectSize" << 16777216 + << "maxMessageSizeBytes" << 48000000 << "maxWriteBatchSize" << 1000 + << "localTime" << mongo::jsTime() << "maxWireVersion" << 2 << "minWireVersion" + << 0 << "ok" << 1); IsMasterReply imr(HostAndPort(), -1, ismaster); @@ -401,34 +389,15 @@ TEST_F(IsMasterReplyTest, IsMasterReplyRSNotInitiated) { TEST_F(IsMasterReplyTest, IsMasterReplyRSPrimary) { BSONObj ismaster = BSON("setName" << "test" - << "setVersion" - << 1 - << "electionId" - << OID("7fffffff0000000000000001") - << "ismaster" - << true - << "secondary" - << false - << "hosts" - << BSON_ARRAY("mongo.example:3000") - << "primary" + << "setVersion" << 1 << "electionId" << OID("7fffffff0000000000000001") + << "ismaster" << true << "secondary" << false << "hosts" + << BSON_ARRAY("mongo.example:3000") << "primary" << "mongo.example:3000" << "me" << "mongo.example:3000" - << "maxBsonObjectSize" - << 16777216 - << "maxMessageSizeBytes" - << 48000000 - << "maxWriteBatchSize" - << 1000 - << "localTime" - << mongo::jsTime() - << "maxWireVersion" - << 2 - << "minWireVersion" - << 0 - << "ok" - << 1); + << "maxBsonObjectSize" << 16777216 << "maxMessageSizeBytes" << 48000000 + << "maxWriteBatchSize" << 1000 << "localTime" << mongo::jsTime() + << "maxWireVersion" << 2 << "minWireVersion" << 0 << "ok" << 1); IsMasterReply imr(HostAndPort("mongo.example:3000"), -1, ismaster); @@ -448,38 +417,16 @@ TEST_F(IsMasterReplyTest, IsMasterReplyRSPrimary) { TEST_F(IsMasterReplyTest, IsMasterReplyPassiveSecondary) { BSONObj ismaster = BSON("setName" << "test" - << "setVersion" - << 2 - << "electionId" - << OID("7fffffff0000000000000001") - << "ismaster" - << false - << "secondary" - << true - << "hosts" - << BSON_ARRAY("mongo.example:3000") - << "passives" - << BSON_ARRAY("mongo.example:3001") - << "primary" + << "setVersion" << 2 << "electionId" << OID("7fffffff0000000000000001") + << "ismaster" << false << "secondary" << true << "hosts" + << BSON_ARRAY("mongo.example:3000") << "passives" + << BSON_ARRAY("mongo.example:3001") << "primary" << "mongo.example:3000" - << "passive" - << true - << "me" + << "passive" << true << "me" << "mongo.example:3001" - << "maxBsonObjectSize" - << 16777216 - << "maxMessageSizeBytes" - << 48000000 - << "maxWriteBatchSize" - << 1000 - << "localTime" - << mongo::jsTime() - << "maxWireVersion" - << 2 - << "minWireVersion" - << 0 - << "ok" - << 1); + << "maxBsonObjectSize" << 16777216 << "maxMessageSizeBytes" << 48000000 + << "maxWriteBatchSize" << 1000 << "localTime" << mongo::jsTime() + << "maxWireVersion" << 2 << "minWireVersion" << 0 << "ok" << 1); IsMasterReply imr(HostAndPort("mongo.example:3001"), -1, ismaster); @@ -501,38 +448,15 @@ TEST_F(IsMasterReplyTest, IsMasterReplyPassiveSecondary) { TEST_F(IsMasterReplyTest, IsMasterReplyHiddenSecondary) { BSONObj ismaster = BSON("setName" << "test" - << "setVersion" - << 2 - << "electionId" - << OID("7fffffff0000000000000001") - << "ismaster" - << false - << "secondary" - << true - << "hosts" - << BSON_ARRAY("mongo.example:3000") - << "primary" + << "setVersion" << 2 << "electionId" << OID("7fffffff0000000000000001") + << "ismaster" << false << "secondary" << true << "hosts" + << BSON_ARRAY("mongo.example:3000") << "primary" << "mongo.example:3000" - << "passive" - << true - << "hidden" - << true - << "me" + << "passive" << true << "hidden" << true << "me" << "mongo.example:3001" - << "maxBsonObjectSize" - << 16777216 - << "maxMessageSizeBytes" - << 48000000 - << "maxWriteBatchSize" - << 1000 - << "localTime" - << mongo::jsTime() - << "maxWireVersion" - << 2 - << "minWireVersion" - << 0 - << "ok" - << 1); + << "maxBsonObjectSize" << 16777216 << "maxMessageSizeBytes" << 48000000 + << "maxWriteBatchSize" << 1000 << "localTime" << mongo::jsTime() + << "maxWireVersion" << 2 << "minWireVersion" << 0 << "ok" << 1); IsMasterReply imr(HostAndPort("mongo.example:3001"), -1, ismaster); @@ -552,40 +476,22 @@ TEST_F(IsMasterReplyTest, IsMasterReplyHiddenSecondary) { TEST_F(IsMasterReplyTest, IsMasterSecondaryWithTags) { BSONObj ismaster = BSON("setName" << "test" - << "setVersion" - << 2 - << "electionId" - << OID("7fffffff0000000000000001") - << "ismaster" - << false - << "secondary" - << true - << "hosts" + << "setVersion" << 2 << "electionId" << OID("7fffffff0000000000000001") + << "ismaster" << false << "secondary" << true << "hosts" << BSON_ARRAY("mongo.example:3000" << "mongo.example:3001") << "primary" << "mongo.example:3000" << "me" << "mongo.example:3001" - << "maxBsonObjectSize" - << 16777216 - << "maxMessageSizeBytes" - << 48000000 - << "maxWriteBatchSize" - << 1000 - << "localTime" - << mongo::jsTime() - << "maxWireVersion" - << 2 - << "minWireVersion" - << 0 - << "tags" + << "maxBsonObjectSize" << 16777216 << "maxMessageSizeBytes" << 48000000 + << "maxWriteBatchSize" << 1000 << "localTime" << mongo::jsTime() + << "maxWireVersion" << 2 << "minWireVersion" << 0 << "tags" << BSON("dc" << "nyc" << "use" << "production") - << "ok" - << 1); + << "ok" << 1); IsMasterReply imr(HostAndPort("mongo.example:3001"), -1, ismaster); diff --git a/src/mongo/client/replica_set_monitor_manager.cpp b/src/mongo/client/replica_set_monitor_manager.cpp index fbf4d3a08d2..94aa109ad26 100644 --- a/src/mongo/client/replica_set_monitor_manager.cpp +++ b/src/mongo/client/replica_set_monitor_manager.cpp @@ -52,15 +52,15 @@ namespace mongo { -using std::shared_ptr; using std::set; +using std::shared_ptr; using std::string; using std::vector; using executor::NetworkInterface; using executor::NetworkInterfaceThreadPool; -using executor::TaskExecutorPool; using executor::TaskExecutor; +using executor::TaskExecutorPool; using executor::ThreadPoolTaskExecutor; ReplicaSetMonitorManager::ReplicaSetMonitorManager() {} @@ -98,7 +98,7 @@ namespace { void uassertNotMixingSSL(transport::ConnectSSLMode a, transport::ConnectSSLMode b) { uassert(51042, "Mixing ssl modes with a single replica set is disallowed", a == b); } -} +} // namespace shared_ptr<ReplicaSetMonitor> ReplicaSetMonitorManager::getOrCreateMonitor( const ConnectionString& connStr) { @@ -165,7 +165,7 @@ void ReplicaSetMonitorManager::shutdown() { } log() << "Dropping all ongoing scans against replica sets"; - for (auto & [ name, monitor ] : monitors) { + for (auto& [name, monitor] : monitors) { auto anchor = monitor.lock(); if (!anchor) { continue; diff --git a/src/mongo/client/replica_set_monitor_scan_test.cpp b/src/mongo/client/replica_set_monitor_scan_test.cpp index c75984cc985..80d5a576b4e 100644 --- a/src/mongo/client/replica_set_monitor_scan_test.cpp +++ b/src/mongo/client/replica_set_monitor_scan_test.cpp @@ -60,16 +60,12 @@ TEST_F(CoreScanTest, CheckAllSeedsSerial) { -1, BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary + << "ismaster" << primary << "secondary" << !primary << "hosts" << BSON_ARRAY("a" << "b" << "c") - << "ok" - << true)); + << "ok" << true)); } NextStep ns = refresher.getNextStep(); @@ -116,16 +112,12 @@ TEST_F(CoreScanTest, CheckAllSeedsParallel) { -1, BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary + << "ismaster" << primary << "secondary" << !primary << "hosts" << BSON_ARRAY("a" << "b" << "c") - << "ok" - << true)); + << "ok" << true)); } // Now all hosts have returned data @@ -163,16 +155,11 @@ TEST_F(CoreScanTest, NoMasterInitAllUp) { -1, BSON("setName" << "name" - << "ismaster" - << false - << "secondary" - << true - << "hosts" + << "ismaster" << false << "secondary" << true << "hosts" << BSON_ARRAY("a" << "b" << "c") - << "ok" - << true)); + << "ok" << true)); } NextStep ns = refresher.getNextStep(); @@ -209,17 +196,12 @@ TEST_F(CoreScanTest, MasterNotInSeeds_NoPrimaryInIsMaster) { -1, BSON("setName" << "name" - << "ismaster" - << false - << "secondary" - << true - << "hosts" + << "ismaster" << false << "secondary" << true << "hosts" << BSON_ARRAY("a" << "b" << "c" << "d") - << "ok" - << true)); + << "ok" << true)); } // Only look at "d" after exhausting all other hosts @@ -230,17 +212,12 @@ TEST_F(CoreScanTest, MasterNotInSeeds_NoPrimaryInIsMaster) { -1, BSON("setName" << "name" - << "ismaster" - << true - << "secondary" - << false - << "hosts" + << "ismaster" << true << "secondary" << false << "hosts" << BSON_ARRAY("a" << "b" << "c" << "d") - << "ok" - << true)); + << "ok" << true)); ns = refresher.getNextStep(); @@ -289,10 +266,7 @@ TEST_F(CoreScanTest, MasterNotInSeeds_PrimaryInIsMaster) { -1, BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary + << "ismaster" << primary << "secondary" << !primary << "primary" << "d" << "hosts" @@ -300,8 +274,7 @@ TEST_F(CoreScanTest, MasterNotInSeeds_PrimaryInIsMaster) { << "b" << "c" << "d") - << "ok" - << true)); + << "ok" << true)); } NextStep ns = refresher.getNextStep(); @@ -346,14 +319,8 @@ TEST_F(CoreScanTest, SlavesUsableEvenIfNoMaster) { -1, BSON("setName" << "name" - << "ismaster" - << false - << "secondary" - << true - << "hosts" - << BSON_ARRAY("a") - << "ok" - << true)); + << "ismaster" << false << "secondary" << true << "hosts" + << BSON_ARRAY("a") << "ok" << true)); // Check intended conditions for entry to getNextStep(). ASSERT(state->currentScan->hostsToScan.empty()); @@ -398,16 +365,11 @@ TEST_F(CoreScanTest, MultipleMasterLastNodeWins) { -1, BSON("setName" << "name" - << "ismaster" - << true - << "secondary" - << false - << "hosts" + << "ismaster" << true << "secondary" << false << "hosts" << BSON_ARRAY("a" << "b" << "c") - << "ok" - << true)); + << "ok" << true)); // Ensure the set primary is the host we just got a reply from HostAndPort currentPrimary = state->getMatchingHost(primaryOnly); @@ -451,14 +413,9 @@ TEST_F(CoreScanTest, MasterIsSourceOfTruth) { -1, BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary - << "hosts" - << (primary ? primaryHosts : secondaryHosts) - << "ok" - << true)); + << "ismaster" << primary << "secondary" << !primary + << "hosts" << (primary ? primaryHosts : secondaryHosts) + << "ok" << true)); ns = refresher.getNextStep(); } @@ -505,14 +462,8 @@ TEST_F(CoreScanTest, MultipleMastersDisagree) { -1, BSON("setName" << "name" - << "ismaster" - << true - << "secondary" - << false - << "hosts" - << hostsForSeed[i % 2] - << "ok" - << true)); + << "ismaster" << true << "secondary" << false << "hosts" + << hostsForSeed[i % 2] << "ok" << true)); // Ensure the primary is the host we just got a reply from HostAndPort currentPrimary = state->getMatchingHost(primaryOnly); @@ -541,14 +492,8 @@ TEST_F(CoreScanTest, MultipleMastersDisagree) { -1, BSON("setName" << "name" - << "ismaster" - << false - << "secondary" - << true - << "hosts" - << hostsForSeed[0] - << "ok" - << true)); + << "ismaster" << false << "secondary" << true << "hosts" + << hostsForSeed[0] << "ok" << true)); // scan should be complete ns = refresher.getNextStep(); @@ -595,16 +540,12 @@ TEST_F(CoreScanTest, GetMatchingDuringScan) { -1, BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary + << "ismaster" << primary << "secondary" << !primary << "hosts" << BSON_ARRAY("a" << "b" << "c") - << "ok" - << true)); + << "ok" << true)); bool hasPrimary = !(state->getMatchingHost(primaryOnly).empty()); bool hasSecondary = !(state->getMatchingHost(secondaryOnly).empty()); @@ -641,16 +582,12 @@ TEST_F(CoreScanTest, OutOfBandFailedHost) { -1, BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary + << "ismaster" << primary << "secondary" << !primary << "hosts" << BSON_ARRAY("a" << "b" << "c") - << "ok" - << true)); + << "ok" << true)); if (i >= 1) { HostAndPort a("a"); @@ -698,18 +635,13 @@ TEST_F(CoreScanTest, NewPrimaryWithMaxElectionId) { BSON( "setName" << "name" - << "ismaster" - << true - << "secondary" - << false - << "hosts" + << "ismaster" << true << "secondary" << false << "hosts" << BSON_ARRAY("a" << "b" << "c") << "electionId" << OID::fromTerm(i) // electionId must increase every cycle. - << "ok" - << true)); + << "ok" << true)); // Ensure the set primary is the host we just got a reply from HostAndPort currentPrimary = state->getMatchingHost(primaryOnly); @@ -756,18 +688,13 @@ TEST_F(CoreScanTest, IgnoreElectionIdFromSecondaries) { -1, BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary + << "ismaster" << primary << "secondary" << !primary << "electionId" - << (primary ? primaryElectionId : OID::gen()) - << "hosts" + << (primary ? primaryElectionId : OID::gen()) << "hosts" << BSON_ARRAY("a" << "b" << "c") - << "ok" - << true)); + << "ok" << true)); } // check that the SetState's maxElectionId == primary's electionId @@ -801,20 +728,13 @@ TEST_F(CoreScanTest, StalePrimaryWithObsoleteElectionId) { -1, BSON("setName" << "name" - << "ismaster" - << true - << "secondary" - << false - << "setVersion" - << 1 - << "electionId" - << secondElectionId + << "ismaster" << true << "secondary" << false + << "setVersion" << 1 << "electionId" << secondElectionId << "hosts" << BSON_ARRAY("a" << "b" << "c") - << "ok" - << true)); + << "ok" << true)); auto node = state->findNode(ns.host); ASSERT(node); @@ -834,18 +754,12 @@ TEST_F(CoreScanTest, StalePrimaryWithObsoleteElectionId) { -1, BSON("setName" << "name" - << "ismaster" - << true - << "secondary" - << false - << "electionId" - << firstElectionId - << "hosts" + << "ismaster" << true << "secondary" << false + << "electionId" << firstElectionId << "hosts" << BSON_ARRAY("a" << "b" << "c") - << "ok" - << true)); + << "ok" << true)); auto node = state->findNode(ns.host); ASSERT(node); @@ -867,16 +781,11 @@ TEST_F(CoreScanTest, StalePrimaryWithObsoleteElectionId) { -1, BSON("setName" << "name" - << "ismaster" - << false - << "secondary" - << true - << "hosts" + << "ismaster" << false << "secondary" << true << "hosts" << BSON_ARRAY("a" << "b" << "c") - << "ok" - << true)); + << "ok" << true)); auto node = state->findNode(ns.host); ASSERT(node); @@ -919,20 +828,13 @@ TEST_F(CoreScanTest, TwoPrimaries2ndHasNewerConfigVersion) { -1, BSON("setName" << "name" - << "ismaster" - << true - << "secondary" - << false - << "setVersion" - << 1 - << "electionId" - << OID("7fffffff0000000000000001") + << "ismaster" << true << "secondary" << false << "setVersion" + << 1 << "electionId" << OID("7fffffff0000000000000001") << "hosts" << BSON_ARRAY("a" << "b" << "c") - << "ok" - << true)); + << "ok" << true)); // check that the SetState's maxElectionId == primary's electionId ASSERT_EQUALS(state->maxElectionId, OID("7fffffff0000000000000001")); @@ -945,20 +847,12 @@ TEST_F(CoreScanTest, TwoPrimaries2ndHasNewerConfigVersion) { -1, BSON("setName" << "name" - << "ismaster" - << true - << "secondary" - << false - << "setVersion" - << 2 - << "electionId" - << primaryElectionId - << "hosts" + << "ismaster" << true << "secondary" << false << "setVersion" + << 2 << "electionId" << primaryElectionId << "hosts" << BSON_ARRAY("a" << "b" << "c") - << "ok" - << true)); + << "ok" << true)); ASSERT_EQUALS(state->maxElectionId, primaryElectionId); ASSERT_EQUALS(state->configVersion, 2); @@ -980,20 +874,12 @@ TEST_F(CoreScanTest, TwoPrimaries2ndHasOlderConfigVersion) { -1, BSON("setName" << "name" - << "ismaster" - << true - << "secondary" - << false - << "electionId" - << primaryElectionId - << "setVersion" - << 2 - << "hosts" + << "ismaster" << true << "secondary" << false << "electionId" + << primaryElectionId << "setVersion" << 2 << "hosts" << BSON_ARRAY("a" << "b" << "c") - << "ok" - << true)); + << "ok" << true)); ASSERT_EQUALS(state->maxElectionId, primaryElectionId); ASSERT_EQUALS(state->configVersion, 2); @@ -1003,20 +889,13 @@ TEST_F(CoreScanTest, TwoPrimaries2ndHasOlderConfigVersion) { -1, BSON("setName" << "name" - << "ismaster" - << true - << "secondary" - << false - << "setVersion" - << 1 - << "electionId" - << OID("7fffffff0000000000000001") + << "ismaster" << true << "secondary" << false << "setVersion" + << 1 << "electionId" << OID("7fffffff0000000000000001") << "hosts" << BSON_ARRAY("a" << "b" << "c") - << "ok" - << true)); + << "ok" << true)); ASSERT_EQUALS(state->maxElectionId, primaryElectionId); ASSERT_EQUALS(state->configVersion, 2); @@ -1049,19 +928,12 @@ TEST_F(MaxStalenessMSTest, MaxStalenessMSMatch) { -1, BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary - << "hosts" - << hosts - << "lastWrite" + << "ismaster" << primary << "secondary" << !primary + << "hosts" << hosts << "lastWrite" << BSON("lastWriteDate" << (nonStale ? lastWriteDateNonStale : lastWriteDateStale) - << "opTime" - << opTime) - << "ok" - << true)); + << "opTime" << opTime) + << "ok" << true)); ns = refresher.getNextStep(); } @@ -1099,19 +971,12 @@ TEST_F(MaxStalenessMSTest, MaxStalenessMSNoMatch) { -1, BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary - << "hosts" - << hosts - << "lastWrite" + << "ismaster" << primary << "secondary" << !primary + << "hosts" << hosts << "lastWrite" << BSON("lastWriteDate" << (primary ? lastWriteDateNonStale : lastWriteDateStale) - << "opTime" - << opTime) - << "ok" - << true)); + << "opTime" << opTime) + << "ok" << true)); ns = refresher.getNextStep(); } @@ -1150,20 +1015,13 @@ TEST_F(MaxStalenessMSTest, MaxStalenessMSNoPrimaryMatch) { -1, BSON("setName" << "name" - << "ismaster" - << false - << "secondary" - << true - << "hosts" - << hosts - << "lastWrite" + << "ismaster" << false << "secondary" << true << "hosts" + << hosts << "lastWrite" << BSON("lastWriteDate" << (isNonStale ? lastWriteDateNonStale : lastWriteDateStale) - << "opTime" - << opTime) - << "ok" - << true)); + << "opTime" << opTime) + << "ok" << true)); ns = refresher.getNextStep(); } @@ -1204,20 +1062,13 @@ TEST_F(MaxStalenessMSTest, MaxStalenessMSAllFailed) { -1, BSON("setName" << "name" - << "ismaster" - << false - << "secondary" - << true - << "hosts" - << hosts - << "lastWrite" + << "ismaster" << false << "secondary" << true << "hosts" + << hosts << "lastWrite" << BSON("lastWriteDate" << (isNonStale ? lastWriteDateNonStale : lastWriteDateStale) - << "opTime" - << opTime) - << "ok" - << true)); + << "opTime" << opTime) + << "ok" << true)); ns = refresher.getNextStep(); } @@ -1257,19 +1108,12 @@ TEST_F(MaxStalenessMSTest, MaxStalenessMSAllButPrimaryFailed) { -1, BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary - << "hosts" - << hosts - << "lastWrite" + << "ismaster" << primary << "secondary" << !primary + << "hosts" << hosts << "lastWrite" << BSON("lastWriteDate" << (primary ? lastWriteDateNonStale : lastWriteDateStale) - << "opTime" - << opTime) - << "ok" - << true)); + << "opTime" << opTime) + << "ok" << true)); ns = refresher.getNextStep(); } @@ -1309,19 +1153,12 @@ TEST_F(MaxStalenessMSTest, MaxStalenessMSOneSecondaryFailed) { -1, BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary - << "hosts" - << hosts - << "lastWrite" + << "ismaster" << primary << "secondary" << !primary + << "hosts" << hosts << "lastWrite" << BSON("lastWriteDate" << (primary ? lastWriteDateNonStale : lastWriteDateStale) - << "opTime" - << opTime) - << "ok" - << true)); + << "opTime" << opTime) + << "ok" << true)); ns = refresher.getNextStep(); } @@ -1361,20 +1198,13 @@ TEST_F(MaxStalenessMSTest, MaxStalenessMSNonStaleSecondaryMatched) { -1, BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary - << "hosts" - << hosts - << "lastWrite" + << "ismaster" << primary << "secondary" << !primary + << "hosts" << hosts << "lastWrite" << BSON("lastWriteDate" << (isNonStale ? lastWriteDateNonStale : lastWriteDateStale) - << "opTime" - << opTime) - << "ok" - << true)); + << "opTime" << opTime) + << "ok" << true)); ns = refresher.getNextStep(); } @@ -1409,14 +1239,8 @@ TEST_F(MaxStalenessMSTest, MaxStalenessMSNoLastWrite) { -1, BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary - << "hosts" - << hosts - << "ok" - << true)); + << "ismaster" << primary << "secondary" << !primary + << "hosts" << hosts << "ok" << true)); ns = refresher.getNextStep(); } @@ -1450,14 +1274,8 @@ TEST_F(MaxStalenessMSTest, MaxStalenessMSZeroNoLastWrite) { -1, BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary - << "hosts" - << hosts - << "ok" - << true)); + << "ismaster" << primary << "secondary" << !primary + << "hosts" << hosts << "ok" << true)); ns = refresher.getNextStep(); } @@ -1496,17 +1314,11 @@ TEST_F(MinOpTimeTest, MinOpTimeMatched) { bool isNonStale = ns.host.host() == "b"; BSONObj bson = BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary - << "hosts" - << hosts + << "ismaster" << primary << "secondary" << !primary << "hosts" << hosts << "lastWrite" << BSON("opTime" << (isNonStale ? opTimeNonStale.toBSON() : opTimeStale.toBSON())) - << "ok" - << true); + << "ok" << true); refresher.receivedIsMaster(ns.host, -1, bson); ns = refresher.getNextStep(); } @@ -1541,17 +1353,11 @@ TEST_F(MinOpTimeTest, MinOpTimeNotMatched) { bool isNonStale = ns.host.host() == "a"; BSONObj bson = BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary - << "hosts" - << hosts + << "ismaster" << primary << "secondary" << !primary << "hosts" << hosts << "lastWrite" << BSON("opTime" << (isNonStale ? opTimeNonStale.toBSON() : opTimeStale.toBSON())) - << "ok" - << true); + << "ok" << true); refresher.receivedIsMaster(ns.host, -1, bson); ns = refresher.getNextStep(); } @@ -1588,20 +1394,13 @@ TEST_F(MinOpTimeTest, MinOpTimeIgnored) { bool isNonStale = ns.host.host() == "c"; BSONObj bson = BSON("setName" << "name" - << "ismaster" - << primary - << "secondary" - << !primary - << "hosts" - << hosts + << "ismaster" << primary << "secondary" << !primary << "hosts" << hosts << "lastWrite" << BSON("lastWriteDate" << (isNonStale || primary ? lastWriteDateNonStale : lastWriteDateStale) - << "opTime" - << opTimeStale.toBSON()) - << "ok" - << true); + << "opTime" << opTimeStale.toBSON()) + << "ok" << true); refresher.receivedIsMaster(ns.host, -1, bson); ns = refresher.getNextStep(); } @@ -1674,7 +1473,7 @@ public: std::set<HostAndPort> members; BSONArrayBuilder arrayBuilder; - for (const auto & [ host, nodeState ] : replicaSet) { + for (const auto& [host, nodeState] : replicaSet) { if (nodeState == NodeState::kStandalone) { continue; } @@ -1690,15 +1489,11 @@ public: auto bsonHosts = arrayBuilder.arr(); auto markIsMaster = [&](auto host, bool isMaster) { - refresher.receivedIsMaster( - host, - -1, - BSON("setName" << kSetName << "ismaster" << isMaster << "secondary" << !isMaster - << "hosts" - << bsonHosts - << "ok" - << true)); - + refresher.receivedIsMaster(host, + -1, + BSON("setName" << kSetName << "ismaster" << isMaster + << "secondary" << !isMaster << "hosts" + << bsonHosts << "ok" << true)); }; auto markFailed = [&](auto host) { @@ -1769,13 +1564,16 @@ TEST_F(ChangeNotifierTest, NotifyNominal) { // 'a' claims to be primary. Signal: Confirmed updateSet({ { - HostAndPort("a"), NodeState::kPrimary, + HostAndPort("a"), + NodeState::kPrimary, }, { - HostAndPort("b"), NodeState::kSecondary, + HostAndPort("b"), + NodeState::kSecondary, }, { - HostAndPort("c"), NodeState::kSecondary, + HostAndPort("c"), + NodeState::kSecondary, }, }); ASSERT_EQ(listener().lastConfirmedSetId, ++currentId); @@ -1783,13 +1581,16 @@ TEST_F(ChangeNotifierTest, NotifyNominal) { // Getting another scan with the same details. Signal: null updateSet({ { - HostAndPort("a"), NodeState::kPrimary, + HostAndPort("a"), + NodeState::kPrimary, }, { - HostAndPort("b"), NodeState::kSecondary, + HostAndPort("b"), + NodeState::kSecondary, }, { - HostAndPort("c"), NodeState::kSecondary, + HostAndPort("c"), + NodeState::kSecondary, }, }); ASSERT_EQ(listener().eventId, currentId); @@ -1812,13 +1613,16 @@ TEST_F(ChangeNotifierTest, NotifyElections) { // 'a' claims to be primary. Signal: ConfirmedSet updateSet({ { - HostAndPort("a"), NodeState::kPrimary, + HostAndPort("a"), + NodeState::kPrimary, }, { - HostAndPort("b"), NodeState::kSecondary, + HostAndPort("b"), + NodeState::kSecondary, }, { - HostAndPort("c"), NodeState::kSecondary, + HostAndPort("c"), + NodeState::kSecondary, }, }); ASSERT_EQ(listener().lastConfirmedSetId, ++currentId); @@ -1826,13 +1630,16 @@ TEST_F(ChangeNotifierTest, NotifyElections) { // 'b' claims to be primary. Signal: ConfirmedSet updateSet({ { - HostAndPort("a"), NodeState::kSecondary, + HostAndPort("a"), + NodeState::kSecondary, }, { - HostAndPort("b"), NodeState::kPrimary, + HostAndPort("b"), + NodeState::kPrimary, }, { - HostAndPort("c"), NodeState::kSecondary, + HostAndPort("c"), + NodeState::kSecondary, }, }); ASSERT_EQ(listener().lastConfirmedSetId, ++currentId); @@ -1840,13 +1647,16 @@ TEST_F(ChangeNotifierTest, NotifyElections) { // All hosts tell us that they are not primary. Signal: null updateSet({ { - HostAndPort("a"), NodeState::kSecondary, + HostAndPort("a"), + NodeState::kSecondary, }, { - HostAndPort("b"), NodeState::kSecondary, + HostAndPort("b"), + NodeState::kSecondary, }, { - HostAndPort("c"), NodeState::kSecondary, + HostAndPort("c"), + NodeState::kSecondary, }, }); ASSERT_EQ(listener().eventId, currentId); @@ -1854,13 +1664,16 @@ TEST_F(ChangeNotifierTest, NotifyElections) { // 'a' claims to be primary again. Signal: ConfirmedSet updateSet({ { - HostAndPort("a"), NodeState::kPrimary, + HostAndPort("a"), + NodeState::kPrimary, }, { - HostAndPort("b"), NodeState::kSecondary, + HostAndPort("b"), + NodeState::kSecondary, }, { - HostAndPort("c"), NodeState::kSecondary, + HostAndPort("c"), + NodeState::kSecondary, }, }); ASSERT_EQ(listener().lastConfirmedSetId, ++currentId); @@ -1883,13 +1696,16 @@ TEST_F(ChangeNotifierTest, NotifyReconfig) { // Update the set with a full scan showing no primary. Signal: PossibleSet updateSet({ { - HostAndPort("a"), NodeState::kSecondary, + HostAndPort("a"), + NodeState::kSecondary, }, { - HostAndPort("b"), NodeState::kSecondary, + HostAndPort("b"), + NodeState::kSecondary, }, { - HostAndPort("c"), NodeState::kSecondary, + HostAndPort("c"), + NodeState::kSecondary, }, }); ASSERT_EQ(listener().eventId, ++currentId); @@ -1897,13 +1713,16 @@ TEST_F(ChangeNotifierTest, NotifyReconfig) { // Mark 'a' as removed. Signal: null updateSet({ { - HostAndPort("a"), NodeState::kStandalone, + HostAndPort("a"), + NodeState::kStandalone, }, { - HostAndPort("b"), NodeState::kSecondary, + HostAndPort("b"), + NodeState::kSecondary, }, { - HostAndPort("c"), NodeState::kSecondary, + HostAndPort("c"), + NodeState::kSecondary, }, }); ASSERT_EQ(listener().eventId, currentId); @@ -1911,16 +1730,20 @@ TEST_F(ChangeNotifierTest, NotifyReconfig) { // Discover 'd' as secondary. Signal: PossibleSet updateSet({ { - HostAndPort("a"), NodeState::kSecondary, + HostAndPort("a"), + NodeState::kSecondary, }, { - HostAndPort("b"), NodeState::kSecondary, + HostAndPort("b"), + NodeState::kSecondary, }, { - HostAndPort("c"), NodeState::kSecondary, + HostAndPort("c"), + NodeState::kSecondary, }, { - HostAndPort("d"), NodeState::kSecondary, + HostAndPort("d"), + NodeState::kSecondary, }, }); ASSERT_EQ(listener().lastPossibleSetId, ++currentId); @@ -1928,16 +1751,20 @@ TEST_F(ChangeNotifierTest, NotifyReconfig) { // Mark 'b' as primary, no 'd'. Signal: ConfirmedSet updateSet({ { - HostAndPort("a"), NodeState::kSecondary, + HostAndPort("a"), + NodeState::kSecondary, }, { - HostAndPort("b"), NodeState::kPrimary, + HostAndPort("b"), + NodeState::kPrimary, }, { - HostAndPort("c"), NodeState::kSecondary, + HostAndPort("c"), + NodeState::kSecondary, }, { - HostAndPort("d"), NodeState::kStandalone, + HostAndPort("d"), + NodeState::kStandalone, }, }); ASSERT_EQ(listener().lastConfirmedSetId, ++currentId); @@ -1945,13 +1772,16 @@ TEST_F(ChangeNotifierTest, NotifyReconfig) { // Mark 'a' as removed. Signal: ConfirmedSet updateSet({ { - HostAndPort("a"), NodeState::kStandalone, + HostAndPort("a"), + NodeState::kStandalone, }, { - HostAndPort("b"), NodeState::kPrimary, + HostAndPort("b"), + NodeState::kPrimary, }, { - HostAndPort("c"), NodeState::kSecondary, + HostAndPort("c"), + NodeState::kSecondary, }, }); ASSERT_EQ(listener().lastConfirmedSetId, ++currentId); @@ -1959,13 +1789,16 @@ TEST_F(ChangeNotifierTest, NotifyReconfig) { // Mark 'a' as secondary again. Signal: ConfirmedSet updateSet({ { - HostAndPort("b"), NodeState::kPrimary, + HostAndPort("b"), + NodeState::kPrimary, }, { - HostAndPort("c"), NodeState::kSecondary, + HostAndPort("c"), + NodeState::kSecondary, }, { - HostAndPort("a"), NodeState::kSecondary, + HostAndPort("a"), + NodeState::kSecondary, }, }); ASSERT_EQ(listener().lastConfirmedSetId, ++currentId); diff --git a/src/mongo/client/sasl_client_authenticate.h b/src/mongo/client/sasl_client_authenticate.h index 307e837c38b..4b342a41a99 100644 --- a/src/mongo/client/sasl_client_authenticate.h +++ b/src/mongo/client/sasl_client_authenticate.h @@ -83,4 +83,4 @@ extern Future<void> (*saslClientAuthenticate)(auth::RunCommandHook runCommand, * into "*payload". In all other cases, returns */ Status saslExtractPayload(const BSONObj& cmdObj, std::string* payload, BSONType* type); -} +} // namespace mongo diff --git a/src/mongo/client/sasl_client_authenticate_impl.cpp b/src/mongo/client/sasl_client_authenticate_impl.cpp index b025000fb5b..4d19e5597d2 100644 --- a/src/mongo/client/sasl_client_authenticate_impl.cpp +++ b/src/mongo/client/sasl_client_authenticate_impl.cpp @@ -56,9 +56,9 @@ namespace mongo { -using std::endl; using executor::RemoteCommandRequest; using executor::RemoteCommandResponse; +using std::endl; namespace { diff --git a/src/mongo/client/sasl_scram_client_conversation.cpp b/src/mongo/client/sasl_scram_client_conversation.cpp index effd369a4ff..c0f38495822 100644 --- a/src/mongo/client/sasl_scram_client_conversation.cpp +++ b/src/mongo/client/sasl_scram_client_conversation.cpp @@ -43,8 +43,8 @@ namespace mongo { -using std::unique_ptr; using std::string; +using std::unique_ptr; StatusWith<bool> SaslSCRAMClientConversation::step(StringData inputData, std::string* outputData) { _step++; @@ -58,8 +58,8 @@ StatusWith<bool> SaslSCRAMClientConversation::step(StringData inputData, std::st return _thirdStep(inputData, outputData); default: return StatusWith<bool>(ErrorCodes::AuthenticationFailed, - str::stream() << "Invalid SCRAM authentication step: " - << _step); + str::stream() + << "Invalid SCRAM authentication step: " << _step); } } @@ -126,8 +126,7 @@ StatusWith<bool> SaslSCRAMClientConversation::_secondStep(StringData inputData, return Status(ErrorCodes::BadValue, str::stream() << "Incorrect number of arguments for first SCRAM server message, got " - << input.size() - << " expected at least 3"); + << input.size() << " expected at least 3"); } if (!str::startsWith(input[0], "r=") || input[0].size() < 3) { diff --git a/src/mongo/client/sasl_sspi.cpp b/src/mongo/client/sasl_sspi.cpp index b917b016844..89f798577a9 100644 --- a/src/mongo/client/sasl_sspi.cpp +++ b/src/mongo/client/sasl_sspi.cpp @@ -439,8 +439,7 @@ sasl_client_plug_t sspiClientPlugin[] = { {sspiPluginName, /* mechanism name */ 112, /* TODO: (taken from gssapi) best mech additional security layer strength factor */ SASL_SEC_NOPLAINTEXT /* eam: copied from gssapi */ - | - SASL_SEC_NOACTIVE | SASL_SEC_NOANONYMOUS | SASL_SEC_MUTUAL_AUTH | + | SASL_SEC_NOACTIVE | SASL_SEC_NOANONYMOUS | SASL_SEC_MUTUAL_AUTH | SASL_SEC_PASS_CREDENTIALS, /* security_flags */ SASL_FEAT_NEEDSERVERFQDN | SASL_FEAT_WANT_CLIENT_FIRST | SASL_FEAT_ALLOWS_PROXY, nullptr, /* required prompt ids, nullptr = user/pass only */ @@ -482,8 +481,7 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SaslSspiClientPlugin, if (SASL_OK != ret) { return Status(ErrorCodes::UnknownError, str::stream() << "could not add SASL Client SSPI plugin " << sspiPluginName - << ": " - << sasl_errstring(ret, nullptr, nullptr)); + << ": " << sasl_errstring(ret, nullptr, nullptr)); } return Status::OK(); @@ -496,8 +494,7 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SaslPlainClientPlugin, if (SASL_OK != ret) { return Status(ErrorCodes::UnknownError, str::stream() << "Could not add SASL Client PLAIN plugin " << sspiPluginName - << ": " - << sasl_errstring(ret, nullptr, nullptr)); + << ": " << sasl_errstring(ret, nullptr, nullptr)); } return Status::OK(); |