diff options
Diffstat (limited to 'src/mongo/db/repl')
88 files changed, 2719 insertions, 5718 deletions
diff --git a/src/mongo/db/repl/abstract_async_component.cpp b/src/mongo/db/repl/abstract_async_component.cpp index 181f2f5ef69..1b99507fc5c 100644 --- a/src/mongo/db/repl/abstract_async_component.cpp +++ b/src/mongo/db/repl/abstract_async_component.cpp @@ -189,16 +189,15 @@ Status AbstractAsyncComponent::_scheduleWorkAtAndSaveHandle_inlock( const std::string& name) { invariant(handle); if (_isShuttingDown_inlock()) { - return Status( - ErrorCodes::CallbackCanceled, - str::stream() << "failed to schedule work " << name << " at " << when.toString() << ": " - << _componentName - << " is shutting down"); + return Status(ErrorCodes::CallbackCanceled, + str::stream() + << "failed to schedule work " << name << " at " << when.toString() << ": " + << _componentName << " is shutting down"); } auto result = _executor->scheduleWorkAt(when, std::move(work)); if (!result.isOK()) { - return result.getStatus().withContext( - str::stream() << "failed to schedule work " << name << " at " << when.toString()); + return result.getStatus().withContext(str::stream() << "failed to schedule work " << name + << " at " << when.toString()); } *handle = result.getValue(); return Status::OK(); diff --git a/src/mongo/db/repl/abstract_async_component.h b/src/mongo/db/repl/abstract_async_component.h index 8d5e784b591..64d88ad41e8 100644 --- a/src/mongo/db/repl/abstract_async_component.h +++ b/src/mongo/db/repl/abstract_async_component.h @@ -247,8 +247,7 @@ Status AbstractAsyncComponent::_startupComponent_inlock(std::unique_ptr<T>& comp component.reset(); return Status(ErrorCodes::CallbackCanceled, str::stream() << "failed to start up " << componentToStartUp << ": " - << _componentName - << " is shutting down"); + << _componentName << " is shutting down"); } auto status = component->startup(); diff --git a/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.cpp b/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.cpp index f3d44242ffb..882cf5f4fa8 100644 --- a/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.cpp +++ b/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.cpp @@ -135,4 +135,4 @@ executor::RemoteCommandRequest AbstractOplogFetcherTest::processNetworkResponse( } } // namespace repl -} // namespace mango +} // namespace mongo diff --git a/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.h b/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.h index 2164f93cac6..7349689bb32 100644 --- a/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.h +++ b/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.h @@ -97,4 +97,4 @@ protected: Date_t lastFetchedWall; }; } // namespace repl -} // namespace mango +} // namespace mongo diff --git a/src/mongo/db/repl/applier_helpers.cpp b/src/mongo/db/repl/applier_helpers.cpp index ef92ed6c52d..1672585a071 100644 --- a/src/mongo/db/repl/applier_helpers.cpp +++ b/src/mongo/db/repl/applier_helpers.cpp @@ -196,8 +196,7 @@ StatusWith<InsertGroup::ConstIterator> InsertGroup::groupAndApplyInserts(ConstIt // application of an individual op. auto status = exceptionToStatus().withContext( str::stream() << "Error applying inserts in bulk: " << redact(groupedInsertObj) - << ". Trying first insert as a lone insert: " - << redact(entry.raw)); + << ". Trying first insert as a lone insert: " << redact(entry.raw)); // It's not an error during initial sync to encounter DuplicateKey errors. if (Mode::kInitialSync == _mode && ErrorCodes::DuplicateKey == status) { diff --git a/src/mongo/db/repl/apply_ops.cpp b/src/mongo/db/repl/apply_ops.cpp index 9b3d0b50632..a562679e63d 100644 --- a/src/mongo/db/repl/apply_ops.cpp +++ b/src/mongo/db/repl/apply_ops.cpp @@ -159,9 +159,7 @@ Status _applyOps(OperationContext* opCtx, ErrorCodes::AtomicityFailure, str::stream() << "cannot apply insert or update operation on a non-existent namespace " - << nss.ns() - << " in atomic applyOps mode: " - << redact(opObj)); + << nss.ns() << " in atomic applyOps mode: " << redact(opObj)); } // Reject malformed operations in an atomic applyOps. @@ -171,8 +169,7 @@ Status _applyOps(OperationContext* opCtx, uasserted(ErrorCodes::AtomicityFailure, str::stream() << "cannot apply a malformed operation in atomic applyOps mode: " - << redact(opObj) - << "; will retry without atomicity: " + << redact(opObj) << "; will retry without atomicity: " << exceptionToStatus().toString()); } @@ -231,9 +228,7 @@ Status _applyOps(OperationContext* opCtx, str::stream() << "cannot apply insert or update operation on a " "non-existent namespace " - << nss.ns() - << ": " - << mongo::redact(opObj)); + << nss.ns() << ": " << mongo::redact(opObj)); } OldClientContext ctx(opCtx, nss.ns()); diff --git a/src/mongo/db/repl/apply_ops.h b/src/mongo/db/repl/apply_ops.h index c5cca31569f..8aac61a39b9 100644 --- a/src/mongo/db/repl/apply_ops.h +++ b/src/mongo/db/repl/apply_ops.h @@ -116,7 +116,7 @@ Status applyOps(OperationContext* opCtx, /** * Applies a non-transactional 'applyOps' oplog entry. That is, an 'applyOps' entry that was not * generated by a transaction. -*/ + */ Status applyApplyOpsOplogEntry(OperationContext* opCtx, const OplogEntry& entry, repl::OplogApplication::Mode oplogApplicationMode); diff --git a/src/mongo/db/repl/apply_ops_test.cpp b/src/mongo/db/repl/apply_ops_test.cpp index 13575d81fb0..2f38aa54a5f 100644 --- a/src/mongo/db/repl/apply_ops_test.cpp +++ b/src/mongo/db/repl/apply_ops_test.cpp @@ -141,17 +141,13 @@ TEST_F(ApplyOpsTest, CommandInNestedApplyOpsReturnsSuccess) { auto mode = OplogApplication::Mode::kApplyOpsCmd; BSONObjBuilder resultBuilder; NamespaceString nss("test", "foo"); - auto innerCmdObj = BSON("op" - << "c" - << "ns" - << nss.getCommandNS().ns() - << "o" - << BSON("create" << nss.coll())); + auto innerCmdObj = + BSON("op" + << "c" + << "ns" << nss.getCommandNS().ns() << "o" << BSON("create" << nss.coll())); auto innerApplyOpsObj = BSON("op" << "c" - << "ns" - << nss.getCommandNS().ns() - << "o" + << "ns" << nss.getCommandNS().ns() << "o" << BSON("applyOps" << BSON_ARRAY(innerCmdObj))); auto cmdObj = BSON("applyOps" << BSON_ARRAY(innerApplyOpsObj)); @@ -169,18 +165,13 @@ TEST_F(ApplyOpsTest, InsertInNestedApplyOpsReturnsSuccess) { NamespaceString nss("test", "foo"); auto innerCmdObj = BSON("op" << "i" - << "ns" - << nss.ns() - << "o" + << "ns" << nss.ns() << "o" << BSON("_id" << "a") - << "ui" - << options.uuid.get()); + << "ui" << options.uuid.get()); auto innerApplyOpsObj = BSON("op" << "c" - << "ns" - << nss.getCommandNS().ns() - << "o" + << "ns" << nss.getCommandNS().ns() << "o" << BSON("applyOps" << BSON_ARRAY(innerCmdObj))); auto cmdObj = BSON("applyOps" << BSON_ARRAY(innerApplyOpsObj)); @@ -206,18 +197,10 @@ BSONObj makeApplyOpsWithInsertOperation(const NamespaceString& nss, const BSONObj& documentToInsert) { auto insertOp = uuid ? BSON("op" << "i" - << "ns" - << nss.ns() - << "o" - << documentToInsert - << "ui" - << *uuid) + << "ns" << nss.ns() << "o" << documentToInsert << "ui" << *uuid) : BSON("op" << "i" - << "ns" - << nss.ns() - << "o" - << documentToInsert); + << "ns" << nss.ns() << "o" << documentToInsert); return BSON("applyOps" << BSON_ARRAY(insertOp)); } @@ -395,53 +378,35 @@ TEST_F(ApplyOpsTest, ExtractOperationsReturnsOperationsWithSameOpTimeAsApplyOps) auto ui1 = UUID::gen(); auto op1 = BSON("op" << "i" - << "ns" - << ns1.ns() - << "ui" - << ui1 - << "o" - << BSON("_id" << 1)); + << "ns" << ns1.ns() << "ui" << ui1 << "o" << BSON("_id" << 1)); NamespaceString ns2("test.b"); auto ui2 = UUID::gen(); auto op2 = BSON("op" << "i" - << "ns" - << ns2.ns() - << "ui" - << ui2 - << "o" - << BSON("_id" << 2)); + << "ns" << ns2.ns() << "ui" << ui2 << "o" << BSON("_id" << 2)); NamespaceString ns3("test.c"); auto ui3 = UUID::gen(); auto op3 = BSON("op" << "u" - << "ns" - << ns3.ns() - << "ui" - << ui3 - << "b" - << true - << "o" - << BSON("x" << 1) - << "o2" - << BSON("_id" << 3)); + << "ns" << ns3.ns() << "ui" << ui3 << "b" << true << "o" << BSON("x" << 1) + << "o2" << BSON("_id" << 3)); auto oplogEntry = makeOplogEntry(OpTypeEnum::kCommand, BSON("applyOps" << BSON_ARRAY(op1 << op2 << op3))); auto operations = ApplyOps::extractOperations(oplogEntry); - ASSERT_EQUALS(3U, operations.size()) << "Unexpected number of operations extracted: " - << oplogEntry.toBSON(); + ASSERT_EQUALS(3U, operations.size()) + << "Unexpected number of operations extracted: " << oplogEntry.toBSON(); // Check extracted CRUD operations. auto it = operations.cbegin(); { ASSERT(operations.cend() != it); const auto& operation1 = *(it++); - ASSERT(OpTypeEnum::kInsert == operation1.getOpType()) << "Unexpected op type: " - << operation1.toBSON(); + ASSERT(OpTypeEnum::kInsert == operation1.getOpType()) + << "Unexpected op type: " << operation1.toBSON(); ASSERT_EQUALS(ui1, *operation1.getUuid()); ASSERT_EQUALS(ns1, operation1.getNss()); ASSERT_BSONOBJ_EQ(BSON("_id" << 1), operation1.getOperationToApply()); @@ -453,8 +418,8 @@ TEST_F(ApplyOpsTest, ExtractOperationsReturnsOperationsWithSameOpTimeAsApplyOps) { ASSERT(operations.cend() != it); const auto& operation2 = *(it++); - ASSERT(OpTypeEnum::kInsert == operation2.getOpType()) << "Unexpected op type: " - << operation2.toBSON(); + ASSERT(OpTypeEnum::kInsert == operation2.getOpType()) + << "Unexpected op type: " << operation2.toBSON(); ASSERT_EQUALS(ui2, *operation2.getUuid()); ASSERT_EQUALS(ns2, operation2.getNss()); ASSERT_BSONOBJ_EQ(BSON("_id" << 2), operation2.getOperationToApply()); @@ -466,8 +431,8 @@ TEST_F(ApplyOpsTest, ExtractOperationsReturnsOperationsWithSameOpTimeAsApplyOps) { ASSERT(operations.cend() != it); const auto& operation3 = *(it++); - ASSERT(OpTypeEnum::kUpdate == operation3.getOpType()) << "Unexpected op type: " - << operation3.toBSON(); + ASSERT(OpTypeEnum::kUpdate == operation3.getOpType()) + << "Unexpected op type: " << operation3.toBSON(); ASSERT_EQUALS(ui3, *operation3.getUuid()); ASSERT_EQUALS(ns3, operation3.getNss()); ASSERT_BSONOBJ_EQ(BSON("x" << 1), operation3.getOperationToApply()); @@ -495,9 +460,7 @@ TEST_F(ApplyOpsTest, ApplyOpsFailsToDropAdmin) { auto dropDatabaseOp = BSON("op" << "c" - << "ns" - << nss.getCommandNS().ns() - << "o" + << "ns" << nss.getCommandNS().ns() << "o" << BSON("dropDatabase" << 1)); auto dropDatabaseCmdObj = BSON("applyOps" << BSON_ARRAY(dropDatabaseOp)); diff --git a/src/mongo/db/repl/base_cloner_test_fixture.cpp b/src/mongo/db/repl/base_cloner_test_fixture.cpp index 359f6a2c4a2..6d7918a7f5c 100644 --- a/src/mongo/db/repl/base_cloner_test_fixture.cpp +++ b/src/mongo/db/repl/base_cloner_test_fixture.cpp @@ -47,8 +47,7 @@ const HostAndPort BaseClonerTest::target("localhost", -1); const NamespaceString BaseClonerTest::nss("db.coll"); const BSONObj BaseClonerTest::idIndexSpec = BSON("v" << 1 << "key" << BSON("_id" << 1) << "name" << "_id_" - << "ns" - << nss.ns()); + << "ns" << nss.ns()); // static BSONObj BaseClonerTest::createCountResponse(int documentCount) { diff --git a/src/mongo/db/repl/bgsync.h b/src/mongo/db/repl/bgsync.h index 7e64afae171..194bf202b8f 100644 --- a/src/mongo/db/repl/bgsync.h +++ b/src/mongo/db/repl/bgsync.h @@ -215,17 +215,17 @@ private: ReplicationProcess* _replicationProcess; /** - * All member variables are labeled with one of the following codes indicating the - * synchronization rules for accessing them: - * - * (PR) Completely private to BackgroundSync. Can be read or written to from within the main - * BackgroundSync thread without synchronization. Shouldn't be accessed outside of this - * thread. - * - * (S) Self-synchronizing; access in any way from any context. - * - * (M) Reads and writes guarded by _mutex - * + * All member variables are labeled with one of the following codes indicating the + * synchronization rules for accessing them: + * + * (PR) Completely private to BackgroundSync. Can be read or written to from within the main + * BackgroundSync thread without synchronization. Shouldn't be accessed outside of this + * thread. + * + * (S) Self-synchronizing; access in any way from any context. + * + * (M) Reads and writes guarded by _mutex + * */ // Protects member data of BackgroundSync. diff --git a/src/mongo/db/repl/check_quorum_for_config_change.cpp b/src/mongo/db/repl/check_quorum_for_config_change.cpp index 7f6f6af9672..8f2dfc40664 100644 --- a/src/mongo/db/repl/check_quorum_for_config_change.cpp +++ b/src/mongo/db/repl/check_quorum_for_config_change.cpp @@ -40,7 +40,6 @@ #include "mongo/db/repl/scatter_gather_algorithm.h" #include "mongo/db/repl/scatter_gather_runner.h" #include "mongo/db/server_options.h" -#include "mongo/db/server_options.h" #include "mongo/rpc/metadata/repl_set_metadata.h" #include "mongo/util/log.h" #include "mongo/util/str.h" @@ -199,8 +198,8 @@ void QuorumChecker::_tabulateHeartbeatResponse(const RemoteCommandRequest& reque Status hbStatus = hbResp.initialize(resBSON, 0, /*requireWallTime*/ false); if (hbStatus.code() == ErrorCodes::InconsistentReplicaSetNames) { - std::string message = str::stream() << "Our set name did not match that of " - << request.target.toString(); + std::string message = str::stream() + << "Our set name did not match that of " << request.target.toString(); _vetoStatus = Status(ErrorCodes::NewReplicaSetConfigurationIncompatible, message); warning() << message; return; diff --git a/src/mongo/db/repl/check_quorum_for_config_change_test.cpp b/src/mongo/db/repl/check_quorum_for_config_change_test.cpp index 89e352b3ae6..a80a9160896 100644 --- a/src/mongo/db/repl/check_quorum_for_config_change_test.cpp +++ b/src/mongo/db/repl/check_quorum_for_config_change_test.cpp @@ -47,18 +47,18 @@ #include "mongo/unittest/unittest.h" #include "mongo/util/net/hostandport.h" -#define ASSERT_REASON_CONTAINS(STATUS, PATTERN) \ - do { \ - const mongo::Status s_ = (STATUS); \ - ASSERT_FALSE(s_.reason().find(PATTERN) == std::string::npos) << #STATUS ".reason() == " \ - << s_.reason(); \ +#define ASSERT_REASON_CONTAINS(STATUS, PATTERN) \ + do { \ + const mongo::Status s_ = (STATUS); \ + ASSERT_FALSE(s_.reason().find(PATTERN) == std::string::npos) \ + << #STATUS ".reason() == " << s_.reason(); \ } while (false) -#define ASSERT_NOT_REASON_CONTAINS(STATUS, PATTERN) \ - do { \ - const mongo::Status s_ = (STATUS); \ - ASSERT_TRUE(s_.reason().find(PATTERN) == std::string::npos) << #STATUS ".reason() == " \ - << s_.reason(); \ +#define ASSERT_NOT_REASON_CONTAINS(STATUS, PATTERN) \ + do { \ + const mongo::Status s_ = (STATUS); \ + ASSERT_TRUE(s_.reason().find(PATTERN) == std::string::npos) \ + << #STATUS ".reason() == " << s_.reason(); \ } while (false) namespace mongo { @@ -140,30 +140,24 @@ ReplSetConfig assertMakeRSConfig(const BSONObj& configBson) { } TEST_F(CheckQuorumForInitiate, ValidSingleNodeSet) { - ReplSetConfig config = assertMakeRSConfig(BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1")))); + ReplSetConfig config = + assertMakeRSConfig(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1")))); startQuorumCheck(config, 0); ASSERT_OK(waitForQuorumCheck()); } TEST_F(CheckQuorumForInitiate, QuorumCheckCanceledByShutdown) { getExecutor().shutdown(); - ReplSetConfig config = assertMakeRSConfig(BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1")))); + ReplSetConfig config = + assertMakeRSConfig(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1")))); startQuorumCheck(config, 0); ASSERT_EQUALS(ErrorCodes::ShutdownInProgress, waitForQuorumCheck()); } @@ -172,23 +166,20 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSeveralDownNodes) { // In this test, "we" are host "h3:1". All other nodes time out on // their heartbeat request, and so the quorum check for initiate // will fail because some members were unavailable. - ReplSetConfig config = assertMakeRSConfig(BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1:1") - << BSON("_id" << 2 << "host" - << "h2:1") - << BSON("_id" << 3 << "host" - << "h3:1") - << BSON("_id" << 4 << "host" - << "h4:1") - << BSON("_id" << 5 << "host" - << "h5:1")))); + ReplSetConfig config = + assertMakeRSConfig(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1:1") + << BSON("_id" << 2 << "host" + << "h2:1") + << BSON("_id" << 3 << "host" + << "h3:1") + << BSON("_id" << 4 << "host" + << "h4:1") + << BSON("_id" << 5 << "host" + << "h5:1")))); startQuorumCheck(config, 2); getNet()->enterNetwork(); const Date_t startDate = getNet()->now(); @@ -254,11 +245,7 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckSuccessForFiveNodes) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -282,8 +269,8 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckSuccessForFiveNodes) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); getNet()->scheduleResponse( noi, startDate + Milliseconds(10), makeHeartbeatResponse(rsConfig, Milliseconds(8))); } @@ -301,19 +288,12 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToOneDownNode) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" << "h2:1" - << "priority" - << 0 - << "votes" - << 0) + << "priority" << 0 << "votes" << 0) << BSON("_id" << 3 << "host" << "h3:1") << BSON("_id" << 4 << "host" @@ -335,8 +315,8 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToOneDownNode) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h2", 1)) { getNet()->scheduleResponse( noi, startDate + Milliseconds(10), {ErrorCodes::NoSuchKey, "No response"}); @@ -368,11 +348,7 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSetNameMismatch) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -396,8 +372,8 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSetNameMismatch) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h4", 1)) { getNet()->scheduleResponse( noi, @@ -433,11 +409,7 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSetIdMismatch) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -448,8 +420,7 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSetIdMismatch) { << "h4:1") << BSON("_id" << 5 << "host" << "h5:1")) - << "settings" - << BSON("replicaSetId" << replicaSetId))); + << "settings" << BSON("replicaSetId" << replicaSetId))); const int myConfigIndex = 2; const BSONObj hbRequest = makeHeartbeatRequest(rsConfig, myConfigIndex); @@ -466,8 +437,8 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSetIdMismatch) { ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); ASSERT_BSONOBJ_EQ(BSON(rpc::kReplSetMetadataFieldName << 1), request.metadata); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == incompatibleHost) { OpTime opTime{Timestamp{10, 10}, 10}; Date_t wallTime = Date_t(); @@ -498,10 +469,8 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSetIdMismatch) { ASSERT_EQUALS(ErrorCodes::NewReplicaSetConfigurationIncompatible, status); ASSERT_REASON_CONTAINS(status, str::stream() << "Our replica set ID of " << replicaSetId - << " did not match that of " - << incompatibleHost.toString() - << ", which is " - << unexpectedId); + << " did not match that of " << incompatibleHost.toString() + << ", which is " << unexpectedId); ASSERT_NOT_REASON_CONTAINS(status, "h1:1"); ASSERT_NOT_REASON_CONTAINS(status, "h2:1"); ASSERT_NOT_REASON_CONTAINS(status, "h3:1"); @@ -517,11 +486,7 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToInitializedNode) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -545,8 +510,8 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToInitializedNode) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h5", 1)) { long long configVersion = 1; getNet()->scheduleResponse( @@ -581,11 +546,7 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToInitializedNodeOnlyOneRespo const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -609,8 +570,8 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToInitializedNodeOnlyOneRespo const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h5", 1)) { long long configVersion = 1; getNet()->scheduleResponse( @@ -641,11 +602,7 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckVetoedDueToHigherConfigVersion) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -665,8 +622,8 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckVetoedDueToHigherConfigVersion) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h1", 1)) { long long configVersion = 5; getNet()->scheduleResponse( @@ -695,11 +652,7 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckVetoedDueToIncompatibleSetName) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -719,8 +672,8 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckVetoedDueToIncompatibleSetName) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h2", 1)) { getNet()->scheduleResponse( noi, @@ -753,11 +706,7 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckFailsDueToInsufficientVoters) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -766,16 +715,10 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckFailsDueToInsufficientVoters) { << "h3:1") << BSON("_id" << 4 << "host" << "h4:1" - << "votes" - << 0 - << "priority" - << 0) + << "votes" << 0 << "priority" << 0) << BSON("_id" << 5 << "host" << "h5:1" - << "votes" - << 0 - << "priority" - << 0)))); + << "votes" << 0 << "priority" << 0)))); const int myConfigIndex = 3; const BSONObj hbRequest = makeHeartbeatRequest(rsConfig, myConfigIndex); @@ -789,8 +732,8 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckFailsDueToInsufficientVoters) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h1", 1) || request.target == HostAndPort("h5", 1)) { getNet()->scheduleResponse(noi, startDate + Milliseconds(10), @@ -819,11 +762,7 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckFailsDueToNoElectableNodeResponding) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -832,12 +771,10 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckFailsDueToNoElectableNodeResponding) { << "h3:1") << BSON("_id" << 4 << "host" << "h4:1" - << "priority" - << 0) + << "priority" << 0) << BSON("_id" << 5 << "host" << "h5:1" - << "priority" - << 0)))); + << "priority" << 0)))); const int myConfigIndex = 3; const BSONObj hbRequest = makeHeartbeatRequest(rsConfig, myConfigIndex); @@ -851,8 +788,8 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckFailsDueToNoElectableNodeResponding) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h5", 1)) { getNet()->scheduleResponse(noi, startDate + Milliseconds(10), @@ -877,11 +814,7 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckSucceedsWithAsSoonAsPossible) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -890,16 +823,10 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckSucceedsWithAsSoonAsPossible) { << "h3:1") << BSON("_id" << 4 << "host" << "h4:1" - << "votes" - << 0 - << "priority" - << 0) + << "votes" << 0 << "priority" << 0) << BSON("_id" << 5 << "host" << "h5:1" - << "votes" - << 0 - << "priority" - << 0)))); + << "votes" << 0 << "priority" << 0)))); const int myConfigIndex = 3; const BSONObj hbRequest = makeHeartbeatRequest(rsConfig, myConfigIndex); @@ -913,8 +840,8 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckSucceedsWithAsSoonAsPossible) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h1", 1) || request.target == HostAndPort("h2", 1)) { getNet()->scheduleResponse(noi, startDate + Milliseconds(10), @@ -937,11 +864,7 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckProcessesCallbackCanceledResponse) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -961,8 +884,8 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckProcessesCallbackCanceledResponse) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h1", 1)) { getNet()->scheduleResponse( noi, diff --git a/src/mongo/db/repl/collection_bulk_loader_impl.cpp b/src/mongo/db/repl/collection_bulk_loader_impl.cpp index a19dc5c6c8d..68f760d284a 100644 --- a/src/mongo/db/repl/collection_bulk_loader_impl.cpp +++ b/src/mongo/db/repl/collection_bulk_loader_impl.cpp @@ -75,42 +75,41 @@ CollectionBulkLoaderImpl::~CollectionBulkLoaderImpl() { } Status CollectionBulkLoaderImpl::init(const std::vector<BSONObj>& secondaryIndexSpecs) { - return _runTaskReleaseResourcesOnFailure( - [ coll = _autoColl->getCollection(), &secondaryIndexSpecs, this ]()->Status { - // All writes in CollectionBulkLoaderImpl should be unreplicated. - // The opCtx is accessed indirectly through _secondaryIndexesBlock. - UnreplicatedWritesBlock uwb(_opCtx.get()); - // This enforces the buildIndexes setting in the replica set configuration. - auto indexCatalog = coll->getIndexCatalog(); - auto specs = - indexCatalog->removeExistingIndexesNoChecks(_opCtx.get(), secondaryIndexSpecs); - if (specs.size()) { - _secondaryIndexesBlock->ignoreUniqueConstraint(); - auto status = - _secondaryIndexesBlock - ->init(_opCtx.get(), _collection, specs, MultiIndexBlock::kNoopOnInitFn) - .getStatus(); - if (!status.isOK()) { - return status; - } - } else { - _secondaryIndexesBlock.reset(); + return _runTaskReleaseResourcesOnFailure([coll = _autoColl->getCollection(), + &secondaryIndexSpecs, + this]() -> Status { + // All writes in CollectionBulkLoaderImpl should be unreplicated. + // The opCtx is accessed indirectly through _secondaryIndexesBlock. + UnreplicatedWritesBlock uwb(_opCtx.get()); + // This enforces the buildIndexes setting in the replica set configuration. + auto indexCatalog = coll->getIndexCatalog(); + auto specs = indexCatalog->removeExistingIndexesNoChecks(_opCtx.get(), secondaryIndexSpecs); + if (specs.size()) { + _secondaryIndexesBlock->ignoreUniqueConstraint(); + auto status = + _secondaryIndexesBlock + ->init(_opCtx.get(), _collection, specs, MultiIndexBlock::kNoopOnInitFn) + .getStatus(); + if (!status.isOK()) { + return status; } - if (!_idIndexSpec.isEmpty()) { - auto status = - _idIndexBlock - ->init( - _opCtx.get(), _collection, _idIndexSpec, MultiIndexBlock::kNoopOnInitFn) - .getStatus(); - if (!status.isOK()) { - return status; - } - } else { - _idIndexBlock.reset(); + } else { + _secondaryIndexesBlock.reset(); + } + if (!_idIndexSpec.isEmpty()) { + auto status = + _idIndexBlock + ->init(_opCtx.get(), _collection, _idIndexSpec, MultiIndexBlock::kNoopOnInitFn) + .getStatus(); + if (!status.isOK()) { + return status; } + } else { + _idIndexBlock.reset(); + } - return Status::OK(); - }); + return Status::OK(); + }); } Status CollectionBulkLoaderImpl::insertDocuments(const std::vector<BSONObj>::const_iterator begin, diff --git a/src/mongo/db/repl/collection_cloner.cpp b/src/mongo/db/repl/collection_cloner.cpp index e86e8ce022c..cf3d0b63bde 100644 --- a/src/mongo/db/repl/collection_cloner.cpp +++ b/src/mongo/db/repl/collection_cloner.cpp @@ -132,8 +132,8 @@ CollectionCloner::CollectionCloner(executor::TaskExecutor* executor, _sourceNss.db().toString(), makeCommandWithUUIDorCollectionName("listIndexes", _options.uuid, sourceNss), [this](const Fetcher::QueryResponseStatus& fetchResult, - Fetcher::NextAction * nextAction, - BSONObjBuilder * getMoreBob) { + Fetcher::NextAction* nextAction, + BSONObjBuilder* getMoreBob) { _listIndexesCallback(fetchResult, nextAction, getMoreBob); }, ReadPreferenceSetting::secondaryPreferredMetadata(), @@ -332,9 +332,7 @@ void CollectionCloner::_countCallback( _finishCallback(countStatus.withContext( str::stream() << "There was an error parsing document count from count " "command result on collection " - << _sourceNss.ns() - << " from " - << _source.toString())); + << _sourceNss.ns() << " from " << _source.toString())); return; } } @@ -343,8 +341,7 @@ void CollectionCloner::_countCallback( _finishCallback({ErrorCodes::BadValue, str::stream() << "Count call on collection " << _sourceNss.ns() << " from " << _source.toString() - << " returned negative document count: " - << count}); + << " returned negative document count: " << count}); return; } diff --git a/src/mongo/db/repl/collection_cloner_test.cpp b/src/mongo/db/repl/collection_cloner_test.cpp index 20c4eb00ae3..09e61df9080 100644 --- a/src/mongo/db/repl/collection_cloner_test.cpp +++ b/src/mongo/db/repl/collection_cloner_test.cpp @@ -261,15 +261,15 @@ void CollectionClonerTest::setUp() { const BSONObj idIndexSpec, const std::vector<BSONObj>& nonIdIndexSpecs) -> StatusWith<std::unique_ptr<CollectionBulkLoaderMock>> { - auto localLoader = std::make_unique<CollectionBulkLoaderMock>(collectionStats); - Status result = localLoader->init(nonIdIndexSpecs); - if (!result.isOK()) - return result; + auto localLoader = std::make_unique<CollectionBulkLoaderMock>(collectionStats); + Status result = localLoader->init(nonIdIndexSpecs); + if (!result.isOK()) + return result; - _loader = localLoader.get(); + _loader = localLoader.get(); - return std::move(localLoader); - }; + return std::move(localLoader); + }; _server = std::make_unique<MockRemoteDBServer>(target.toString()); _server->assignCollectionUuid(nss.ns(), *options.uuid); _client = new FailableMockDBClientConnection(_server.get(), getNet()); @@ -283,12 +283,10 @@ void CollectionClonerTest::setUp() { std::vector<BSONObj> CollectionClonerTest::makeSecondaryIndexSpecs(const NamespaceString& nss) { return {BSON("v" << 1 << "key" << BSON("a" << 1) << "name" << "a_1" - << "ns" - << nss.ns()), + << "ns" << nss.ns()), BSON("v" << 1 << "key" << BSON("b" << 1) << "name" << "b_1" - << "ns" - << nss.ns())}; + << "ns" << nss.ns())}; } void CollectionClonerTest::tearDown() { @@ -443,8 +441,7 @@ TEST_F(CollectionClonerTest, CollectionClonerPassesThroughCommandStatusErrorFrom executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); processNetworkResponse(BSON("ok" << 0 << "errmsg" << "count error" - << "code" - << int(ErrorCodes::OperationFailed))); + << "code" << int(ErrorCodes::OperationFailed))); } collectionCloner->join(); ASSERT_EQUALS(ErrorCodes::OperationFailed, getStatus()); @@ -566,15 +563,15 @@ TEST_F(CollectionClonerNoAutoIndexTest, DoNotCreateIDIndexIfAutoIndexIdUsed) { const BSONObj idIndexSpec, const std::vector<BSONObj>& theIndexSpecs) -> StatusWith<std::unique_ptr<CollectionBulkLoader>> { - auto loader = std::make_unique<CollectionBulkLoaderMock>(collectionStats); - collNss = theNss; - collOptions = theOptions; - collIndexSpecs = theIndexSpecs; - const auto status = loader->init(theIndexSpecs); - if (!status.isOK()) - return status; - return std::move(loader); - }; + auto loader = std::make_unique<CollectionBulkLoaderMock>(collectionStats); + collNss = theNss; + collOptions = theOptions; + collIndexSpecs = theIndexSpecs; + const auto status = loader->init(theIndexSpecs); + if (!status.isOK()) + return status; + return std::move(loader); + }; const BSONObj doc = BSON("_id" << 1); _server->insert(nss.ns(), doc); @@ -633,13 +630,14 @@ TEST_F(CollectionClonerTest, ListIndexesReturnedNamespaceNotFound) { bool collectionCreated = false; bool writesAreReplicatedOnOpCtx = false; NamespaceString collNss; - storageInterface->createCollFn = [&collNss, &collectionCreated, &writesAreReplicatedOnOpCtx]( - OperationContext* opCtx, const NamespaceString& nss, const CollectionOptions& options) { - writesAreReplicatedOnOpCtx = opCtx->writesAreReplicated(); - collectionCreated = true; - collNss = nss; - return Status::OK(); - }; + storageInterface->createCollFn = + [&collNss, &collectionCreated, &writesAreReplicatedOnOpCtx]( + OperationContext* opCtx, const NamespaceString& nss, const CollectionOptions& options) { + writesAreReplicatedOnOpCtx = opCtx->writesAreReplicated(); + collectionCreated = true; + collNss = nss; + return Status::OK(); + }; // Using a non-zero cursor to ensure that // the cloner stops the fetcher from retrieving more results. { @@ -688,9 +686,9 @@ TEST_F(CollectionClonerTest, // status. auto exec = &getExecutor(); collectionCloner->setScheduleDbWorkFn_forTest([exec]( - executor::TaskExecutor::CallbackFn workFn) { + executor::TaskExecutor::CallbackFn workFn) { auto wrappedTask = [workFn = std::move(workFn)]( - const executor::TaskExecutor::CallbackArgs& cbd) { + const executor::TaskExecutor::CallbackArgs& cbd) { workFn(executor::TaskExecutor::CallbackArgs( cbd.executor, cbd.myHandle, Status(ErrorCodes::CallbackCanceled, ""), cbd.opCtx)); }; @@ -698,8 +696,9 @@ TEST_F(CollectionClonerTest, }); bool collectionCreated = false; - storageInterface->createCollFn = [&collectionCreated]( - OperationContext*, const NamespaceString& nss, const CollectionOptions&) { + storageInterface->createCollFn = [&collectionCreated](OperationContext*, + const NamespaceString& nss, + const CollectionOptions&) { collectionCreated = true; return Status::OK(); }; @@ -1402,8 +1401,7 @@ TEST_F(CollectionClonerRenamedBeforeStartTest, BeginCollectionWithUUID) { BSONObj expectedIdIndexSpec = BSON("v" << 1 << "key" << BSON("_id" << 1) << "name" << "_id_" - << "ns" - << alternateNss.ns()); + << "ns" << alternateNss.ns()); ASSERT_BSONOBJ_EQ(collIdIndexSpec, expectedIdIndexSpec); auto expectedNonIdIndexSpecs = makeSecondaryIndexSpecs(alternateNss); diff --git a/src/mongo/db/repl/database_cloner.cpp b/src/mongo/db/repl/database_cloner.cpp index 267428f3831..1d1f3dda338 100644 --- a/src/mongo/db/repl/database_cloner.cpp +++ b/src/mongo/db/repl/database_cloner.cpp @@ -117,8 +117,8 @@ DatabaseCloner::DatabaseCloner(executor::TaskExecutor* executor, _dbname, createListCollectionsCommandObject(_listCollectionsFilter), [=](const StatusWith<Fetcher::QueryResponse>& result, - Fetcher::NextAction * nextAction, - BSONObjBuilder * getMoreBob) { + Fetcher::NextAction* nextAction, + BSONObjBuilder* getMoreBob) { _listCollectionsCallback(result, nextAction, getMoreBob); }, ReadPreferenceSetting::secondaryPreferredMetadata(), @@ -263,9 +263,8 @@ void DatabaseCloner::_listCollectionsCallback(const StatusWith<Fetcher::QueryRes BSONObjBuilder* getMoreBob) { if (!result.isOK()) { _finishCallback(result.getStatus().withContext( - str::stream() << "Error issuing listCollections on db '" << _dbname << "' (host:" - << _source.toString() - << ")")); + str::stream() << "Error issuing listCollections on db '" << _dbname + << "' (host:" << _source.toString() << ")")); return; } @@ -311,12 +310,11 @@ void DatabaseCloner::_listCollectionsCallback(const StatusWith<Fetcher::QueryRes for (auto&& info : _collectionInfos) { BSONElement nameElement = info.getField(kNameFieldName); if (nameElement.eoo()) { - _finishCallback_inlock( - lk, - {ErrorCodes::FailedToParse, - str::stream() << "collection info must contain '" << kNameFieldName << "' " - << "field : " - << info}); + _finishCallback_inlock(lk, + {ErrorCodes::FailedToParse, + str::stream() << "collection info must contain '" + << kNameFieldName << "' " + << "field : " << info}); return; } if (nameElement.type() != mongo::String) { @@ -332,29 +330,24 @@ void DatabaseCloner::_listCollectionsCallback(const StatusWith<Fetcher::QueryRes {ErrorCodes::Error(51005), str::stream() << "collection info contains duplicate collection name " - << "'" - << collectionName - << "': " - << info}); + << "'" << collectionName << "': " << info}); return; } BSONElement optionsElement = info.getField(kOptionsFieldName); if (optionsElement.eoo()) { - _finishCallback_inlock( - lk, - {ErrorCodes::FailedToParse, - str::stream() << "collection info must contain '" << kOptionsFieldName << "' " - << "field : " - << info}); + _finishCallback_inlock(lk, + {ErrorCodes::FailedToParse, + str::stream() << "collection info must contain '" + << kOptionsFieldName << "' " + << "field : " << info}); return; } if (!optionsElement.isABSONObj()) { _finishCallback_inlock(lk, Status(ErrorCodes::TypeMismatch, str::stream() << "'" << kOptionsFieldName - << "' field must be an object: " - << info)); + << "' field must be an object: " << info)); return; } const BSONObj optionsObj = optionsElement.Obj(); @@ -426,8 +419,8 @@ void DatabaseCloner::_collectionClonerCallback(const Status& status, const Names // Record failure, but do not return just yet, in case we want to do some logging. if (!status.isOK()) { - collStatus = status.withContext( - str::stream() << "Error cloning collection '" << nss.toString() << "'"); + collStatus = status.withContext(str::stream() + << "Error cloning collection '" << nss.toString() << "'"); } // Forward collection cloner result to caller. diff --git a/src/mongo/db/repl/database_cloner_test.cpp b/src/mongo/db/repl/database_cloner_test.cpp index 66948a482ef..25fc845b088 100644 --- a/src/mongo/db/repl/database_cloner_test.cpp +++ b/src/mongo/db/repl/database_cloner_test.cpp @@ -126,16 +126,16 @@ void DatabaseClonerTest::setUp() { const BSONObj& idIndexSpec, const std::vector<BSONObj>& secondaryIndexSpecs) -> StatusWith<std::unique_ptr<CollectionBulkLoaderMock>> { - const auto collInfo = &_collections[nss]; + const auto collInfo = &_collections[nss]; - auto localLoader = std::make_unique<CollectionBulkLoaderMock>(collInfo->stats); - auto status = localLoader->init(secondaryIndexSpecs); - if (!status.isOK()) - return status; - collInfo->loader = localLoader.get(); + auto localLoader = std::make_unique<CollectionBulkLoaderMock>(collInfo->stats); + auto status = localLoader->init(secondaryIndexSpecs); + if (!status.isOK()) + return status; + collInfo->loader = localLoader.get(); - return std::move(localLoader); - }; + return std::move(localLoader); + }; } void DatabaseClonerTest::tearDown() { @@ -335,8 +335,7 @@ TEST_F(DatabaseClonerTest, InvalidListCollectionsFilter) { executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); processNetworkResponse(BSON("ok" << 0 << "errmsg" << "unknown operator" - << "code" - << ErrorCodes::BadValue)); + << "code" << ErrorCodes::BadValue)); } ASSERT_EQUALS(ErrorCodes::BadValue, getStatus().code()); @@ -391,16 +390,13 @@ TEST_F(DatabaseClonerTest, ListCollectionsPredicate) { const std::vector<BSONObj> sourceInfos = {BSON("name" << "a" - << "options" - << _options1.toBSON()), + << "options" << _options1.toBSON()), BSON("name" << "b" - << "options" - << _options2.toBSON()), + << "options" << _options2.toBSON()), BSON("name" << "c" - << "options" - << _options3.toBSON())}; + << "options" << _options3.toBSON())}; { executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); processNetworkResponse(createListCollectionsResponse( @@ -425,12 +421,10 @@ TEST_F(DatabaseClonerTest, ListCollectionsMultipleBatches) { const std::vector<BSONObj> sourceInfos = {BSON("name" << "a" - << "options" - << _options1.toBSON()), + << "options" << _options1.toBSON()), BSON("name" << "b" - << "options" - << _options2.toBSON())}; + << "options" << _options2.toBSON())}; { executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); processNetworkResponse(createListCollectionsResponse(1, BSON_ARRAY(sourceInfos[0]))); @@ -512,8 +506,7 @@ TEST_F(DatabaseClonerTest, CollectionInfoNameEmpty) { createListCollectionsResponse(0, BSON_ARRAY(BSON("name" << "" - << "options" - << _options1.toBSON())))); + << "options" << _options1.toBSON())))); } ASSERT_EQUALS(ErrorCodes::BadValue, getStatus().code()); @@ -534,12 +527,10 @@ TEST_F(DatabaseClonerTest, CollectionInfoNameDuplicate) { createListCollectionsResponse(0, BSON_ARRAY(BSON("name" << "a" - << "options" - << _options1.toBSON()) + << "options" << _options1.toBSON()) << BSON("name" << "a" - << "options" - << _options2.toBSON())))); + << "options" << _options2.toBSON())))); } ASSERT_EQUALS(51005, getStatus().code()); @@ -575,11 +566,11 @@ TEST_F(DatabaseClonerTest, CollectionInfoOptionsNotAnObject) { { executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); - processNetworkResponse(createListCollectionsResponse(0, - BSON_ARRAY(BSON("name" - << "a" - << "options" - << 123)))); + processNetworkResponse( + createListCollectionsResponse(0, + BSON_ARRAY(BSON("name" + << "a" + << "options" << 123)))); } ASSERT_EQUALS(ErrorCodes::TypeMismatch, getStatus().code()); @@ -596,12 +587,11 @@ TEST_F(DatabaseClonerTest, InvalidCollectionOptions) { { executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); - processNetworkResponse( - createListCollectionsResponse(0, - BSON_ARRAY(BSON("name" - << "a" - << "options" - << BSON("storageEngine" << 1))))); + processNetworkResponse(createListCollectionsResponse( + 0, + BSON_ARRAY(BSON("name" + << "a" + << "options" << BSON("storageEngine" << 1))))); } ASSERT_EQUALS(ErrorCodes::BadValue, getStatus().code()); @@ -617,11 +607,11 @@ TEST_F(DatabaseClonerTest, InvalidMissingUUID) { { executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); - processNetworkResponse(createListCollectionsResponse(0, - BSON_ARRAY(BSON("name" - << "a" - << "options" - << BSONObj())))); + processNetworkResponse( + createListCollectionsResponse(0, + BSON_ARRAY(BSON("name" + << "a" + << "options" << BSONObj())))); } ASSERT_EQUALS(50953, getStatus().code()); @@ -670,11 +660,11 @@ TEST_F(DatabaseClonerTest, ListCollectionsReturnsEmptyCollectionName) { { executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); - processNetworkResponse(createListCollectionsResponse(0, - BSON_ARRAY(BSON("name" - << "" - << "options" - << BSONObj())))); + processNetworkResponse( + createListCollectionsResponse(0, + BSON_ARRAY(BSON("name" + << "" + << "options" << BSONObj())))); } ASSERT_EQUALS(ErrorCodes::BadValue, getStatus().code()); @@ -700,8 +690,7 @@ TEST_F(DatabaseClonerTest, StartFirstCollectionClonerFailed) { createListCollectionsResponse(0, BSON_ARRAY(BSON("name" << "a" - << "options" - << _options1.toBSON())))); + << "options" << _options1.toBSON())))); } ASSERT_EQUALS(ErrorCodes::OperationFailed, getStatus().code()); @@ -732,12 +721,10 @@ TEST_F(DatabaseClonerTest, StartSecondCollectionClonerFailed) { createListCollectionsResponse(0, BSON_ARRAY(BSON("name" << "a" - << "options" - << _options1.toBSON()) + << "options" << _options1.toBSON()) << BSON("name" << "b" - << "options" - << _options2.toBSON())))); + << "options" << _options2.toBSON())))); processNetworkResponse(createCountResponse(0)); processNetworkResponse(createListIndexesResponse(0, BSON_ARRAY(idIndexSpec))); @@ -763,8 +750,7 @@ TEST_F(DatabaseClonerTest, ShutdownCancelsCollectionCloning) { 0, BSON_ARRAY(BSON("name" << "a" - << "options" - << _options1.toBSON()))))); + << "options" << _options1.toBSON()))))); net->runReadyNetworkOperations(); // CollectionCloner sends collection count request on startup. @@ -797,12 +783,10 @@ TEST_F(DatabaseClonerTest, FirstCollectionListIndexesFailed) { const std::vector<BSONObj> sourceInfos = {BSON("name" << "a" - << "options" - << _options1.toBSON()), + << "options" << _options1.toBSON()), BSON("name" << "b" - << "options" - << _options2.toBSON())}; + << "options" << _options2.toBSON())}; { executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); processNetworkResponse( @@ -818,8 +802,7 @@ TEST_F(DatabaseClonerTest, FirstCollectionListIndexesFailed) { processNetworkResponse(createCountResponse(0)); processNetworkResponse(BSON("ok" << 0 << "errmsg" << "fake message" - << "code" - << ErrorCodes::CursorNotFound)); + << "code" << ErrorCodes::CursorNotFound)); processNetworkResponse(createCountResponse(0)); processNetworkResponse(createListIndexesResponse(0, BSON_ARRAY(idIndexSpec))); @@ -854,12 +837,10 @@ TEST_F(DatabaseClonerTest, CreateCollections) { const std::vector<BSONObj> sourceInfos = {BSON("name" << "a" - << "options" - << _options1.toBSON()), + << "options" << _options1.toBSON()), BSON("name" << "b" - << "options" - << _options2.toBSON())}; + << "options" << _options2.toBSON())}; { executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); processNetworkResponse( diff --git a/src/mongo/db/repl/databases_cloner_test.cpp b/src/mongo/db/repl/databases_cloner_test.cpp index c13154b179a..a631fff5dbc 100644 --- a/src/mongo/db/repl/databases_cloner_test.cpp +++ b/src/mongo/db/repl/databases_cloner_test.cpp @@ -177,19 +177,19 @@ protected: const BSONObj idIndexSpec, const std::vector<BSONObj>& secondaryIndexSpecs) -> StatusWith<std::unique_ptr<CollectionBulkLoaderMock>> { - // Get collection info from map. - const auto collInfo = &_collections[nss]; - if (collInfo->stats->initCalled) { - log() << "reusing collection during test which may cause problems, ns:" << nss; - } - auto localLoader = std::make_unique<CollectionBulkLoaderMock>(collInfo->stats); - auto status = localLoader->init(secondaryIndexSpecs); - if (!status.isOK()) - return status; - collInfo->loader = localLoader.get(); - - return std::move(localLoader); - }; + // Get collection info from map. + const auto collInfo = &_collections[nss]; + if (collInfo->stats->initCalled) { + log() << "reusing collection during test which may cause problems, ns:" << nss; + } + auto localLoader = std::make_unique<CollectionBulkLoaderMock>(collInfo->stats); + auto status = localLoader->init(secondaryIndexSpecs); + if (!status.isOK()) + return status; + collInfo->loader = localLoader.get(); + + return std::move(localLoader); + }; _dbWorkThreadPool.startup(); _target = HostAndPort{"local:1234"}; @@ -924,13 +924,13 @@ TEST_F(DBsClonerTest, SingleDatabaseCopiesCompletely) { {"listDatabases", fromjson("{ok:1, databases:[{name:'a'}]}")}, // listCollections for "a" {"listCollections", - BSON("ok" << 1 << "cursor" << BSON("id" << 0ll << "ns" - << "a.$cmd.listCollections" - << "firstBatch" - << BSON_ARRAY(BSON("name" - << "a" - << "options" - << options.toBSON()))))}, + BSON("ok" << 1 << "cursor" + << BSON("id" << 0ll << "ns" + << "a.$cmd.listCollections" + << "firstBatch" + << BSON_ARRAY(BSON("name" + << "a" + << "options" << options.toBSON()))))}, // count:a {"count", BSON("n" << 1 << "ok" << 1)}, // listIndexes:a @@ -957,13 +957,13 @@ TEST_F(DBsClonerTest, TwoDatabasesCopiesCompletely) { {"listDatabases", fromjson("{ok:1, databases:[{name:'a'}, {name:'b'}]}")}, // listCollections for "a" {"listCollections", - BSON("ok" << 1 << "cursor" << BSON("id" << 0ll << "ns" - << "a.$cmd.listCollections" - << "firstBatch" - << BSON_ARRAY(BSON("name" - << "a" - << "options" - << options1.toBSON()))))}, + BSON("ok" << 1 << "cursor" + << BSON("id" << 0ll << "ns" + << "a.$cmd.listCollections" + << "firstBatch" + << BSON_ARRAY(BSON("name" + << "a" + << "options" << options1.toBSON()))))}, // count:a {"count", BSON("n" << 1 << "ok" << 1)}, // listIndexes:a @@ -974,13 +974,13 @@ TEST_F(DBsClonerTest, TwoDatabasesCopiesCompletely) { << ", key:{_id:1}, name:'_id_', ns:'a.a'}]}}")}, // listCollections for "b" {"listCollections", - BSON("ok" << 1 << "cursor" << BSON("id" << 0ll << "ns" - << "b.$cmd.listCollections" - << "firstBatch" - << BSON_ARRAY(BSON("name" - << "b" - << "options" - << options2.toBSON()))))}, + BSON("ok" << 1 << "cursor" + << BSON("id" << 0ll << "ns" + << "b.$cmd.listCollections" + << "firstBatch" + << BSON_ARRAY(BSON("name" + << "b" + << "options" << options2.toBSON()))))}, // count:b {"count", BSON("n" << 2 << "ok" << 1)}, // listIndexes:b diff --git a/src/mongo/db/repl/dbcheck.cpp b/src/mongo/db/repl/dbcheck.cpp index 19c9507e981..a69b2c07e71 100644 --- a/src/mongo/db/repl/dbcheck.cpp +++ b/src/mongo/db/repl/dbcheck.cpp @@ -40,7 +40,6 @@ #include "mongo/db/operation_context.h" #include "mongo/db/query/internal_plans.h" #include "mongo/db/repl/dbcheck.h" -#include "mongo/db/repl/dbcheck.h" #include "mongo/db/repl/dbcheck_gen.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/optime.h" @@ -132,7 +131,7 @@ std::unique_ptr<HealthLogEntry> dbCheckHealthLogEntry(const NamespaceString& nss entry->setData(data); return entry; } -} +} // namespace /** * Get an error message if the check fails. @@ -161,14 +160,9 @@ std::unique_ptr<HealthLogEntry> dbCheckBatchEntry(const NamespaceString& nss, const repl::OpTime& optime) { auto hashes = expectedFound(expectedHash, foundHash); - auto data = - BSON("success" << true << "count" << count << "bytes" << bytes << "md5" << hashes.second - << "minKey" - << minKey.elem() - << "maxKey" - << maxKey.elem() - << "optime" - << optime); + auto data = BSON("success" << true << "count" << count << "bytes" << bytes << "md5" + << hashes.second << "minKey" << minKey.elem() << "maxKey" + << maxKey.elem() << "optime" << optime); auto severity = hashes.first ? SeverityEnum::Info : SeverityEnum::Error; std::string msg = @@ -284,19 +278,9 @@ std::unique_ptr<HealthLogEntry> dbCheckCollectionEntry(const NamespaceString& ns std::string msg = "dbCheck collection " + (match ? std::string("consistent") : std::string("inconsistent")); auto data = BSON("success" << true << "uuid" << uuid.toString() << "found" << true << "name" - << names.second - << "prev" - << prevs.second - << "next" - << nexts.second - << "indexes" - << indices.second - << "options" - << options.second - << "md5" - << md5s.second - << "optime" - << optime); + << names.second << "prev" << prevs.second << "next" << nexts.second + << "indexes" << indices.second << "options" << options.second + << "md5" << md5s.second << "optime" << optime); return dbCheckHealthLogEntry(nss, severity, msg, OplogEntriesEnum::Collection, data); } @@ -520,7 +504,7 @@ Status dbCheckDatabaseOnSecondary(OperationContext* opCtx, return Status::OK(); } -} +} // namespace namespace repl { diff --git a/src/mongo/db/repl/dbcheck.h b/src/mongo/db/repl/dbcheck.h index dde6de369b8..457087a9365 100644 --- a/src/mongo/db/repl/dbcheck.h +++ b/src/mongo/db/repl/dbcheck.h @@ -228,5 +228,5 @@ Status dbCheckOplogCommand(OperationContext* opCtx, const repl::OplogEntry& entry, OplogApplication::Mode mode, boost::optional<Timestamp> stableTimestampForRecovery); -} -} +} // namespace repl +} // namespace mongo diff --git a/src/mongo/db/repl/dbcheck_idl.h b/src/mongo/db/repl/dbcheck_idl.h index c49bff7a5b1..9e2d9c880e6 100644 --- a/src/mongo/db/repl/dbcheck_idl.h +++ b/src/mongo/db/repl/dbcheck_idl.h @@ -91,4 +91,4 @@ private: explicit BSONKey(const BSONElement& elem); BSONObj _obj; }; -} +} // namespace mongo diff --git a/src/mongo/db/repl/do_txn.cpp b/src/mongo/db/repl/do_txn.cpp index 7f0f50787c9..d9d6f7bf2ce 100644 --- a/src/mongo/db/repl/do_txn.cpp +++ b/src/mongo/db/repl/do_txn.cpp @@ -126,9 +126,7 @@ Status _doTxn(OperationContext* opCtx, uasserted(ErrorCodes::NamespaceNotFound, str::stream() << "cannot apply insert, delete, or update operation on a " "non-existent namespace " - << nss->ns() - << ": " - << mongo::redact(opObj)); + << nss->ns() << ": " << mongo::redact(opObj)); } if (opObj.hasField("ui")) { @@ -155,9 +153,7 @@ Status _doTxn(OperationContext* opCtx, if (!collection) { uasserted(ErrorCodes::NamespaceNotFound, str::stream() << "cannot apply operation on a non-existent namespace " - << nss->ns() - << " with doTxn: " - << redact(opObj)); + << nss->ns() << " with doTxn: " << redact(opObj)); } // Setting alwaysUpsert to true makes sense only during oplog replay, and doTxn commands diff --git a/src/mongo/db/repl/do_txn_test.cpp b/src/mongo/db/repl/do_txn_test.cpp index 3b92a944ea0..561579a069c 100644 --- a/src/mongo/db/repl/do_txn_test.cpp +++ b/src/mongo/db/repl/do_txn_test.cpp @@ -218,18 +218,10 @@ BSONObj makeInsertOperation(const NamespaceString& nss, const BSONObj& documentToInsert) { return uuid ? BSON("op" << "i" - << "ns" - << nss.ns() - << "o" - << documentToInsert - << "ui" - << *uuid) + << "ns" << nss.ns() << "o" << documentToInsert << "ui" << *uuid) : BSON("op" << "i" - << "ns" - << nss.ns() - << "o" - << documentToInsert); + << "ns" << nss.ns() << "o" << documentToInsert); } /** diff --git a/src/mongo/db/repl/drop_pending_collection_reaper_test.cpp b/src/mongo/db/repl/drop_pending_collection_reaper_test.cpp index 281b864d0d1..1e87ffa17e6 100644 --- a/src/mongo/db/repl/drop_pending_collection_reaper_test.cpp +++ b/src/mongo/db/repl/drop_pending_collection_reaper_test.cpp @@ -253,7 +253,7 @@ TEST_F(DropPendingCollectionReaperTest, decltype(dpns) droppedNss; bool writesAreReplicatedDuringDrop = true; storageInterfaceMock.dropCollFn = [&droppedNss, &writesAreReplicatedDuringDrop]( - OperationContext* opCtx, const NamespaceString& nss) { + OperationContext* opCtx, const NamespaceString& nss) { droppedNss = nss; writesAreReplicatedDuringDrop = opCtx->writesAreReplicated(); return Status::OK(); diff --git a/src/mongo/db/repl/idempotency_test_fixture.cpp b/src/mongo/db/repl/idempotency_test_fixture.cpp index a6c643b0ff0..0146f92a19d 100644 --- a/src/mongo/db/repl/idempotency_test_fixture.cpp +++ b/src/mongo/db/repl/idempotency_test_fixture.cpp @@ -661,12 +661,7 @@ template OplogEntry IdempotencyTest::update<const char*>(char const* _id, const BSONObj makeInsertApplyOpsEntry(const NamespaceString& nss, const UUID& uuid, const BSONObj& doc) { return BSON("op" << "i" - << "ns" - << nss.toString() - << "ui" - << uuid - << "o" - << doc); + << "ns" << nss.toString() << "ui" << uuid << "o" << doc); } } // namespace repl } // namespace mongo diff --git a/src/mongo/db/repl/initial_syncer.cpp b/src/mongo/db/repl/initial_syncer.cpp index 09127b6c6ba..9376eccb3dd 100644 --- a/src/mongo/db/repl/initial_syncer.cpp +++ b/src/mongo/db/repl/initial_syncer.cpp @@ -483,8 +483,7 @@ void InitialSyncer::_startInitialSyncAttemptCallback( auto status = _checkForShutdownAndConvertStatus_inlock( callbackArgs, str::stream() << "error while starting initial sync attempt " << (initialSyncAttempt + 1) - << " of " - << initialSyncMaxAttempts); + << " of " << initialSyncMaxAttempts); if (!status.isOK()) { _finishInitialSyncAttempt(status); return; @@ -748,11 +747,8 @@ void InitialSyncer::_getBeginFetchingOpTimeCallback( Status(ErrorCodes::TooManyMatchingDocuments, str::stream() << "Expected to receive one document for the oldest active " "transaction entry, but received: " - << docs.size() - << ". First: " - << redact(docs.front()) - << ". Last: " - << redact(docs.back()))); + << docs.size() << ". First: " << redact(docs.front()) + << ". Last: " << redact(docs.back()))); return; } @@ -859,11 +855,8 @@ void InitialSyncer::_fcvFetcherCallback(const StatusWith<Fetcher::QueryResponse> Status(ErrorCodes::TooManyMatchingDocuments, str::stream() << "Expected to receive one feature compatibility version " "document, but received: " - << docs.size() - << ". First: " - << redact(docs.front()) - << ". Last: " - << redact(docs.back()))); + << docs.size() << ". First: " << redact(docs.front()) + << ". Last: " << redact(docs.back()))); return; } const auto hasDoc = docs.begin() != docs.end(); @@ -1528,8 +1521,8 @@ void InitialSyncer::_finishCallback(StatusWith<OpTimeAndWallTime> lastApplied) { } Status InitialSyncer::_scheduleLastOplogEntryFetcher_inlock(Fetcher::CallbackFn callback) { - BSONObj query = BSON( - "find" << _opts.remoteOplogNS.coll() << "sort" << BSON("$natural" << -1) << "limit" << 1); + BSONObj query = BSON("find" << _opts.remoteOplogNS.coll() << "sort" << BSON("$natural" << -1) + << "limit" << 1); _lastOplogEntryFetcher = stdx::make_unique<Fetcher>(_exec, @@ -1680,13 +1673,12 @@ Status InitialSyncer::_scheduleWorkAtAndSaveHandle_inlock( if (_isShuttingDown_inlock()) { return Status(ErrorCodes::CallbackCanceled, str::stream() << "failed to schedule work " << name << " at " - << when.toString() - << ": initial syncer is shutting down"); + << when.toString() << ": initial syncer is shutting down"); } auto result = _exec->scheduleWorkAt(when, std::move(work)); if (!result.isOK()) { - return result.getStatus().withContext( - str::stream() << "failed to schedule work " << name << " at " << when.toString()); + return result.getStatus().withContext(str::stream() << "failed to schedule work " << name + << " at " << when.toString()); } *handle = result.getValue(); return Status::OK(); diff --git a/src/mongo/db/repl/initial_syncer_test.cpp b/src/mongo/db/repl/initial_syncer_test.cpp index 9bc286759ff..f9b94d7193d 100644 --- a/src/mongo/db/repl/initial_syncer_test.cpp +++ b/src/mongo/db/repl/initial_syncer_test.cpp @@ -299,19 +299,19 @@ protected: const BSONObj idIndexSpec, const std::vector<BSONObj>& secondaryIndexSpecs) -> StatusWith<std::unique_ptr<CollectionBulkLoaderMock>> { - // Get collection info from map. - const auto collInfo = &_collections[nss]; - if (collInfo->stats->initCalled) { - log() << "reusing collection during test which may cause problems, ns:" << nss; - } - auto localLoader = std::make_unique<CollectionBulkLoaderMock>(collInfo->stats); - auto status = localLoader->init(secondaryIndexSpecs); - if (!status.isOK()) - return status; - collInfo->loader = localLoader.get(); - - return std::move(localLoader); - }; + // Get collection info from map. + const auto collInfo = &_collections[nss]; + if (collInfo->stats->initCalled) { + log() << "reusing collection during test which may cause problems, ns:" << nss; + } + auto localLoader = std::make_unique<CollectionBulkLoaderMock>(collInfo->stats); + auto status = localLoader->init(secondaryIndexSpecs); + if (!status.isOK()) + return status; + collInfo->loader = localLoader.get(); + + return std::move(localLoader); + }; _storageInterface->upgradeNonReplicatedUniqueIndexesFn = [this](OperationContext* opCtx) { LockGuard lock(_storageInterfaceWorkDoneMutex); if (_storageInterfaceWorkDone.upgradeNonReplicatedUniqueIndexesShouldFail) { @@ -372,17 +372,13 @@ protected: dataReplicatorExternalState->lastCommittedOpTime = _myLastOpTime; { ReplSetConfig config; - ASSERT_OK(config.initialize(BSON("_id" - << "myset" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "localhost:12345")) - << "settings" - << BSON("electionTimeoutMillis" << 10000)))); + ASSERT_OK( + config.initialize(BSON("_id" + << "myset" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "localhost:12345")) + << "settings" << BSON("electionTimeoutMillis" << 10000)))); dataReplicatorExternalState->replSetConfigResult = config; } _externalState = dataReplicatorExternalState.get(); @@ -1170,14 +1166,14 @@ TEST_F(InitialSyncerTest, InitialSyncerPassesThroughGetBeginFetchingOpTimeSchedu // We reject the 'find' command for the begin fetching optime and save the request for // inspection at the end of this test case. executor::RemoteCommandRequest request; - _executorProxy->shouldFailScheduleRemoteCommandRequest = [&request]( - const executor::RemoteCommandRequestOnAny& requestToSend) { - request = {requestToSend, 0}; - auto elem = requestToSend.cmdObj.firstElement(); - return ( - ("find" == elem.fieldNameStringData()) && - (NamespaceString::kSessionTransactionsTableNamespace.coll() == elem.valueStringData())); - }; + _executorProxy->shouldFailScheduleRemoteCommandRequest = + [&request](const executor::RemoteCommandRequestOnAny& requestToSend) { + request = {requestToSend, 0}; + auto elem = requestToSend.cmdObj.firstElement(); + return (("find" == elem.fieldNameStringData()) && + (NamespaceString::kSessionTransactionsTableNamespace.coll() == + elem.valueStringData())); + }; HostAndPort syncSource("localhost", 12345); _syncSourceSelector->setChooseNewSyncSourceResult_forTest(syncSource); @@ -1260,12 +1256,13 @@ TEST_F(InitialSyncerTest, InitialSyncerPassesThroughLastOplogEntryFetcherSchedul // We reject the 'find' command on the oplog and save the request for inspection at the end of // this test case. executor::RemoteCommandRequest request; - _executorProxy->shouldFailScheduleRemoteCommandRequest = [&request]( - const executor::RemoteCommandRequestOnAny& requestToSend) { - request = {requestToSend, 0}; - auto elem = requestToSend.cmdObj.firstElement(); - return (("find" == elem.fieldNameStringData()) && ("oplog.rs" == elem.valueStringData())); - }; + _executorProxy->shouldFailScheduleRemoteCommandRequest = + [&request](const executor::RemoteCommandRequestOnAny& requestToSend) { + request = {requestToSend, 0}; + auto elem = requestToSend.cmdObj.firstElement(); + return (("find" == elem.fieldNameStringData()) && + ("oplog.rs" == elem.valueStringData())); + }; HostAndPort syncSource("localhost", 12345); _syncSourceSelector->setChooseNewSyncSourceResult_forTest(syncSource); @@ -1680,8 +1677,7 @@ TEST_F(InitialSyncerTest, TEST_F(InitialSyncerTest, InitialSyncerReturnsIncompatibleServerVersionWhenFCVFetcherReturnsUpgradeTargetVersion) { auto docs = {BSON("_id" << FeatureCompatibilityVersionParser::kParameterName << "version" - << FeatureCompatibilityVersionParser::kVersion40 - << "targetVersion" + << FeatureCompatibilityVersionParser::kVersion40 << "targetVersion" << FeatureCompatibilityVersionParser::kVersion42)}; runInitialSyncWithBadFCVResponse(docs, ErrorCodes::IncompatibleServerVersion); } @@ -1689,8 +1685,7 @@ TEST_F(InitialSyncerTest, TEST_F(InitialSyncerTest, InitialSyncerReturnsIncompatibleServerVersionWhenFCVFetcherReturnsDowngradeTargetVersion) { auto docs = {BSON("_id" << FeatureCompatibilityVersionParser::kParameterName << "version" - << FeatureCompatibilityVersionParser::kVersion40 - << "targetVersion" + << FeatureCompatibilityVersionParser::kVersion40 << "targetVersion" << FeatureCompatibilityVersionParser::kVersion40)}; runInitialSyncWithBadFCVResponse(docs, ErrorCodes::IncompatibleServerVersion); } @@ -2241,8 +2236,7 @@ TEST_F(InitialSyncerTest, << "dbinfo") << BSON("name" << "b")) - << "ok" - << 1))); + << "ok" << 1))); net->runReadyNetworkOperations(); // Oplog tailing query. @@ -2609,8 +2603,7 @@ TEST_F( // Second last oplog entry fetcher. processSuccessfulLastOplogEntryFetcherResponse({BSON("ts" << "not a timestamp" - << "t" - << 1)}); + << "t" << 1)}); // _lastOplogEntryFetcherCallbackAfterCloningData() will shut down the OplogFetcher after // setting the completion status. @@ -3226,8 +3219,7 @@ TEST_F(InitialSyncerTest, LastOpTimeShouldBeSetEvenIfNoOperationsAreAppliedAfter NamespaceString(nss.getCommandNS()), {BSON("v" << OplogEntry::kOplogVersion << "key" << BSON("_id" << 1) << "name" << "_id_" - << "ns" - << nss.ns())}))); + << "ns" << nss.ns())}))); ASSERT_EQUALS(*_options1.uuid, UUID::parse(request.cmdObj.firstElement())); ASSERT_EQUALS(nss.db(), request.dbname); @@ -3960,8 +3952,7 @@ TEST_F(InitialSyncerTest, NamespaceString(nss.getCommandNS()), {BSON("v" << OplogEntry::kOplogVersion << "key" << BSON("_id" << 1) << "name" << "_id_" - << "ns" - << nss.ns())})); + << "ns" << nss.ns())})); assertRemoteCommandNameEquals("listIndexes", request); ASSERT_EQUALS(*_options1.uuid, UUID::parse(request.cmdObj.firstElement())); ASSERT_EQUALS(nss.db(), request.dbname); @@ -4344,8 +4335,7 @@ TEST_F(InitialSyncerTest, GetInitialSyncProgressReturnsCorrectProgress) { NamespaceString(nss.getCommandNS()), {BSON("v" << OplogEntry::kOplogVersion << "key" << BSON("_id" << 1) << "name" << "_id_" - << "ns" - << nss.ns())})); + << "ns" << nss.ns())})); assertRemoteCommandNameEquals("listIndexes", request); ASSERT_EQUALS(*_options1.uuid, UUID::parse(request.cmdObj.firstElement())); ASSERT_EQUALS(nss.db(), request.dbname); diff --git a/src/mongo/db/repl/is_master_response.cpp b/src/mongo/db/repl/is_master_response.cpp index e160054208b..06e0d1c1896 100644 --- a/src/mongo/db/repl/is_master_response.cpp +++ b/src/mongo/db/repl/is_master_response.cpp @@ -220,8 +220,7 @@ Status IsMasterResponse::initialize(const BSONObj& doc) { str::stream() << "Found \"" << kIsReplicaSetFieldName << "\" field which should indicate that no valid config " "is loaded, but we didn't also have an \"" - << kInfoFieldName - << "\" field as we expected"); + << kInfoFieldName << "\" field as we expected"); } } @@ -248,8 +247,7 @@ Status IsMasterResponse::initialize(const BSONObj& doc) { return Status(ErrorCodes::TypeMismatch, str::stream() << "Elements in \"" << kHostsFieldName << "\" array of isMaster response must be of type " - << typeName(String) - << " but found type " + << typeName(String) << " but found type " << typeName(hostElement.type())); } _hosts.push_back(HostAndPort(hostElement.String())); @@ -269,8 +267,7 @@ Status IsMasterResponse::initialize(const BSONObj& doc) { return Status(ErrorCodes::TypeMismatch, str::stream() << "Elements in \"" << kPassivesFieldName << "\" array of isMaster response must be of type " - << typeName(String) - << " but found type " + << typeName(String) << " but found type " << typeName(passiveElement.type())); } _passives.push_back(HostAndPort(passiveElement.String())); @@ -290,8 +287,7 @@ Status IsMasterResponse::initialize(const BSONObj& doc) { return Status(ErrorCodes::TypeMismatch, str::stream() << "Elements in \"" << kArbitersFieldName << "\" array of isMaster response must be of type " - << typeName(String) - << " but found type " + << typeName(String) << " but found type " << typeName(arbiterElement.type())); } _arbiters.push_back(HostAndPort(arbiterElement.String())); @@ -364,8 +360,7 @@ Status IsMasterResponse::initialize(const BSONObj& doc) { str::stream() << "Elements in \"" << kTagsFieldName << "\" obj " "of isMaster response must be of type " - << typeName(String) - << " but found type " + << typeName(String) << " but found type " << typeName(tagsElement.type())); } _tags[tagElement.fieldNameStringData().toString()] = tagElement.String(); @@ -397,8 +392,7 @@ Status IsMasterResponse::initialize(const BSONObj& doc) { str::stream() << "Elements in \"" << kLastWriteOpTimeFieldName << "\" obj " "of isMaster response must be of type " - << typeName(Object) - << " but found type " + << typeName(Object) << " but found type " << typeName(lastWriteOpTimeElement.type())); } auto lastWriteOpTime = OpTime::parseFromOplogEntry(lastWriteOpTimeElement.Obj()); @@ -418,8 +412,7 @@ Status IsMasterResponse::initialize(const BSONObj& doc) { str::stream() << "Elements in \"" << kLastWriteDateFieldName << "\" obj " "of isMaster response must be of type " - << typeName(Date) - << " but found type " + << typeName(Date) << " but found type " << typeName(lastWriteDateElement.type())); } if (_lastWrite) { @@ -439,8 +432,7 @@ Status IsMasterResponse::initialize(const BSONObj& doc) { str::stream() << "Elements in \"" << kLastMajorityWriteOpTimeFieldName << "\" obj " "of isMaster response must be of type " - << typeName(Object) - << " but found type " + << typeName(Object) << " but found type " << typeName(lastMajorityWriteOpTimeElement.type())); } auto lastMajorityWriteOpTime = @@ -461,8 +453,7 @@ Status IsMasterResponse::initialize(const BSONObj& doc) { str::stream() << "Elements in \"" << kLastMajorityWriteDateFieldName << "\" obj " "of isMaster response must be of type " - << typeName(Date) - << " but found type " + << typeName(Date) << " but found type " << typeName(lastMajorityWriteDateElement.type())); } if (_lastMajorityWrite) { diff --git a/src/mongo/db/repl/isself.cpp b/src/mongo/db/repl/isself.cpp index a78298933fd..3d62a2b60b4 100644 --- a/src/mongo/db/repl/isself.cpp +++ b/src/mongo/db/repl/isself.cpp @@ -273,8 +273,7 @@ std::vector<std::string> getBoundAddrs(const bool ipv6enabled) { for (int tries = 0; tries < 3; ++tries) { err = GetAdaptersAddresses(family, GAA_FLAG_SKIP_ANYCAST | // only want unicast addrs - GAA_FLAG_SKIP_MULTICAST | - GAA_FLAG_SKIP_DNS_SERVER, + GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER, NULL, adapters, &adaptersLen); diff --git a/src/mongo/db/repl/member_config.cpp b/src/mongo/db/repl/member_config.cpp index 02fb978173e..5ab43763c8c 100644 --- a/src/mongo/db/repl/member_config.cpp +++ b/src/mongo/db/repl/member_config.cpp @@ -178,9 +178,9 @@ MemberConfig::MemberConfig(const BSONObj& mcfg, ReplSetTagConfig* tagConfig) { for (auto&& tag : tagsElement.Obj()) { if (tag.type() != String) { uasserted(ErrorCodes::TypeMismatch, - str::stream() << "tags." << tag.fieldName() - << " field has non-string value of type " - << typeName(tag.type())); + str::stream() + << "tags." << tag.fieldName() + << " field has non-string value of type " << typeName(tag.type())); } _tags.push_back(tagConfig->makeTag(tag.fieldNameStringData(), tag.valueStringData())); } @@ -240,9 +240,9 @@ Status MemberConfig::validate() const { } if (_slaveDelay < Seconds(0) || _slaveDelay > kMaxSlaveDelay) { return Status(ErrorCodes::BadValue, - str::stream() << kSlaveDelayFieldName << " field value of " - << durationCount<Seconds>(_slaveDelay) - << " seconds is out of range"); + str::stream() + << kSlaveDelayFieldName << " field value of " + << durationCount<Seconds>(_slaveDelay) << " seconds is out of range"); } // Check for additional electable requirements, when priority is non zero if (_priority != 0) { diff --git a/src/mongo/db/repl/member_config_test.cpp b/src/mongo/db/repl/member_config_test.cpp index 6176d230463..cf84b37ccdc 100644 --- a/src/mongo/db/repl/member_config_test.cpp +++ b/src/mongo/db/repl/member_config_test.cpp @@ -60,8 +60,7 @@ TEST(MemberConfig, ParseFailsWithIllegalFieldName) { ReplSetTagConfig tagConfig; ASSERT_THROWS(MemberConfig(BSON("_id" << 0 << "host" << "localhost" - << "frim" - << 1), + << "frim" << 1), &tagConfig), ExceptionFor<ErrorCodes::BadValue>); } @@ -133,8 +132,7 @@ TEST(MemberConfig, ParseArbiterOnly) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "arbiterOnly" - << 1.0), + << "arbiterOnly" << 1.0), &tagConfig); ASSERT_TRUE(mc.isArbiter()); ASSERT_EQUALS(0.0, mc.getPriority()); @@ -142,8 +140,7 @@ TEST(MemberConfig, ParseArbiterOnly) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "arbiterOnly" - << false), + << "arbiterOnly" << false), &tagConfig); ASSERT_TRUE(!mc.isArbiter()); ASSERT_EQUALS(1.0, mc.getPriority()); @@ -155,16 +152,14 @@ TEST(MemberConfig, ParseHidden) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "hidden" - << 1.0), + << "hidden" << 1.0), &tagConfig); ASSERT_TRUE(mc.isHidden()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "hidden" - << false), + << "hidden" << false), &tagConfig); ASSERT_TRUE(!mc.isHidden()); } @@ -181,16 +176,14 @@ TEST(MemberConfig, ParseBuildIndexes) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "buildIndexes" - << 1.0), + << "buildIndexes" << 1.0), &tagConfig); ASSERT_TRUE(mc.shouldBuildIndexes()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "buildIndexes" - << false), + << "buildIndexes" << false), &tagConfig); ASSERT_TRUE(!mc.shouldBuildIndexes()); } @@ -201,18 +194,14 @@ TEST(MemberConfig, ParseVotes) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << 1.0), + << "votes" << 1.0), &tagConfig); ASSERT_TRUE(mc.isVoter()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << 0 - << "priority" - << 0), + << "votes" << 0 << "priority" << 0), &tagConfig); ASSERT_FALSE(mc.isVoter()); } @@ -220,38 +209,33 @@ TEST(MemberConfig, ParseVotes) { // For backwards compatibility, truncate 1.X to 1, and 0.X to 0 (and -0.X to 0). MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << 1.5), + << "votes" << 1.5), &tagConfig); ASSERT_TRUE(mc.isVoter()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << 0.5), + << "votes" << 0.5), &tagConfig); ASSERT_FALSE(mc.isVoter()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << -0.5), + << "votes" << -0.5), &tagConfig); ASSERT_FALSE(mc.isVoter()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << 2), + << "votes" << 2), &tagConfig); } ASSERT_THROWS(MemberConfig(BSON("_id" << 0 << "host" << "h" - << "votes" - << Date_t::fromMillisSinceEpoch(2)), + << "votes" << Date_t::fromMillisSinceEpoch(2)), &tagConfig), ExceptionFor<ErrorCodes::TypeMismatch>); } @@ -261,31 +245,27 @@ TEST(MemberConfig, ParsePriority) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << 1), + << "priority" << 1), &tagConfig); ASSERT_EQUALS(1.0, mc.getPriority()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << 0), + << "priority" << 0), &tagConfig); ASSERT_EQUALS(0.0, mc.getPriority()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << 100.8), + << "priority" << 100.8), &tagConfig); ASSERT_EQUALS(100.8, mc.getPriority()); } ASSERT_THROWS(MemberConfig(BSON("_id" << 0 << "host" << "h" - << "priority" - << Date_t::fromMillisSinceEpoch(2)), + << "priority" << Date_t::fromMillisSinceEpoch(2)), &tagConfig), ExceptionFor<ErrorCodes::TypeMismatch>); } @@ -294,8 +274,7 @@ TEST(MemberConfig, ParseSlaveDelay) { ReplSetTagConfig tagConfig; MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "slaveDelay" - << 100), + << "slaveDelay" << 100), &tagConfig); ASSERT_EQUALS(Seconds(100), mc.getSlaveDelay()); } @@ -365,14 +344,13 @@ TEST(MemberConfig, DuplicateHorizonNames) { ASSERT_NOT_EQUALS(s.reason().find("Duplicate horizon name found"), std::string::npos); } try { - MemberConfig(BSON("_id" << 0 << "host" - << "h" - << "horizons" - << BSON("someUniqueHorizonName" - << "a.host:43" - << SplitHorizon::kDefaultHorizon - << "b.host:256")), - &tagConfig); + MemberConfig( + BSON("_id" << 0 << "host" + << "h" + << "horizons" + << BSON("someUniqueHorizonName" + << "a.host:43" << SplitHorizon::kDefaultHorizon << "b.host:256")), + &tagConfig); ASSERT_TRUE(false); // Should not succeed. } catch (const ExceptionFor<ErrorCodes::BadValue>& ex) { const Status& s = ex.toStatus(); @@ -489,8 +467,7 @@ TEST(MemberConfig, ValidateVotes) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << 1.0), + << "votes" << 1.0), &tagConfig); ASSERT_OK(mc.validate()); ASSERT_TRUE(mc.isVoter()); @@ -498,10 +475,7 @@ TEST(MemberConfig, ValidateVotes) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << 0 - << "priority" - << 0), + << "votes" << 0 << "priority" << 0), &tagConfig); ASSERT_OK(mc.validate()); ASSERT_FALSE(mc.isVoter()); @@ -510,8 +484,7 @@ TEST(MemberConfig, ValidateVotes) { // For backwards compatibility, truncate 1.X to 1, and 0.X to 0 (and -0.X to 0). MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << 1.5), + << "votes" << 1.5), &tagConfig); ASSERT_OK(mc.validate()); ASSERT_TRUE(mc.isVoter()); @@ -519,10 +492,7 @@ TEST(MemberConfig, ValidateVotes) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << 0.5 - << "priority" - << 0), + << "votes" << 0.5 << "priority" << 0), &tagConfig); ASSERT_OK(mc.validate()); ASSERT_FALSE(mc.isVoter()); @@ -530,10 +500,7 @@ TEST(MemberConfig, ValidateVotes) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << -0.5 - << "priority" - << 0), + << "votes" << -0.5 << "priority" << 0), &tagConfig); ASSERT_OK(mc.validate()); ASSERT_FALSE(mc.isVoter()); @@ -542,16 +509,14 @@ TEST(MemberConfig, ValidateVotes) { // Invalid values MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << 2), + << "votes" << 2), &tagConfig); ASSERT_EQUALS(ErrorCodes::BadValue, mc.validate()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << -1), + << "votes" << -1), &tagConfig); ASSERT_EQUALS(ErrorCodes::BadValue, mc.validate()); } @@ -562,32 +527,28 @@ TEST(MemberConfig, ValidatePriorityRanges) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << 0), + << "priority" << 0), &tagConfig); ASSERT_OK(mc.validate()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << 1000), + << "priority" << 1000), &tagConfig); ASSERT_OK(mc.validate()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << -1), + << "priority" << -1), &tagConfig); ASSERT_EQUALS(ErrorCodes::BadValue, mc.validate()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << 1001), + << "priority" << 1001), &tagConfig); ASSERT_EQUALS(ErrorCodes::BadValue, mc.validate()); } @@ -598,40 +559,28 @@ TEST(MemberConfig, ValidateSlaveDelays) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << 0 - << "slaveDelay" - << 0), + << "priority" << 0 << "slaveDelay" << 0), &tagConfig); ASSERT_OK(mc.validate()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << 0 - << "slaveDelay" - << 3600 * 10), + << "priority" << 0 << "slaveDelay" << 3600 * 10), &tagConfig); ASSERT_OK(mc.validate()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << 0 - << "slaveDelay" - << -1), + << "priority" << 0 << "slaveDelay" << -1), &tagConfig); ASSERT_EQUALS(ErrorCodes::BadValue, mc.validate()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << 0 - << "slaveDelay" - << 3600 * 24 * 400), + << "priority" << 0 << "slaveDelay" << 3600 * 24 * 400), &tagConfig); ASSERT_EQUALS(ErrorCodes::BadValue, mc.validate()); } @@ -641,10 +590,7 @@ TEST(MemberConfig, ValidatePriorityAndSlaveDelayRelationship) { ReplSetTagConfig tagConfig; MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << 1 - << "slaveDelay" - << 60), + << "priority" << 1 << "slaveDelay" << 60), &tagConfig); ASSERT_EQUALS(ErrorCodes::BadValue, mc.validate()); } @@ -654,20 +600,14 @@ TEST(MemberConfig, ValidatePriorityAndHiddenRelationship) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << 1 - << "hidden" - << true), + << "priority" << 1 << "hidden" << true), &tagConfig); ASSERT_EQUALS(ErrorCodes::BadValue, mc.validate()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << 1 - << "hidden" - << false), + << "priority" << 1 << "hidden" << false), &tagConfig); ASSERT_OK(mc.validate()); } @@ -678,10 +618,7 @@ TEST(MemberConfig, ValidatePriorityAndBuildIndexesRelationship) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << 1 - << "buildIndexes" - << false), + << "priority" << 1 << "buildIndexes" << false), &tagConfig); ASSERT_EQUALS(ErrorCodes::BadValue, mc.validate()); @@ -689,10 +626,7 @@ TEST(MemberConfig, ValidatePriorityAndBuildIndexesRelationship) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "priority" - << 1 - << "buildIndexes" - << true), + << "priority" << 1 << "buildIndexes" << true), &tagConfig); ASSERT_OK(mc.validate()); } @@ -703,42 +637,28 @@ TEST(MemberConfig, ValidateArbiterVotesRelationship) { { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << 1 - << "arbiterOnly" - << true), + << "votes" << 1 << "arbiterOnly" << true), &tagConfig); ASSERT_OK(mc.validate()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << 0 - << "priority" - << 0 - << "arbiterOnly" - << false), + << "votes" << 0 << "priority" << 0 << "arbiterOnly" << false), &tagConfig); ASSERT_OK(mc.validate()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << 1 - << "arbiterOnly" - << false), + << "votes" << 1 << "arbiterOnly" << false), &tagConfig); ASSERT_OK(mc.validate()); } { MemberConfig mc(BSON("_id" << 0 << "host" << "h" - << "votes" - << 0 - << "arbiterOnly" - << true), + << "votes" << 0 << "arbiterOnly" << true), &tagConfig); ASSERT_EQUALS(ErrorCodes::BadValue, mc.validate()); } diff --git a/src/mongo/db/repl/member_data.cpp b/src/mongo/db/repl/member_data.cpp index 40a081ba6a2..247167bc150 100644 --- a/src/mongo/db/repl/member_data.cpp +++ b/src/mongo/db/repl/member_data.cpp @@ -141,8 +141,9 @@ void MemberData::setLastDurableOpTimeAndWallTime(OpTimeAndWallTime opTime, Date_ // TODO(russotto): We think this should never happen, rollback or no rollback. Make this an // invariant and see what happens. log() << "Durable progress (" << opTime.opTime << ") is ahead of the applied progress (" - << _lastAppliedOpTime << ". This is likely due to a " - "rollback." + << _lastAppliedOpTime + << ". This is likely due to a " + "rollback." << " memberid: " << _memberId << _hostAndPort.toString() << " previous durable progress: " << _lastDurableOpTime; } else { diff --git a/src/mongo/db/repl/mock_repl_coord_server_fixture.h b/src/mongo/db/repl/mock_repl_coord_server_fixture.h index 9bac2e16d74..7f52f4a3f21 100644 --- a/src/mongo/db/repl/mock_repl_coord_server_fixture.h +++ b/src/mongo/db/repl/mock_repl_coord_server_fixture.h @@ -39,7 +39,7 @@ class OperationContext; namespace repl { class OplogEntry; class StorageInterfaceMock; -} +} // namespace repl /** * This is a basic fixture that is backed by an ephemeral storage engine and a mock replication diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index d9fc1390de3..35719c01913 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -409,7 +409,7 @@ OplogDocWriter _logOpWriter(OperationContext* opCtx, return OplogDocWriter(OplogDocWriter(b.obj(), obj)); } -} // end anon namespace +} // namespace /* we write to local.oplog.rs: { ts : ..., h: ..., v: ..., op: ..., etc } @@ -429,8 +429,8 @@ OplogDocWriter _logOpWriter(OperationContext* opCtx, * writers - an array with size nDocs of DocWriter objects. * timestamps - an array with size nDocs of respective Timestamp objects for each DocWriter. * oplogCollection - collection to be written to. - * finalOpTime - the OpTime of the last DocWriter object. - * wallTime - the wall clock time of the corresponding oplog entry. + * finalOpTime - the OpTime of the last DocWriter object. + * wallTime - the wall clock time of the corresponding oplog entry. */ void _logOpsInner(OperationContext* opCtx, const NamespaceString& nss, @@ -459,8 +459,7 @@ void _logOpsInner(OperationContext* opCtx, // are logging within one WriteUnitOfWork. invariant(finalOpTime.getTimestamp() <= *commitTime, str::stream() << "Final OpTime: " << finalOpTime.toString() - << ". Commit Time: " - << commitTime->toString()); + << ". Commit Time: " << commitTime->toString()); } // Optionally hang before advancing lastApplied. @@ -495,12 +494,8 @@ OpTime logOp(OperationContext* opCtx, // All collections should have UUIDs now, so all insert, update, and delete oplog entries should // also have uuids. Some no-op (n) and command (c) entries may still elide the uuid field. invariant(uuid || 'n' == *opstr || 'c' == *opstr, - str::stream() << "Expected uuid for logOp with opstr: " << opstr << ", nss: " - << nss.ns() - << ", obj: " - << obj - << ", os: " - << o2); + str::stream() << "Expected uuid for logOp with opstr: " << opstr + << ", nss: " << nss.ns() << ", obj: " << obj << ", os: " << o2); auto replCoord = ReplicationCoordinator::get(opCtx); // For commands, the test below is on the command ns and therefore does not check for @@ -629,7 +624,7 @@ std::vector<OpTime> logInsertOps(OperationContext* opCtx, sleepmillis(numMillis); } - std::unique_ptr<DocWriter const* []> basePtrs(new DocWriter const*[count]); + std::unique_ptr<DocWriter const*[]> basePtrs(new DocWriter const*[count]); for (size_t i = 0; i < count; i++) { basePtrs[i] = &writers[i]; } @@ -656,7 +651,7 @@ long long getNewOplogSizeBytes(OperationContext* opCtx, const ReplSettings& repl LOG(3) << "32bit system; choosing " << sz << " bytes oplog"; return sz; } -// First choose a minimum size. + // First choose a minimum size. #if defined(__APPLE__) // typically these are desktops (dev machines), so keep it smallish @@ -786,8 +781,7 @@ std::pair<OptionalCollectionUUID, NamespaceString> parseCollModUUIDAndNss(Operat const auto nsByUUID = catalog.lookupNSSByUUID(uuid); uassert(ErrorCodes::NamespaceNotFound, str::stream() << "Failed to apply operation due to missing collection (" << uuid - << "): " - << redact(cmd.toString()), + << "): " << redact(cmd.toString()), nsByUUID); return std::pair<OptionalCollectionUUID, NamespaceString>(uuid, *nsByUUID); } @@ -1342,8 +1336,7 @@ Status applyOperation_inlock(OperationContext* opCtx, collection = catalog.lookupCollectionByUUID(uuid); uassert(ErrorCodes::NamespaceNotFound, str::stream() << "Failed to apply operation due to missing collection (" << uuid - << "): " - << redact(op.toString()), + << "): " << redact(op.toString()), collection); requestNss = collection->ns(); dassert(opCtx->lockState()->isCollectionLockedForMode( diff --git a/src/mongo/db/repl/oplog_buffer_collection.cpp b/src/mongo/db/repl/oplog_buffer_collection.cpp index 39c5ab03036..cfea973d17d 100644 --- a/src/mongo/db/repl/oplog_buffer_collection.cpp +++ b/src/mongo/db/repl/oplog_buffer_collection.cpp @@ -66,17 +66,16 @@ std::tuple<BSONObj, Timestamp, std::size_t> OplogBufferCollection::addIdToDocume const BSONObj& orig, const Timestamp& lastTimestamp, std::size_t sentinelCount) { if (orig.isEmpty()) { return std::make_tuple( - BSON(kIdFieldName << BSON( - kTimestampFieldName << lastTimestamp << kSentinelFieldName - << static_cast<long long>(sentinelCount + 1))), + BSON(kIdFieldName << BSON(kTimestampFieldName + << lastTimestamp << kSentinelFieldName + << static_cast<long long>(sentinelCount + 1))), lastTimestamp, sentinelCount + 1); } const auto ts = orig[kTimestampFieldName].timestamp(); invariant(!ts.isNull()); auto doc = BSON(kIdFieldName << BSON(kTimestampFieldName << ts << kSentinelFieldName << 0) - << kOplogEntryFieldName - << orig); + << kOplogEntryFieldName << orig); return std::make_tuple(doc, ts, 0); } diff --git a/src/mongo/db/repl/oplog_buffer_collection_test.cpp b/src/mongo/db/repl/oplog_buffer_collection_test.cpp index 0d544104fc6..64ee03f9d0f 100644 --- a/src/mongo/db/repl/oplog_buffer_collection_test.cpp +++ b/src/mongo/db/repl/oplog_buffer_collection_test.cpp @@ -111,12 +111,9 @@ NamespaceString makeNamespace(const T& t, const char* suffix = "") { BSONObj makeOplogEntry(int t) { return BSON("ts" << Timestamp(t, t) << "ns" << "a.a" - << "v" - << 2 - << "op" + << "v" << 2 << "op" << "i" - << "o" - << BSON("_id" << t << "a" << t)); + << "o" << BSON("_id" << t << "a" << t)); } TEST_F(OplogBufferCollectionTest, DefaultNamespace) { @@ -623,7 +620,9 @@ TEST_F(OplogBufferCollectionTest, PopAndPeekReturnDocumentsInOrder) { oplogBuffer.startup(_opCtx.get()); const std::vector<BSONObj> oplog = { - makeOplogEntry(1), makeOplogEntry(2), makeOplogEntry(3), + makeOplogEntry(1), + makeOplogEntry(2), + makeOplogEntry(3), }; ASSERT_EQUALS(oplogBuffer.getCount(), 0UL); oplogBuffer.pushAllNonBlocking(_opCtx.get(), oplog.begin(), oplog.end()); @@ -666,7 +665,9 @@ TEST_F(OplogBufferCollectionTest, LastObjectPushedReturnsNewestOplogEntry) { oplogBuffer.startup(_opCtx.get()); const std::vector<BSONObj> oplog = { - makeOplogEntry(1), makeOplogEntry(2), makeOplogEntry(3), + makeOplogEntry(1), + makeOplogEntry(2), + makeOplogEntry(3), }; ASSERT_EQUALS(oplogBuffer.getCount(), 0UL); oplogBuffer.pushAllNonBlocking(_opCtx.get(), oplog.begin(), oplog.end()); @@ -702,7 +703,9 @@ TEST_F(OplogBufferCollectionTest, oplogBuffer.startup(_opCtx.get()); const std::vector<BSONObj> oplog = { - makeOplogEntry(3), makeOplogEntry(4), makeOplogEntry(5), + makeOplogEntry(3), + makeOplogEntry(4), + makeOplogEntry(5), }; ASSERT_BSONOBJ_EQ(*oplogBuffer.lastObjectPushed(_opCtx.get()), secondDoc); @@ -929,7 +932,12 @@ void _testPushSentinelsProperly( OplogBufferCollection oplogBuffer(storageInterface, nss); oplogBuffer.startup(opCtx); const std::vector<BSONObj> oplog = { - BSONObj(), makeOplogEntry(1), BSONObj(), BSONObj(), makeOplogEntry(2), BSONObj(), + BSONObj(), + makeOplogEntry(1), + BSONObj(), + BSONObj(), + makeOplogEntry(2), + BSONObj(), }; ASSERT_EQUALS(oplogBuffer.getCount(), 0UL); pushDocsFn(opCtx, &oplogBuffer, oplog); @@ -1016,7 +1024,8 @@ DEATH_TEST_F( oplogBuffer.startup(_opCtx.get()); const std::vector<BSONObj> oplog = { - makeOplogEntry(2), makeOplogEntry(1), + makeOplogEntry(2), + makeOplogEntry(1), }; ASSERT_EQUALS(oplogBuffer.getCount(), 0UL); oplogBuffer.pushAllNonBlocking(_opCtx.get(), oplog.begin(), oplog.end()); @@ -1028,7 +1037,10 @@ TEST_F(OplogBufferCollectionTest, SentinelInMiddleIsReturnedInOrder) { oplogBuffer.startup(_opCtx.get()); const std::vector<BSONObj> oplog = { - makeOplogEntry(1), makeOplogEntry(2), BSONObj(), makeOplogEntry(3), + makeOplogEntry(1), + makeOplogEntry(2), + BSONObj(), + makeOplogEntry(3), }; ASSERT_EQUALS(oplogBuffer.getCount(), 0UL); oplogBuffer.pushEvenIfFull(_opCtx.get(), oplog[0]); @@ -1149,7 +1161,12 @@ TEST_F(OplogBufferCollectionTest, MultipleSentinelsAreReturnedInOrder) { oplogBuffer.startup(_opCtx.get()); const std::vector<BSONObj> oplog = { - BSONObj(), makeOplogEntry(1), BSONObj(), BSONObj(), makeOplogEntry(2), BSONObj(), + BSONObj(), + makeOplogEntry(1), + BSONObj(), + BSONObj(), + makeOplogEntry(2), + BSONObj(), }; ASSERT_EQUALS(oplogBuffer.getCount(), 0UL); oplogBuffer.pushAllNonBlocking(_opCtx.get(), oplog.cbegin(), oplog.cend()); diff --git a/src/mongo/db/repl/oplog_entry.cpp b/src/mongo/db/repl/oplog_entry.cpp index 6d549dd1965..38a71114cf1 100644 --- a/src/mongo/db/repl/oplog_entry.cpp +++ b/src/mongo/db/repl/oplog_entry.cpp @@ -81,8 +81,7 @@ OplogEntry::CommandType parseCommandType(const BSONObj& objectField) { } else { uasserted(ErrorCodes::BadValue, str::stream() << "Unknown oplog entry command type: " << commandString - << " Object field: " - << redact(objectField)); + << " Object field: " << redact(objectField)); } MONGO_UNREACHABLE; } diff --git a/src/mongo/db/repl/oplog_fetcher.cpp b/src/mongo/db/repl/oplog_fetcher.cpp index 9c4df1a1bec..3162319ab2b 100644 --- a/src/mongo/db/repl/oplog_fetcher.cpp +++ b/src/mongo/db/repl/oplog_fetcher.cpp @@ -161,11 +161,10 @@ Status checkRemoteOplogStart(const Fetcher::Documents& documents, // sync source is now behind us, choose a new sync source to prevent going into rollback. if (remoteLastOpApplied && (*remoteLastOpApplied < lastFetched)) { return Status(ErrorCodes::InvalidSyncSource, - str::stream() << "Sync source's last applied OpTime " - << remoteLastOpApplied->toString() - << " is older than our last fetched OpTime " - << lastFetched.toString() - << ". Choosing new sync source."); + str::stream() + << "Sync source's last applied OpTime " << remoteLastOpApplied->toString() + << " is older than our last fetched OpTime " << lastFetched.toString() + << ". Choosing new sync source."); } // If 'requireFresherSyncSource' is true, we must check that the sync source's @@ -181,8 +180,7 @@ Status checkRemoteOplogStart(const Fetcher::Documents& documents, return Status(ErrorCodes::InvalidSyncSource, str::stream() << "Sync source must be ahead of me. My last fetched oplog optime: " - << lastFetched.toString() - << ", latest oplog optime of sync source: " + << lastFetched.toString() << ", latest oplog optime of sync source: " << remoteLastOpApplied->toString()); } @@ -202,9 +200,7 @@ Status checkRemoteOplogStart(const Fetcher::Documents& documents, return Status(ErrorCodes::InvalidBSON, str::stream() << "our last optime fetched: " << lastFetched.toString() << ". failed to parse optime from first oplog on source: " - << o.toString() - << ": " - << opTimeResult.getStatus().toString()); + << o.toString() << ": " << opTimeResult.getStatus().toString()); } auto opTime = opTimeResult.getValue(); if (opTime != lastFetched) { @@ -289,15 +285,9 @@ StatusWith<OplogFetcher::DocumentsInfo> OplogFetcher::validateDocuments( if (lastTS >= docTS) { return Status(ErrorCodes::OplogOutOfOrder, str::stream() << "Out of order entries in oplog. lastTS: " - << lastTS.toString() - << " outOfOrderTS:" - << docTS.toString() - << " in batch with " - << info.networkDocumentCount - << "docs; first-batch:" - << first - << ", doc:" - << doc); + << lastTS.toString() << " outOfOrderTS:" << docTS.toString() + << " in batch with " << info.networkDocumentCount + << "docs; first-batch:" << first << ", doc:" << doc); } lastTS = docTS; } diff --git a/src/mongo/db/repl/oplog_interface_mock.cpp b/src/mongo/db/repl/oplog_interface_mock.cpp index 6352fa7566a..95930bf6d62 100644 --- a/src/mongo/db/repl/oplog_interface_mock.cpp +++ b/src/mongo/db/repl/oplog_interface_mock.cpp @@ -90,8 +90,7 @@ public: str::stream() << "oplog no longer contains the complete write history of this " "transaction, log with opTime " - << _nextOpTime.toBSON() - << " cannot be found"); + << _nextOpTime.toBSON() << " cannot be found"); } // We shouldn't get any other error. MONGO_UNREACHABLE; diff --git a/src/mongo/db/repl/oplog_test.cpp b/src/mongo/db/repl/oplog_test.cpp index b95f8d2d4fc..00f76f96c4d 100644 --- a/src/mongo/db/repl/oplog_test.cpp +++ b/src/mongo/db/repl/oplog_test.cpp @@ -124,9 +124,9 @@ TEST_F(OplogTest, LogOpReturnsOpTimeOnSuccessfulInsertIntoOplogCollection) { << "OpTime returned from logOp() did not match that in the oplog entry written to the " "oplog: " << oplogEntry.toBSON(); - ASSERT(OpTypeEnum::kNoop == oplogEntry.getOpType()) << "Expected 'n' op type but found '" - << OpType_serializer(oplogEntry.getOpType()) - << "' instead: " << oplogEntry.toBSON(); + ASSERT(OpTypeEnum::kNoop == oplogEntry.getOpType()) + << "Expected 'n' op type but found '" << OpType_serializer(oplogEntry.getOpType()) + << "' instead: " << oplogEntry.toBSON(); ASSERT_BSONOBJ_EQ(msgObj, oplogEntry.getObject()); // Ensure that the msg optime returned is the same as the last optime in the ReplClientInfo. diff --git a/src/mongo/db/repl/optime_extract_test.cpp b/src/mongo/db/repl/optime_extract_test.cpp index d1e2b0d7e49..9192738a31c 100644 --- a/src/mongo/db/repl/optime_extract_test.cpp +++ b/src/mongo/db/repl/optime_extract_test.cpp @@ -51,8 +51,7 @@ TEST(ExtractBSON, ExtractOpTimeField) { // Missing timestamp field. obj = BSON("a" << BSON("ts" << "notATimestamp" - << "t" - << 2)); + << "t" << 2)); ASSERT_EQUALS(ErrorCodes::TypeMismatch, bsonExtractOpTimeField(obj, "a", &opTime)); // Wrong typed timestamp field. obj = BSON("a" << BSON("t" << 2)); diff --git a/src/mongo/db/repl/read_concern_args.cpp b/src/mongo/db/repl/read_concern_args.cpp index 89545a0fb4a..5ec5ae968c1 100644 --- a/src/mongo/db/repl/read_concern_args.cpp +++ b/src/mongo/db/repl/read_concern_args.cpp @@ -202,23 +202,20 @@ Status ReadConcernArgs::initialize(const BSONElement& readConcernElem) { } else { return Status(ErrorCodes::InvalidOptions, str::stream() << "Unrecognized option in " << kReadConcernFieldName - << ": " - << fieldName); + << ": " << fieldName); } } if (_afterClusterTime && _opTime) { return Status(ErrorCodes::InvalidOptions, str::stream() << "Can not specify both " << kAfterClusterTimeFieldName - << " and " - << kAfterOpTimeFieldName); + << " and " << kAfterOpTimeFieldName); } if (_afterClusterTime && _atClusterTime) { return Status(ErrorCodes::InvalidOptions, str::stream() << "Can not specify both " << kAfterClusterTimeFieldName - << " and " - << kAtClusterTimeFieldName); + << " and " << kAtClusterTimeFieldName); } // Note: 'available' should not be used with after cluster time, as cluster time can wait for @@ -228,30 +225,24 @@ Status ReadConcernArgs::initialize(const BSONElement& readConcernElem) { getLevel() != ReadConcernLevel::kLocalReadConcern && getLevel() != ReadConcernLevel::kSnapshotReadConcern) { return Status(ErrorCodes::InvalidOptions, - str::stream() << kAfterClusterTimeFieldName << " field can be set only if " - << kLevelFieldName - << " is equal to " - << kMajorityReadConcernStr - << ", " - << kLocalReadConcernStr - << ", or " - << kSnapshotReadConcernStr); + str::stream() + << kAfterClusterTimeFieldName << " field can be set only if " + << kLevelFieldName << " is equal to " << kMajorityReadConcernStr << ", " + << kLocalReadConcernStr << ", or " << kSnapshotReadConcernStr); } if (_opTime && getLevel() == ReadConcernLevel::kSnapshotReadConcern) { return Status(ErrorCodes::InvalidOptions, - str::stream() << kAfterOpTimeFieldName << " field cannot be set if " - << kLevelFieldName - << " is equal to " - << kSnapshotReadConcernStr); + str::stream() + << kAfterOpTimeFieldName << " field cannot be set if " << kLevelFieldName + << " is equal to " << kSnapshotReadConcernStr); } if (_atClusterTime && getLevel() != ReadConcernLevel::kSnapshotReadConcern) { return Status(ErrorCodes::InvalidOptions, - str::stream() << kAtClusterTimeFieldName << " field can be set only if " - << kLevelFieldName - << " is equal to " - << kSnapshotReadConcernStr); + str::stream() + << kAtClusterTimeFieldName << " field can be set only if " + << kLevelFieldName << " is equal to " << kSnapshotReadConcernStr); } if (_afterClusterTime && _afterClusterTime == LogicalTime::kUninitialized) { @@ -294,8 +285,7 @@ Status ReadConcernArgs::upconvertReadConcernLevelToSnapshot() { if (_opTime) { return Status(ErrorCodes::InvalidOptions, str::stream() << "Cannot upconvert the readConcern level to 'snapshot' when '" - << kAfterOpTimeFieldName - << "' is provided"); + << kAfterOpTimeFieldName << "' is provided"); } _originalLevel = _level; diff --git a/src/mongo/db/repl/read_concern_args_test.cpp b/src/mongo/db/repl/read_concern_args_test.cpp index ed6ec48875c..d6907a31f26 100644 --- a/src/mongo/db/repl/read_concern_args_test.cpp +++ b/src/mongo/db/repl/read_concern_args_test.cpp @@ -39,13 +39,12 @@ namespace { TEST(ReadAfterParse, OpTimeOnly) { ReadConcernArgs readConcern; - ASSERT_OK(readConcern.initialize(BSON( - "find" - << "test" - << ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kAfterOpTimeFieldName - << BSON(OpTime::kTimestampFieldName << Timestamp(20, 30) << OpTime::kTermFieldName - << 2))))); + ASSERT_OK(readConcern.initialize(BSON("find" + << "test" << ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kAfterOpTimeFieldName + << BSON(OpTime::kTimestampFieldName + << Timestamp(20, 30) + << OpTime::kTermFieldName << 2))))); ASSERT_TRUE(readConcern.getArgsOpTime()); ASSERT_TRUE(!readConcern.getArgsAfterClusterTime()); @@ -59,8 +58,7 @@ TEST(ReadAfterParse, AfterClusterTimeOnly) { ReadConcernArgs readConcern; auto afterClusterTime = LogicalTime(Timestamp(20, 30)); ASSERT_OK(readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kAfterClusterTimeFieldName << afterClusterTime.asTimestamp())))); auto argsAfterClusterTime = readConcern.getArgsAfterClusterTime(); @@ -73,13 +71,12 @@ TEST(ReadAfterParse, AfterClusterTimeAndLevelLocal) { ReadConcernArgs readConcern; // Must have level=majority auto afterClusterTime = LogicalTime(Timestamp(20, 30)); - ASSERT_OK(readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kAfterClusterTimeFieldName - << afterClusterTime.asTimestamp() - << ReadConcernArgs::kLevelFieldName - << "local")))); + ASSERT_OK( + readConcern.initialize(BSON("find" + << "test" << ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kAfterClusterTimeFieldName + << afterClusterTime.asTimestamp() + << ReadConcernArgs::kLevelFieldName << "local")))); auto argsAfterClusterTime = readConcern.getArgsAfterClusterTime(); ASSERT_TRUE(argsAfterClusterTime); ASSERT_TRUE(!readConcern.getArgsOpTime()); @@ -91,13 +88,12 @@ TEST(ReadAfterParse, AfterClusterTimeAndLevelMajority) { ReadConcernArgs readConcern; // Must have level=majority auto afterClusterTime = LogicalTime(Timestamp(20, 30)); - ASSERT_OK(readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kAfterClusterTimeFieldName - << afterClusterTime.asTimestamp() - << ReadConcernArgs::kLevelFieldName - << "majority")))); + ASSERT_OK( + readConcern.initialize(BSON("find" + << "test" << ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kAfterClusterTimeFieldName + << afterClusterTime.asTimestamp() + << ReadConcernArgs::kLevelFieldName << "majority")))); auto argsAfterClusterTime = readConcern.getArgsAfterClusterTime(); ASSERT_TRUE(argsAfterClusterTime); ASSERT_TRUE(!readConcern.getArgsOpTime()); @@ -108,13 +104,12 @@ TEST(ReadAfterParse, AfterClusterTimeAndLevelMajority) { TEST(ReadAfterParse, AfterClusterTimeAndLevelSnapshot) { ReadConcernArgs readConcern; auto afterClusterTime = LogicalTime(Timestamp(20, 30)); - ASSERT_OK(readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kAfterClusterTimeFieldName - << afterClusterTime.asTimestamp() - << ReadConcernArgs::kLevelFieldName - << "snapshot")))); + ASSERT_OK( + readConcern.initialize(BSON("find" + << "test" << ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kAfterClusterTimeFieldName + << afterClusterTime.asTimestamp() + << ReadConcernArgs::kLevelFieldName << "snapshot")))); auto argsAfterClusterTime = readConcern.getArgsAfterClusterTime(); ASSERT_TRUE(argsAfterClusterTime); ASSERT_TRUE(!readConcern.getArgsOpTime()); @@ -127,8 +122,7 @@ TEST(ReadAfterParse, AtClusterTimeOnly) { auto atClusterTime = LogicalTime(Timestamp(20, 30)); ASSERT_EQ(ErrorCodes::InvalidOptions, readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kAtClusterTimeFieldName << atClusterTime.asTimestamp())))); } @@ -136,13 +130,12 @@ TEST(ReadAfterParse, AtClusterTimeOnly) { TEST(ReadAfterParse, AtClusterTimeAndLevelSnapshot) { ReadConcernArgs readConcern; auto atClusterTime = LogicalTime(Timestamp(20, 30)); - ASSERT_OK(readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kAtClusterTimeFieldName - << atClusterTime.asTimestamp() - << ReadConcernArgs::kLevelFieldName - << "snapshot")))); + ASSERT_OK( + readConcern.initialize(BSON("find" + << "test" << ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kAtClusterTimeFieldName + << atClusterTime.asTimestamp() + << ReadConcernArgs::kLevelFieldName << "snapshot")))); auto argsAtClusterTime = readConcern.getArgsAtClusterTime(); ASSERT_TRUE(argsAtClusterTime); ASSERT_FALSE(readConcern.getArgsOpTime()); @@ -153,40 +146,37 @@ TEST(ReadAfterParse, AtClusterTimeAndLevelSnapshot) { TEST(ReadAfterParse, AtClusterTimeAndLevelMajority) { ReadConcernArgs readConcern; auto atClusterTime = LogicalTime(Timestamp(20, 30)); - ASSERT_EQ(ErrorCodes::InvalidOptions, - readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kAtClusterTimeFieldName - << atClusterTime.asTimestamp() - << ReadConcernArgs::kLevelFieldName - << "majority")))); + ASSERT_EQ( + ErrorCodes::InvalidOptions, + readConcern.initialize(BSON("find" + << "test" << ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kAtClusterTimeFieldName + << atClusterTime.asTimestamp() + << ReadConcernArgs::kLevelFieldName << "majority")))); } TEST(ReadAfterParse, AtClusterTimeAndLevelLocal) { ReadConcernArgs readConcern; auto atClusterTime = LogicalTime(Timestamp(20, 30)); - ASSERT_EQ(ErrorCodes::InvalidOptions, - readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kAtClusterTimeFieldName - << atClusterTime.asTimestamp() - << ReadConcernArgs::kLevelFieldName - << "local")))); + ASSERT_EQ( + ErrorCodes::InvalidOptions, + readConcern.initialize(BSON("find" + << "test" << ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kAtClusterTimeFieldName + << atClusterTime.asTimestamp() + << ReadConcernArgs::kLevelFieldName << "local")))); } TEST(ReadAfterParse, AtClusterTimeAndLevelAvailable) { ReadConcernArgs readConcern; auto atClusterTime = LogicalTime(Timestamp(20, 30)); - ASSERT_EQ(ErrorCodes::InvalidOptions, - readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kAtClusterTimeFieldName - << atClusterTime.asTimestamp() - << ReadConcernArgs::kLevelFieldName - << "available")))); + ASSERT_EQ( + ErrorCodes::InvalidOptions, + readConcern.initialize(BSON("find" + << "test" << ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kAtClusterTimeFieldName + << atClusterTime.asTimestamp() + << ReadConcernArgs::kLevelFieldName << "available")))); } TEST(ReadAfterParse, AtClusterTimeAndLevelLinearizable) { @@ -194,8 +184,7 @@ TEST(ReadAfterParse, AtClusterTimeAndLevelLinearizable) { auto atClusterTime = LogicalTime(Timestamp(20, 30)); ASSERT_EQ(ErrorCodes::InvalidOptions, readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kAtClusterTimeFieldName << atClusterTime.asTimestamp() << ReadConcernArgs::kLevelFieldName @@ -206,8 +195,7 @@ TEST(ReadAfterParse, LevelMajorityOnly) { ReadConcernArgs readConcern; ASSERT_OK( readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kLevelFieldName << "majority")))); ASSERT_TRUE(!readConcern.getArgsOpTime()); @@ -219,8 +207,7 @@ TEST(ReadAfterParse, LevelSnapshotOnly) { ReadConcernArgs readConcern; ASSERT_OK( readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kLevelFieldName << "snapshot")))); ASSERT_TRUE(!readConcern.getArgsOpTime()); @@ -234,15 +221,12 @@ TEST(ReadAfterParse, ReadCommittedFullSpecification) { auto afterClusterTime = LogicalTime(Timestamp(100, 200)); ASSERT_NOT_OK(readConcern.initialize(BSON( "find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kAfterOpTimeFieldName << BSON(OpTime::kTimestampFieldName << Timestamp(20, 30) << OpTime::kTermFieldName << 2) - << ReadConcernArgs::kAfterClusterTimeFieldName - << afterClusterTime.asTimestamp() - << ReadConcernArgs::kLevelFieldName - << "majority")))); + << ReadConcernArgs::kAfterClusterTimeFieldName << afterClusterTime.asTimestamp() + << ReadConcernArgs::kLevelFieldName << "majority")))); } TEST(ReadAfterParse, Empty) { @@ -257,58 +241,51 @@ TEST(ReadAfterParse, Empty) { TEST(ReadAfterParse, BadRootType) { ReadConcernArgs readConcern; - ASSERT_NOT_OK(readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName - << "x"))); + ASSERT_NOT_OK( + readConcern.initialize(BSON("find" + << "test" << ReadConcernArgs::kReadConcernFieldName << "x"))); } TEST(ReadAfterParse, BadAtClusterTimeType) { ReadConcernArgs readConcern; ASSERT_EQ(ErrorCodes::TypeMismatch, readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kAtClusterTimeFieldName - << 2 - << ReadConcernArgs::kLevelFieldName + << 2 << ReadConcernArgs::kLevelFieldName << "snapshot")))); } TEST(ReadAfterParse, BadAtClusterTimeValue) { ReadConcernArgs readConcern; - ASSERT_EQ(ErrorCodes::InvalidOptions, - readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kAtClusterTimeFieldName - << LogicalTime::kUninitialized.asTimestamp() - << ReadConcernArgs::kLevelFieldName - << "snapshot")))); + ASSERT_EQ( + ErrorCodes::InvalidOptions, + readConcern.initialize(BSON("find" + << "test" << ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kAtClusterTimeFieldName + << LogicalTime::kUninitialized.asTimestamp() + << ReadConcernArgs::kLevelFieldName << "snapshot")))); } TEST(ReadAfterParse, BadOpTimeType) { ReadConcernArgs readConcern; ASSERT_NOT_OK( readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kAfterOpTimeFieldName << 2)))); } TEST(ReadAfterParse, OpTimeNotNeededForValidReadConcern) { ReadConcernArgs readConcern; ASSERT_OK(readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSONObj()))); } TEST(ReadAfterParse, NoOpTimeTS) { ReadConcernArgs readConcern; ASSERT_NOT_OK(readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kAfterOpTimeFieldName << BSON(OpTime::kTimestampFieldName << 2))))); } @@ -316,40 +293,36 @@ TEST(ReadAfterParse, NoOpTimeTS) { TEST(ReadAfterParse, NoOpTimeTerm) { ReadConcernArgs readConcern; ASSERT_NOT_OK(readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kAfterOpTimeFieldName << BSON(OpTime::kTermFieldName << 2))))); } TEST(ReadAfterParse, BadOpTimeTSType) { ReadConcernArgs readConcern; - ASSERT_NOT_OK(readConcern.initialize( - BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kAfterOpTimeFieldName - << BSON(OpTime::kTimestampFieldName << BSON("x" << 1) << OpTime::kTermFieldName - << 2))))); + ASSERT_NOT_OK(readConcern.initialize(BSON("find" + << "test" << ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kAfterOpTimeFieldName + << BSON(OpTime::kTimestampFieldName + << BSON("x" << 1) + << OpTime::kTermFieldName << 2))))); } TEST(ReadAfterParse, BadOpTimeTermType) { ReadConcernArgs readConcern; - ASSERT_NOT_OK(readConcern.initialize(BSON( - "find" - << "test" - << ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kAfterOpTimeFieldName - << BSON(OpTime::kTimestampFieldName << Timestamp(1, 0) << OpTime::kTermFieldName - << "y"))))); + ASSERT_NOT_OK(readConcern.initialize(BSON("find" + << "test" << ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kAfterOpTimeFieldName + << BSON(OpTime::kTimestampFieldName + << Timestamp(1, 0) + << OpTime::kTermFieldName << "y"))))); } TEST(ReadAfterParse, BadLevelType) { ReadConcernArgs readConcern; ASSERT_EQ(ErrorCodes::TypeMismatch, readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kLevelFieldName << 7)))); } @@ -357,8 +330,7 @@ TEST(ReadAfterParse, BadLevelValue) { ReadConcernArgs readConcern; ASSERT_EQ(ErrorCodes::FailedToParse, readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kLevelFieldName << "seven is not a real level")))); } @@ -367,39 +339,35 @@ TEST(ReadAfterParse, BadOption) { ReadConcernArgs readConcern; ASSERT_EQ(ErrorCodes::InvalidOptions, readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON("asdf" << 1)))); } TEST(ReadAfterParse, AtClusterTimeAndAfterClusterTime) { ReadConcernArgs readConcern; auto clusterTime = LogicalTime(Timestamp(20, 30)); - ASSERT_EQ(ErrorCodes::InvalidOptions, - readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kAtClusterTimeFieldName - << clusterTime.asTimestamp() - << ReadConcernArgs::kAfterClusterTimeFieldName - << clusterTime.asTimestamp() - << ReadConcernArgs::kLevelFieldName - << "snapshot")))); + ASSERT_EQ( + ErrorCodes::InvalidOptions, + readConcern.initialize(BSON("find" + << "test" << ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kAtClusterTimeFieldName + << clusterTime.asTimestamp() + << ReadConcernArgs::kAfterClusterTimeFieldName + << clusterTime.asTimestamp() + << ReadConcernArgs::kLevelFieldName << "snapshot")))); } TEST(ReadAfterParse, AfterOpTimeAndLevelSnapshot) { ReadConcernArgs readConcern; - ASSERT_EQ(ErrorCodes::InvalidOptions, - readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kAfterOpTimeFieldName - << BSON(OpTime::kTimestampFieldName - << Timestamp(20, 30) - << OpTime::kTermFieldName - << 2) - << ReadConcernArgs::kLevelFieldName - << "snapshot")))); + ASSERT_EQ( + ErrorCodes::InvalidOptions, + readConcern.initialize(BSON("find" + << "test" << ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kAfterOpTimeFieldName + << BSON(OpTime::kTimestampFieldName + << Timestamp(20, 30) << OpTime::kTermFieldName + << 2) + << ReadConcernArgs::kLevelFieldName << "snapshot")))); } TEST(ReadAfterSerialize, Empty) { @@ -430,10 +398,10 @@ TEST(ReadAfterSerialize, AfterOpTimeOnly) { ReadConcernArgs readConcern(OpTime(Timestamp(20, 30), 2), boost::none); readConcern.appendInfo(&builder); - BSONObj expectedObj(BSON( - ReadConcernArgs::kReadConcernFieldName << BSON( - ReadConcernArgs::kAfterOpTimeFieldName << BSON( - OpTime::kTimestampFieldName << Timestamp(20, 30) << OpTime::kTermFieldName << 2)))); + BSONObj expectedObj(BSON(ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kAfterOpTimeFieldName << BSON( + OpTime::kTimestampFieldName + << Timestamp(20, 30) << OpTime::kTermFieldName << 2)))); ASSERT_BSONOBJ_EQ(expectedObj, builder.done()); } @@ -455,11 +423,10 @@ TEST(ReadAfterSerialize, iAfterCLusterTimeAndLevel) { ReadConcernArgs readConcern(afterClusterTime, ReadConcernLevel::kMajorityReadConcern); readConcern.appendInfo(&builder); - BSONObj expectedObj( - BSON(ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kLevelFieldName << "majority" - << ReadConcernArgs::kAfterClusterTimeFieldName - << afterClusterTime.asTimestamp()))); + BSONObj expectedObj(BSON(ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kLevelFieldName + << "majority" << ReadConcernArgs::kAfterClusterTimeFieldName + << afterClusterTime.asTimestamp()))); ASSERT_BSONOBJ_EQ(expectedObj, builder.done()); } @@ -470,13 +437,11 @@ TEST(ReadAfterSerialize, AfterOpTimeAndLevel) { ReadConcernLevel::kMajorityReadConcern); readConcern.appendInfo(&builder); - BSONObj expectedObj(BSON( - ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kLevelFieldName - << "majority" - << ReadConcernArgs::kAfterOpTimeFieldName - << BSON(OpTime::kTimestampFieldName << Timestamp(20, 30) << OpTime::kTermFieldName - << 2)))); + BSONObj expectedObj(BSON(ReadConcernArgs::kReadConcernFieldName << BSON( + ReadConcernArgs::kLevelFieldName + << "majority" << ReadConcernArgs::kAfterOpTimeFieldName + << BSON(OpTime::kTimestampFieldName + << Timestamp(20, 30) << OpTime::kTermFieldName << 2)))); ASSERT_BSONOBJ_EQ(expectedObj, builder.done()); } @@ -486,8 +451,7 @@ TEST(ReadAfterSerialize, AtClusterTimeAndLevelSnapshot) { ReadConcernArgs readConcern; auto atClusterTime = LogicalTime(Timestamp(20, 30)); ASSERT_OK(readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kLevelFieldName << "snapshot" << ReadConcernArgs::kAtClusterTimeFieldName @@ -495,11 +459,10 @@ TEST(ReadAfterSerialize, AtClusterTimeAndLevelSnapshot) { readConcern.appendInfo(&builder); - BSONObj expectedObj( - BSON(ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kLevelFieldName << "snapshot" - << ReadConcernArgs::kAtClusterTimeFieldName - << atClusterTime.asTimestamp()))); + BSONObj expectedObj(BSON(ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kLevelFieldName + << "snapshot" << ReadConcernArgs::kAtClusterTimeFieldName + << atClusterTime.asTimestamp()))); ASSERT_BSONOBJ_EQ(expectedObj, builder.done()); } @@ -516,8 +479,7 @@ TEST(UpconvertReadConcernLevelToSnapshot, EmptyLevel) { TEST(UpconvertReadConcernLevelToSnapshot, LevelLocal) { ReadConcernArgs readConcern; ASSERT_OK(readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kLevelFieldName << "local")))); ASSERT(ReadConcernLevel::kLocalReadConcern == readConcern.getLevel()); @@ -530,8 +492,7 @@ TEST(UpconvertReadConcernLevelToSnapshot, LevelMajority) { ReadConcernArgs readConcern; ASSERT_OK( readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kLevelFieldName << "majority")))); ASSERT(ReadConcernLevel::kMajorityReadConcern == readConcern.getLevel()); @@ -544,8 +505,7 @@ TEST(UpconvertReadConcernLevelToSnapshot, LevelSnapshot) { ReadConcernArgs readConcern; ASSERT_OK( readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kLevelFieldName << "snapshot")))); ASSERT(ReadConcernLevel::kSnapshotReadConcern == readConcern.getLevel()); @@ -558,8 +518,7 @@ TEST(UpconvertReadConcernLevelToSnapshot, LevelSnapshotWithAtClusterTime) { ReadConcernArgs readConcern; auto atClusterTime = LogicalTime(Timestamp(20, 30)); ASSERT_OK(readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kLevelFieldName << "snapshot" << ReadConcernArgs::kAtClusterTimeFieldName @@ -577,8 +536,7 @@ TEST(UpconvertReadConcernLevelToSnapshot, AfterClusterTime) { ReadConcernArgs readConcern; auto afterClusterTime = LogicalTime(Timestamp(20, 30)); ASSERT_OK(readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kAfterClusterTimeFieldName << afterClusterTime.asTimestamp())))); ASSERT(ReadConcernLevel::kLocalReadConcern == readConcern.getLevel()); @@ -594,8 +552,7 @@ TEST(UpconvertReadConcernLevelToSnapshot, LevelAvailable) { ReadConcernArgs readConcern; ASSERT_OK( readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kLevelFieldName << "available")))); ASSERT(ReadConcernLevel::kAvailableReadConcern == readConcern.getLevel()); @@ -608,8 +565,7 @@ TEST(UpconvertReadConcernLevelToSnapshot, LevelLinearizable) { ReadConcernArgs readConcern; ASSERT_OK( readConcern.initialize(BSON("find" - << "test" - << ReadConcernArgs::kReadConcernFieldName + << "test" << ReadConcernArgs::kReadConcernFieldName << BSON(ReadConcernArgs::kLevelFieldName << "linearizable")))); ASSERT(ReadConcernLevel::kLinearizableReadConcern == readConcern.getLevel()); @@ -620,13 +576,12 @@ TEST(UpconvertReadConcernLevelToSnapshot, LevelLinearizable) { TEST(UpconvertReadConcernLevelToSnapshot, AfterOpTime) { ReadConcernArgs readConcern; - ASSERT_OK(readConcern.initialize(BSON( - "find" - << "test" - << ReadConcernArgs::kReadConcernFieldName - << BSON(ReadConcernArgs::kAfterOpTimeFieldName - << BSON(OpTime::kTimestampFieldName << Timestamp(20, 30) << OpTime::kTermFieldName - << 2))))); + ASSERT_OK(readConcern.initialize(BSON("find" + << "test" << ReadConcernArgs::kReadConcernFieldName + << BSON(ReadConcernArgs::kAfterOpTimeFieldName + << BSON(OpTime::kTimestampFieldName + << Timestamp(20, 30) + << OpTime::kTermFieldName << 2))))); ASSERT(ReadConcernLevel::kLocalReadConcern == readConcern.getLevel()); ASSERT_TRUE(readConcern.getArgsOpTime()); diff --git a/src/mongo/db/repl/repl_set_config.cpp b/src/mongo/db/repl/repl_set_config.cpp index 7614bd7ff7b..db794713203 100644 --- a/src/mongo/db/repl/repl_set_config.cpp +++ b/src/mongo/db/repl/repl_set_config.cpp @@ -138,17 +138,16 @@ Status ReplSetConfig::_initialize(const BSONObj& cfg, bool forInitiate, OID defa if (memberElement.type() != Object) { return Status(ErrorCodes::TypeMismatch, str::stream() << "Expected type of " << kMembersFieldName << "." - << memberElement.fieldName() - << " to be Object, but found " + << memberElement.fieldName() << " to be Object, but found " << typeName(memberElement.type())); } const auto& memberBSON = memberElement.Obj(); try { _members.emplace_back(memberBSON, &_tagConfig); } catch (const DBException& ex) { - return Status( - ErrorCodes::InvalidReplicaSetConfig, - str::stream() << ex.toStatus().toString() << " for member:" << memberBSON); + return Status(ErrorCodes::InvalidReplicaSetConfig, + str::stream() + << ex.toStatus().toString() << " for member:" << memberBSON); } } @@ -348,43 +347,35 @@ Status ReplSetConfig::_parseSettingsSubdocument(const BSONObj& settings) { if (_customWriteConcernModes.find(modeElement.fieldNameStringData()) != _customWriteConcernModes.end()) { return Status(ErrorCodes::Error(51001), - str::stream() << kSettingsFieldName << '.' << kGetLastErrorModesFieldName - << " contains multiple fields named " - << modeElement.fieldName()); + str::stream() + << kSettingsFieldName << '.' << kGetLastErrorModesFieldName + << " contains multiple fields named " << modeElement.fieldName()); } if (modeElement.type() != Object) { return Status(ErrorCodes::TypeMismatch, - str::stream() << "Expected " << kSettingsFieldName << '.' - << kGetLastErrorModesFieldName - << '.' - << modeElement.fieldName() - << " to be an Object, not " - << typeName(modeElement.type())); + str::stream() + << "Expected " << kSettingsFieldName << '.' + << kGetLastErrorModesFieldName << '.' << modeElement.fieldName() + << " to be an Object, not " << typeName(modeElement.type())); } ReplSetTagPattern pattern = _tagConfig.makePattern(); for (auto&& constraintElement : modeElement.Obj()) { if (!constraintElement.isNumber()) { return Status(ErrorCodes::TypeMismatch, - str::stream() << "Expected " << kSettingsFieldName << '.' - << kGetLastErrorModesFieldName - << '.' - << modeElement.fieldName() - << '.' - << constraintElement.fieldName() - << " to be a number, not " - << typeName(constraintElement.type())); + str::stream() + << "Expected " << kSettingsFieldName << '.' + << kGetLastErrorModesFieldName << '.' << modeElement.fieldName() + << '.' << constraintElement.fieldName() << " to be a number, not " + << typeName(constraintElement.type())); } const int minCount = constraintElement.numberInt(); if (minCount <= 0) { return Status(ErrorCodes::BadValue, - str::stream() << "Value of " << kSettingsFieldName << '.' - << kGetLastErrorModesFieldName - << '.' - << modeElement.fieldName() - << '.' - << constraintElement.fieldName() - << " must be positive, but found " - << minCount); + str::stream() + << "Value of " << kSettingsFieldName << '.' + << kGetLastErrorModesFieldName << '.' << modeElement.fieldName() + << '.' << constraintElement.fieldName() + << " must be positive, but found " << minCount); } status = _tagConfig.addTagCountConstraintToPattern( &pattern, constraintElement.fieldNameStringData(), minCount); @@ -420,8 +411,7 @@ Status ReplSetConfig::validate() const { if (_replSetName.empty()) { return Status(ErrorCodes::BadValue, str::stream() << "Replica set configuration must have non-empty " - << kIdFieldName - << " field"); + << kIdFieldName << " field"); } if (_heartbeatInterval < Milliseconds(0)) { return Status(ErrorCodes::BadValue, @@ -506,41 +496,22 @@ Status ReplSetConfig::validate() const { const MemberConfig& memberJ = _members[j]; if (memberI.getId() == memberJ.getId()) { return Status(ErrorCodes::BadValue, - str::stream() << "Found two member configurations with same " - << MemberConfig::kIdFieldName - << " field, " - << kMembersFieldName - << "." - << i - << "." - << MemberConfig::kIdFieldName - << " == " - << kMembersFieldName - << "." - << j - << "." - << MemberConfig::kIdFieldName - << " == " - << memberI.getId()); + str::stream() + << "Found two member configurations with same " + << MemberConfig::kIdFieldName << " field, " << kMembersFieldName + << "." << i << "." << MemberConfig::kIdFieldName + << " == " << kMembersFieldName << "." << j << "." + << MemberConfig::kIdFieldName << " == " << memberI.getId()); } if (memberI.getHostAndPort() == memberJ.getHostAndPort()) { return Status(ErrorCodes::BadValue, - str::stream() << "Found two member configurations with same " - << MemberConfig::kHostFieldName - << " field, " - << kMembersFieldName - << "." - << i - << "." - << MemberConfig::kHostFieldName - << " == " - << kMembersFieldName - << "." - << j - << "." - << MemberConfig::kHostFieldName - << " == " - << memberI.getHostAndPort().toString()); + str::stream() + << "Found two member configurations with same " + << MemberConfig::kHostFieldName << " field, " << kMembersFieldName + << "." << i << "." << MemberConfig::kHostFieldName + << " == " << kMembersFieldName << "." << j << "." + << MemberConfig::kHostFieldName + << " == " << memberI.getHostAndPort().toString()); } } } @@ -593,9 +564,7 @@ Status ReplSetConfig::validate() const { str::stream() << "Either all host names in a replica set configuration must be localhost " "references, or none must be; found " - << localhostCount - << " out of " - << _members.size()); + << localhostCount << " out of " << _members.size()); } if (voterCount > kMaxVotingMembers || voterCount == 0) { @@ -636,9 +605,9 @@ Status ReplSetConfig::validate() const { } if (_protocolVersion != 1) { return Status(ErrorCodes::BadValue, - str::stream() << kProtocolVersionFieldName - << " of 1 is the only supported value. Found: " - << _protocolVersion); + str::stream() + << kProtocolVersionFieldName + << " of 1 is the only supported value. Found: " << _protocolVersion); } if (_configServer) { @@ -708,8 +677,7 @@ Status ReplSetConfig::checkIfWriteConcernCanBeSatisfied( // write concern mode. return Status(ErrorCodes::UnsatisfiableWriteConcern, str::stream() << "Not enough nodes match write concern mode \"" - << writeConcern.wMode - << "\""); + << writeConcern.wMode << "\""); } else { int nodesRemaining = writeConcern.wNumNodes; for (size_t j = 0; j < _members.size(); ++j) { diff --git a/src/mongo/db/repl/repl_set_config_checks.cpp b/src/mongo/db/repl/repl_set_config_checks.cpp index 14cc8e99e61..5c0eeecdb97 100644 --- a/src/mongo/db/repl/repl_set_config_checks.cpp +++ b/src/mongo/db/repl/repl_set_config_checks.cpp @@ -63,10 +63,8 @@ StatusWith<int> findSelfInConfig(ReplicationCoordinatorExternalState* externalSt if (meConfigs.empty()) { return StatusWith<int>(ErrorCodes::NodeNotFound, str::stream() << "No host described in new configuration " - << newConfig.getConfigVersion() - << " for replica set " - << newConfig.getReplSetName() - << " maps to this node"); + << newConfig.getConfigVersion() << " for replica set " + << newConfig.getReplSetName() << " maps to this node"); } if (meConfigs.size() > 1) { str::stream message; @@ -95,11 +93,9 @@ Status checkElectable(const ReplSetConfig& newConfig, int configIndex) { if (!myConfig.isElectable()) { return Status(ErrorCodes::NodeNotElectable, str::stream() << "This node, " << myConfig.getHostAndPort().toString() - << ", with _id " - << myConfig.getId() + << ", with _id " << myConfig.getId() << " is not electable under the new configuration version " - << newConfig.getConfigVersion() - << " for replica set " + << newConfig.getConfigVersion() << " for replica set " << newConfig.getReplSetName()); } return Status::OK(); @@ -133,8 +129,7 @@ Status validateArbiterPriorities(const ReplSetConfig& config) { if (iter->isArbiter() && iter->getPriority() != 0) { return Status(ErrorCodes::InvalidReplicaSetConfig, str::stream() << "Member " << iter->getHostAndPort().toString() - << " is an arbiter but has priority " - << iter->getPriority() + << " is an arbiter but has priority " << iter->getPriority() << ". Arbiter priority must be 0."); } } @@ -164,10 +159,8 @@ Status validateOldAndNewConfigsCompatible(const ReplSetConfig& oldConfig, return Status(ErrorCodes::NewReplicaSetConfigurationIncompatible, str::stream() << "New replica set configuration version must be greater than old, but " - << newConfig.getConfigVersion() - << " is not greater than " - << oldConfig.getConfigVersion() - << " for replica set " + << newConfig.getConfigVersion() << " is not greater than " + << oldConfig.getConfigVersion() << " for replica set " << newConfig.getReplSetName()); } @@ -175,8 +168,7 @@ Status validateOldAndNewConfigsCompatible(const ReplSetConfig& oldConfig, return Status(ErrorCodes::NewReplicaSetConfigurationIncompatible, str::stream() << "New and old configurations differ in replica set name; " "old was " - << oldConfig.getReplSetName() - << ", and new is " + << oldConfig.getReplSetName() << ", and new is " << newConfig.getReplSetName()); } @@ -184,8 +176,7 @@ Status validateOldAndNewConfigsCompatible(const ReplSetConfig& oldConfig, return Status(ErrorCodes::NewReplicaSetConfigurationIncompatible, str::stream() << "New and old configurations differ in replica set ID; " "old was " - << oldConfig.getReplicaSetId() - << ", and new is " + << oldConfig.getReplicaSetId() << ", and new is " << newConfig.getReplicaSetId()); } @@ -216,18 +207,14 @@ Status validateOldAndNewConfigsCompatible(const ReplSetConfig& oldConfig, } if (hostsEqual && !idsEqual) { return Status(ErrorCodes::NewReplicaSetConfigurationIncompatible, - str::stream() << "New and old configurations both have members with " - << MemberConfig::kHostFieldName - << " of " - << mOld->getHostAndPort().toString() - << " but in the new configuration the " - << MemberConfig::kIdFieldName - << " field is " - << mNew->getId() - << " and in the old configuration it is " - << mOld->getId() - << " for replica set " - << newConfig.getReplSetName()); + str::stream() + << "New and old configurations both have members with " + << MemberConfig::kHostFieldName << " of " + << mOld->getHostAndPort().toString() + << " but in the new configuration the " + << MemberConfig::kIdFieldName << " field is " << mNew->getId() + << " and in the old configuration it is " << mOld->getId() + << " for replica set " << newConfig.getReplSetName()); } // At this point, the _id and host fields are equal, so we're looking at the old and // new configurations for the same member node. diff --git a/src/mongo/db/repl/repl_set_config_checks_test.cpp b/src/mongo/db/repl/repl_set_config_checks_test.cpp index b8579f1f6e2..c887e11f69b 100644 --- a/src/mongo/db/repl/repl_set_config_checks_test.cpp +++ b/src/mongo/db/repl/repl_set_config_checks_test.cpp @@ -49,34 +49,28 @@ TEST_F(ServiceContextTest, ValidateConfigForInitiate_VersionMustBe1) { rses.addSelf(HostAndPort("h1")); ReplSetConfig config; - ASSERT_OK(config.initializeForInitiate(BSON("_id" - << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1"))))); + ASSERT_OK( + config.initializeForInitiate(BSON("_id" + << "rs0" + << "version" << 2 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1"))))); ASSERT_EQUALS(ErrorCodes::NewReplicaSetConfigurationIncompatible, validateConfigForInitiate(&rses, config, getGlobalServiceContext()).getStatus()); } TEST_F(ServiceContextTest, ValidateConfigForInitiate_MustFindSelf) { ReplSetConfig config; - ASSERT_OK(config.initializeForInitiate(BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1") - << BSON("_id" << 2 << "host" - << "h2") - << BSON("_id" << 3 << "host" - << "h3"))))); + ASSERT_OK( + config.initializeForInitiate(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1") + << BSON("_id" << 2 << "host" + << "h2") + << BSON("_id" << 3 << "host" + << "h3"))))); ReplicationCoordinatorExternalStateMock notPresentExternalState; ReplicationCoordinatorExternalStateMock presentOnceExternalState; presentOnceExternalState.addSelf(HostAndPort("h2")); @@ -99,21 +93,17 @@ TEST_F(ServiceContextTest, ValidateConfigForInitiate_MustFindSelf) { TEST_F(ServiceContextTest, ValidateConfigForInitiate_SelfMustBeElectable) { ReplSetConfig config; - ASSERT_OK(config.initializeForInitiate(BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1") - << BSON("_id" << 2 << "host" - << "h2" - << "priority" - << 0) - << BSON("_id" << 3 << "host" - << "h3"))))); + ASSERT_OK( + config.initializeForInitiate(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1") + << BSON("_id" << 2 << "host" + << "h2" + << "priority" << 0) + << BSON("_id" << 3 << "host" + << "h3"))))); ReplicationCoordinatorExternalStateMock presentOnceExternalState; presentOnceExternalState.addSelf(HostAndPort("h2")); @@ -128,11 +118,7 @@ TEST_F(ServiceContextTest, ValidateConfigForInitiate_WriteConcernMustBeSatisfiab ASSERT_OK( config.initializeForInitiate(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1")) << "settings" @@ -152,55 +138,37 @@ TEST_F(ServiceContextTest, ValidateConfigForInitiate_ArbiterPriorityMustBeZeroOr ReplSetConfig twoConfig; ASSERT_OK(zeroConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 0 - << "arbiterOnly" - << true) + << "priority" << 0 + << "arbiterOnly" << true) << BSON("_id" << 3 << "host" << "h3"))))); ASSERT_OK(oneConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 1 - << "arbiterOnly" - << true) + << "priority" << 1 + << "arbiterOnly" << true) << BSON("_id" << 3 << "host" << "h3"))))); ASSERT_OK(twoConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 2 - << "arbiterOnly" - << true) + << "priority" << 2 + << "arbiterOnly" << true) << BSON("_id" << 3 << "host" << "h3"))))); ReplicationCoordinatorExternalStateMock presentOnceExternalState; @@ -228,11 +196,7 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_NewConfigVersionNumberMustB // Two configurations, identical except for version. ASSERT_OK(oldConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" @@ -242,11 +206,7 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_NewConfigVersionNumberMustB ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 3 - << "protocolVersion" - << 1 - << "members" + << "version" << 3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" @@ -296,11 +256,7 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_NewConfigMustNotChangeSetNa // Two configurations, compatible except for set name. ASSERT_OK(oldConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" @@ -310,11 +266,7 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_NewConfigMustNotChangeSetNa ASSERT_OK(newConfig.initialize(BSON("_id" << "rs1" - << "version" - << 3 - << "protocolVersion" - << 1 - << "members" + << "version" << 3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" @@ -345,35 +297,25 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_NewConfigMustNotChangeSetId // Two configurations, compatible except for set ID. ASSERT_OK(oldConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" << "h2") << BSON("_id" << 3 << "host" << "h3")) - << "settings" - << BSON("replicaSetId" << OID::gen())))); + << "settings" << BSON("replicaSetId" << OID::gen())))); ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 3 - << "protocolVersion" - << 1 - << "members" + << "version" << 3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" << "h2") << BSON("_id" << 3 << "host" << "h3")) - << "settings" - << BSON("replicaSetId" << OID::gen())))); + << "settings" << BSON("replicaSetId" << OID::gen())))); ASSERT_OK(oldConfig.validate()); ASSERT_OK(newConfig.validate()); @@ -402,57 +344,40 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_NewConfigMustNotFlipBuildIn // The third, compatible with the first. ASSERT_OK(oldConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" << "h2" - << "buildIndexes" - << false - << "priority" - << 0) + << "buildIndexes" << false + << "priority" << 0) << BSON("_id" << 3 << "host" << "h3"))))); ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 3 - << "protocolVersion" - << 1 - << "members" + << "version" << 3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" << "h2" - << "buildIndexes" - << true - << "priority" - << 0) + << "buildIndexes" << true + << "priority" << 0) << BSON("_id" << 3 << "host" << "h3"))))); - ASSERT_OK(oldConfigRefresh.initialize(BSON("_id" - << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1") - << BSON("_id" << 2 << "host" - << "h2" - << "buildIndexes" - << false - << "priority" - << 0) - << BSON("_id" << 3 << "host" - << "h3"))))); + ASSERT_OK( + oldConfigRefresh.initialize(BSON("_id" + << "rs0" + << "version" << 2 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1") + << BSON("_id" << 2 << "host" + << "h2" + << "buildIndexes" << false + << "priority" << 0) + << BSON("_id" << 3 << "host" + << "h3"))))); ASSERT_OK(oldConfig.validate()); ASSERT_OK(newConfig.validate()); @@ -484,51 +409,37 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_NewConfigMustNotFlipArbiter // The third, compatible with the first. ASSERT_OK(oldConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" << "h2" - << "arbiterOnly" - << false) + << "arbiterOnly" << false) << BSON("_id" << 3 << "host" << "h3"))))); ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 3 - << "protocolVersion" - << 1 - << "members" + << "version" << 3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" << "h2" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 3 << "host" << "h3"))))); - ASSERT_OK(oldConfigRefresh.initialize(BSON("_id" - << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1") - << BSON("_id" << 2 << "host" - << "h2" - << "arbiterOnly" - << false) - << BSON("_id" << 3 << "host" - << "h3"))))); + ASSERT_OK( + oldConfigRefresh.initialize(BSON("_id" + << "rs0" + << "version" << 2 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1") + << BSON("_id" << 2 << "host" + << "h2" + << "arbiterOnly" << false) + << BSON("_id" << 3 << "host" + << "h3"))))); ASSERT_OK(oldConfig.validate()); ASSERT_OK(newConfig.validate()); @@ -562,11 +473,7 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_HostAndIdRemappingRestricte ASSERT_OK(oldConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" @@ -582,10 +489,7 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_HostAndIdRemappingRestricte ASSERT_OK( legalNewConfigWithNewHostAndId.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") @@ -607,11 +511,8 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_HostAndIdRemappingRestricte // ASSERT_OK(illegalNewConfigReusingHost.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" + << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 4 << "host" @@ -638,10 +539,7 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_HostAndIdRemappingRestricte // ASSERT_OK(illegalNewConfigReusingId.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") @@ -662,11 +560,7 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_MustFindSelf) { ReplSetConfig oldConfig; ASSERT_OK(oldConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" @@ -677,11 +571,7 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_MustFindSelf) { ReplSetConfig newConfig; ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" @@ -738,69 +628,46 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_ArbiterPriorityValueMustBeZ ASSERT_OK(oldConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" << "h2" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 3 << "host" << "h3"))))); ASSERT_OK(zeroConfig.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 0 - << "arbiterOnly" - << true) + << "priority" << 0 + << "arbiterOnly" << true) << BSON("_id" << 3 << "host" << "h3"))))); ASSERT_OK(oneConfig.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 1 - << "arbiterOnly" - << true) + << "priority" << 1 + << "arbiterOnly" << true) << BSON("_id" << 3 << "host" << "h3"))))); ASSERT_OK(twoConfig.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 2 - << "arbiterOnly" - << true) + << "priority" << 2 + << "arbiterOnly" << true) << BSON("_id" << 3 << "host" << "h3"))))); @@ -831,11 +698,7 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_SelfMustEndElectable) { ReplSetConfig oldConfig; ASSERT_OK(oldConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" @@ -846,17 +709,12 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_SelfMustEndElectable) { ReplSetConfig newConfig; ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1") << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 0) + << "priority" << 0) << BSON("_id" << 3 << "host" << "h3"))))); ReplicationCoordinatorExternalStateMock presentOnceExternalState; @@ -880,10 +738,7 @@ TEST_F(ServiceContextTest, ValidateConfigForInitiate_NewConfigInvalid) { ReplSetConfig newConfig; ASSERT_OK(newConfig.initializeForInitiate(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "h2") @@ -905,22 +760,14 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_NewConfigInvalid) { ReplSetConfig oldConfig; ASSERT_OK(oldConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "h2"))))); ReplSetConfig newConfig; ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "h2") << BSON("_id" << 0 << "host" @@ -948,22 +795,14 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_NewConfigWriteConcernNotSat ReplSetConfig oldConfig; ASSERT_OK(oldConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "h2"))))); ReplSetConfig newConfig; ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "h2")) << "settings" @@ -991,11 +830,7 @@ TEST_F(ServiceContextTest, ValidateConfigForStartUp_NewConfigInvalid) { ReplSetConfig newConfig; ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "h2") << BSON("_id" << 0 << "host" @@ -1015,15 +850,10 @@ TEST_F(ServiceContextTest, ValidateConfigForStartUp_NewConfigValid) { ReplSetConfig newConfig; ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "h2" - << "priority" - << 3) + << "priority" << 3) << BSON("_id" << 1 << "host" << "h3"))))); @@ -1041,11 +871,7 @@ TEST_F(ServiceContextTest, ValidateConfigForStartUp_NewConfigWriteConcernNotSati ReplSetConfig newConfig; ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "h2")) << "settings" @@ -1065,11 +891,7 @@ TEST_F(ServiceContextTest, ValidateConfigForHeartbeatReconfig_NewConfigInvalid) ReplSetConfig newConfig; ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "h2") << BSON("_id" << 0 << "host" @@ -1089,11 +911,7 @@ TEST_F(ServiceContextTest, ValidateConfigForHeartbeatReconfig_NewConfigValid) { ReplSetConfig newConfig; ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "h2") << BSON("_id" << 1 << "host" @@ -1112,11 +930,7 @@ TEST_F(ServiceContextTest, ValidateConfigForHeartbeatReconfig_NewConfigWriteConc ReplSetConfig newConfig; ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "h2") << BSON("_id" << 1 << "host" @@ -1137,11 +951,7 @@ TEST_F(ServiceContextTest, ValidateForReconfig_ForceStillNeedsValidConfig) { ReplSetConfig oldConfig; ASSERT_OK(oldConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "h2") << BSON("_id" << 1 << "host" @@ -1151,11 +961,7 @@ TEST_F(ServiceContextTest, ValidateForReconfig_ForceStillNeedsValidConfig) { ReplSetConfig newConfig; ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "h2") << BSON("_id" << 0 << "host" @@ -1176,11 +982,7 @@ TEST_F(ServiceContextTest, ValidateForReconfig_ForceStillNeedsSelfPresent) { ReplSetConfig oldConfig; ASSERT_OK(oldConfig.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "h2") << BSON("_id" << 1 << "host" @@ -1190,11 +992,7 @@ TEST_F(ServiceContextTest, ValidateForReconfig_ForceStillNeedsSelfPresent) { ReplSetConfig newConfig; ASSERT_OK(newConfig.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h3") << BSON("_id" << 2 << "host" diff --git a/src/mongo/db/repl/repl_set_config_test.cpp b/src/mongo/db/repl/repl_set_config_test.cpp index c795d711aa3..88d36b1b174 100644 --- a/src/mongo/db/repl/repl_set_config_test.cpp +++ b/src/mongo/db/repl/repl_set_config_test.cpp @@ -63,11 +63,7 @@ TEST(ReplSetConfig, ParseMinimalConfigAndCheckDefaults) { ReplSetConfig config; ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345"))))); ASSERT_OK(config.validate()); @@ -92,32 +88,24 @@ TEST(ReplSetConfig, ParseMinimalConfigAndCheckDefaults) { TEST(ReplSetConfig, ParseLargeConfigAndCheckAccessors) { ReplSetConfig config; - ASSERT_OK(config.initialize(BSON("_id" - << "rs0" - << "version" - << 1234 - << "members" - << BSON_ARRAY(BSON("_id" << 234 << "host" - << "localhost:12345" - << "tags" - << BSON("NYC" - << "NY"))) - << "protocolVersion" - << 1 - << "settings" - << BSON("getLastErrorDefaults" - << BSON("w" - << "majority") - << "getLastErrorModes" - << BSON("eastCoast" << BSON("NYC" << 1)) - << "chainingAllowed" - << false - << "heartbeatIntervalMillis" - << 5000 - << "heartbeatTimeoutSecs" - << 120 - << "electionTimeoutMillis" - << 10)))); + ASSERT_OK( + config.initialize(BSON("_id" + << "rs0" + << "version" << 1234 << "members" + << BSON_ARRAY(BSON("_id" << 234 << "host" + << "localhost:12345" + << "tags" + << BSON("NYC" + << "NY"))) + << "protocolVersion" << 1 << "settings" + << BSON("getLastErrorDefaults" + << BSON("w" + << "majority") + << "getLastErrorModes" + << BSON("eastCoast" << BSON("NYC" << 1)) << "chainingAllowed" + << false << "heartbeatIntervalMillis" << 5000 + << "heartbeatTimeoutSecs" << 120 << "electionTimeoutMillis" + << 10)))); ASSERT_OK(config.validate()); ASSERT_EQUALS("rs0", config.getReplSetName()); ASSERT_EQUALS(1234, config.getConfigVersion()); @@ -139,27 +127,20 @@ TEST(ReplSetConfig, ParseLargeConfigAndCheckAccessors) { TEST(ReplSetConfig, GetConnectionStringFiltersHiddenNodes) { ReplSetConfig config; - ASSERT_OK(config.initialize(BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "localhost:11111") - << BSON("_id" << 1 << "host" - << "localhost:22222" - << "arbiterOnly" - << true) - << BSON("_id" << 2 << "host" - << "localhost:33333" - << "hidden" - << true - << "priority" - << 0) - << BSON("_id" << 3 << "host" - << "localhost:44444"))))); + ASSERT_OK( + config.initialize(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "localhost:11111") + << BSON("_id" << 1 << "host" + << "localhost:22222" + << "arbiterOnly" << true) + << BSON("_id" << 2 << "host" + << "localhost:33333" + << "hidden" << true << "priority" << 0) + << BSON("_id" << 3 << "host" + << "localhost:44444"))))); ASSERT_OK(config.validate()); ASSERT_EQUALS(ConnectionString::forReplicaSet( "rs0", {HostAndPort{"localhost:11111"}, HostAndPort{"localhost:44444"}}) @@ -169,31 +150,22 @@ TEST(ReplSetConfig, GetConnectionStringFiltersHiddenNodes) { TEST(ReplSetConfig, MajorityCalculationThreeVotersNoArbiters) { ReplSetConfig config; - ASSERT_OK(config.initialize(BSON("_id" - << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1:1") - << BSON("_id" << 2 << "host" - << "h2:1") - << BSON("_id" << 3 << "host" - << "h3:1") - << BSON("_id" << 4 << "host" - << "h4:1" - << "votes" - << 0 - << "priority" - << 0) - << BSON("_id" << 5 << "host" - << "h5:1" - << "votes" - << 0 - << "priority" - << 0))))); + ASSERT_OK( + config.initialize(BSON("_id" + << "rs0" + << "version" << 2 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1:1") + << BSON("_id" << 2 << "host" + << "h2:1") + << BSON("_id" << 3 << "host" + << "h3:1") + << BSON("_id" << 4 << "host" + << "h4:1" + << "votes" << 0 << "priority" << 0) + << BSON("_id" << 5 << "host" + << "h5:1" + << "votes" << 0 << "priority" << 0))))); ASSERT_OK(config.validate()); ASSERT_EQUALS(2, config.getWriteMajority()); @@ -201,37 +173,25 @@ TEST(ReplSetConfig, MajorityCalculationThreeVotersNoArbiters) { TEST(ReplSetConfig, MajorityCalculationNearlyHalfArbiters) { ReplSetConfig config; - ASSERT_OK(config.initialize(BSON("_id" - << "mySet" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("host" - << "node1:12345" - << "_id" - << 0) - << BSON("host" - << "node2:12345" - << "_id" - << 1) - << BSON("host" - << "node3:12345" - << "_id" - << 2) - << BSON("host" - << "node4:12345" - << "_id" - << 3 - << "arbiterOnly" - << true) - << BSON("host" - << "node5:12345" - << "_id" - << 4 - << "arbiterOnly" - << true))))); + ASSERT_OK( + config.initialize(BSON("_id" + << "mySet" + << "version" << 2 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("host" + << "node1:12345" + << "_id" << 0) + << BSON("host" + << "node2:12345" + << "_id" << 1) + << BSON("host" + << "node3:12345" + << "_id" << 2) + << BSON("host" + << "node4:12345" + << "_id" << 3 << "arbiterOnly" << true) + << BSON("host" + << "node5:12345" + << "_id" << 4 << "arbiterOnly" << true))))); ASSERT_OK(config.validate()); ASSERT_EQUALS(3, config.getWriteMajority()); } @@ -240,68 +200,45 @@ TEST(ReplSetConfig, MajorityCalculationEvenNumberOfMembers) { ReplSetConfig config; ASSERT_OK(config.initialize(BSON("_id" << "mySet" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2) + << "_id" << 2) << BSON("host" << "node4:12345" - << "_id" - << 3))))); + << "_id" << 3))))); ASSERT_OK(config.validate()); ASSERT_EQUALS(3, config.getWriteMajority()); } TEST(ReplSetConfig, MajorityCalculationNearlyHalfSecondariesNoVotes) { ReplSetConfig config; - ASSERT_OK(config.initialize(BSON("_id" - << "mySet" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("host" - << "node1:12345" - << "_id" - << 0) - << BSON("host" - << "node2:12345" - << "_id" - << 1 - << "votes" - << 0 - << "priority" - << 0) - << BSON("host" - << "node3:12345" - << "_id" - << 2 - << "votes" - << 0 - << "priority" - << 0) - << BSON("host" - << "node4:12345" - << "_id" - << 3) - << BSON("host" - << "node5:12345" - << "_id" - << 4))))); + ASSERT_OK( + config.initialize(BSON("_id" + << "mySet" + << "version" << 2 << "protocolVersion" << 1 << "members" + << BSON_ARRAY( + BSON("host" + << "node1:12345" + << "_id" << 0) + << BSON("host" + << "node2:12345" + << "_id" << 1 << "votes" << 0 << "priority" << 0) + << BSON("host" + << "node3:12345" + << "_id" << 2 << "votes" << 0 << "priority" << 0) + << BSON("host" + << "node4:12345" + << "_id" << 3) + << BSON("host" + << "node5:12345" + << "_id" << 4))))); ASSERT_OK(config.validate()); ASSERT_EQUALS(2, config.getWriteMajority()); } @@ -317,18 +254,14 @@ TEST(ReplSetConfig, ParseFailsWithBadOrMissingIdField) { // Replica set name must be present. ASSERT_EQUALS( ErrorCodes::NoSuchKey, - config.initialize( - BSON("version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" - << "localhost:12345"))))); + config.initialize(BSON("version" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "localhost:12345"))))); // Empty repl set name parses, but does not validate. ASSERT_OK(config.initialize(BSON("_id" << "" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345"))))); @@ -341,9 +274,7 @@ TEST(ReplSetConfig, ParseFailsWithBadOrMissingVersionField) { ASSERT_EQUALS(ErrorCodes::NoSuchKey, config.initialize(BSON("_id" << "rs0" - << "protocolVersion" - << 1 - << "members" + << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345"))))); ASSERT_EQUALS(ErrorCodes::TypeMismatch, @@ -351,29 +282,19 @@ TEST(ReplSetConfig, ParseFailsWithBadOrMissingVersionField) { << "rs0" << "version" << "1" - << "protocolVersion" - << 1 - << "members" + << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345"))))); ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 1.0 - << "protocolVersion" - << 1 - << "members" + << "version" << 1.0 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345"))))); ASSERT_OK(config.validate()); ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 0.0 - << "protocolVersion" - << 1 - << "members" + << "version" << 0.0 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345"))))); ASSERT_EQUALS(ErrorCodes::BadValue, config.validate()); @@ -381,9 +302,7 @@ TEST(ReplSetConfig, ParseFailsWithBadOrMissingVersionField) { << "rs0" << "version" << static_cast<long long>(std::numeric_limits<int>::max()) + 1 - << "protocolVersion" - << 1 - << "members" + << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345"))))); ASSERT_EQUALS(ErrorCodes::BadValue, config.validate()); @@ -394,21 +313,13 @@ TEST(ReplSetConfig, ParseFailsWithBadMembers) { ASSERT_EQUALS(ErrorCodes::TypeMismatch, config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345") << "localhost:23456")))); ASSERT_NOT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("host" << "localhost:12345"))))); } @@ -417,11 +328,7 @@ TEST(ReplSetConfig, ParseFailsWithLocalNonLocalHostMix) { ReplSetConfig config; ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost") << BSON("_id" << 1 << "host" @@ -433,15 +340,11 @@ TEST(ReplSetConfig, ParseFailsWithNoElectableNodes) { ReplSetConfig config; const BSONObj configBsonNoElectableNodes = BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:1" - << "priority" - << 0) + << "priority" << 0) << BSON("_id" << 1 << "host" << "localhost:2" << "priority" @@ -450,57 +353,41 @@ TEST(ReplSetConfig, ParseFailsWithNoElectableNodes) { ASSERT_OK(config.initialize(configBsonNoElectableNodes)); ASSERT_EQUALS(ErrorCodes::BadValue, config.validate()); - const BSONObj configBsonNoElectableNodesOneArbiter = BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY( - BSON("_id" << 0 << "host" - << "localhost:1" - << "arbiterOnly" - << 1) - << BSON("_id" << 1 << "host" - << "localhost:2" - << "priority" - << 0))); + const BSONObj configBsonNoElectableNodesOneArbiter = + BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "localhost:1" + << "arbiterOnly" << 1) + << BSON("_id" << 1 << "host" + << "localhost:2" + << "priority" << 0))); ASSERT_OK(config.initialize(configBsonNoElectableNodesOneArbiter)); ASSERT_EQUALS(ErrorCodes::BadValue, config.validate()); - const BSONObj configBsonNoElectableNodesTwoArbiters = BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY( - BSON("_id" << 0 << "host" - << "localhost:1" - << "arbiterOnly" - << 1) - << BSON("_id" << 1 << "host" - << "localhost:2" - << "arbiterOnly" - << 1))); + const BSONObj configBsonNoElectableNodesTwoArbiters = + BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "localhost:1" + << "arbiterOnly" << 1) + << BSON("_id" << 1 << "host" + << "localhost:2" + << "arbiterOnly" << 1))); ASSERT_OK(config.initialize(configBsonNoElectableNodesOneArbiter)); ASSERT_EQUALS(ErrorCodes::BadValue, config.validate()); const BSONObj configBsonOneElectableNode = BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:1" - << "priority" - << 0) + << "priority" << 0) << BSON("_id" << 1 << "host" << "localhost:2" << "priority" @@ -511,46 +398,30 @@ TEST(ReplSetConfig, ParseFailsWithNoElectableNodes) { TEST(ReplSetConfig, ParseFailsWithTooFewVoters) { ReplSetConfig config; - const BSONObj configBsonNoVoters = BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "localhost:1" - << "votes" - << 0 - << "priority" - << 0) - << BSON("_id" << 1 << "host" - << "localhost:2" - << "votes" - << 0 - << "priority" - << 0))); + const BSONObj configBsonNoVoters = + BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "localhost:1" + << "votes" << 0 << "priority" << 0) + << BSON("_id" << 1 << "host" + << "localhost:2" + << "votes" << 0 << "priority" << 0))); ASSERT_OK(config.initialize(configBsonNoVoters)); ASSERT_EQUALS(ErrorCodes::BadValue, config.validate()); const BSONObj configBsonOneVoter = BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:1" - << "votes" - << 0 - << "priority" + << "votes" << 0 << "priority" << 0) << BSON("_id" << 1 << "host" << "localhost:2" - << "votes" - << 1))); + << "votes" << 1))); ASSERT_OK(config.initialize(configBsonOneVoter)); ASSERT_OK(config.validate()); } @@ -567,11 +438,7 @@ TEST(ReplSetConfig, ParseFailsWithDuplicateHost) { ReplSetConfig config; const BSONObj configBson = BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:1") << BSON("_id" << 1 << "host" @@ -621,14 +488,11 @@ TEST(ReplSetConfig, ParseFailsWithTooManyNodes) { TEST(ReplSetConfig, ParseFailsWithUnexpectedField) { ReplSetConfig config; - Status status = config.initialize(BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "unexpectedfield" - << "value")); + Status status = + config.initialize(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "unexpectedfield" + << "value")); ASSERT_EQUALS(ErrorCodes::BadValue, status); } @@ -636,11 +500,7 @@ TEST(ReplSetConfig, ParseFailsWithNonArrayMembersField) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << "value")); ASSERT_EQUALS(ErrorCodes::TypeMismatch, status); } @@ -649,11 +509,7 @@ TEST(ReplSetConfig, ParseFailsWithNonNumericHeartbeatIntervalMillisField) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) << "settings" @@ -671,11 +527,7 @@ TEST(ReplSetConfig, ParseFailsWithNonNumericElectionTimeoutMillisField) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) << "settings" @@ -688,11 +540,7 @@ TEST(ReplSetConfig, ParseFailsWithNonNumericHeartbeatTimeoutSecsField) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) << "settings" @@ -705,11 +553,7 @@ TEST(ReplSetConfig, ParseFailsWithNonBoolChainingAllowedField) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) << "settings" @@ -722,11 +566,7 @@ TEST(ReplSetConfig, ParseFailsWithNonBoolConfigServerField) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) << "configsvr" @@ -738,11 +578,7 @@ TEST(ReplSetConfig, ParseFailsWithNonObjectSettingsField) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) << "settings" @@ -754,11 +590,7 @@ TEST(ReplSetConfig, ParseFailsWithGetLastErrorDefaultsFieldUnparseable) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) << "settings" @@ -771,11 +603,7 @@ TEST(ReplSetConfig, ParseFailsWithNonObjectGetLastErrorDefaultsField) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) << "settings" @@ -788,11 +616,7 @@ TEST(ReplSetConfig, ParseFailsWithNonObjectGetLastErrorModesField) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) << "settings" @@ -805,11 +629,7 @@ TEST(ReplSetConfig, ParseFailsWithDuplicateGetLastErrorModesField) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" << "tags" @@ -824,20 +644,16 @@ TEST(ReplSetConfig, ParseFailsWithDuplicateGetLastErrorModesField) { TEST(ReplSetConfig, ParseFailsWithNonObjectGetLastErrorModesEntryField) { ReplSetConfig config; - Status status = config.initialize(BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "localhost:12345" - << "tags" - << BSON("tag" - << "yes"))) - << "settings" - << BSON("getLastErrorModes" << BSON("one" << 1)))); + Status status = + config.initialize(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "localhost:12345" + << "tags" + << BSON("tag" + << "yes"))) + << "settings" << BSON("getLastErrorModes" << BSON("one" << 1)))); ASSERT_EQUALS(ErrorCodes::TypeMismatch, status); } @@ -846,11 +662,7 @@ TEST(ReplSetConfig, ParseFailsWithNonNumericGetLastErrorModesConstraintValue) { Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" << "tags" @@ -867,11 +679,7 @@ TEST(ReplSetConfig, ParseFailsWithNegativeGetLastErrorModesConstraintValue) { Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" << "tags" @@ -887,11 +695,7 @@ TEST(ReplSetConfig, ParseFailsWithNonExistentGetLastErrorModesConstraintTag) { Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" << "tags" @@ -906,13 +710,8 @@ TEST(ReplSetConfig, ParseFailsWithRepairField) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "repaired" - << true - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "repaired" << true << "version" << 1 + << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")))); ASSERT_EQUALS(ErrorCodes::RepairedReplicaSetNode, status); @@ -922,11 +721,7 @@ TEST(ReplSetConfig, ValidateFailsWithBadProtocolVersion) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "protocolVersion" - << 3 - << "version" - << 1 - << "members" + << "protocolVersion" << 3 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345") << BSON("_id" << 1 << "host" @@ -941,11 +736,7 @@ TEST(ReplSetConfig, ValidateFailsWithProtocolVersion0) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "protocolVersion" - << 0 - << "version" - << 1 - << "members" + << "protocolVersion" << 0 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345") << BSON("_id" << 1 << "host" @@ -960,11 +751,7 @@ TEST(ReplSetConfig, ValidateFailsWithDuplicateMemberId) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345") << BSON("_id" << 0 << "host" @@ -979,15 +766,10 @@ TEST(ReplSetConfig, ValidateFailsWithInvalidMember) { ReplSetConfig config; Status status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" - << "hidden" - << true)))); + << "hidden" << true)))); ASSERT_OK(status); status = config.validate(); @@ -998,29 +780,19 @@ TEST(ReplSetConfig, ChainingAllowedField) { ReplSetConfig config; ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) - << "settings" - << BSON("chainingAllowed" << true)))); + << "settings" << BSON("chainingAllowed" << true)))); ASSERT_OK(config.validate()); ASSERT_TRUE(config.isChainingAllowed()); ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) - << "settings" - << BSON("chainingAllowed" << false)))); + << "settings" << BSON("chainingAllowed" << false)))); ASSERT_OK(config.validate()); ASSERT_FALSE(config.isChainingAllowed()); } @@ -1029,13 +801,8 @@ TEST(ReplSetConfig, ConfigServerField) { ReplSetConfig config; ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "protocolVersion" - << 1 - << "version" - << 1 - << "configsvr" - << true - << "members" + << "protocolVersion" << 1 << "version" << 1 << "configsvr" + << true << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345"))))); ASSERT_TRUE(config.isConfigServer()); @@ -1043,13 +810,8 @@ TEST(ReplSetConfig, ConfigServerField) { ReplSetConfig config2; ASSERT_OK(config2.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "configsvr" - << false - << "members" + << "version" << 1 << "protocolVersion" << 1 << "configsvr" + << false << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345"))))); ASSERT_FALSE(config2.isConfigServer()); @@ -1072,25 +834,18 @@ TEST(ReplSetConfig, ConfigServerFieldDefaults) { ReplSetConfig config; ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" + << "protocolVersion" << 1 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345"))))); ASSERT_FALSE(config.isConfigServer()); ReplSetConfig config2; - ASSERT_OK(config2.initializeForInitiate(BSON("_id" - << "rs0" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "localhost:12345"))))); + ASSERT_OK( + config2.initializeForInitiate(BSON("_id" + << "rs0" + << "protocolVersion" << 1 << "version" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "localhost:12345"))))); ASSERT_FALSE(config2.isConfigServer()); serverGlobalParams.clusterRole = ClusterRole::ConfigServer; @@ -1099,25 +854,18 @@ TEST(ReplSetConfig, ConfigServerFieldDefaults) { ReplSetConfig config3; ASSERT_OK(config3.initialize(BSON("_id" << "rs0" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" + << "protocolVersion" << 1 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345"))))); ASSERT_FALSE(config3.isConfigServer()); ReplSetConfig config4; - ASSERT_OK(config4.initializeForInitiate(BSON("_id" - << "rs0" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "localhost:12345"))))); + ASSERT_OK( + config4.initializeForInitiate(BSON("_id" + << "rs0" + << "protocolVersion" << 1 << "version" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "localhost:12345"))))); ASSERT_TRUE(config4.isConfigServer()); } @@ -1125,29 +873,19 @@ TEST(ReplSetConfig, HeartbeatIntervalField) { ReplSetConfig config; ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) - << "settings" - << BSON("heartbeatIntervalMillis" << 5000)))); + << "settings" << BSON("heartbeatIntervalMillis" << 5000)))); ASSERT_OK(config.validate()); ASSERT_EQUALS(Seconds(5), config.getHeartbeatInterval()); ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) - << "settings" - << BSON("heartbeatIntervalMillis" << -5000)))); + << "settings" << BSON("heartbeatIntervalMillis" << -5000)))); ASSERT_EQUALS(ErrorCodes::BadValue, config.validate()); } @@ -1155,29 +893,19 @@ TEST(ReplSetConfig, ElectionTimeoutField) { ReplSetConfig config; ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) - << "settings" - << BSON("electionTimeoutMillis" << 20)))); + << "settings" << BSON("electionTimeoutMillis" << 20)))); ASSERT_OK(config.validate()); ASSERT_EQUALS(Milliseconds(20), config.getElectionTimeoutPeriod()); auto status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) - << "settings" - << BSON("electionTimeoutMillis" << -20))); + << "settings" << BSON("electionTimeoutMillis" << -20))); ASSERT_EQUALS(ErrorCodes::BadValue, status); ASSERT_STRING_CONTAINS(status.reason(), "election timeout must be greater than 0"); } @@ -1186,29 +914,19 @@ TEST(ReplSetConfig, HeartbeatTimeoutField) { ReplSetConfig config; ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) - << "settings" - << BSON("heartbeatTimeoutSecs" << 20)))); + << "settings" << BSON("heartbeatTimeoutSecs" << 20)))); ASSERT_OK(config.validate()); ASSERT_EQUALS(Seconds(20), config.getHeartbeatTimeoutPeriod()); auto status = config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) - << "settings" - << BSON("heartbeatTimeoutSecs" << -20))); + << "settings" << BSON("heartbeatTimeoutSecs" << -20))); ASSERT_EQUALS(ErrorCodes::BadValue, status); ASSERT_STRING_CONTAINS(status.reason(), "heartbeat timeout must be greater than 0"); } @@ -1217,11 +935,7 @@ TEST(ReplSetConfig, GleDefaultField) { ReplSetConfig config; ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) << "settings" @@ -1232,11 +946,7 @@ TEST(ReplSetConfig, GleDefaultField) { ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) << "settings" @@ -1244,27 +954,19 @@ TEST(ReplSetConfig, GleDefaultField) { << "frim"))))); ASSERT_EQUALS(ErrorCodes::BadValue, config.validate()); - ASSERT_OK(config.initialize(BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "localhost:12345")) - << "settings" - << BSON("getLastErrorDefaults" << BSON("w" << 0))))); + ASSERT_OK( + config.initialize(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "localhost:12345")) + << "settings" << BSON("getLastErrorDefaults" << BSON("w" << 0))))); ASSERT_EQUALS(ErrorCodes::BadValue, config.validate()); ASSERT_OK( config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" << "tags" @@ -1352,19 +1054,15 @@ bool operator==(const ReplSetConfig& a, const ReplSetConfig& b) { TEST(ReplSetConfig, toBSONRoundTripAbility) { ReplSetConfig configA; ReplSetConfig configB; - ASSERT_OK(configA.initialize(BSON( - "_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "localhost:12345")) - << "settings" - << BSON("heartbeatIntervalMillis" << 5000 << "heartbeatTimeoutSecs" << 20 << "replicaSetId" - << OID::gen())))); + ASSERT_OK(configA.initialize(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "localhost:12345")) + << "settings" + << BSON("heartbeatIntervalMillis" + << 5000 << "heartbeatTimeoutSecs" << 20 + << "replicaSetId" << OID::gen())))); ASSERT_OK(configB.initialize(configA.toBSON())); ASSERT_TRUE(configA == configB); } @@ -1372,132 +1070,83 @@ TEST(ReplSetConfig, toBSONRoundTripAbility) { TEST(ReplSetConfig, toBSONRoundTripAbilityWithHorizon) { ReplSetConfig configA; ReplSetConfig configB; + ASSERT_OK(configA.initialize(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "localhost:12345" + << "horizons" + << BSON("horizon" + << "example.com:42"))) + << "settings" + << BSON("heartbeatIntervalMillis" + << 5000 << "heartbeatTimeoutSecs" << 20 + << "replicaSetId" << OID::gen())))); + ASSERT_OK(configB.initialize(configA.toBSON())); + ASSERT_TRUE(configA == configB); +} + +TEST(ReplSetConfig, toBSONRoundTripAbilityLarge) { + ReplSetConfig configA; + ReplSetConfig configB; ASSERT_OK(configA.initialize(BSON( "_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "asdf" + << "version" << 9 << "writeConcernMajorityJournalDefault" << true << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" - << "horizons" - << BSON("horizon" - << "example.com:42"))) - << "settings" - << BSON("heartbeatIntervalMillis" << 5000 << "heartbeatTimeoutSecs" << 20 << "replicaSetId" - << OID::gen())))); - ASSERT_OK(configB.initialize(configA.toBSON())); + << "arbiterOnly" << true << "votes" << 1) + << BSON("_id" << 3 << "host" + << "localhost:3828" + << "arbiterOnly" << false << "hidden" << true << "buildIndexes" + << false << "priority" << 0 << "slaveDelay" << 17 << "votes" + << 0 << "tags" + << BSON("coast" + << "east" + << "ssd" + << "true")) + << BSON("_id" << 2 << "host" + << "foo.com:3828" + << "votes" << 0 << "priority" << 0 << "tags" + << BSON("coast" + << "west" + << "hdd" + << "true"))) + << "protocolVersion" << 1 << "settings" + + << BSON("heartbeatIntervalMillis" << 5000 << "heartbeatTimeoutSecs" << 20 + << "electionTimeoutMillis" << 4 << "chainingAllowd" + << true << "getLastErrorDefaults" + << BSON("w" + << "majority") + << "getLastErrorModes" + << BSON("disks" << BSON("ssd" << 1 << "hdd" << 1) + << "coasts" << BSON("coast" << 2)))))); + BSONObj configObjA = configA.toBSON(); + ASSERT_OK(configB.initialize(configObjA)); ASSERT_TRUE(configA == configB); } -TEST(ReplSetConfig, toBSONRoundTripAbilityLarge) { +TEST(ReplSetConfig, toBSONRoundTripAbilityInvalid) { ReplSetConfig configA; ReplSetConfig configB; ASSERT_OK(configA.initialize( BSON("_id" - << "asdf" - << "version" - << 9 - << "writeConcernMajorityJournalDefault" - << true - << "members" + << "" + << "version" << -3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" - << "arbiterOnly" - << true - << "votes" - << 1) - << BSON("_id" << 3 << "host" + << "arbiterOnly" << true << "votes" << 0 << "priority" << 0) + << BSON("_id" << 0 << "host" << "localhost:3828" - << "arbiterOnly" - << false - << "hidden" - << true - << "buildIndexes" - << false - << "priority" - << 0 - << "slaveDelay" - << 17 - << "votes" - << 0 - << "tags" - << BSON("coast" - << "east" - << "ssd" - << "true")) + << "arbiterOnly" << false << "buildIndexes" << false + << "priority" << 2) << BSON("_id" << 2 << "host" - << "foo.com:3828" - << "votes" - << 0 - << "priority" - << 0 - << "tags" - << BSON("coast" - << "west" - << "hdd" - << "true"))) - << "protocolVersion" - << 1 + << "localhost:3828" + << "votes" << 0 << "priority" << 0)) << "settings" - - << BSON("heartbeatIntervalMillis" << 5000 << "heartbeatTimeoutSecs" << 20 - << "electionTimeoutMillis" - << 4 - << "chainingAllowd" - << true - << "getLastErrorDefaults" - << BSON("w" - << "majority") - << "getLastErrorModes" - << BSON("disks" << BSON("ssd" << 1 << "hdd" << 1) - << "coasts" - << BSON("coast" << 2)))))); - BSONObj configObjA = configA.toBSON(); - ASSERT_OK(configB.initialize(configObjA)); - ASSERT_TRUE(configA == configB); -} - -TEST(ReplSetConfig, toBSONRoundTripAbilityInvalid) { - ReplSetConfig configA; - ReplSetConfig configB; - ASSERT_OK( - configA.initialize(BSON("_id" - << "" - << "version" - << -3 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "localhost:12345" - << "arbiterOnly" - << true - << "votes" - << 0 - << "priority" - << 0) - << BSON("_id" << 0 << "host" - << "localhost:3828" - << "arbiterOnly" - << false - << "buildIndexes" - << false - << "priority" - << 2) - << BSON("_id" << 2 << "host" - << "localhost:3828" - << "votes" - << 0 - << "priority" - << 0)) - << "settings" - << BSON("heartbeatIntervalMillis" << -5000 << "heartbeatTimeoutSecs" - << 20 - << "electionTimeoutMillis" - << 2)))); + << BSON("heartbeatIntervalMillis" << -5000 << "heartbeatTimeoutSecs" << 20 + << "electionTimeoutMillis" << 2)))); ASSERT_OK(configB.initialize(configA.toBSON())); ASSERT_NOT_OK(configA.validate()); ASSERT_NOT_OK(configB.validate()); @@ -1506,59 +1155,52 @@ TEST(ReplSetConfig, toBSONRoundTripAbilityInvalid) { TEST(ReplSetConfig, CheckIfWriteConcernCanBeSatisfied) { ReplSetConfig configA; - ASSERT_OK(configA.initialize(BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "node0" - << "tags" - << BSON("dc" - << "NA" - << "rack" - << "rackNA1")) - << BSON("_id" << 1 << "host" - << "node1" - << "tags" - << BSON("dc" - << "NA" - << "rack" - << "rackNA2")) - << BSON("_id" << 2 << "host" - << "node2" - << "tags" - << BSON("dc" - << "NA" - << "rack" - << "rackNA3")) - << BSON("_id" << 3 << "host" - << "node3" - << "tags" - << BSON("dc" - << "EU" - << "rack" - << "rackEU1")) - << BSON("_id" << 4 << "host" - << "node4" - << "tags" - << BSON("dc" - << "EU" - << "rack" - << "rackEU2")) - << BSON("_id" << 5 << "host" - << "node5" - << "arbiterOnly" - << true)) - << "settings" - << BSON("getLastErrorModes" - << BSON("valid" << BSON("dc" << 2 << "rack" << 3) - << "invalidNotEnoughValues" - << BSON("dc" << 3) - << "invalidNotEnoughNodes" - << BSON("rack" << 6)))))); + ASSERT_OK(configA.initialize(BSON( + "_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "node0" + << "tags" + << BSON("dc" + << "NA" + << "rack" + << "rackNA1")) + << BSON("_id" << 1 << "host" + << "node1" + << "tags" + << BSON("dc" + << "NA" + << "rack" + << "rackNA2")) + << BSON("_id" << 2 << "host" + << "node2" + << "tags" + << BSON("dc" + << "NA" + << "rack" + << "rackNA3")) + << BSON("_id" << 3 << "host" + << "node3" + << "tags" + << BSON("dc" + << "EU" + << "rack" + << "rackEU1")) + << BSON("_id" << 4 << "host" + << "node4" + << "tags" + << BSON("dc" + << "EU" + << "rack" + << "rackEU2")) + << BSON("_id" << 5 << "host" + << "node5" + << "arbiterOnly" << true)) + << "settings" + << BSON("getLastErrorModes" << BSON( + "valid" << BSON("dc" << 2 << "rack" << 3) << "invalidNotEnoughValues" + << BSON("dc" << 3) << "invalidNotEnoughNodes" << BSON("rack" << 6)))))); WriteConcernOptions validNumberWC; validNumberWC.wNumNodes = 5; @@ -1619,19 +1261,13 @@ TEST(ReplSetConfig, CheckConfigServerCantHaveArbiters) { ReplSetConfig configA; ASSERT_OK(configA.initialize(BSON("_id" << "rs0" - << "protocolVersion" - << 1 - << "version" - << 1 - << "configsvr" - << true - << "members" + << "protocolVersion" << 1 << "version" << 1 << "configsvr" + << true << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345") << BSON("_id" << 1 << "host" << "localhost:54321" - << "arbiterOnly" - << true))))); + << "arbiterOnly" << true))))); Status status = configA.validate(); ASSERT_EQUALS(ErrorCodes::BadValue, status); ASSERT_STRING_CONTAINS(status.reason(), "Arbiters are not allowed"); @@ -1641,21 +1277,14 @@ TEST(ReplSetConfig, CheckConfigServerMustBuildIndexes) { ReplSetConfig configA; ASSERT_OK(configA.initialize(BSON("_id" << "rs0" - << "protocolVersion" - << 1 - << "version" - << 1 - << "configsvr" - << true - << "members" + << "protocolVersion" << 1 << "version" << 1 << "configsvr" + << true << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345") << BSON("_id" << 1 << "host" << "localhost:54321" - << "priority" - << 0 - << "buildIndexes" - << false))))); + << "priority" << 0 + << "buildIndexes" << false))))); Status status = configA.validate(); ASSERT_EQUALS(ErrorCodes::BadValue, status); ASSERT_STRING_CONTAINS(status.reason(), "must build indexes"); @@ -1665,20 +1294,13 @@ TEST(ReplSetConfig, CheckConfigServerCantHaveSlaveDelay) { ReplSetConfig configA; ASSERT_OK(configA.initialize(BSON("_id" << "rs0" - << "protocolVersion" - << 1 - << "version" - << 1 - << "configsvr" - << true - << "members" + << "protocolVersion" << 1 << "version" << 1 << "configsvr" + << true << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345") << BSON("_id" << 1 << "host" << "localhost:54321" - << "priority" - << 0 - << "slaveDelay" + << "priority" << 0 << "slaveDelay" << 3))))); Status status = configA.validate(); ASSERT_EQUALS(ErrorCodes::BadValue, status); @@ -1691,19 +1313,13 @@ TEST(ReplSetConfig, CheckConfigServerMustHaveTrueForWriteConcernMajorityJournalD ReplSetConfig configA; ASSERT_OK(configA.initialize(BSON("_id" << "rs0" - << "protocolVersion" - << 1 - << "version" - << 1 - << "configsvr" - << true - << "members" + << "protocolVersion" << 1 << "version" << 1 << "configsvr" + << true << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345") << BSON("_id" << 1 << "host" << "localhost:54321")) - << "writeConcernMajorityJournalDefault" - << false))); + << "writeConcernMajorityJournalDefault" << false))); Status status = configA.validate(); ASSERT_EQUALS(ErrorCodes::BadValue, status); ASSERT_STRING_CONTAINS(status.reason(), " must be true in replica set configurations being "); @@ -1713,33 +1329,23 @@ TEST(ReplSetConfig, GetPriorityTakeoverDelay) { ReplSetConfig configA; ASSERT_OK(configA.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" - << "priority" - << 1) + << "priority" << 1) << BSON("_id" << 1 << "host" << "localhost:54321" - << "priority" - << 2) + << "priority" << 2) << BSON("_id" << 2 << "host" << "localhost:5321" - << "priority" - << 3) + << "priority" << 3) << BSON("_id" << 3 << "host" << "localhost:5421" - << "priority" - << 4) + << "priority" << 4) << BSON("_id" << 4 << "host" << "localhost:5431" - << "priority" - << 5)) - << "settings" - << BSON("electionTimeoutMillis" << 1000)))); + << "priority" << 5)) + << "settings" << BSON("electionTimeoutMillis" << 1000)))); ASSERT_OK(configA.validate()); ASSERT_EQUALS(Milliseconds(5000), configA.getPriorityTakeoverDelay(0)); ASSERT_EQUALS(Milliseconds(4000), configA.getPriorityTakeoverDelay(1)); @@ -1750,33 +1356,23 @@ TEST(ReplSetConfig, GetPriorityTakeoverDelay) { ReplSetConfig configB; ASSERT_OK(configB.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" - << "priority" - << 1) + << "priority" << 1) << BSON("_id" << 1 << "host" << "localhost:54321" - << "priority" - << 2) + << "priority" << 2) << BSON("_id" << 2 << "host" << "localhost:5321" - << "priority" - << 2) + << "priority" << 2) << BSON("_id" << 3 << "host" << "localhost:5421" - << "priority" - << 3) + << "priority" << 3) << BSON("_id" << 4 << "host" << "localhost:5431" - << "priority" - << 3)) - << "settings" - << BSON("electionTimeoutMillis" << 1000)))); + << "priority" << 3)) + << "settings" << BSON("electionTimeoutMillis" << 1000)))); ASSERT_OK(configB.validate()); ASSERT_EQUALS(Milliseconds(5000), configB.getPriorityTakeoverDelay(0)); ASSERT_EQUALS(Milliseconds(3000), configB.getPriorityTakeoverDelay(1)); @@ -1789,29 +1385,20 @@ TEST(ReplSetConfig, GetCatchUpTakeoverDelay) { ReplSetConfig config; ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) - << "settings" - << BSON("catchUpTakeoverDelayMillis" << 5000)))); + << "settings" << BSON("catchUpTakeoverDelayMillis" << 5000)))); ASSERT_OK(config.validate()); ASSERT_EQUALS(Milliseconds(5000), config.getCatchUpTakeoverDelay()); - Status status = config.initialize(BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "localhost:12345")) - << "settings" - << BSON("catchUpTakeoverDelayMillis" << -5000))); + Status status = + config.initialize(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "localhost:12345")) + << "settings" << BSON("catchUpTakeoverDelayMillis" << -5000))); ASSERT_EQUALS(ErrorCodes::BadValue, status); ASSERT_STRING_CONTAINS( status.reason(), @@ -1822,23 +1409,16 @@ TEST(ReplSetConfig, GetCatchUpTakeoverDelayDefault) { ReplSetConfig config; ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" - << "priority" - << 1) + << "priority" << 1) << BSON("_id" << 1 << "host" << "localhost:54321" - << "priority" - << 2) + << "priority" << 2) << BSON("_id" << 2 << "host" << "localhost:5321" - << "priority" - << 3))))); + << "priority" << 3))))); ASSERT_OK(config.validate()); ASSERT_EQUALS(Milliseconds(30000), config.getCatchUpTakeoverDelay()); } @@ -1849,11 +1429,7 @@ TEST(ReplSetConfig, ConfirmDefaultValuesOfAndAbilityToSetWriteConcernMajorityJou // PV1, should default to true. ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" + << "protocolVersion" << 1 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345"))))); ASSERT_OK(config.validate()); @@ -1863,15 +1439,10 @@ TEST(ReplSetConfig, ConfirmDefaultValuesOfAndAbilityToSetWriteConcernMajorityJou // Should be able to set it false in PV1. ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" + << "protocolVersion" << 1 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345")) - << "writeConcernMajorityJournalDefault" - << false))); + << "writeConcernMajorityJournalDefault" << false))); ASSERT_OK(config.validate()); ASSERT_FALSE(config.getWriteConcernMajorityShouldJournal()); ASSERT_TRUE(config.toBSON().hasField("writeConcernMajorityJournalDefault")); @@ -1881,11 +1452,7 @@ TEST(ReplSetConfig, HorizonConsistency) { ReplSetConfig config; ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" + << "protocolVersion" << 1 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" << "horizons" @@ -1914,8 +1481,7 @@ TEST(ReplSetConfig, HorizonConsistency) { << "delta" << "c.host3:44"))) - << "writeConcernMajorityJournalDefault" - << false))); + << "writeConcernMajorityJournalDefault" << false))); Status status = config.validate(); ASSERT_NOT_OK(status); @@ -1929,11 +1495,7 @@ TEST(ReplSetConfig, HorizonConsistency) { // in the member-config code path. status = config.initialize(BSON("_id" << "rs0" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" + << "protocolVersion" << 1 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "same1" << "horizons" @@ -1978,8 +1540,7 @@ TEST(ReplSetConfig, HorizonConsistency) { << "d.host3:44" << "delta" << "d.host4:44"))) - << "writeConcernMajorityJournalDefault" - << false)); + << "writeConcernMajorityJournalDefault" << false)); ASSERT_OK(status) << " failing status was: " << status.reason(); status = config.validate(); @@ -2003,15 +1564,11 @@ TEST(ReplSetConfig, ReplSetId) { auto status = ReplSetConfig().initializeForInitiate(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" - << "priority" - << 1)) + << "priority" << 1)) << "settings" << BSON("replicaSetId" << OID::gen()))); ASSERT_EQUALS(ErrorCodes::InvalidReplicaSetConfig, status); @@ -2025,15 +1582,11 @@ TEST(ReplSetConfig, ReplSetId) { ASSERT_OK( configInitiate.initializeForInitiate(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" - << "priority" - << 1))))); + << "priority" << 1))))); ASSERT_OK(configInitiate.validate()); ASSERT_TRUE(configInitiate.hasReplicaSetId()); OID replicaSetId = configInitiate.getReplicaSetId(); @@ -2042,17 +1595,11 @@ TEST(ReplSetConfig, ReplSetId) { ReplSetConfig configLocal; ASSERT_OK(configLocal.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" - << "priority" - << 1)) - << "settings" - << BSON("replicaSetId" << replicaSetId)))); + << "priority" << 1)) + << "settings" << BSON("replicaSetId" << replicaSetId)))); ASSERT_OK(configLocal.validate()); ASSERT_TRUE(configLocal.hasReplicaSetId()); ASSERT_EQUALS(replicaSetId, configLocal.getReplicaSetId()); @@ -2061,15 +1608,10 @@ TEST(ReplSetConfig, ReplSetId) { OID defaultReplicaSetId = OID::gen(); ASSERT_OK(configLocal.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" - << "priority" - << 1))), + << "priority" << 1))), defaultReplicaSetId)); ASSERT_OK(configLocal.validate()); ASSERT_TRUE(configLocal.hasReplicaSetId()); @@ -2078,34 +1620,22 @@ TEST(ReplSetConfig, ReplSetId) { // 'replicaSetId' field cannot be null. status = configLocal.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" - << "priority" - << 1)) - << "settings" - << BSON("replicaSetId" << OID()))); + << "priority" << 1)) + << "settings" << BSON("replicaSetId" << OID()))); ASSERT_EQUALS(ErrorCodes::BadValue, status); ASSERT_STRING_CONTAINS(status.reason(), "replicaSetId field value cannot be null"); // 'replicaSetId' field must be an OID. status = configLocal.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345" - << "priority" - << 1)) - << "settings" - << BSON("replicaSetId" << 12345))); + << "priority" << 1)) + << "settings" << BSON("replicaSetId" << 12345))); ASSERT_EQUALS(ErrorCodes::TypeMismatch, status); ASSERT_STRING_CONTAINS(status.reason(), "\"replicaSetId\" had the wrong type. Expected objectId, found int"); diff --git a/src/mongo/db/repl/repl_set_heartbeat_args_v1.cpp b/src/mongo/db/repl/repl_set_heartbeat_args_v1.cpp index 3b79768db8d..a7cc785995e 100644 --- a/src/mongo/db/repl/repl_set_heartbeat_args_v1.cpp +++ b/src/mongo/db/repl/repl_set_heartbeat_args_v1.cpp @@ -78,10 +78,9 @@ Status ReplSetHeartbeatArgsV1::initialize(const BSONObj& argsObj) { if (status.isOK()) { if (tempHeartbeatVersion != 1) { return Status(ErrorCodes::Error(40666), - str::stream() << "Found invalid value for field " - << kHeartbeatVersionFieldName - << ": " - << tempHeartbeatVersion); + str::stream() + << "Found invalid value for field " << kHeartbeatVersionFieldName + << ": " << tempHeartbeatVersion); } _heartbeatVersion = tempHeartbeatVersion; _hasHeartbeatVersion = true; diff --git a/src/mongo/db/repl/repl_set_heartbeat_response.cpp b/src/mongo/db/repl/repl_set_heartbeat_response.cpp index 4b16c88e389..5c43a35c71b 100644 --- a/src/mongo/db/repl/repl_set_heartbeat_response.cpp +++ b/src/mongo/db/repl/repl_set_heartbeat_response.cpp @@ -193,18 +193,18 @@ Status ReplSetHeartbeatResponse::initialize(const BSONObj& doc, if (memberStateElement.eoo()) { _stateSet = false; } else if (memberStateElement.type() != NumberInt && memberStateElement.type() != NumberLong) { - return Status( - ErrorCodes::TypeMismatch, - str::stream() << "Expected \"" << kMemberStateFieldName + return Status(ErrorCodes::TypeMismatch, + str::stream() + << "Expected \"" << kMemberStateFieldName << "\" field in response to replSetHeartbeat " "command to have type NumberInt or NumberLong, but found type " << typeName(memberStateElement.type())); } else { long long stateInt = memberStateElement.numberLong(); if (stateInt < 0 || stateInt > MemberState::RS_MAX) { - return Status( - ErrorCodes::BadValue, - str::stream() << "Value for \"" << kMemberStateFieldName + return Status(ErrorCodes::BadValue, + str::stream() + << "Value for \"" << kMemberStateFieldName << "\" in response to replSetHeartbeat is " "out of range; legal values are non-negative and no more than " << MemberState::RS_MAX); @@ -217,8 +217,7 @@ Status ReplSetHeartbeatResponse::initialize(const BSONObj& doc, if (configVersionElement.eoo()) { return Status(ErrorCodes::NoSuchKey, str::stream() << "Response to replSetHeartbeat missing required \"" - << kConfigVersionFieldName - << "\" field"); + << kConfigVersionFieldName << "\" field"); } if (configVersionElement.type() != NumberInt) { return Status(ErrorCodes::TypeMismatch, diff --git a/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp b/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp index f3f0f1ce8bb..352456c929d 100644 --- a/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp +++ b/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp @@ -166,19 +166,16 @@ TEST(ReplSetHeartbeatResponse, InitializeNoDurableWallTime) { TEST(ReplSetHeartbeatResponse, InitializeWrongAppliedOpTimeType) { ReplSetHeartbeatResponse hbResponse; - BSONObj initializerObj = BSON( - "ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "durableWallTime" - << Date_t() + Seconds(100) - << "opTime" - << "hello"); + BSONObj initializerObj = + BSON("ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() + << "durableWallTime" << Date_t() + Seconds(100) << "opTime" + << "hello"); Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); ASSERT_EQUALS("\"opTime\" had the wrong type. Expected object, found string", result.reason()); initializerObj = BSON("ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() - << "durableWallTime" - << Date_t() + Seconds(100) - << "opTime" + << "durableWallTime" << Date_t() + Seconds(100) << "opTime" << OpTime().getTimestamp()); result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); @@ -190,9 +187,7 @@ TEST(ReplSetHeartbeatResponse, InitializeNoAppliedWallTime) { ReplSetHeartbeatResponse hbResponse; BSONObj initializerObj = BSON( "ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "durableWallTime" - << Date_t() + Seconds(100) - << "opTime" - << OpTime(Timestamp(100, 0), 0).toBSON()); + << Date_t() + Seconds(100) << "opTime" << OpTime(Timestamp(100, 0), 0).toBSON()); Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); ASSERT_EQUALS(ErrorCodes::NoSuchKey, result); ASSERT_EQUALS("Missing expected field \"wallTime\"", result.reason()); @@ -202,12 +197,8 @@ TEST(ReplSetHeartbeatResponse, InitializeMemberStateWrongType) { ReplSetHeartbeatResponse hbResponse; BSONObj initializerObj = BSON( "ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "durableWallTime" - << Date_t() + Seconds(100) - << "opTime" - << OpTime(Timestamp(100, 0), 0).toBSON() - << "wallTime" - << Date_t() + Seconds(100) - << "state" + << Date_t() + Seconds(100) << "opTime" << OpTime(Timestamp(100, 0), 0).toBSON() + << "wallTime" << Date_t() + Seconds(100) << "state" << "hello"); Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); @@ -221,13 +212,8 @@ TEST(ReplSetHeartbeatResponse, InitializeMemberStateTooLow) { ReplSetHeartbeatResponse hbResponse; BSONObj initializerObj = BSON( "ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "durableWallTime" - << Date_t() + Seconds(100) - << "opTime" - << OpTime(Timestamp(100, 0), 0).toBSON() - << "wallTime" - << Date_t() + Seconds(100) - << "state" - << -1); + << Date_t() + Seconds(100) << "opTime" << OpTime(Timestamp(100, 0), 0).toBSON() + << "wallTime" << Date_t() + Seconds(100) << "state" << -1); Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); ASSERT_EQUALS(ErrorCodes::BadValue, result); ASSERT_EQUALS( @@ -240,13 +226,8 @@ TEST(ReplSetHeartbeatResponse, InitializeMemberStateTooHigh) { ReplSetHeartbeatResponse hbResponse; BSONObj initializerObj = BSON( "ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "durableWallTime" - << Date_t() + Seconds(100) - << "opTime" - << OpTime(Timestamp(100, 0), 0).toBSON() - << "wallTime" - << Date_t() + Seconds(100) - << "state" - << 11); + << Date_t() + Seconds(100) << "opTime" << OpTime(Timestamp(100, 0), 0).toBSON() + << "wallTime" << Date_t() + Seconds(100) << "state" << 11); Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); ASSERT_EQUALS(ErrorCodes::BadValue, result); ASSERT_EQUALS( @@ -259,12 +240,8 @@ TEST(ReplSetHeartbeatResponse, InitializeVersionWrongType) { ReplSetHeartbeatResponse hbResponse; BSONObj initializerObj = BSON( "ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "durableWallTime" - << Date_t() + Seconds(100) - << "opTime" - << OpTime(Timestamp(100, 0), 0).toBSON() - << "wallTime" - << Date_t() + Seconds(100) - << "v" + << Date_t() + Seconds(100) << "opTime" << OpTime(Timestamp(100, 0), 0).toBSON() + << "wallTime" << Date_t() + Seconds(100) << "v" << "hello"); Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); @@ -276,17 +253,12 @@ TEST(ReplSetHeartbeatResponse, InitializeVersionWrongType) { TEST(ReplSetHeartbeatResponse, InitializeReplSetNameWrongType) { ReplSetHeartbeatResponse hbResponse; - BSONObj initializerObj = BSON( - "ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "durableWallTime" - << Date_t() + Seconds(100) - << "opTime" - << OpTime(Timestamp(100, 0), 0).toBSON() - << "wallTime" - << Date_t() + Seconds(100) - << "v" - << 2 // needs a version to get this far in initialize() - << "set" - << 4); + BSONObj initializerObj = + BSON("ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() + << "durableWallTime" << Date_t() + Seconds(100) << "opTime" + << OpTime(Timestamp(100, 0), 0).toBSON() << "wallTime" << Date_t() + Seconds(100) + << "v" << 2 // needs a version to get this far in initialize() + << "set" << 4); Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); ASSERT_EQUALS( @@ -297,17 +269,12 @@ TEST(ReplSetHeartbeatResponse, InitializeReplSetNameWrongType) { TEST(ReplSetHeartbeatResponse, InitializeSyncingToWrongType) { ReplSetHeartbeatResponse hbResponse; - BSONObj initializerObj = BSON( - "ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "durableWallTime" - << Date_t() + Seconds(100) - << "opTime" - << OpTime(Timestamp(100, 0), 0).toBSON() - << "wallTime" - << Date_t() + Seconds(100) - << "v" - << 2 // needs a version to get this far in initialize() - << "syncingTo" - << 4); + BSONObj initializerObj = + BSON("ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() + << "durableWallTime" << Date_t() + Seconds(100) << "opTime" + << OpTime(Timestamp(100, 0), 0).toBSON() << "wallTime" << Date_t() + Seconds(100) + << "v" << 2 // needs a version to get this far in initialize() + << "syncingTo" << 4); Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); ASSERT_EQUALS( @@ -318,17 +285,12 @@ TEST(ReplSetHeartbeatResponse, InitializeSyncingToWrongType) { TEST(ReplSetHeartbeatResponse, InitializeConfigWrongType) { ReplSetHeartbeatResponse hbResponse; - BSONObj initializerObj = BSON( - "ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "durableWallTime" - << Date_t() + Seconds(100) - << "opTime" - << OpTime(Timestamp(100, 0), 0).toBSON() - << "wallTime" - << Date_t() + Seconds(100) - << "v" - << 2 // needs a version to get this far in initialize() - << "config" - << 4); + BSONObj initializerObj = + BSON("ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() + << "durableWallTime" << Date_t() + Seconds(100) << "opTime" + << OpTime(Timestamp(100, 0), 0).toBSON() << "wallTime" << Date_t() + Seconds(100) + << "v" << 2 // needs a version to get this far in initialize() + << "config" << 4); Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); ASSERT_EQUALS( @@ -339,17 +301,12 @@ TEST(ReplSetHeartbeatResponse, InitializeConfigWrongType) { TEST(ReplSetHeartbeatResponse, InitializeBadConfig) { ReplSetHeartbeatResponse hbResponse; - BSONObj initializerObj = BSON( - "ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "durableWallTime" - << Date_t() + Seconds(100) - << "opTime" - << OpTime(Timestamp(100, 0), 0).toBSON() - << "wallTime" - << Date_t() + Seconds(100) - << "v" - << 2 // needs a version to get this far in initialize() - << "config" - << BSON("illegalFieldName" << 2)); + BSONObj initializerObj = + BSON("ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() + << "durableWallTime" << Date_t() + Seconds(100) << "opTime" + << OpTime(Timestamp(100, 0), 0).toBSON() << "wallTime" << Date_t() + Seconds(100) + << "v" << 2 // needs a version to get this far in initialize() + << "config" << BSON("illegalFieldName" << 2)); Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); ASSERT_EQUALS(ErrorCodes::BadValue, result); ASSERT_EQUALS("Unexpected field illegalFieldName in replica set configuration", @@ -371,12 +328,9 @@ TEST(ReplSetHeartbeatResponse, InvalidResponseOpTimeMissesConfigVersion) { ReplSetHeartbeatResponse hbResp; Status result = hbResp.initialize(BSON("ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() - << "durableWallTime" - << Date_t() + Seconds(100) - << "opTime" - << OpTime(Timestamp(100, 0), 0).toBSON() - << "wallTime" - << Date_t() + Seconds(100)), + << "durableWallTime" << Date_t() + Seconds(100) + << "opTime" << OpTime(Timestamp(100, 0), 0).toBSON() + << "wallTime" << Date_t() + Seconds(100)), 0, /*requireWallTime*/ true); ASSERT_EQUALS(ErrorCodes::NoSuchKey, result.code()); diff --git a/src/mongo/db/repl/replication_consistency_markers_impl.cpp b/src/mongo/db/repl/replication_consistency_markers_impl.cpp index f2127b70518..a57b7e35ceb 100644 --- a/src/mongo/db/repl/replication_consistency_markers_impl.cpp +++ b/src/mongo/db/repl/replication_consistency_markers_impl.cpp @@ -100,8 +100,7 @@ void ReplicationConsistencyMarkersImpl::initializeMinValidDocument(OperationCont // will always be greater than the provided ones. TimestampedBSONObj upsert; upsert.obj = BSON("$max" << BSON(MinValidDocument::kMinValidTimestampFieldName - << Timestamp() - << MinValidDocument::kMinValidTermFieldName + << Timestamp() << MinValidDocument::kMinValidTermFieldName << OpTime::kUninitializedTerm)); // The initialization write should go into the first checkpoint taken, so we provide no @@ -153,10 +152,8 @@ void ReplicationConsistencyMarkersImpl::clearInitialSyncFlag(OperationContext* o update.obj = BSON("$unset" << kInitialSyncFlag << "$set" << BSON(MinValidDocument::kMinValidTimestampFieldName << time.getTimestamp() - << MinValidDocument::kMinValidTermFieldName - << time.getTerm() - << MinValidDocument::kAppliedThroughFieldName - << time)); + << MinValidDocument::kMinValidTermFieldName << time.getTerm() + << MinValidDocument::kAppliedThroughFieldName << time)); // We clear the initial sync flag at the 'lastAppliedOpTime'. This is unnecessary, since there // should not be any stable checkpoints being taken that this write could inadvertantly enter. @@ -194,10 +191,10 @@ void ReplicationConsistencyMarkersImpl::setMinValid(OperationContext* opCtx, LOG(3) << "setting minvalid to exactly: " << minValid.toString() << "(" << minValid.toBSON() << ")"; TimestampedBSONObj update; - update.obj = BSON("$set" << BSON(MinValidDocument::kMinValidTimestampFieldName - << minValid.getTimestamp() - << MinValidDocument::kMinValidTermFieldName - << minValid.getTerm())); + update.obj = + BSON("$set" << BSON(MinValidDocument::kMinValidTimestampFieldName + << minValid.getTimestamp() << MinValidDocument::kMinValidTermFieldName + << minValid.getTerm())); // This method is only used with storage engines that do not support recover to stable // timestamp. As a result, their timestamps do not matter. @@ -346,8 +343,8 @@ Status ReplicationConsistencyMarkersImpl::createInternalCollections(OperationCon auto status = _storageInterface->createCollection(opCtx, nss, CollectionOptions()); if (!status.isOK() && status.code() != ErrorCodes::NamespaceExists) { return {ErrorCodes::CannotCreateCollection, - str::stream() << "Failed to create collection. Ns: " << nss.ns() << " Error: " - << status.toString()}; + str::stream() << "Failed to create collection. Ns: " << nss.ns() + << " Error: " << status.toString()}; } } diff --git a/src/mongo/db/repl/replication_coordinator.h b/src/mongo/db/repl/replication_coordinator.h index b9eee2a78a9..8b767924eac 100644 --- a/src/mongo/db/repl/replication_coordinator.h +++ b/src/mongo/db/repl/replication_coordinator.h @@ -774,12 +774,12 @@ public: virtual std::vector<MemberData> getMemberData() const = 0; /* - * Handles an incoming replSetRequestVotes command. - * - * Populates the given 'response' object with the result of the request. If there is a failure - * processing the vote request, returns an error status. If an error is returned, the value of - * the populated 'response' object is invalid. - */ + * Handles an incoming replSetRequestVotes command. + * + * Populates the given 'response' object with the result of the request. If there is a failure + * processing the vote request, returns an error status. If an error is returned, the value of + * the populated 'response' object is invalid. + */ virtual Status processReplSetRequestVotes(OperationContext* opCtx, const ReplSetRequestVotesArgs& args, ReplSetRequestVotesResponse* response) = 0; diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp index 0df40b457c2..1052ccec515 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp @@ -171,13 +171,13 @@ auto makeTaskExecutor(ServiceContext* service, const std::string& poolName) { * down. */ void scheduleWork(executor::TaskExecutor* executor, executor::TaskExecutor::CallbackFn work) { - auto cbh = executor->scheduleWork([work = std::move(work)]( - const executor::TaskExecutor::CallbackArgs& args) { - if (args.status == ErrorCodes::CallbackCanceled) { - return; - } - work(args); - }); + auto cbh = executor->scheduleWork( + [work = std::move(work)](const executor::TaskExecutor::CallbackArgs& args) { + if (args.status == ErrorCodes::CallbackCanceled) { + return; + } + work(args); + }); if (cbh == ErrorCodes::ShutdownInProgress) { return; } @@ -552,9 +552,7 @@ Status ReplicationCoordinatorExternalStateImpl::createLocalLastVoteCollection( if (!status.isOK() && status.code() != ErrorCodes::NamespaceExists) { return {ErrorCodes::CannotCreateCollection, str::stream() << "Failed to create local last vote collection. Ns: " - << lastVoteCollectionName - << " Error: " - << status.toString()}; + << lastVoteCollectionName << " Error: " << status.toString()}; } // Make sure there's always a last vote document. @@ -682,9 +680,7 @@ StatusWith<OpTimeAndWallTime> ReplicationCoordinatorExternalStateImpl::loadLastO return StatusWith<OpTimeAndWallTime>( ErrorCodes::NoSuchKey, str::stream() << "Most recent entry in " << NamespaceString::kRsOplogNamespace.ns() - << " missing \"" - << tsFieldName - << "\" field"); + << " missing \"" << tsFieldName << "\" field"); } if (tsElement.type() != bsonTimestamp) { return StatusWith<OpTimeAndWallTime>( diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.h b/src/mongo/db/repl/replication_coordinator_external_state_impl.h index af36200521b..41abb8bc4e6 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_impl.h +++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.h @@ -134,11 +134,11 @@ private: void _shardingOnTransitionToPrimaryHook(OperationContext* opCtx); /** - * Drops all temporary collections on all databases except "local". - * - * The implementation may assume that the caller has acquired the global exclusive lock - * for "opCtx". - */ + * Drops all temporary collections on all databases except "local". + * + * The implementation may assume that the caller has acquired the global exclusive lock + * for "opCtx". + */ void _dropAllTempCollections(OperationContext* opCtx); ServiceContext* _service; diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index db61adde61d..2509aa1d29e 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -927,10 +927,9 @@ Status ReplicationCoordinatorImpl::waitForMemberState(MemberState expectedState, auto pred = [this, expectedState]() { return _memberState == expectedState; }; if (!_memberStateChange.wait_for(lk, timeout.toSystemDuration(), pred)) { return Status(ErrorCodes::ExceededTimeLimit, - str::stream() << "Timed out waiting for state to become " - << expectedState.toString() - << ". Current state is " - << _memberState.toString()); + str::stream() + << "Timed out waiting for state to become " << expectedState.toString() + << ". Current state is " << _memberState.toString()); } return Status::OK(); } @@ -1642,8 +1641,9 @@ bool ReplicationCoordinatorImpl::_doneWaitingForReplication_inlock( "'committed' optime " << opTime << ". There are still drop pending collections (earliest drop optime: " - << *dropOpTime << ") that have to be removed from storage before we can " - "satisfy the write concern " + << *dropOpTime + << ") that have to be removed from storage before we can " + "satisfy the write concern " << writeConcern.toBSON(); return false; } diff --git a/src/mongo/db/repl/replication_coordinator_impl.h b/src/mongo/db/repl/replication_coordinator_impl.h index 8bb0ca7488c..73fa6dbae41 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.h +++ b/src/mongo/db/repl/replication_coordinator_impl.h @@ -546,7 +546,7 @@ private: * Loops continuously to kill all conflicting operations. And, aborts all stashed (inactive) * transactions. * Terminates once killSignaled is set true. - */ + */ void _killOpThreadFn(); /* diff --git a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp index b0d3d8c3556..0402d4a2aed 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp @@ -59,11 +59,7 @@ using ApplierState = ReplicationCoordinator::ApplierState; TEST_F(ReplCoordTest, RandomizedElectionOffsetWithinProperBounds) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -90,18 +86,14 @@ TEST_F(ReplCoordTest, RandomizedElectionOffsetWithinProperBounds) { TEST_F(ReplCoordTest, RandomizedElectionOffsetAvoidsDivideByZero) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1 - << "settings" + << "protocolVersion" << 1 << "settings" << BSON("electionTimeoutMillis" << 1)); assertStartSuccess(configObj, HostAndPort("node1", 12345)); @@ -112,24 +104,17 @@ TEST_F(ReplCoordTest, RandomizedElectionOffsetAvoidsDivideByZero) { } TEST_F(ReplCoordTest, ElectionSucceedsWhenNodeIsTheOnlyElectableNode) { - assertStartSuccess(BSON("_id" - << "mySet" - << "version" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "node1:12345") - << BSON("_id" << 2 << "host" - << "node2:12345" - << "votes" - << 0 - << "hidden" - << true - << "priority" - << 0)) - << "protocolVersion" - << 1), - HostAndPort("node1", 12345)); + assertStartSuccess( + BSON("_id" + << "mySet" + << "version" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "node1:12345") + << BSON("_id" << 2 << "host" + << "node2:12345" + << "votes" << 0 << "hidden" << true << "priority" << 0)) + << "protocolVersion" << 1), + HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); @@ -184,15 +169,12 @@ TEST_F(ReplCoordTest, ElectionSucceedsWhenNodeIsTheOnlyElectableNode) { TEST_F(ReplCoordTest, StartElectionDoesNotStartAnElectionWhenNodeIsRecovering) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_RECOVERING)); @@ -212,13 +194,10 @@ TEST_F(ReplCoordTest, ElectionSucceedsWhenNodeIsTheOnlyNode) { startCapturingLogMessages(); assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), HostAndPort("node1", 12345)); replCoordSetMyLastAppliedOpTime(OpTime(Timestamp(10, 1), 0), Date_t() + Seconds(10)); @@ -246,17 +225,14 @@ TEST_F(ReplCoordTest, ElectionSucceedsWhenNodeIsTheOnlyNode) { TEST_F(ReplCoordTest, ElectionSucceedsWhenAllNodesVoteYea) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); OperationContextNoop opCtx; replCoordSetMyLastAppliedOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)); @@ -279,9 +255,7 @@ TEST_F(ReplCoordTest, ElectionSucceedsWhenAllNodesVoteYea) { TEST_F(ReplCoordTest, ElectionSucceedsWhenMaxSevenNodesVoteYea) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -296,8 +270,7 @@ TEST_F(ReplCoordTest, ElectionSucceedsWhenMaxSevenNodesVoteYea) { << "node6:12345") << BSON("_id" << 7 << "host" << "node7:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); OperationContextNoop opCtx; replCoordSetMyLastAppliedOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)); @@ -321,17 +294,14 @@ TEST_F(ReplCoordTest, ElectionFailsWhenInsufficientVotesAreReceivedDuringDryRun) startCapturingLogMessages(); BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -363,9 +333,9 @@ TEST_F(ReplCoordTest, ElectionFailsWhenInsufficientVotesAreReceivedDuringDryRun) } else if (request.cmdObj.firstElement().fieldNameStringData() == "replSetRequestVotes") { net->scheduleResponse(noi, net->now(), - makeResponseStatus(BSON( - "ok" << 1 << "term" << 0 << "voteGranted" << false << "reason" - << "don't like him much"))); + makeResponseStatus(BSON("ok" << 1 << "term" << 0 << "voteGranted" + << false << "reason" + << "don't like him much"))); voteRequests++; } else { net->blackHole(noi); @@ -382,17 +352,14 @@ TEST_F(ReplCoordTest, ElectionFailsWhenDryRunResponseContainsANewerTerm) { startCapturingLogMessages(); BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -426,9 +393,7 @@ TEST_F(ReplCoordTest, ElectionFailsWhenDryRunResponseContainsANewerTerm) { noi, net->now(), makeResponseStatus(BSON("ok" << 1 << "term" << request.cmdObj["term"].Long() + 1 - << "voteGranted" - << false - << "reason" + << "voteGranted" << false << "reason" << "quit living in the past"))); voteRequests++; } else { @@ -449,9 +414,7 @@ TEST_F(ReplCoordTest, NodeWillNotStandForElectionDuringHeartbeatReconfig) { OperationContextNoop opCtx; assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -462,8 +425,7 @@ TEST_F(ReplCoordTest, NodeWillNotStandForElectionDuringHeartbeatReconfig) { << "node4:12345") << BSON("_id" << 5 << "host" << "node5:12345")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)); @@ -481,15 +443,12 @@ TEST_F(ReplCoordTest, NodeWillNotStandForElectionDuringHeartbeatReconfig) { config .initialize(BSON("_id" << "mySet" - << "version" - << 3 - << "members" + << "version" << 3 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345")) - << "protocolVersion" - << 1)) + << "protocolVersion" << 1)) .transitional_ignore(); hbResp2.setConfig(config); hbResp2.setConfigVersion(3); @@ -576,17 +535,14 @@ TEST_F(ReplCoordTest, ElectionFailsWhenInsufficientVotesAreReceivedDuringRequest startCapturingLogMessages(); BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -610,9 +566,9 @@ TEST_F(ReplCoordTest, ElectionFailsWhenInsufficientVotesAreReceivedDuringRequest } else { net->scheduleResponse(noi, net->now(), - makeResponseStatus(BSON( - "ok" << 1 << "term" << 1 << "voteGranted" << false << "reason" - << "don't like him much"))); + makeResponseStatus(BSON("ok" << 1 << "term" << 1 << "voteGranted" + << false << "reason" + << "don't like him much"))); } net->runReadyNetworkOperations(); } @@ -627,17 +583,14 @@ TEST_F(ReplCoordTest, ElectionFailsWhenInsufficientVotesAreReceivedDuringRequest TEST_F(ReplCoordTest, TransitionToRollbackFailsWhenElectionInProgress) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -666,17 +619,14 @@ TEST_F(ReplCoordTest, ElectionFailsWhenVoteRequestResponseContainsANewerTerm) { startCapturingLogMessages(); BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -702,9 +652,7 @@ TEST_F(ReplCoordTest, ElectionFailsWhenVoteRequestResponseContainsANewerTerm) { noi, net->now(), makeResponseStatus(BSON("ok" << 1 << "term" << request.cmdObj["term"].Long() + 1 - << "voteGranted" - << false - << "reason" + << "voteGranted" << false << "reason" << "quit living in the past"))); } net->runReadyNetworkOperations(); @@ -721,17 +669,14 @@ TEST_F(ReplCoordTest, ElectionFailsWhenTermChangesDuringDryRun) { startCapturingLogMessages(); BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -762,17 +707,14 @@ TEST_F(ReplCoordTest, ElectionFailsWhenTermChangesDuringActualElection) { startCapturingLogMessages(); BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -799,10 +741,9 @@ TEST_F(ReplCoordTest, ElectionFailsWhenTermChangesDuringActualElection) { net->scheduleResponse( noi, net->now(), - makeResponseStatus(BSON( - "ok" << 1 << "term" << request.cmdObj["term"].Long() << "voteGranted" << true - << "reason" - << ""))); + makeResponseStatus(BSON("ok" << 1 << "term" << request.cmdObj["term"].Long() + << "voteGranted" << true << "reason" + << ""))); } net->runReadyNetworkOperations(); } @@ -965,18 +906,14 @@ private: TEST_F(TakeoverTest, DoesntScheduleCatchupTakeoverIfCatchupDisabledButTakeoverDelaySet) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1 - << "settings" + << "protocolVersion" << 1 << "settings" << BSON("catchUpTimeoutMillis" << 0 << "catchUpTakeoverDelay" << 10000)); assertStartSuccess(configObj, HostAndPort("node1", 12345)); @@ -1007,17 +944,14 @@ TEST_F(TakeoverTest, DoesntScheduleCatchupTakeoverIfCatchupDisabledButTakeoverDe TEST_F(TakeoverTest, SchedulesCatchupTakeoverIfNodeIsFresherThanCurrentPrimary) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -1054,21 +988,16 @@ TEST_F(TakeoverTest, SchedulesCatchupTakeoverIfNodeIsFresherThanCurrentPrimary) TEST_F(TakeoverTest, SchedulesCatchupTakeoverIfBothTakeoversAnOption) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345" - << "priority" - << 2) + << "priority" << 2) << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345" - << "priority" - << 3)) - << "protocolVersion" - << 1); + << "priority" << 3)) + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -1106,19 +1035,15 @@ TEST_F(TakeoverTest, SchedulesCatchupTakeoverIfBothTakeoversAnOption) { TEST_F(TakeoverTest, PrefersPriorityToCatchupTakeoverIfNodeHasHighestPriority) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345" - << "priority" - << 2) + << "priority" << 2) << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(2)); startCapturingLogMessages(); @@ -1162,17 +1087,14 @@ TEST_F(TakeoverTest, PrefersPriorityToCatchupTakeoverIfNodeHasHighestPriority) { TEST_F(TakeoverTest, CatchupTakeoverNotScheduledTwice) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -1219,21 +1141,16 @@ TEST_F(TakeoverTest, CatchupTakeoverNotScheduledTwice) { TEST_F(TakeoverTest, CatchupAndPriorityTakeoverNotScheduledAtSameTime) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345" - << "priority" - << 2) + << "priority" << 2) << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345" - << "priority" - << 3)) - << "protocolVersion" - << 1); + << "priority" << 3)) + << "protocolVersion" << 1); // In order for node 1 to first schedule a catchup takeover, then a priority takeover // once the first gets canceled, it must have a higher priority than the current primary // (node 2). But, it must not have the highest priority in the replica set. Otherwise, @@ -1285,17 +1202,14 @@ TEST_F(TakeoverTest, CatchupAndPriorityTakeoverNotScheduledAtSameTime) { TEST_F(TakeoverTest, CatchupTakeoverCallbackCanceledIfElectionTimeoutRuns) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -1359,17 +1273,14 @@ TEST_F(TakeoverTest, CatchupTakeoverCallbackCanceledIfElectionTimeoutRuns) { TEST_F(TakeoverTest, CatchupTakeoverCanceledIfTransitionToRollback) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -1422,17 +1333,14 @@ TEST_F(TakeoverTest, CatchupTakeoverCanceledIfTransitionToRollback) { TEST_F(TakeoverTest, SuccessfulCatchupTakeover) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); HostAndPort primaryHostAndPort("node2", 12345); @@ -1489,9 +1397,7 @@ TEST_F(TakeoverTest, CatchupTakeoverDryRunFailsPrimarySaysNo) { startCapturingLogMessages(); BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -1502,8 +1408,7 @@ TEST_F(TakeoverTest, CatchupTakeoverDryRunFailsPrimarySaysNo) { << "node4:12345") << BSON("_id" << 5 << "host" << "node5:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); HostAndPort primaryHostAndPort("node2", 12345); @@ -1565,12 +1470,11 @@ TEST_F(TakeoverTest, CatchupTakeoverDryRunFailsPrimarySaysNo) { net->blackHole(noi); } else { bool voteGranted = request.target != primaryHostAndPort; - net->scheduleResponse( - noi, - until, - makeResponseStatus(BSON("ok" << 1 << "term" << 1 << "voteGranted" << voteGranted - << "reason" - << ""))); + net->scheduleResponse(noi, + until, + makeResponseStatus(BSON("ok" << 1 << "term" << 1 << "voteGranted" + << voteGranted << "reason" + << ""))); voteRequests++; } net->runReadyNetworkOperations(); @@ -1598,17 +1502,14 @@ TEST_F(TakeoverTest, CatchupTakeoverDryRunFailsPrimarySaysNo) { TEST_F(TakeoverTest, PrimaryCatchesUpBeforeCatchupTakeover) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -1659,21 +1560,16 @@ TEST_F(TakeoverTest, PrimaryCatchesUpBeforeCatchupTakeover) { TEST_F(TakeoverTest, PrimaryCatchesUpBeforeHighPriorityNodeCatchupTakeover) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345" - << "priority" - << 2) + << "priority" << 2) << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345" - << "priority" - << 3)) - << "protocolVersion" - << 1); + << "priority" << 3)) + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -1743,19 +1639,15 @@ TEST_F(TakeoverTest, PrimaryCatchesUpBeforeHighPriorityNodeCatchupTakeover) { TEST_F(TakeoverTest, SchedulesPriorityTakeoverIfNodeHasHigherPriorityThanCurrentPrimary) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345" - << "priority" - << 2) + << "priority" << 2) << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -1790,19 +1682,15 @@ TEST_F(TakeoverTest, SchedulesPriorityTakeoverIfNodeHasHigherPriorityThanCurrent TEST_F(TakeoverTest, SuccessfulPriorityTakeover) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345" - << "priority" - << 2) + << "priority" << 2) << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); @@ -1845,19 +1733,15 @@ TEST_F(TakeoverTest, SuccessfulPriorityTakeover) { TEST_F(TakeoverTest, DontCallForPriorityTakeoverWhenLaggedSameSecond) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345" - << "priority" - << 2) + << "priority" << 2) << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); HostAndPort primaryHostAndPort("node2", 12345); @@ -1924,19 +1808,15 @@ TEST_F(TakeoverTest, DontCallForPriorityTakeoverWhenLaggedSameSecond) { TEST_F(TakeoverTest, DontCallForPriorityTakeoverWhenLaggedDifferentSecond) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345" - << "priority" - << 2) + << "priority" << 2) << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); HostAndPort primaryHostAndPort("node2", 12345); @@ -2004,19 +1884,14 @@ TEST_F(ReplCoordTest, NodeCancelsElectionUponReceivingANewConfigDuringDryRun) { // Start up and become electable. assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 3 << "host" << "node3:12345") << BSON("_id" << 2 << "host" << "node2:12345")) - << "settings" - << BSON("heartbeatIntervalMillis" << 100)), + << "settings" << BSON("heartbeatIntervalMillis" << 100)), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)); @@ -2044,11 +1919,7 @@ TEST_F(ReplCoordTest, NodeCancelsElectionUponReceivingANewConfigDuringDryRun) { ReplicationCoordinatorImpl::ReplSetReconfigArgs config = { BSON("_id" << "mySet" - << "version" - << 4 - << "protocolVersion" - << 1 - << "members" + << "version" << 4 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -2069,19 +1940,14 @@ TEST_F(ReplCoordTest, NodeCancelsElectionUponReceivingANewConfigDuringVotePhase) // Start up and become electable. assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 3 << "host" << "node3:12345") << BSON("_id" << 2 << "host" << "node2:12345")) - << "settings" - << BSON("heartbeatIntervalMillis" << 100)), + << "settings" << BSON("heartbeatIntervalMillis" << 100)), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)); @@ -2094,11 +1960,7 @@ TEST_F(ReplCoordTest, NodeCancelsElectionUponReceivingANewConfigDuringVotePhase) ReplicationCoordinatorImpl::ReplSetReconfigArgs config = { BSON("_id" << "mySet" - << "version" - << 4 - << "protocolVersion" - << 1 - << "members" + << "version" << 4 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -2160,14 +2022,13 @@ protected: net->getNextReadyRequest(), net->now(), makeHeartbeatResponse(opTime)); } else if (request.cmdObj.firstElement().fieldNameStringData() == "replSetRequestVotes") { - net->scheduleResponse(net->getNextReadyRequest(), - net->now(), - makeResponseStatus(BSON("ok" << 1 << "reason" - << "" - << "term" - << request.cmdObj["term"].Long() - << "voteGranted" - << true))); + net->scheduleResponse( + net->getNextReadyRequest(), + net->now(), + makeResponseStatus(BSON("ok" << 1 << "reason" + << "" + << "term" << request.cmdObj["term"].Long() + << "voteGranted" << true))); } else { // Stop the loop and let the caller handle unexpected requests. net->exitNetwork(); @@ -2181,18 +2042,14 @@ protected: ReplSetConfig setUp3NodeReplSetAndRunForElection(OpTime opTime, long long timeout = 5000) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345") << BSON("_id" << 3 << "host" << "node3:12345")) - << "protocolVersion" - << 1 - << "settings" + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 1 << "catchUpTimeoutMillis" << timeout)); assertStartSuccess(configObj, HostAndPort("node1", 12345)); diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp index 62834fe3d0c..5af7e96e979 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp @@ -174,11 +174,11 @@ void ReplicationCoordinatorImpl::_handleHeartbeatResponse( if (replMetadata.isOK() && _rsConfig.isInitialized() && _rsConfig.hasReplicaSetId() && replMetadata.getValue().getReplicaSetId().isSet() && _rsConfig.getReplicaSetId() != replMetadata.getValue().getReplicaSetId()) { - responseStatus = Status(ErrorCodes::InvalidReplicaSetConfig, - str::stream() << "replica set IDs do not match, ours: " - << _rsConfig.getReplicaSetId() - << "; remote node's: " - << replMetadata.getValue().getReplicaSetId()); + responseStatus = + Status(ErrorCodes::InvalidReplicaSetConfig, + str::stream() + << "replica set IDs do not match, ours: " << _rsConfig.getReplicaSetId() + << "; remote node's: " << replMetadata.getValue().getReplicaSetId()); // Ignore metadata. replMetadata = responseStatus; } diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp index 53eedf88523..ec9fb647668 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp @@ -88,17 +88,14 @@ TEST_F(ReplCoordHBV1Test, logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(3)); ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "mySet" - << "version" - << 3 - << "members" + << "version" << 3 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" << "h2:1") << BSON("_id" << 3 << "host" << "h3:1")) - << "protocolVersion" - << 1)); + << "protocolVersion" << 1)); init("mySet"); addSelf(HostAndPort("h2", 1)); const Date_t startDate = getNet()->now(); @@ -158,21 +155,18 @@ TEST_F(ReplCoordHBV1Test, TEST_F(ReplCoordHBV1Test, ArbiterJoinsExistingReplSetWhenReceivingAConfigContainingTheArbiterViaHeartbeat) { logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(3)); - ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" - << "mySet" - << "version" - << 3 - << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1:1") - << BSON("_id" << 2 << "host" - << "h2:1" - << "arbiterOnly" - << true) - << BSON("_id" << 3 << "host" - << "h3:1")) - << "protocolVersion" - << 1)); + ReplSetConfig rsConfig = + assertMakeRSConfig(BSON("_id" + << "mySet" + << "version" << 3 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1:1") + << BSON("_id" << 2 << "host" + << "h2:1" + << "arbiterOnly" << true) + << BSON("_id" << 3 << "host" + << "h3:1")) + << "protocolVersion" << 1)); init("mySet"); addSelf(HostAndPort("h2", 1)); const Date_t startDate = getNet()->now(); @@ -236,17 +230,14 @@ TEST_F(ReplCoordHBV1Test, logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(3)); ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "mySet" - << "version" - << 3 - << "members" + << "version" << 3 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" << "h2:1") << BSON("_id" << 3 << "host" << "h3:1")) - << "protocolVersion" - << 1)); + << "protocolVersion" << 1)); init("mySet"); addSelf(HostAndPort("h4", 1)); const Date_t startDate = getNet()->now(); @@ -321,9 +312,7 @@ TEST_F(ReplCoordHBV1Test, logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(3)); assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -336,12 +325,12 @@ TEST_F(ReplCoordHBV1Test, const NetworkInterfaceMock::NetworkOperationIterator noi = getNet()->getNextReadyRequest(); const RemoteCommandRequest& request = noi->getRequest(); log() << request.target.toString() << " processing " << request.cmdObj; - getNet()->scheduleResponse(noi, - getNet()->now(), - makeResponseStatus(BSON("ok" << 0.0 << "errmsg" - << "unauth'd" - << "code" - << ErrorCodes::Unauthorized))); + getNet()->scheduleResponse( + noi, + getNet()->now(), + makeResponseStatus(BSON("ok" << 0.0 << "errmsg" + << "unauth'd" + << "code" << ErrorCodes::Unauthorized))); if (request.target != HostAndPort("node2", 12345) && request.cmdObj.firstElement().fieldNameStringData() != "replSetHeartbeat") { @@ -362,15 +351,11 @@ TEST_F(ReplCoordHBV1Test, IgnoreTheContentsOfMetadataWhenItsReplicaSetIdDoesNotM HostAndPort host2("node2:12345"); assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << host2.toString())) - << "settings" - << BSON("replicaSetId" << OID::gen()) - << "protocolVersion" + << "settings" << BSON("replicaSetId" << OID::gen()) << "protocolVersion" << 1), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); @@ -442,10 +427,9 @@ TEST_F(ReplCoordHBV1Test, IgnoreTheContentsOfMetadataWhenItsReplicaSetIdDoesNotM ASSERT_EQ(MemberState(MemberState::RS_DOWN).toString(), MemberState(member["state"].numberInt()).toString()); ASSERT_EQ(member["lastHeartbeatMessage"].String(), - std::string(str::stream() << "replica set IDs do not match, ours: " - << rsConfig.getReplicaSetId() - << "; remote node's: " - << unexpectedId)); + std::string(str::stream() + << "replica set IDs do not match, ours: " << rsConfig.getReplicaSetId() + << "; remote node's: " << unexpectedId)); } } // namespace diff --git a/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp index 3fad34dfe2a..738ff86ef87 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp @@ -73,9 +73,7 @@ TEST_F(ReplCoordTest, NodeReturnsNotMasterWhenReconfigReceivedWhileSecondary) { init(); assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -99,9 +97,7 @@ TEST_F(ReplCoordTest, NodeReturnsInvalidReplicaSetConfigWhenReconfigReceivedWith // start up, become primary, receive uninitializable config assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -117,21 +113,14 @@ TEST_F(ReplCoordTest, NodeReturnsInvalidReplicaSetConfigWhenReconfigReceivedWith args.force = false; args.newConfigObj = BSON("_id" << "mySet" - << "version" - << 2 - << "protocolVersion" - << 1 - << "invalidlyNamedField" - << 3 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "invalidlyNamedField" + << 3 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 2 << "host" << "node2:12345" - << "arbiterOnly" - << true))); + << "arbiterOnly" << true))); const auto opCtx = makeOperationContext(); // ErrorCodes::BadValue should be propagated from ReplSetConfig::initialize() ASSERT_EQUALS(ErrorCodes::InvalidReplicaSetConfig, @@ -143,9 +132,7 @@ TEST_F(ReplCoordTest, NodeReturnsInvalidReplicaSetConfigWhenReconfigReceivedWith // start up, become primary, receive config with incorrect replset name assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -161,11 +148,7 @@ TEST_F(ReplCoordTest, NodeReturnsInvalidReplicaSetConfigWhenReconfigReceivedWith args.force = false; args.newConfigObj = BSON("_id" << "notMySet" - << "version" - << 3 - << "protocolVersion" - << 1 - << "members" + << "version" << 3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -181,15 +164,12 @@ TEST_F(ReplCoordTest, NodeReturnsInvalidReplicaSetConfigWhenReconfigReceivedWith // start up, become primary, receive config with incorrect replset name assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345")) - << "settings" - << BSON("replicaSetId" << OID::gen())), + << "settings" << BSON("replicaSetId" << OID::gen())), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)); @@ -201,17 +181,12 @@ TEST_F(ReplCoordTest, NodeReturnsInvalidReplicaSetConfigWhenReconfigReceivedWith args.force = false; args.newConfigObj = BSON("_id" << "mySet" - << "version" - << 3 - << "protocolVersion" - << 1 - << "members" + << "version" << 3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345")) - << "settings" - << BSON("replicaSetId" << OID::gen())); + << "settings" << BSON("replicaSetId" << OID::gen())); const auto opCtx = makeOperationContext(); ASSERT_EQUALS(ErrorCodes::NewReplicaSetConfigurationIncompatible, @@ -224,9 +199,7 @@ TEST_F(ReplCoordTest, // start up, become primary, validate fails assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -242,11 +215,7 @@ TEST_F(ReplCoordTest, args.force = false; args.newConfigObj = BSON("_id" << "mySet" - << "version" - << -3 - << "protocolVersion" - << 1 - << "members" + << "version" << -3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -266,9 +235,7 @@ void doReplSetInitiate(ReplicationCoordinatorImpl* replCoord, replCoord->processReplSetInitiate(opCtx, BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -285,17 +252,12 @@ void doReplSetReconfig(ReplicationCoordinatorImpl* replCoord, // Replica set id will be copied from existing configuration. args.newConfigObj = BSON("_id" << "mySet" - << "version" - << 3 - << "protocolVersion" - << 1 - << "members" + << "version" << 3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345" - << "priority" - << 3))); + << "priority" << 3))); *status = replCoord->processReplSetReconfig(opCtx, args, &garbage); } @@ -305,9 +267,7 @@ TEST_F(ReplCoordTest, // containing a higher config version assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -348,9 +308,7 @@ TEST_F(ReplCoordTest, NodeReturnsOutOfDiskSpaceWhenSavingANewConfigFailsDuringRe // start up, become primary, saving the config fails assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -377,9 +335,7 @@ TEST_F(ReplCoordTest, // start up, become primary, reconfig, then before that reconfig concludes, reconfig again assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -404,11 +360,7 @@ TEST_F(ReplCoordTest, args.force = false; args.newConfigObj = BSON("_id" << "mySet" - << "version" - << 3 - << "protocolVersion" - << 1 - << "members" + << "version" << 3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -443,11 +395,7 @@ TEST_F(ReplCoordTest, NodeReturnsConfigurationInProgressWhenReceivingAReconfigWh args.force = false; args.newConfigObj = BSON("_id" << "mySet" - << "version" - << 3 - << "protocolVersion" - << 1 - << "members" + << "version" << 3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -464,15 +412,12 @@ TEST_F(ReplCoordTest, PrimaryNodeAcceptsNewConfigWhenReceivingAReconfigWithAComp // start up, become primary, reconfig successfully assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345")) - << "settings" - << BSON("replicaSetId" << OID::gen())), + << "settings" << BSON("replicaSetId" << OID::gen())), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)); @@ -512,9 +457,7 @@ TEST_F( // from reconfig assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -538,11 +481,7 @@ TEST_F( config .initialize(BSON("_id" << "mySet" - << "version" - << 3 - << "protocolVersion" - << 1 - << "members" + << "version" << 3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -581,9 +520,7 @@ TEST_F(ReplCoordTest, NodeDoesNotAcceptHeartbeatReconfigWhileInTheMidstOfReconfi // start up, become primary, reconfig, while reconfigging receive reconfig via heartbeat assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -614,9 +551,7 @@ TEST_F(ReplCoordTest, NodeDoesNotAcceptHeartbeatReconfigWhileInTheMidstOfReconfi config .initialize(BSON("_id" << "mySet" - << "version" - << 4 - << "members" + << "version" << 4 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -652,9 +587,7 @@ TEST_F(ReplCoordTest, NodeAcceptsConfigFromAReconfigWithForceTrueWhileNotPrimary init(); assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -670,11 +603,7 @@ TEST_F(ReplCoordTest, NodeAcceptsConfigFromAReconfigWithForceTrueWhileNotPrimary args.force = false; args.newConfigObj = BSON("_id" << "mySet" - << "version" - << 3 - << "protocolVersion" - << 1 - << "members" + << "version" << 3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp index a7ff18688e8..ee40d510288 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp @@ -120,15 +120,12 @@ void killOperation(OperationContext* opCtx) { TEST_F(ReplCoordTest, IsMasterIsFalseDuringStepdown) { BSONObj configObj = BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" << "node2:12345")) - << "protocolVersion" - << 1); + << "protocolVersion" << 1); assertStartSuccess(configObj, HostAndPort("node1", 12345)); ReplSetConfig config = assertMakeRSConfig(configObj); auto replCoord = getReplCoord(); @@ -162,9 +159,7 @@ TEST_F(ReplCoordTest, IsMasterIsFalseDuringStepdown) { TEST_F(ReplCoordTest, NodeEntersStartup2StateWhenStartingUpWithValidLocalConfig) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345"))), HostAndPort("node1", 12345)); @@ -175,13 +170,10 @@ TEST_F(ReplCoordTest, NodeEntersStartup2StateWhenStartingUpWithValidLocalConfig) TEST_F(ReplCoordTest, NodeEntersArbiterStateWhenStartingUpWithValidLocalConfigWhereItIsAnArbiter) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 2 << "host" << "node2:12345"))), HostAndPort("node1", 12345)); @@ -193,9 +185,7 @@ TEST_F(ReplCoordTest, NodeEntersRemovedStateWhenStartingUpWithALocalConfigWhichL startCapturingLogMessages(); assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -212,9 +202,7 @@ TEST_F(ReplCoordTest, startCapturingLogMessages(); assertStartSuccess(BSON("_id" << "notMySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "node1:12345"))), HostAndPort("node1", 12345)); @@ -255,9 +243,7 @@ TEST_F(ReplCoordTest, getReplCoord()->processReplSetInitiate(opCtx.get(), BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "node1:12345"))), &result1)); @@ -271,9 +257,7 @@ TEST_F(ReplCoordTest, getReplCoord()->processReplSetInitiate(opCtx.get(), BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "node1:12345"))), &result2)); @@ -296,9 +280,7 @@ TEST_F(ReplCoordTest, getReplCoord()->processReplSetInitiate(opCtx.get(), BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "node1:12345" << "arbiterOnly" @@ -327,9 +309,7 @@ TEST_F(ReplCoordTest, getReplCoord()->processReplSetInitiate(opCtx.get(), BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "node1:12345"))), &result1)); @@ -347,9 +327,7 @@ TEST_F(ReplCoordTest, getReplCoord()->processReplSetInitiate(opCtx.get(), BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "node4"))), &result)); @@ -363,9 +341,7 @@ void doReplSetInitiate(ReplicationCoordinatorImpl* replCoord, Status* status) { replCoord->processReplSetInitiate(opCtx.get(), BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "node1:12345") << BSON("_id" << 1 << "host" @@ -460,9 +436,7 @@ TEST_F(ReplCoordTest, getReplCoord()->processReplSetInitiate(opCtx.get(), BSON("_id" << "wrongSet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "node1:12345"))), &result1)); @@ -491,8 +465,9 @@ TEST_F(ReplCoordTest, NodeReturnsInvalidReplicaSetConfigWhenInitiatingWithoutAn_ BSONObjBuilder result1; auto status = getReplCoord()->processReplSetInitiate( opCtx.get(), - BSON("version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" - << "node1:12345"))), + BSON("version" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "node1:12345"))), &result1); ASSERT_EQUALS(ErrorCodes::InvalidReplicaSetConfig, status); ASSERT_STRING_CONTAINS(status.reason(), "Missing expected field \"_id\""); @@ -511,9 +486,7 @@ TEST_F(ReplCoordTest, getReplCoord()->processReplSetInitiate(opCtx.get(), BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "node1:12345"))), &result1); @@ -534,9 +507,7 @@ TEST_F(ReplCoordTest, InitiateFailsWithoutReplSetFlag) { getReplCoord()->processReplSetInitiate(opCtx.get(), BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "node1:12345"))), &result1)); @@ -557,9 +528,7 @@ TEST_F(ReplCoordTest, NodeReturnsOutOfDiskSpaceWhenInitiateCannotWriteConfigToDi getReplCoord()->processReplSetInitiate(opCtx.get(), BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "node1:12345"))), &result1)); @@ -611,13 +580,10 @@ TEST_F( TEST_F(ReplCoordTest, NodeReturnsOkWhenCheckReplEnabledForCommandAfterReceivingAConfig) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); // check status OK and result is empty @@ -647,21 +613,16 @@ TEST_F(ReplCoordTest, NodeReturnsImmediatelyWhenAwaitReplicationIsRanAgainstASta TEST_F(ReplCoordTest, NodeReturnsNotMasterWhenRunningAwaitReplicationAgainstASecondaryNode) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2))), + << "_id" << 2))), HostAndPort("node1", 12345)); auto opCtx = makeOperationContext(); @@ -682,21 +643,16 @@ TEST_F(ReplCoordTest, NodeReturnsNotMasterWhenRunningAwaitReplicationAgainstASec TEST_F(ReplCoordTest, NodeReturnsOkWhenRunningAwaitReplicationAgainstPrimaryWithWTermOne) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2))), + << "_id" << 2))), HostAndPort("node1", 12345)); OpTimeWithTermOne time(100, 1); @@ -724,25 +680,19 @@ TEST_F(ReplCoordTest, NodeReturnsWriteConcernFailedUntilASufficientNumberOfNodesHaveTheWriteDurable) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2) + << "_id" << 2) << BSON("host" << "node4:12345" - << "_id" - << 3))), + << "_id" << 3))), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100)); @@ -804,25 +754,19 @@ TEST_F(ReplCoordTest, TEST_F(ReplCoordTest, NodeReturnsWriteConcernFailedUntilASufficientNumberOfNodesHaveTheWrite) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2) + << "_id" << 2) << BSON("host" << "node4:12345" - << "_id" - << 3))), + << "_id" << 3))), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100)); @@ -881,9 +825,7 @@ TEST_F(ReplCoordTest, NodeReturnsUnknownReplWriteConcernWhenAwaitReplicationReceivesAnInvalidWriteConcernMode) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "node0") << BSON("_id" << 1 << "host" @@ -920,9 +862,7 @@ TEST_F( assertStartSuccess( BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "node0" << "tags" @@ -1102,21 +1042,16 @@ private: TEST_F(ReplCoordTest, NodeReturnsOkWhenAWriteConcernWithNoTimeoutHasBeenSatisfied) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2))), + << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100)); @@ -1166,21 +1101,16 @@ TEST_F(ReplCoordTest, NodeReturnsOkWhenAWriteConcernWithNoTimeoutHasBeenSatisfie TEST_F(ReplCoordTest, NodeReturnsWriteConcernFailedWhenAWriteConcernTimesOutBeforeBeingSatisified) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2))), + << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100)); @@ -1217,21 +1147,16 @@ TEST_F(ReplCoordTest, NodeReturnsShutDownInProgressWhenANodeShutsDownPriorToSatisfyingAWriteConcern) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2))), + << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100)); @@ -1267,21 +1192,16 @@ TEST_F(ReplCoordTest, NodeReturnsNotMasterWhenSteppingDownBeforeSatisfyingAWrite // if the node steps down while it is waiting. assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2))), + << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100)); @@ -1315,9 +1235,7 @@ TEST_F(ReplCoordTest, // Tests that a thread blocked in awaitReplication can be killed by a killOp operation assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "node1") << BSON("_id" << 1 << "host" @@ -1435,9 +1353,7 @@ private: init("mySet/test1:1234,test2:1234,test3:1234"); assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" @@ -1462,9 +1378,7 @@ TEST_F(ReplCoordTest, UpdatePositionArgsAdvancesWallTimes) { init("mySet/test1:1234,test2:1234,test3:1234"); assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" @@ -1498,33 +1412,27 @@ TEST_F(ReplCoordTest, UpdatePositionArgsAdvancesWallTimes) { ASSERT_OK(updatePositionArgsInitialize( updatePositionArgs, - BSON(UpdatePositionArgs::kCommandFieldName - << 1 - << UpdatePositionArgs::kUpdateArrayFieldName - << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName - << configVersion - << UpdatePositionArgs::kMemberIdFieldName - << 1 - << UpdatePositionArgs::kAppliedOpTimeFieldName - << opTime2.asOpTime().toBSON() - << UpdatePositionArgs::kAppliedWallTimeFieldName - << memberOneAppliedWallTime - << UpdatePositionArgs::kDurableOpTimeFieldName - << opTime2.asOpTime().toBSON() - << UpdatePositionArgs::kDurableWallTimeFieldName - << memberOneDurableWallTime) - << BSON(UpdatePositionArgs::kConfigVersionFieldName - << configVersion - << UpdatePositionArgs::kMemberIdFieldName - << 2 - << UpdatePositionArgs::kAppliedOpTimeFieldName - << opTime2.asOpTime().toBSON() - << UpdatePositionArgs::kAppliedWallTimeFieldName - << memberTwoAppliedWallTime - << UpdatePositionArgs::kDurableOpTimeFieldName - << opTime2.asOpTime().toBSON() - << UpdatePositionArgs::kDurableWallTimeFieldName - << memberTwoDurableWallTime))))); + BSON( + UpdatePositionArgs::kCommandFieldName + << 1 << UpdatePositionArgs::kUpdateArrayFieldName + << BSON_ARRAY( + BSON( + UpdatePositionArgs::kConfigVersionFieldName + << configVersion << UpdatePositionArgs::kMemberIdFieldName << 1 + << UpdatePositionArgs::kAppliedOpTimeFieldName << opTime2.asOpTime().toBSON() + << UpdatePositionArgs::kAppliedWallTimeFieldName << memberOneAppliedWallTime + << UpdatePositionArgs::kDurableOpTimeFieldName << opTime2.asOpTime().toBSON() + << UpdatePositionArgs::kDurableWallTimeFieldName << memberOneDurableWallTime) + << BSON(UpdatePositionArgs::kConfigVersionFieldName + << configVersion << UpdatePositionArgs::kMemberIdFieldName << 2 + << UpdatePositionArgs::kAppliedOpTimeFieldName + << opTime2.asOpTime().toBSON() + << UpdatePositionArgs::kAppliedWallTimeFieldName + << memberTwoAppliedWallTime + << UpdatePositionArgs::kDurableOpTimeFieldName + << opTime2.asOpTime().toBSON() + << UpdatePositionArgs::kDurableWallTimeFieldName + << memberTwoDurableWallTime))))); ASSERT_OK(repl->processReplSetUpdatePosition(updatePositionArgs, &configVersion)); @@ -1546,17 +1454,14 @@ TEST_F(ReplCoordTest, ElectionIdTracksTermInPV1) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" << "test2:1234") << BSON("_id" << 2 << "host" << "test3:1234")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), HostAndPort("test1", 1234)); replCoordSetMyLastAppliedOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)); replCoordSetMyLastDurableOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)); @@ -1610,17 +1515,14 @@ TEST_F(ReplCoordTest, NodeChangesTermAndStepsDownWhenAndOnlyWhenUpdateTermSuppli assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" << "test2:1234") << BSON("_id" << 2 << "host" << "test3:1234")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), HostAndPort("test1", 1234)); replCoordSetMyLastAppliedOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)); replCoordSetMyLastDurableOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)); @@ -1656,17 +1558,14 @@ TEST_F(ReplCoordTest, ConcurrentStepDownShouldNotSignalTheSameFinishEventMoreTha assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" << "test2:1234") << BSON("_id" << 2 << "host" << "test3:1234")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), HostAndPort("test1", 1234)); replCoordSetMyLastAppliedOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)); replCoordSetMyLastDurableOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)); @@ -1712,17 +1611,14 @@ TEST_F(ReplCoordTest, DrainCompletionMidStepDown) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" << "test2:1234") << BSON("_id" << 2 << "host" << "test3:1234")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), HostAndPort("test1", 1234)); replCoordSetMyLastAppliedOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)); replCoordSetMyLastDurableOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)); @@ -1784,12 +1680,9 @@ TEST_F(StepDownTest, StepDownCanCompleteBasedOnReplSetUpdatePositionAlone) { ASSERT_OK(updatePositionArgsInitialize( updatePositionArgs, BSON(UpdatePositionArgs::kCommandFieldName - << 1 - << UpdatePositionArgs::kUpdateArrayFieldName + << 1 << UpdatePositionArgs::kUpdateArrayFieldName << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName - << configVersion - << UpdatePositionArgs::kMemberIdFieldName - << 1 + << configVersion << UpdatePositionArgs::kMemberIdFieldName << 1 << UpdatePositionArgs::kAppliedOpTimeFieldName << opTime2.asOpTime().toBSON() << UpdatePositionArgs::kAppliedWallTimeFieldName @@ -1799,9 +1692,7 @@ TEST_F(StepDownTest, StepDownCanCompleteBasedOnReplSetUpdatePositionAlone) { << UpdatePositionArgs::kDurableWallTimeFieldName << Date_t() + Seconds(opTime2.asOpTime().getSecs())) << BSON(UpdatePositionArgs::kConfigVersionFieldName - << configVersion - << UpdatePositionArgs::kMemberIdFieldName - << 2 + << configVersion << UpdatePositionArgs::kMemberIdFieldName << 2 << UpdatePositionArgs::kAppliedOpTimeFieldName << opTime1.asOpTime().toBSON() << UpdatePositionArgs::kAppliedWallTimeFieldName @@ -1886,17 +1777,12 @@ private: init("mySet/test1:1234,test2:1234,test3:1234"); assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" << "test2:1234" - << "priority" - << 0) + << "priority" << 0) << BSON("_id" << 2 << "host" << "test3:1234"))), HostAndPort("test1", 1234)); @@ -1936,12 +1822,9 @@ TEST_F(StepDownTestWithUnelectableNode, ASSERT_OK(updatePositionArgsInitialize( catchupFirstSecondary, BSON(UpdatePositionArgs::kCommandFieldName - << 1 - << UpdatePositionArgs::kUpdateArrayFieldName + << 1 << UpdatePositionArgs::kUpdateArrayFieldName << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName - << configVersion - << UpdatePositionArgs::kMemberIdFieldName - << 1 + << configVersion << UpdatePositionArgs::kMemberIdFieldName << 1 << UpdatePositionArgs::kAppliedOpTimeFieldName << opTime2.asOpTime().toBSON() << UpdatePositionArgs::kAppliedWallTimeFieldName @@ -1951,9 +1834,7 @@ TEST_F(StepDownTestWithUnelectableNode, << UpdatePositionArgs::kDurableWallTimeFieldName << Date_t() + Seconds(opTime2.asOpTime().getSecs())) << BSON(UpdatePositionArgs::kConfigVersionFieldName - << configVersion - << UpdatePositionArgs::kMemberIdFieldName - << 2 + << configVersion << UpdatePositionArgs::kMemberIdFieldName << 2 << UpdatePositionArgs::kAppliedOpTimeFieldName << opTime1.asOpTime().toBSON() << UpdatePositionArgs::kAppliedWallTimeFieldName @@ -1975,12 +1856,9 @@ TEST_F(StepDownTestWithUnelectableNode, ASSERT_OK(updatePositionArgsInitialize( catchupOtherSecondary, BSON(UpdatePositionArgs::kCommandFieldName - << 1 - << UpdatePositionArgs::kUpdateArrayFieldName + << 1 << UpdatePositionArgs::kUpdateArrayFieldName << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName - << configVersion - << UpdatePositionArgs::kMemberIdFieldName - << 1 + << configVersion << UpdatePositionArgs::kMemberIdFieldName << 1 << UpdatePositionArgs::kAppliedOpTimeFieldName << opTime2.asOpTime().toBSON() << UpdatePositionArgs::kAppliedWallTimeFieldName @@ -1990,9 +1868,7 @@ TEST_F(StepDownTestWithUnelectableNode, << UpdatePositionArgs::kDurableWallTimeFieldName << Date_t() + Seconds(opTime2.asOpTime().getSecs())) << BSON(UpdatePositionArgs::kConfigVersionFieldName - << configVersion - << UpdatePositionArgs::kMemberIdFieldName - << 2 + << configVersion << UpdatePositionArgs::kMemberIdFieldName << 2 << UpdatePositionArgs::kAppliedOpTimeFieldName << opTime2.asOpTime().toBSON() << UpdatePositionArgs::kAppliedWallTimeFieldName @@ -2121,9 +1997,7 @@ private: assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" @@ -2220,14 +2094,10 @@ TEST_F(ReplCoordTest, SingleNodeReplSetStepDownTimeoutAndElectionTimeoutExpiresA assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234")) - << "protocolVersion" - << 1 - << "settings" + << "protocolVersion" << 1 << "settings" << BSON("electionTimeoutMillis" << 1000)), HostAndPort("test1", 1234)); auto opCtx = makeOperationContext(); @@ -2256,14 +2126,10 @@ TEST_F(ReplCoordTest, SingleNodeReplSetUnfreeze) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234")) - << "protocolVersion" - << 1 - << "settings" + << "protocolVersion" << 1 << "settings" << BSON("electionTimeoutMillis" << 10000)), HostAndPort("test1", 1234)); auto opCtx = makeOperationContext(); @@ -2305,9 +2171,7 @@ TEST_F(ReplCoordTest, NodeBecomesPrimaryAgainWhenStepDownTimeoutExpiresInASingle assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234"))), HostAndPort("test1", 1234)); @@ -2337,9 +2201,7 @@ TEST_F( assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234"))), HostAndPort("test1", 1234)); @@ -2693,13 +2555,10 @@ TEST_F(ReplCoordTest, ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s); assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); } @@ -2707,9 +2566,7 @@ TEST_F(ReplCoordTest, NodeIncludesOtherMembersProgressInUpdatePositionCommand) { init("mySet/test1:1234,test2:1234,test3:1234"); assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" @@ -2786,11 +2643,7 @@ TEST_F(ReplCoordTest, init("mySet/test1:1234,test2:1234,test3:1234"); assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" + << "protocolVersion" << 1 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" @@ -2813,11 +2666,7 @@ TEST_F(ReplCoordTest, init("mySet/test1:1234,test2:1234,test3:1234"); assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" + << "protocolVersion" << 1 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" @@ -2849,11 +2698,7 @@ TEST_F(ReplCoordTest, AllowAsManyUnsetMaintenanceModesAsThereHaveBeenSetMaintena init("mySet/test1:1234,test2:1234,test3:1234"); assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" + << "protocolVersion" << 1 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" @@ -2883,11 +2728,7 @@ TEST_F(ReplCoordTest, SettingAndUnsettingMaintenanceModeShouldNotAffectRollbackS init("mySet/test1:1234,test2:1234,test3:1234"); assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" + << "protocolVersion" << 1 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" @@ -2929,11 +2770,7 @@ TEST_F(ReplCoordTest, DoNotAllowMaintenanceModeWhilePrimary) { init("mySet/test1:1234,test2:1234,test3:1234"); assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" + << "protocolVersion" << 1 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" @@ -2968,11 +2805,7 @@ TEST_F(ReplCoordTest, DoNotAllowSettingMaintenanceModeWhileConductingAnElection) init("mySet/test1:1234,test2:1234,test3:1234"); assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" + << "protocolVersion" << 1 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" @@ -3040,9 +2873,7 @@ TEST_F(ReplCoordTest, HostAndPort client2Host("node3:12345"); assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << myHost.toString()) << BSON("_id" << 1 << "host" << client1Host.toString()) << BSON("_id" << 2 << "host" << client2Host.toString()))), @@ -3085,9 +2916,7 @@ TEST_F(ReplCoordTest, HostAndPort client2Host("node3:12345"); assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << myHost.toString()) << BSON("_id" << 1 << "host" << client1Host.toString()) << BSON("_id" << 2 << "host" << client2Host.toString()))), @@ -3123,19 +2952,14 @@ TEST_F(ReplCoordTest, NodeReturnsNoNodesWhenGetOtherNodesInReplSetIsRunBeforeHav TEST_F(ReplCoordTest, NodeReturnsListOfNodesOtherThanItselfInResponseToGetOtherNodesInReplSet) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "h1") << BSON("_id" << 1 << "host" << "h2") << BSON("_id" << 2 << "host" << "h3" - << "priority" - << 0 - << "hidden" - << true))), + << "priority" << 0 << "hidden" << true))), HostAndPort("h1")); std::vector<HostAndPort> otherNodes = getReplCoord()->getOtherNodesInReplSet(); @@ -3173,9 +2997,7 @@ TEST_F(ReplCoordTest, IsMaster) { BSON( "_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << h1.toString()) << BSON("_id" << 1 << "host" << h2.toString()) << BSON("_id" << 2 << "host" << h3.toString() << "arbiterOnly" << true) @@ -3238,9 +3060,7 @@ TEST_F(ReplCoordTest, IsMasterWithCommittedSnapshot) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234"))), HostAndPort("test1", 1234)); @@ -3270,9 +3090,7 @@ TEST_F(ReplCoordTest, IsMasterInShutdown) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234"))), HostAndPort("test1", 1234)); @@ -3308,21 +3126,16 @@ TEST_F(ReplCoordTest, LogAMessageWhenShutDownBeforeReplicationStartUpFinished) { TEST_F(ReplCoordTest, DoNotProcessSelfWhenUpdatePositionContainsInfoAboutSelf) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2))), + << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100)); @@ -3349,18 +3162,13 @@ TEST_F(ReplCoordTest, DoNotProcessSelfWhenUpdatePositionContainsInfoAboutSelf) { ASSERT_OK(updatePositionArgsInitialize( args, BSON(UpdatePositionArgs::kCommandFieldName - << 1 - << UpdatePositionArgs::kUpdateArrayFieldName + << 1 << UpdatePositionArgs::kUpdateArrayFieldName << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName - << 2 - << UpdatePositionArgs::kMemberIdFieldName - << 0 - << UpdatePositionArgs::kDurableOpTimeFieldName - << time2.toBSON() + << 2 << UpdatePositionArgs::kMemberIdFieldName << 0 + << UpdatePositionArgs::kDurableOpTimeFieldName << time2.toBSON() << UpdatePositionArgs::kDurableWallTimeFieldName << Date_t() + Seconds(time2.getSecs()) - << UpdatePositionArgs::kAppliedOpTimeFieldName - << time2.toBSON() + << UpdatePositionArgs::kAppliedOpTimeFieldName << time2.toBSON() << UpdatePositionArgs::kAppliedWallTimeFieldName << Date_t() + Seconds(time2.getSecs())))))); @@ -3372,21 +3180,16 @@ TEST_F(ReplCoordTest, DoNotProcessSelfWhenUpdatePositionContainsInfoAboutSelf) { TEST_F(ReplCoordTest, DoNotProcessUpdatePositionWhenItsConfigVersionIsIncorrect) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2))), + << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100)); @@ -3407,18 +3210,13 @@ TEST_F(ReplCoordTest, DoNotProcessUpdatePositionWhenItsConfigVersionIsIncorrect) ASSERT_OK(updatePositionArgsInitialize( args, BSON(UpdatePositionArgs::kCommandFieldName - << 1 - << UpdatePositionArgs::kUpdateArrayFieldName + << 1 << UpdatePositionArgs::kUpdateArrayFieldName << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName - << 3 - << UpdatePositionArgs::kMemberIdFieldName - << 1 - << UpdatePositionArgs::kDurableOpTimeFieldName - << time2.toBSON() + << 3 << UpdatePositionArgs::kMemberIdFieldName << 1 + << UpdatePositionArgs::kDurableOpTimeFieldName << time2.toBSON() << UpdatePositionArgs::kDurableWallTimeFieldName << Date_t() + Seconds(time2.getSecs()) - << UpdatePositionArgs::kAppliedOpTimeFieldName - << time2.toBSON() + << UpdatePositionArgs::kAppliedOpTimeFieldName << time2.toBSON() << UpdatePositionArgs::kAppliedWallTimeFieldName << Date_t() + Seconds(time2.getSecs())))))); @@ -3435,21 +3233,16 @@ TEST_F(ReplCoordTest, DoNotProcessUpdatePositionWhenItsConfigVersionIsIncorrect) TEST_F(ReplCoordTest, DoNotProcessUpdatePositionOfMembersWhoseIdsAreNotInTheConfig) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2))), + << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100)); @@ -3470,18 +3263,13 @@ TEST_F(ReplCoordTest, DoNotProcessUpdatePositionOfMembersWhoseIdsAreNotInTheConf ASSERT_OK(updatePositionArgsInitialize( args, BSON(UpdatePositionArgs::kCommandFieldName - << 1 - << UpdatePositionArgs::kUpdateArrayFieldName + << 1 << UpdatePositionArgs::kUpdateArrayFieldName << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName - << 2 - << UpdatePositionArgs::kMemberIdFieldName - << 9 - << UpdatePositionArgs::kDurableOpTimeFieldName - << time2.toBSON() + << 2 << UpdatePositionArgs::kMemberIdFieldName << 9 + << UpdatePositionArgs::kDurableOpTimeFieldName << time2.toBSON() << UpdatePositionArgs::kDurableWallTimeFieldName << Date_t() + Seconds(time2.getSecs()) - << UpdatePositionArgs::kAppliedOpTimeFieldName - << time2.toBSON() + << UpdatePositionArgs::kAppliedOpTimeFieldName << time2.toBSON() << UpdatePositionArgs::kAppliedWallTimeFieldName << Date_t() + Seconds(time2.getSecs())))))); @@ -3497,21 +3285,16 @@ TEST_F(ReplCoordTest, ProcessUpdateWhenUpdatePositionContainsOnlyConfigVersionAndMemberIdsWithoutRIDs) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2))), + << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100)); @@ -3535,32 +3318,26 @@ TEST_F(ReplCoordTest, ASSERT_OK(updatePositionArgsInitialize( args, BSON(UpdatePositionArgs::kCommandFieldName - << 1 - << UpdatePositionArgs::kUpdateArrayFieldName - << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName - << 2 - << UpdatePositionArgs::kMemberIdFieldName - << 1 - << UpdatePositionArgs::kAppliedOpTimeFieldName - << time2.asOpTime().toBSON() - << UpdatePositionArgs::kAppliedWallTimeFieldName - << Date_t() + Seconds(time2.asOpTime().getSecs()) - << UpdatePositionArgs::kDurableOpTimeFieldName - << time2.asOpTime().toBSON() - << UpdatePositionArgs::kDurableWallTimeFieldName - << Date_t() + Seconds(time2.asOpTime().getSecs())) - << BSON(UpdatePositionArgs::kConfigVersionFieldName - << 2 - << UpdatePositionArgs::kMemberIdFieldName - << 2 - << UpdatePositionArgs::kAppliedOpTimeFieldName - << time2.asOpTime().toBSON() - << UpdatePositionArgs::kAppliedWallTimeFieldName - << Date_t() + Seconds(time2.asOpTime().getSecs()) - << UpdatePositionArgs::kDurableOpTimeFieldName - << time2.asOpTime().toBSON() - << UpdatePositionArgs::kDurableWallTimeFieldName - << Date_t() + Seconds(time2.asOpTime().getSecs())))))); + << 1 << UpdatePositionArgs::kUpdateArrayFieldName + << BSON_ARRAY( + BSON(UpdatePositionArgs::kConfigVersionFieldName + << 2 << UpdatePositionArgs::kMemberIdFieldName << 1 + << UpdatePositionArgs::kAppliedOpTimeFieldName << time2.asOpTime().toBSON() + << UpdatePositionArgs::kAppliedWallTimeFieldName + << Date_t() + Seconds(time2.asOpTime().getSecs()) + << UpdatePositionArgs::kDurableOpTimeFieldName << time2.asOpTime().toBSON() + << UpdatePositionArgs::kDurableWallTimeFieldName + << Date_t() + Seconds(time2.asOpTime().getSecs())) + << BSON(UpdatePositionArgs::kConfigVersionFieldName + << 2 << UpdatePositionArgs::kMemberIdFieldName << 2 + << UpdatePositionArgs::kAppliedOpTimeFieldName + << time2.asOpTime().toBSON() + << UpdatePositionArgs::kAppliedWallTimeFieldName + << Date_t() + Seconds(time2.asOpTime().getSecs()) + << UpdatePositionArgs::kDurableOpTimeFieldName + << time2.asOpTime().toBSON() + << UpdatePositionArgs::kDurableWallTimeFieldName + << Date_t() + Seconds(time2.asOpTime().getSecs())))))); auto opCtx = makeOperationContext(); @@ -3581,15 +3358,10 @@ void doReplSetReconfig(ReplicationCoordinatorImpl* replCoord, Status* status) { args.force = false; args.newConfigObj = BSON("_id" << "mySet" - << "version" - << 3 - << "protocolVersion" - << 1 - << "members" + << "version" << 3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "node1:12345" - << "priority" - << 3) + << "priority" << 3) << BSON("_id" << 1 << "host" << "node2:12345") << BSON("_id" << 2 << "host" @@ -3600,21 +3372,16 @@ void doReplSetReconfig(ReplicationCoordinatorImpl* replCoord, Status* status) { TEST_F(ReplCoordTest, AwaitReplicationShouldResolveAsNormalDuringAReconfig) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2))), + << "_id" << 2))), HostAndPort("node1", 12345)); // Turn off readconcern majority support, and snapshots. @@ -3681,11 +3448,7 @@ void doReplSetReconfigToFewer(ReplicationCoordinatorImpl* replCoord, Status* sta args.force = false; args.newConfigObj = BSON("_id" << "mySet" - << "version" - << 3 - << "protocolVersion" - << 1 - << "members" + << "version" << 3 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "node1:12345") << BSON("_id" << 2 << "host" @@ -3698,21 +3461,16 @@ TEST_F( NodeReturnsUnsatisfiableWriteConcernWhenReconfiggingToAClusterThatCannotSatisfyTheWriteConcern) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2))), + << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 2), Date_t() + Seconds(100)); @@ -3759,29 +3517,22 @@ TEST_F(ReplCoordTest, NodeReturnsOKFromAwaitReplicationWhenReconfiggingToASetWhereMajorityIsSmallerAndSatisfied) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2) + << "_id" << 2) << BSON("host" << "node4:12345" - << "_id" - << 3) + << "_id" << 3) << BSON("host" << "node5:12345" - << "_id" - << 4))), + << "_id" << 4))), HostAndPort("node1", 12345)); // Turn off readconcern majority support, and snapshots. @@ -3842,35 +3593,22 @@ TEST_F(ReplCoordTest, // satisfied by voting data-bearing members. assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2) + << "_id" << 2) << BSON("host" << "node4:12345" - << "_id" - << 3 - << "votes" - << 0 - << "priority" - << 0) + << "_id" << 3 << "votes" << 0 << "priority" << 0) << BSON("host" << "node5:12345" - << "_id" - << 4 - << "arbiterOnly" - << true))), + << "_id" << 4 << "arbiterOnly" << true))), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); OpTime time(Timestamp(100, 1), 1); @@ -3910,35 +3648,22 @@ TEST_F(ReplCoordTest, // Test that the commit level advances properly. assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2) + << "_id" << 2) << BSON("host" << "node4:12345" - << "_id" - << 3 - << "votes" - << 0 - << "priority" - << 0) + << "_id" << 3 << "votes" << 0 << "priority" << 0) << BSON("host" << "node5:12345" - << "_id" - << 4 - << "arbiterOnly" - << true))), + << "_id" << 4 << "arbiterOnly" << true))), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); OpTime zero(Timestamp(0, 0), 0); @@ -4170,11 +3895,7 @@ TEST_F(StableOpTimeTest, SetMyLastAppliedSetsStableOpTimeForStorage) { init("mySet/test1:1234,test2:1234,test3:1234"); assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" + << "protocolVersion" << 1 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" @@ -4238,11 +3959,7 @@ TEST_F(StableOpTimeTest, SetMyLastAppliedSetsStableOpTimeForStorageDisableMajori init("mySet/test1:1234,test2:1234,test3:1234"); assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" + << "protocolVersion" << 1 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" @@ -4275,11 +3992,7 @@ TEST_F(StableOpTimeTest, AdvanceCommitPointSetsStableOpTimeForStorage) { init("mySet/test1:1234,test2:1234,test3:1234"); assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 1 - << "members" + << "protocolVersion" << 1 << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" @@ -4337,15 +4050,11 @@ TEST_F(StableOpTimeTest, ClearOpTimeCandidatesPastCommonPointAfterRollback) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0)) - << "protocolVersion" - << 1), + << "_id" << 0)) + << "protocolVersion" << 1), HostAndPort("node1", 12345)); auto repl = getReplCoord(); @@ -4441,13 +4150,10 @@ TEST_F(StableOpTimeTest, OpTimeCandidatesAreNotAddedWhenStateIsNotConsistent) { TEST_F(ReplCoordTest, NodeReturnsShutdownInProgressWhenWaitingUntilAnOpTimeDuringShutdown) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(10, 1), Date_t() + Seconds(100)); @@ -4466,13 +4172,10 @@ TEST_F(ReplCoordTest, NodeReturnsShutdownInProgressWhenWaitingUntilAnOpTimeDurin TEST_F(ReplCoordTest, NodeReturnsInterruptedWhenWaitingUntilAnOpTimeIsInterrupted) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(10, 1), Date_t() + Seconds(100)); @@ -4490,13 +4193,10 @@ TEST_F(ReplCoordTest, NodeReturnsInterruptedWhenWaitingUntilAnOpTimeIsInterrupte TEST_F(ReplCoordTest, NodeReturnsOkImmediatelyWhenWaitingUntilOpTimePassesNoOpTime) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); auto opCtx = makeOperationContext(); @@ -4507,13 +4207,10 @@ TEST_F(ReplCoordTest, NodeReturnsOkImmediatelyWhenWaitingUntilOpTimePassesNoOpTi TEST_F(ReplCoordTest, NodeReturnsOkImmediatelyWhenWaitingUntilOpTimePassesAnOpTimePriorToOurLast) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100)); @@ -4529,13 +4226,10 @@ TEST_F(ReplCoordTest, NodeReturnsOkImmediatelyWhenWaitingUntilOpTimePassesAnOpTi TEST_F(ReplCoordTest, NodeReturnsOkImmediatelyWhenWaitingUntilOpTimePassesAnOpTimeEqualToOurLast) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); @@ -4576,13 +4270,10 @@ TEST_F(ReplCoordTest, NodeReturnsNotAReplicaSetWhenWaitUntilOpTimeIsRunAgainstAS TEST_F(ReplCoordTest, ReadAfterCommittedWhileShutdown) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); auto opCtx = makeOperationContext(); @@ -4602,13 +4293,10 @@ TEST_F(ReplCoordTest, ReadAfterCommittedWhileShutdown) { TEST_F(ReplCoordTest, ReadAfterCommittedInterrupted) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); const auto opCtx = makeOperationContext(); runSingleNodeElection(opCtx.get()); @@ -4625,13 +4313,10 @@ TEST_F(ReplCoordTest, ReadAfterCommittedInterrupted) { TEST_F(ReplCoordTest, ReadAfterCommittedGreaterOpTime) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); auto opCtx = makeOperationContext(); runSingleNodeElection(opCtx.get()); @@ -4647,13 +4332,10 @@ TEST_F(ReplCoordTest, ReadAfterCommittedGreaterOpTime) { TEST_F(ReplCoordTest, ReadAfterCommittedEqualOpTime) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); auto opCtx = makeOperationContext(); runSingleNodeElection(opCtx.get()); @@ -4669,13 +4351,10 @@ TEST_F(ReplCoordTest, ReadAfterCommittedEqualOpTime) { TEST_F(ReplCoordTest, ReadAfterCommittedDeferredGreaterOpTime) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); auto opCtx = makeOperationContext(); @@ -4697,13 +4376,10 @@ TEST_F(ReplCoordTest, ReadAfterCommittedDeferredGreaterOpTime) { TEST_F(ReplCoordTest, ReadAfterCommittedDeferredEqualOpTime) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); auto opCtx = makeOperationContext(); runSingleNodeElection(opCtx.get()); @@ -4727,13 +4403,10 @@ TEST_F(ReplCoordTest, ReadAfterCommittedDeferredEqualOpTime) { TEST_F(ReplCoordTest, WaitUntilOpTimeforReadRejectsUnsupportedMajorityReadConcern) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); auto opCtx = makeOperationContext(); @@ -4759,21 +4432,16 @@ TEST_F(ReplCoordTest, IgnoreTheContentsOfMetadataWhenItsConfigVersionDoesNotMatc // Ensure that we do not process ReplSetMetadata when ConfigVersions do not match. assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2))), + << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT_EQUALS(OpTime(Timestamp(0, 0), 0), getReplCoord()->getLastCommittedOpTime()); @@ -4781,35 +4449,20 @@ TEST_F(ReplCoordTest, IgnoreTheContentsOfMetadataWhenItsConfigVersionDoesNotMatc StatusWith<rpc::ReplSetMetadata> metadata = replReadFromMetadata(BSON( rpc::kReplSetMetadataFieldName << BSON( "lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 2) << "lastCommittedWall" - << Date_t() + Seconds(100) - << "lastOpVisible" - << BSON("ts" << Timestamp(10, 0) << "t" << 2) - << "configVersion" - << 1 - << "primaryIndex" - << 2 - << "term" - << 2 - << "syncSourceIndex" - << 1))); + << Date_t() + Seconds(100) << "lastOpVisible" + << BSON("ts" << Timestamp(10, 0) << "t" << 2) << "configVersion" << 1 + << "primaryIndex" << 2 << "term" << 2 << "syncSourceIndex" << 1))); getReplCoord()->processReplSetMetadata(metadata.getValue()); ASSERT_EQUALS(0, getReplCoord()->getTerm()); // higher configVersion - StatusWith<rpc::ReplSetMetadata> metadata2 = replReadFromMetadata(BSON( - rpc::kReplSetMetadataFieldName << BSON( - "lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 2) << "lastCommittedWall" - << Date_t() + Seconds(100) - << "lastOpVisible" - << BSON("ts" << Timestamp(10, 0) << "t" << 2) - << "configVersion" - << 100 - << "primaryIndex" - << 2 - << "term" - << 2 - << "syncSourceIndex" - << 1))); + StatusWith<rpc::ReplSetMetadata> metadata2 = replReadFromMetadata( + BSON(rpc::kReplSetMetadataFieldName + << BSON("lastOpCommitted" + << BSON("ts" << Timestamp(10, 0) << "t" << 2) << "lastCommittedWall" + << Date_t() + Seconds(100) << "lastOpVisible" + << BSON("ts" << Timestamp(10, 0) << "t" << 2) << "configVersion" << 100 + << "primaryIndex" << 2 << "term" << 2 << "syncSourceIndex" << 1))); getReplCoord()->processReplSetMetadata(metadata2.getValue()); ASSERT_EQUALS(0, getReplCoord()->getTerm()); } @@ -4819,23 +4472,17 @@ TEST_F(ReplCoordTest, UpdateLastCommittedOpTimeWhenTheLastCommittedOpTimeIsNewer // but not if the OpTime is older than the current LastCommittedOpTime. assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2)) - << "protocolVersion" - << 1), + << "_id" << 2)) + << "protocolVersion" << 1), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); ASSERT_EQUALS(OpTime(Timestamp(0, 0), 0), getReplCoord()->getLastCommittedOpTime()); @@ -4865,23 +4512,17 @@ TEST_F(ReplCoordTest, UpdateTermWhenTheTermFromMetadataIsNewerButNeverUpdateCurr // Ensure that currentPrimaryIndex is never altered by ReplSetMetadata. assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2)) - << "protocolVersion" - << 1), + << "_id" << 2)) + << "protocolVersion" << 1), HostAndPort("node1", 12345)); ASSERT_EQUALS(OpTime(Timestamp(0, 0), 0), getReplCoord()->getLastCommittedOpTime()); auto opCtx = makeOperationContext(); @@ -4892,17 +4533,9 @@ TEST_F(ReplCoordTest, UpdateTermWhenTheTermFromMetadataIsNewerButNeverUpdateCurr StatusWith<rpc::ReplSetMetadata> metadata = replReadFromMetadata(BSON( rpc::kReplSetMetadataFieldName << BSON( "lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 3) << "lastCommittedWall" - << Date_t() + Seconds(100) - << "lastOpVisible" - << BSON("ts" << Timestamp(10, 0) << "t" << 3) - << "configVersion" - << 2 - << "primaryIndex" - << 2 - << "term" - << 3 - << "syncSourceIndex" - << 1))); + << Date_t() + Seconds(100) << "lastOpVisible" + << BSON("ts" << Timestamp(10, 0) << "t" << 3) << "configVersion" << 2 + << "primaryIndex" << 2 << "term" << 3 << "syncSourceIndex" << 1))); getReplCoord()->processReplSetMetadata(metadata.getValue()); ASSERT_EQUALS(3, getReplCoord()->getTerm()); ASSERT_EQUALS(-1, getTopoCoord().getCurrentPrimaryIndex()); @@ -4912,17 +4545,9 @@ TEST_F(ReplCoordTest, UpdateTermWhenTheTermFromMetadataIsNewerButNeverUpdateCurr StatusWith<rpc::ReplSetMetadata> metadata2 = replReadFromMetadata(BSON( rpc::kReplSetMetadataFieldName << BSON( "lastOpCommitted" << BSON("ts" << Timestamp(11, 0) << "t" << 3) << "lastCommittedWall" - << Date_t() + Seconds(100) - << "lastOpVisible" - << BSON("ts" << Timestamp(11, 0) << "t" << 3) - << "configVersion" - << 2 - << "primaryIndex" - << 1 - << "term" - << 2 - << "syncSourceIndex" - << 1))); + << Date_t() + Seconds(100) << "lastOpVisible" + << BSON("ts" << Timestamp(11, 0) << "t" << 3) << "configVersion" << 2 + << "primaryIndex" << 1 << "term" << 2 << "syncSourceIndex" << 1))); getReplCoord()->processReplSetMetadata(metadata2.getValue()); ASSERT_EQUALS(3, getReplCoord()->getTerm()); ASSERT_EQUALS(-1, getTopoCoord().getCurrentPrimaryIndex()); @@ -4932,17 +4557,9 @@ TEST_F(ReplCoordTest, UpdateTermWhenTheTermFromMetadataIsNewerButNeverUpdateCurr StatusWith<rpc::ReplSetMetadata> metadata3 = replReadFromMetadata(BSON( rpc::kReplSetMetadataFieldName << BSON( "lastOpCommitted" << BSON("ts" << Timestamp(11, 0) << "t" << 3) << "lastCommittedWall" - << Date_t() + Seconds(100) - << "lastOpVisible" - << BSON("ts" << Timestamp(11, 0) << "t" << 3) - << "configVersion" - << 2 - << "primaryIndex" - << 1 - << "term" - << 3 - << "syncSourceIndex" - << 1))); + << Date_t() + Seconds(100) << "lastOpVisible" + << BSON("ts" << Timestamp(11, 0) << "t" << 3) << "configVersion" << 2 + << "primaryIndex" << 1 << "term" << 3 << "syncSourceIndex" << 1))); getReplCoord()->processReplSetMetadata(metadata3.getValue()); ASSERT_EQUALS(3, getReplCoord()->getTerm()); ASSERT_EQUALS(-1, getTopoCoord().getCurrentPrimaryIndex()); @@ -4954,19 +4571,14 @@ TEST_F(ReplCoordTest, // Ensure that the metadata is processed if it is contained in a heartbeat response. assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1)) - << "protocolVersion" - << 1), + << "_id" << 1)) + << "protocolVersion" << 1), HostAndPort("node1", 12345)); ASSERT_EQUALS(OpTime(Timestamp(0, 0), 0), getReplCoord()->getLastCommittedOpTime()); auto opCtx = makeOperationContext(); @@ -4978,19 +4590,12 @@ TEST_F(ReplCoordTest, // Higher term - should update term but not last committed optime. StatusWith<rpc::ReplSetMetadata> metadata = replReadFromMetadata(BSON( - rpc::kReplSetMetadataFieldName << BSON( - "lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 3) << "lastCommittedWall" - << Date_t() + Seconds(100) - << "lastOpVisible" - << BSON("ts" << Timestamp(10, 0) << "t" << 3) - << "configVersion" - << config.getConfigVersion() - << "primaryIndex" - << 1 - << "term" - << 3 - << "syncSourceIndex" - << 1))); + rpc::kReplSetMetadataFieldName + << BSON("lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 3) + << "lastCommittedWall" << Date_t() + Seconds(100) + << "lastOpVisible" << BSON("ts" << Timestamp(10, 0) << "t" << 3) + << "configVersion" << config.getConfigVersion() << "primaryIndex" + << 1 << "term" << 3 << "syncSourceIndex" << 1))); BSONObjBuilder responseBuilder; ASSERT_OK(metadata.getValue().writeToMetadata(&responseBuilder)); @@ -5021,19 +4626,14 @@ TEST_F(ReplCoordTest, LastCommittedOpTimeOnlyUpdatedFromHeartbeatWhenLastApplied // Ensure that the metadata is processed if it is contained in a heartbeat response. assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1)) - << "protocolVersion" - << 1), + << "_id" << 1)) + << "protocolVersion" << 1), HostAndPort("node1", 12345)); ASSERT_EQUALS(OpTime(), getReplCoord()->getLastCommittedOpTime()); @@ -5103,19 +4703,14 @@ TEST_F(ReplCoordTest, LastCommittedOpTimeOnlyUpdatedFromHeartbeatInFCV42) { // Ensure that the metadata is processed if it is contained in a heartbeat response. assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1)) - << "protocolVersion" - << 1), + << "_id" << 1)) + << "protocolVersion" << 1), HostAndPort("node1", 12345)); ASSERT_EQUALS(OpTime(), getReplCoord()->getLastCommittedOpTime()); @@ -5182,19 +4777,14 @@ TEST_F(ReplCoordTest, LastCommittedOpTimeOnlyUpdatedFromHeartbeatInFCV42) { TEST_F(ReplCoordTest, AdvanceCommitPointFromSyncSourceCanSetCommitPointToLastAppliedIgnoringTerm) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1)) - << "protocolVersion" - << 1), + << "_id" << 1)) + << "protocolVersion" << 1), HostAndPort("node1", 12345)); ASSERT_EQUALS(OpTime(), getReplCoord()->getLastCommittedOpTime()); @@ -5212,23 +4802,17 @@ TEST_F(ReplCoordTest, AdvanceCommitPointFromSyncSourceCanSetCommitPointToLastApp TEST_F(ReplCoordTest, PrepareOplogQueryMetadata) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2)) - << "protocolVersion" - << 1), + << "_id" << 2)) + << "protocolVersion" << 1), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); @@ -5276,21 +4860,14 @@ TEST_F(ReplCoordTest, TermAndLastCommittedOpTimeUpdatedFromHeartbeatWhenArbiter) // Ensure that the metadata is processed if it is contained in a heartbeat response. assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0 - << "arbiterOnly" - << true) + << "_id" << 0 << "arbiterOnly" << true) << BSON("host" << "node2:12345" - << "_id" - << 1)) - << "protocolVersion" - << 1), + << "_id" << 1)) + << "protocolVersion" << 1), HostAndPort("node1", 12345)); ASSERT_EQUALS(OpTime(Timestamp(0, 0), 0), getReplCoord()->getLastCommittedOpTime()); auto opCtx = makeOperationContext(); @@ -5303,19 +4880,12 @@ TEST_F(ReplCoordTest, TermAndLastCommittedOpTimeUpdatedFromHeartbeatWhenArbiter) // Higher term - should update term and lastCommittedOpTime since arbiters learn of the // commit point via heartbeats. StatusWith<rpc::ReplSetMetadata> metadata = replReadFromMetadata(BSON( - rpc::kReplSetMetadataFieldName << BSON( - "lastOpCommitted" << BSON("ts" << Timestamp(10, 1) << "t" << 3) << "lastCommittedWall" - << Date_t() + Seconds(100) - << "lastOpVisible" - << BSON("ts" << Timestamp(10, 1) << "t" << 3) - << "configVersion" - << config.getConfigVersion() - << "primaryIndex" - << 1 - << "term" - << 3 - << "syncSourceIndex" - << 1))); + rpc::kReplSetMetadataFieldName + << BSON("lastOpCommitted" << BSON("ts" << Timestamp(10, 1) << "t" << 3) + << "lastCommittedWall" << Date_t() + Seconds(100) + << "lastOpVisible" << BSON("ts" << Timestamp(10, 1) << "t" << 3) + << "configVersion" << config.getConfigVersion() << "primaryIndex" + << 1 << "term" << 3 << "syncSourceIndex" << 1))); BSONObjBuilder responseBuilder; ASSERT_OK(metadata.getValue().writeToMetadata(&responseBuilder)); @@ -5346,19 +4916,13 @@ TEST_F(ReplCoordTest, ScheduleElectionToBeRunInElectionTimeoutFromNowWhenCancelAndRescheduleElectionTimeoutIsRun) { assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 2 - << "members" + << "protocolVersion" << 1 << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1))), + << "_id" << 1))), HostAndPort("node1", 12345)); ReplicationCoordinatorImpl* replCoord = getReplCoord(); @@ -5397,19 +4961,13 @@ TEST_F(ReplCoordTest, TEST_F(ReplCoordTest, DoNotScheduleElectionWhenCancelAndRescheduleElectionTimeoutIsRunInRollback) { assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 2 - << "members" + << "protocolVersion" << 1 << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1))), + << "_id" << 1))), HostAndPort("node1", 12345)); ReplicationCoordinatorImpl* replCoord = getReplCoord(); @@ -5428,23 +4986,13 @@ TEST_F(ReplCoordTest, DoNotScheduleElectionWhenCancelAndRescheduleElectionTimeoutIsRunWhileUnelectable) { assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 2 - << "members" + << "protocolVersion" << 1 << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0 - << "priority" - << 0 - << "hidden" - << true) + << "_id" << 0 << "priority" << 0 << "hidden" << true) << BSON("host" << "node2:12345" - << "_id" - << 1))), + << "_id" << 1))), HostAndPort("node1", 12345)); ReplicationCoordinatorImpl* replCoord = getReplCoord(); ASSERT_OK(replCoord->setFollowerMode(MemberState::RS_SECONDARY)); @@ -5459,19 +5007,13 @@ TEST_F(ReplCoordTest, DoNotScheduleElectionWhenCancelAndRescheduleElectionTimeoutIsRunWhileRemoved) { assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 2 - << "members" + << "protocolVersion" << 1 << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1))), + << "_id" << 1))), HostAndPort("node1", 12345)); ReplicationCoordinatorImpl* replCoord = getReplCoord(); @@ -5497,15 +5039,10 @@ TEST_F(ReplCoordTest, config .initialize(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 3 - << "members" + << "protocolVersion" << 1 << "version" << 3 << "members" << BSON_ARRAY(BSON("host" << "node2:12345" - << "_id" - << 1)))) + << "_id" << 1)))) .transitional_ignore(); hbResp.setConfig(config); hbResp.setConfigVersion(3); @@ -5529,19 +5066,13 @@ TEST_F(ReplCoordTest, RescheduleElectionTimeoutWhenProcessingHeartbeatResponseFromPrimaryInSameTerm) { assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 2 - << "members" + << "protocolVersion" << 1 << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1))), + << "_id" << 1))), HostAndPort("node1", 12345)); ReplicationCoordinatorImpl* replCoord = getReplCoord(); @@ -5586,19 +5117,13 @@ TEST_F(ReplCoordTest, DontRescheduleElectionTimeoutWhenProcessingHeartbeatResponseFromPrimaryInDiffertTerm) { assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 2 - << "members" + << "protocolVersion" << 1 << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1))), + << "_id" << 1))), HostAndPort("node1", 12345)); ReplicationCoordinatorImpl* replCoord = getReplCoord(); @@ -5640,19 +5165,13 @@ TEST_F(ReplCoordTest, CancelAndRescheduleElectionTimeoutWhenProcessingHeartbeatResponseWithoutState) { assertStartSuccess(BSON("_id" << "mySet" - << "protocolVersion" - << 1 - << "version" - << 2 - << "members" + << "protocolVersion" << 1 << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1))), + << "_id" << 1))), HostAndPort("node1", 12345)); ReplicationCoordinatorImpl* replCoord = getReplCoord(); @@ -5692,9 +5211,7 @@ TEST_F(ReplCoordTest, AdvanceCommittedSnapshotToMostRecentSnapshotPriorToOpTimeW assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234"))), HostAndPort("test1", 1234)); @@ -5728,9 +5245,7 @@ TEST_F(ReplCoordTest, ZeroCommittedSnapshotWhenAllSnapshotsAreDropped) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234"))), HostAndPort("test1", 1234)); @@ -5760,9 +5275,7 @@ TEST_F(ReplCoordTest, DoNotAdvanceCommittedSnapshotWhenAppliedOpTimeChanges) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234"))), HostAndPort("test1", 1234)); @@ -5785,13 +5298,10 @@ TEST_F(ReplCoordTest, NodeChangesMyLastOpTimeWhenAndOnlyWhensetMyLastDurableOpTimeReceivesANewerOpTime4DurableSE) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); @@ -5815,13 +5325,10 @@ DEATH_TEST_F(ReplCoordTest, "opTime.getTimestamp() > myLastAppliedOpTime.getTimestamp()") { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); @@ -5841,13 +5348,10 @@ DEATH_TEST_F(ReplCoordTest, "opTime.getTimestamp() > myLastAppliedOpTime.getTimestamp()") { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); @@ -5867,13 +5371,10 @@ DEATH_TEST_F(ReplCoordTest, "opTime.getTimestamp() < myLastAppliedOpTime.getTimestamp()") { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); @@ -5893,13 +5394,10 @@ DEATH_TEST_F(ReplCoordTest, "opTime.getTimestamp() < myLastAppliedOpTime.getTimestamp()") { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0))), + << "_id" << 0))), HostAndPort("node1", 12345)); @@ -5918,18 +5416,14 @@ TEST_F(ReplCoordTest, OnlyForwardSyncProgressForOtherNodesWhenTheNodesAreBelieve assertStartSuccess( BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" << "test2:1234") << BSON("_id" << 2 << "host" << "test3:1234")) - << "protocolVersion" - << 1 - << "settings" + << "protocolVersion" << 1 << "settings" << BSON("electionTimeoutMillis" << 2000 << "heartbeatIntervalMillis" << 40000)), HostAndPort("test1", 1234)); OpTime optime(Timestamp(100, 2), 0); @@ -5992,18 +5486,14 @@ TEST_F(ReplCoordTest, UpdatePositionCmdHasMetadata) { assertStartSuccess( BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234") << BSON("_id" << 1 << "host" << "test2:1234") << BSON("_id" << 2 << "host" << "test3:1234")) - << "protocolVersion" - << 1 - << "settings" + << "protocolVersion" << 1 << "settings" << BSON("electionTimeoutMillis" << 2000 << "heartbeatIntervalMillis" << 40000)), HostAndPort("test1", 1234)); OpTime optime(Timestamp(100, 2), 0); @@ -6033,32 +5523,23 @@ TEST_F(ReplCoordTest, StepDownWhenHandleLivenessTimeoutMarksAMajorityOfVotingNod assertStartSuccess( BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2) + << "_id" << 2) << BSON("host" << "node4:12345" - << "_id" - << 3) + << "_id" << 3) << BSON("host" << "node5:12345" - << "_id" - << 4)) - << "protocolVersion" - << 1 - << "settings" + << "_id" << 4)) + << "protocolVersion" << 1 << "settings" << BSON("electionTimeoutMillis" << 2000 << "heartbeatIntervalMillis" << 40000)), HostAndPort("node1", 12345)); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); @@ -6070,57 +5551,42 @@ TEST_F(ReplCoordTest, StepDownWhenHandleLivenessTimeoutMarksAMajorityOfVotingNod UpdatePositionArgs args; ASSERT_OK(updatePositionArgsInitialize( args, - BSON(UpdatePositionArgs::kCommandFieldName - << 1 - << UpdatePositionArgs::kUpdateArrayFieldName - << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName - << 2 - << UpdatePositionArgs::kMemberIdFieldName - << 1 - << UpdatePositionArgs::kAppliedOpTimeFieldName - << startingOpTime.toBSON() - << UpdatePositionArgs::kAppliedWallTimeFieldName - << Date_t() + Seconds(startingOpTime.getSecs()) - << UpdatePositionArgs::kDurableOpTimeFieldName - << startingOpTime.toBSON() - << UpdatePositionArgs::kDurableWallTimeFieldName - << Date_t() + Seconds(startingOpTime.getSecs())) - << BSON(UpdatePositionArgs::kConfigVersionFieldName - << 2 - << UpdatePositionArgs::kMemberIdFieldName - << 2 - << UpdatePositionArgs::kAppliedOpTimeFieldName - << startingOpTime.toBSON() - << UpdatePositionArgs::kAppliedWallTimeFieldName - << Date_t() + Seconds(startingOpTime.getSecs()) - << UpdatePositionArgs::kDurableOpTimeFieldName - << startingOpTime.toBSON() - << UpdatePositionArgs::kDurableWallTimeFieldName - << Date_t() + Seconds(startingOpTime.getSecs())) - << BSON(UpdatePositionArgs::kConfigVersionFieldName - << 2 - << UpdatePositionArgs::kMemberIdFieldName - << 3 - << UpdatePositionArgs::kAppliedOpTimeFieldName - << startingOpTime.toBSON() - << UpdatePositionArgs::kAppliedWallTimeFieldName - << Date_t() + Seconds(startingOpTime.getSecs()) - << UpdatePositionArgs::kDurableOpTimeFieldName - << startingOpTime.toBSON() - << UpdatePositionArgs::kDurableWallTimeFieldName - << Date_t() + Seconds(startingOpTime.getSecs())) - << BSON(UpdatePositionArgs::kConfigVersionFieldName - << 2 - << UpdatePositionArgs::kMemberIdFieldName - << 4 - << UpdatePositionArgs::kAppliedOpTimeFieldName - << startingOpTime.toBSON() - << UpdatePositionArgs::kAppliedWallTimeFieldName - << Date_t() + Seconds(startingOpTime.getSecs()) - << UpdatePositionArgs::kDurableOpTimeFieldName - << startingOpTime.toBSON() - << UpdatePositionArgs::kDurableWallTimeFieldName - << Date_t() + Seconds(startingOpTime.getSecs())))))); + BSON( + UpdatePositionArgs::kCommandFieldName + << 1 << UpdatePositionArgs::kUpdateArrayFieldName + << BSON_ARRAY( + BSON(UpdatePositionArgs::kConfigVersionFieldName + << 2 << UpdatePositionArgs::kMemberIdFieldName << 1 + << UpdatePositionArgs::kAppliedOpTimeFieldName << startingOpTime.toBSON() + << UpdatePositionArgs::kAppliedWallTimeFieldName + << Date_t() + Seconds(startingOpTime.getSecs()) + << UpdatePositionArgs::kDurableOpTimeFieldName << startingOpTime.toBSON() + << UpdatePositionArgs::kDurableWallTimeFieldName + << Date_t() + Seconds(startingOpTime.getSecs())) + << BSON(UpdatePositionArgs::kConfigVersionFieldName + << 2 << UpdatePositionArgs::kMemberIdFieldName << 2 + << UpdatePositionArgs::kAppliedOpTimeFieldName << startingOpTime.toBSON() + << UpdatePositionArgs::kAppliedWallTimeFieldName + << Date_t() + Seconds(startingOpTime.getSecs()) + << UpdatePositionArgs::kDurableOpTimeFieldName << startingOpTime.toBSON() + << UpdatePositionArgs::kDurableWallTimeFieldName + << Date_t() + Seconds(startingOpTime.getSecs())) + << BSON(UpdatePositionArgs::kConfigVersionFieldName + << 2 << UpdatePositionArgs::kMemberIdFieldName << 3 + << UpdatePositionArgs::kAppliedOpTimeFieldName << startingOpTime.toBSON() + << UpdatePositionArgs::kAppliedWallTimeFieldName + << Date_t() + Seconds(startingOpTime.getSecs()) + << UpdatePositionArgs::kDurableOpTimeFieldName << startingOpTime.toBSON() + << UpdatePositionArgs::kDurableWallTimeFieldName + << Date_t() + Seconds(startingOpTime.getSecs())) + << BSON(UpdatePositionArgs::kConfigVersionFieldName + << 2 << UpdatePositionArgs::kMemberIdFieldName << 4 + << UpdatePositionArgs::kAppliedOpTimeFieldName << startingOpTime.toBSON() + << UpdatePositionArgs::kAppliedWallTimeFieldName + << Date_t() + Seconds(startingOpTime.getSecs()) + << UpdatePositionArgs::kDurableOpTimeFieldName << startingOpTime.toBSON() + << UpdatePositionArgs::kDurableWallTimeFieldName + << Date_t() + Seconds(startingOpTime.getSecs())))))); ASSERT_OK(getReplCoord()->processReplSetUpdatePosition(args, 0)); // Become PRIMARY. @@ -6130,33 +5596,26 @@ TEST_F(ReplCoordTest, StepDownWhenHandleLivenessTimeoutMarksAMajorityOfVotingNod UpdatePositionArgs args1; ASSERT_OK(updatePositionArgsInitialize( args1, - BSON(UpdatePositionArgs::kCommandFieldName - << 1 - << UpdatePositionArgs::kUpdateArrayFieldName - << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName - << 2 - << UpdatePositionArgs::kMemberIdFieldName - << 1 - << UpdatePositionArgs::kAppliedOpTimeFieldName - << startingOpTime.toBSON() - << UpdatePositionArgs::kAppliedWallTimeFieldName - << Date_t() + Seconds(startingOpTime.getSecs()) - << UpdatePositionArgs::kDurableOpTimeFieldName - << startingOpTime.toBSON() - << UpdatePositionArgs::kDurableWallTimeFieldName - << Date_t() + Seconds(startingOpTime.getSecs())) - << BSON(UpdatePositionArgs::kConfigVersionFieldName - << 2 - << UpdatePositionArgs::kMemberIdFieldName - << 2 - << UpdatePositionArgs::kAppliedOpTimeFieldName - << startingOpTime.toBSON() - << UpdatePositionArgs::kAppliedWallTimeFieldName - << Date_t() + Seconds(startingOpTime.getSecs()) - << UpdatePositionArgs::kDurableOpTimeFieldName - << startingOpTime.toBSON() - << UpdatePositionArgs::kDurableWallTimeFieldName - << Date_t() + Seconds(startingOpTime.getSecs())))), + BSON( + UpdatePositionArgs::kCommandFieldName + << 1 << UpdatePositionArgs::kUpdateArrayFieldName + << BSON_ARRAY( + BSON(UpdatePositionArgs::kConfigVersionFieldName + << 2 << UpdatePositionArgs::kMemberIdFieldName << 1 + << UpdatePositionArgs::kAppliedOpTimeFieldName << startingOpTime.toBSON() + << UpdatePositionArgs::kAppliedWallTimeFieldName + << Date_t() + Seconds(startingOpTime.getSecs()) + << UpdatePositionArgs::kDurableOpTimeFieldName << startingOpTime.toBSON() + << UpdatePositionArgs::kDurableWallTimeFieldName + << Date_t() + Seconds(startingOpTime.getSecs())) + << BSON(UpdatePositionArgs::kConfigVersionFieldName + << 2 << UpdatePositionArgs::kMemberIdFieldName << 2 + << UpdatePositionArgs::kAppliedOpTimeFieldName << startingOpTime.toBSON() + << UpdatePositionArgs::kAppliedWallTimeFieldName + << Date_t() + Seconds(startingOpTime.getSecs()) + << UpdatePositionArgs::kDurableOpTimeFieldName << startingOpTime.toBSON() + << UpdatePositionArgs::kDurableWallTimeFieldName + << Date_t() + Seconds(startingOpTime.getSecs())))), /*requireWallTime*/ true)); const Date_t startDate = getNet()->now(); getNet()->enterNetwork(); @@ -6198,20 +5657,16 @@ TEST_F(ReplCoordTest, StepDownWhenHandleLivenessTimeoutMarksAMajorityOfVotingNod ASSERT_OK(updatePositionArgsInitialize( args2, BSON(UpdatePositionArgs::kCommandFieldName - << 1 - << UpdatePositionArgs::kUpdateArrayFieldName - << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName - << 2 - << UpdatePositionArgs::kMemberIdFieldName - << 1 - << UpdatePositionArgs::kDurableOpTimeFieldName - << startingOpTime.toBSON() - << UpdatePositionArgs::kDurableWallTimeFieldName - << Date_t() + Seconds(startingOpTime.getSecs()) - << UpdatePositionArgs::kAppliedOpTimeFieldName - << startingOpTime.toBSON() - << UpdatePositionArgs::kAppliedWallTimeFieldName - << Date_t() + Seconds(startingOpTime.getSecs())))))); + << 1 << UpdatePositionArgs::kUpdateArrayFieldName + << BSON_ARRAY( + BSON(UpdatePositionArgs::kConfigVersionFieldName + << 2 << UpdatePositionArgs::kMemberIdFieldName << 1 + << UpdatePositionArgs::kDurableOpTimeFieldName << startingOpTime.toBSON() + << UpdatePositionArgs::kDurableWallTimeFieldName + << Date_t() + Seconds(startingOpTime.getSecs()) + << UpdatePositionArgs::kAppliedOpTimeFieldName << startingOpTime.toBSON() + << UpdatePositionArgs::kAppliedWallTimeFieldName + << Date_t() + Seconds(startingOpTime.getSecs())))))); ASSERT_OK(getReplCoord()->processReplSetUpdatePosition(args2, 0)); hbArgs.setSetName("mySet"); @@ -6241,9 +5696,7 @@ TEST_F(ReplCoordTest, WaitForMemberState) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234"))), HostAndPort("test1", 1234)); @@ -6278,9 +5731,7 @@ TEST_F(ReplCoordTest, WaitForDrainFinish) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234"))), HostAndPort("test1", 1234)); @@ -6319,13 +5770,10 @@ TEST_F( assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234")) - << "writeConcernMajorityJournalDefault" - << false), + << "writeConcernMajorityJournalDefault" << false), HostAndPort("test1", 1234)); WriteConcernOptions wc; @@ -6342,13 +5790,10 @@ TEST_F( assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234")) - << "writeConcernMajorityJournalDefault" - << true), + << "writeConcernMajorityJournalDefault" << true), HostAndPort("test1", 1234)); WriteConcernOptions wc; @@ -6363,13 +5808,10 @@ TEST_F(ReplCoordTest, PopulateUnsetWriteConcernOptionsSyncModeReturnsInputIfSync assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234")) - << "writeConcernMajorityJournalDefault" - << false), + << "writeConcernMajorityJournalDefault" << false), HostAndPort("test1", 1234)); WriteConcernOptions wc; @@ -6391,13 +5833,10 @@ TEST_F(ReplCoordTest, PopulateUnsetWriteConcernOptionsSyncModeReturnsInputIfWMod assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234")) - << "writeConcernMajorityJournalDefault" - << false), + << "writeConcernMajorityJournalDefault" << false), HostAndPort("test1", 1234)); WriteConcernOptions wc; @@ -6414,21 +5853,16 @@ TEST_F(ReplCoordTest, PopulateUnsetWriteConcernOptionsSyncModeReturnsInputIfWMod TEST_F(ReplCoordTest, NodeStoresElectionVotes) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2))), + << "_id" << 2))), HostAndPort("node1", 12345)); auto time = OpTimeWithTermOne(100, 1); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); @@ -6441,15 +5875,9 @@ TEST_F(ReplCoordTest, NodeStoresElectionVotes) { ReplSetRequestVotesArgs args; ASSERT_OK(args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "mySet" - << "term" - << 7LL - << "candidateIndex" - << 2LL - << "configVersion" - << 2LL - << "dryRun" - << false - << "lastCommittedOp" + << "term" << 7LL << "candidateIndex" << 2LL + << "configVersion" << 2LL << "dryRun" + << false << "lastCommittedOp" << time.asOpTime().toBSON()))); ReplSetRequestVotesResponse response; @@ -6468,21 +5896,16 @@ TEST_F(ReplCoordTest, NodeStoresElectionVotes) { TEST_F(ReplCoordTest, NodeDoesNotStoreDryRunVotes) { assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1) + << "_id" << 1) << BSON("host" << "node3:12345" - << "_id" - << 2))), + << "_id" << 2))), HostAndPort("node1", 12345)); auto time = OpTimeWithTermOne(100, 1); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); @@ -6495,15 +5918,9 @@ TEST_F(ReplCoordTest, NodeDoesNotStoreDryRunVotes) { ReplSetRequestVotesArgs args; ASSERT_OK(args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "mySet" - << "term" - << 7LL - << "candidateIndex" - << 2LL - << "configVersion" - << 2LL - << "dryRun" - << true - << "lastCommittedOp" + << "term" << 7LL << "candidateIndex" << 2LL + << "configVersion" << 2LL << "dryRun" + << true << "lastCommittedOp" << time.asOpTime().toBSON()))); ReplSetRequestVotesResponse response; @@ -6524,17 +5941,13 @@ TEST_F(ReplCoordTest, NodeFailsVoteRequestIfItFailsToStoreLastVote) { // Set up a 2-node replica set config. assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1))), + << "_id" << 1))), HostAndPort("node1", 12345)); auto time = OpTimeWithTermOne(100, 1); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); @@ -6549,18 +5962,12 @@ TEST_F(ReplCoordTest, NodeFailsVoteRequestIfItFailsToStoreLastVote) { auto opCtx = makeOperationContext(); ReplSetRequestVotesArgs args; - ASSERT_OK(args.initialize(BSON("replSetRequestVotes" << 1 << "setName" - << "mySet" - << "term" - << initTerm + 1 // term of new candidate. - << "candidateIndex" - << 1LL - << "configVersion" - << 2LL - << "dryRun" - << false - << "lastCommittedOp" - << time.asOpTime().toBSON()))); + ASSERT_OK(args.initialize(BSON("replSetRequestVotes" + << 1 << "setName" + << "mySet" + << "term" << initTerm + 1 // term of new candidate. + << "candidateIndex" << 1LL << "configVersion" << 2LL << "dryRun" + << false << "lastCommittedOp" << time.asOpTime().toBSON()))); ReplSetRequestVotesResponse response; // Simulate a failure to write the 'last vote' document. The specific error code isn't @@ -6585,17 +5992,13 @@ TEST_F(ReplCoordTest, NodeNodesNotGrantVoteIfInTerminalShutdown) { // Set up a 2-node replica set config. assertStartSuccess(BSON("_id" << "mySet" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" - << "_id" - << 0) + << "_id" << 0) << BSON("host" << "node2:12345" - << "_id" - << 1))), + << "_id" << 1))), HostAndPort("node1", 12345)); auto time = OpTimeWithTermOne(100, 1); ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); @@ -6610,18 +6013,12 @@ TEST_F(ReplCoordTest, NodeNodesNotGrantVoteIfInTerminalShutdown) { auto opCtx = makeOperationContext(); ReplSetRequestVotesArgs args; - ASSERT_OK(args.initialize(BSON("replSetRequestVotes" << 1 << "setName" - << "mySet" - << "term" - << initTerm + 1 // term of new candidate. - << "candidateIndex" - << 1LL - << "configVersion" - << 2LL - << "dryRun" - << false - << "lastCommittedOp" - << time.asOpTime().toBSON()))); + ASSERT_OK(args.initialize(BSON("replSetRequestVotes" + << 1 << "setName" + << "mySet" + << "term" << initTerm + 1 // term of new candidate. + << "candidateIndex" << 1LL << "configVersion" << 2LL << "dryRun" + << false << "lastCommittedOp" << time.asOpTime().toBSON()))); ReplSetRequestVotesResponse response; getReplCoord()->enterTerminalShutdown(); diff --git a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp index 82317b139a2..068a769e735 100644 --- a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp +++ b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp @@ -276,14 +276,13 @@ void ReplCoordTest::simulateSuccessfulDryRun( if (request.cmdObj.firstElement().fieldNameStringData() == "replSetRequestVotes") { ASSERT_TRUE(request.cmdObj.getBoolField("dryRun")); onDryRunRequest(request); - net->scheduleResponse(noi, - net->now(), - makeResponseStatus(BSON("ok" << 1 << "reason" - << "" - << "term" - << request.cmdObj["term"].Long() - << "voteGranted" - << true))); + net->scheduleResponse( + noi, + net->now(), + makeResponseStatus(BSON("ok" << 1 << "reason" + << "" + << "term" << request.cmdObj["term"].Long() + << "voteGranted" << true))); voteRequests++; } else if (consumeHeartbeatV1(noi)) { // The heartbeat has been consumed. @@ -345,14 +344,13 @@ void ReplCoordTest::simulateSuccessfulV1ElectionWithoutExitingDrainMode(Date_t e hbResp.setConfigVersion(rsConfig.getConfigVersion()); net->scheduleResponse(noi, net->now(), makeResponseStatus(hbResp.toBSON())); } else if (request.cmdObj.firstElement().fieldNameStringData() == "replSetRequestVotes") { - net->scheduleResponse(noi, - net->now(), - makeResponseStatus(BSON("ok" << 1 << "reason" - << "" - << "term" - << request.cmdObj["term"].Long() - << "voteGranted" - << true))); + net->scheduleResponse( + noi, + net->now(), + makeResponseStatus(BSON("ok" << 1 << "reason" + << "" + << "term" << request.cmdObj["term"].Long() + << "voteGranted" << true))); } else { error() << "Black holing unexpected request to " << request.target << ": " << request.cmdObj; diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp index e3f26e73513..40c1499ef67 100644 --- a/src/mongo/db/repl/replication_info.cpp +++ b/src/mongo/db/repl/replication_info.cpp @@ -66,10 +66,10 @@ namespace mongo { MONGO_FAIL_POINT_DEFINE(waitInIsMaster); -using std::unique_ptr; using std::list; using std::string; using std::stringstream; +using std::unique_ptr; namespace repl { namespace { @@ -328,8 +328,7 @@ public: } else { uasserted(ErrorCodes::BadValue, str::stream() << "Unrecognized field of 'internalClient': '" - << fieldName - << "'"); + << fieldName << "'"); } } diff --git a/src/mongo/db/repl/replication_recovery.cpp b/src/mongo/db/repl/replication_recovery.cpp index fba6d41fd6d..f4dd3e104c5 100644 --- a/src/mongo/db/repl/replication_recovery.cpp +++ b/src/mongo/db/repl/replication_recovery.cpp @@ -413,8 +413,7 @@ void ReplicationRecoveryImpl::_applyToEndOfOplog(OperationContext* opCtx, invariant(applyThroughOpTime.getTimestamp() == topOfOplog, str::stream() << "Did not apply to top of oplog. Applied through: " << applyThroughOpTime.toString() - << ". Top of oplog: " - << topOfOplog.toString()); + << ". Top of oplog: " << topOfOplog.toString()); oplogBuffer.shutdown(opCtx); // We may crash before setting appliedThrough. If we have a stable checkpoint, we will recover diff --git a/src/mongo/db/repl/replication_recovery_test.cpp b/src/mongo/db/repl/replication_recovery_test.cpp index 0d12cd58fa8..c97746080e5 100644 --- a/src/mongo/db/repl/replication_recovery_test.cpp +++ b/src/mongo/db/repl/replication_recovery_test.cpp @@ -1051,9 +1051,7 @@ TEST_F(ReplicationRecoveryTest, CommitTransactionOplogEntryCorrectlyUpdatesConfi const auto txnOperations = BSON_ARRAY(BSON("op" << "i" - << "ns" - << testNs.toString() - << "o" + << "ns" << testNs.toString() << "o" << BSON("_id" << 1))); const auto prepareDate = Date_t::now(); const auto prepareOp = @@ -1128,9 +1126,7 @@ TEST_F(ReplicationRecoveryTest, const auto txnOperations = BSON_ARRAY(BSON("op" << "i" - << "ns" - << testNs.toString() - << "o" + << "ns" << testNs.toString() << "o" << BSON("_id" << 1))); const auto prepareDate = Date_t::now(); const auto prepareOp = diff --git a/src/mongo/db/repl/reporter_test.cpp b/src/mongo/db/repl/reporter_test.cpp index 6213eb4fe26..f056fee9332 100644 --- a/src/mongo/db/repl/reporter_test.cpp +++ b/src/mongo/db/repl/reporter_test.cpp @@ -379,8 +379,7 @@ TEST_F(ReporterTestNoTriggerAtSetUp, processNetworkResponse(BSON("ok" << 0 << "code" << int(ErrorCodes::InvalidReplicaSetConfig) << "errmsg" << "newer config" - << "configVersion" - << 100)); + << "configVersion" << 100)); ASSERT_EQUALS(Status(ErrorCodes::InvalidReplicaSetConfig, "invalid config"), reporter->join()); assertReporterDone(); @@ -399,8 +398,7 @@ TEST_F(ReporterTest, InvalidReplicaSetResponseWithSameConfigVersionOnSyncTargetS processNetworkResponse(BSON("ok" << 0 << "code" << int(ErrorCodes::InvalidReplicaSetConfig) << "errmsg" << "invalid config" - << "configVersion" - << posUpdater->getConfigVersion())); + << "configVersion" << posUpdater->getConfigVersion())); ASSERT_EQUALS(Status(ErrorCodes::InvalidReplicaSetConfig, "invalid config"), reporter->join()); assertReporterDone(); @@ -416,8 +414,7 @@ TEST_F(ReporterTest, processNetworkResponse(BSON("ok" << 0 << "code" << int(ErrorCodes::InvalidReplicaSetConfig) << "errmsg" << "newer config" - << "configVersion" - << posUpdater->getConfigVersion() + 1)); + << "configVersion" << posUpdater->getConfigVersion() + 1)); ASSERT_TRUE(reporter->isActive()); } diff --git a/src/mongo/db/repl/roll_back_local_operations.cpp b/src/mongo/db/repl/roll_back_local_operations.cpp index 09047074164..1e5b102a595 100644 --- a/src/mongo/db/repl/roll_back_local_operations.cpp +++ b/src/mongo/db/repl/roll_back_local_operations.cpp @@ -123,14 +123,11 @@ StatusWith<RollBackLocalOperations::RollbackCommonPoint> RollBackLocalOperations auto result = _localOplogIterator->next(); if (!result.isOK()) { return Status(ErrorCodes::NoMatchingDocument, - str::stream() << "reached beginning of local oplog: {" - << "scanned: " - << _scanned - << ", theirTime: " - << getTimestamp(operation).toString() - << ", ourTime: " - << getTimestamp(_localOplogValue).toString() - << "}"); + str::stream() + << "reached beginning of local oplog: {" + << "scanned: " << _scanned + << ", theirTime: " << getTimestamp(operation).toString() + << ", ourTime: " << getTimestamp(_localOplogValue).toString() << "}"); } opAfterCurrentEntry = _localOplogValue.first; _localOplogValue = result.getValue(); @@ -200,11 +197,8 @@ StatusWith<RollBackLocalOperations::RollbackCommonPoint> syncRollBackLocalOperat } return Status(ErrorCodes::NoMatchingDocument, str::stream() << "reached beginning of remote oplog: {" - << "them: " - << remoteOplog.toString() - << ", theirTime: " - << theirTime.toString() - << "}"); + << "them: " << remoteOplog.toString() + << ", theirTime: " << theirTime.toString() << "}"); } } // namespace repl diff --git a/src/mongo/db/repl/roll_back_local_operations_test.cpp b/src/mongo/db/repl/roll_back_local_operations_test.cpp index 1f8a933b67c..67fff417d0a 100644 --- a/src/mongo/db/repl/roll_back_local_operations_test.cpp +++ b/src/mongo/db/repl/roll_back_local_operations_test.cpp @@ -50,26 +50,18 @@ BSONObj makeOp(long long seconds, long long term = 1LL) { auto uuid = unittest::assertGet(UUID::parse("b4c66a44-c1ca-4d86-8d25-12e82fa2de5b")); return BSON("ts" << Timestamp(seconds, seconds) << "t" << term << "op" << "n" - << "o" - << BSONObj() - << "ns" + << "o" << BSONObj() << "ns" << "roll_back_local_operations.test" - << "ui" - << uuid); + << "ui" << uuid); } BSONObj makeOpWithWallClockTime(long count, long wallClockMillis, long long term = 1LL) { auto uuid = unittest::assertGet(UUID::parse("b4c66a44-c1ca-4d86-8d25-12e82fa2de5b")); return BSON("ts" << Timestamp(count, count) << "t" << term << "op" << "n" - << "o" - << BSONObj() - << "ns" + << "o" << BSONObj() << "ns" << "roll_back_local_operations.test" - << "ui" - << uuid - << "wall" - << Date_t::fromMillisSinceEpoch(wallClockMillis)); + << "ui" << uuid << "wall" << Date_t::fromMillisSinceEpoch(wallClockMillis)); }; int recordId = 0; @@ -150,7 +142,8 @@ TEST(RollBackLocalOperationsTest, RollbackMultipleLocalOperations) { TEST(RollBackLocalOperationsTest, RollbackOperationFailed) { auto commonOperation = makeOpAndRecordId(1); OplogInterfaceMock::Operations localOperations({ - makeOpAndRecordId(2), commonOperation, + makeOpAndRecordId(2), + commonOperation, }); OplogInterfaceMock localOplog(localOperations); auto rollbackOperation = [&](const BSONObj& operation) { @@ -175,7 +168,10 @@ TEST(RollBackLocalOperationsTest, EndOfLocalOplog) { TEST(RollBackLocalOperationsTest, SkipRemoteOperations) { auto commonOperation = makeOpAndRecordId(1); OplogInterfaceMock::Operations localOperations({ - makeOpAndRecordId(5), makeOpAndRecordId(4), makeOpAndRecordId(2), commonOperation, + makeOpAndRecordId(5), + makeOpAndRecordId(4), + makeOpAndRecordId(2), + commonOperation, }); OplogInterfaceMock localOplog(localOperations); auto i = localOperations.cbegin(); @@ -209,7 +205,8 @@ TEST(RollBackLocalOperationsTest, SkipRemoteOperations) { TEST(RollBackLocalOperationsTest, SameTimestampDifferentTermsRollbackNoSuchKey) { auto commonOperation = makeOpAndRecordId(1, 1); OplogInterfaceMock::Operations localOperations({ - makeOpAndRecordId(2, 3), commonOperation, + makeOpAndRecordId(2, 3), + commonOperation, }); OplogInterfaceMock localOplog(localOperations); auto rollbackOperation = [&](const BSONObj& operation) { @@ -242,7 +239,9 @@ TEST(SyncRollBackLocalOperationsTest, RollbackTwoOperations) { auto commonOperation = makeOpWithWallClockTimeAndRecordId(1, 1 * 5000); auto firstOpAfterCommonPoint = makeOpWithWallClockTimeAndRecordId(2, 2 * 60 * 60 * 24 * 1000); OplogInterfaceMock::Operations localOperations({ - makeOpAndRecordId(3), firstOpAfterCommonPoint, commonOperation, + makeOpAndRecordId(3), + firstOpAfterCommonPoint, + commonOperation, }); auto i = localOperations.cbegin(); auto result = syncRollBackLocalOperations(OplogInterfaceMock(localOperations), diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp index b6aca140721..73c484ec452 100644 --- a/src/mongo/db/repl/rollback_impl.cpp +++ b/src/mongo/db/repl/rollback_impl.cpp @@ -100,8 +100,9 @@ boost::optional<long long> _parseDroppedCollectionCount(const OplogEntry& oplogE auto obj2 = oplogEntry.getObject2(); if (!obj2) { - warning() << "Unable to get collection count from " << desc << " without the o2 " - "field. oplog op: " + warning() << "Unable to get collection count from " << desc + << " without the o2 " + "field. oplog op: " << redact(oplogEntry.toBSON()); return boost::none; } @@ -324,10 +325,10 @@ Status RollbackImpl::_transitionToRollback(OperationContext* opCtx) { auto status = _replicationCoordinator->setFollowerModeStrict(opCtx, MemberState::RS_ROLLBACK); if (!status.isOK()) { - status.addContext(str::stream() << "Cannot transition from " - << _replicationCoordinator->getMemberState().toString() - << " to " - << MemberState(MemberState::RS_ROLLBACK).toString()); + status.addContext(str::stream() + << "Cannot transition from " + << _replicationCoordinator->getMemberState().toString() << " to " + << MemberState(MemberState::RS_ROLLBACK).toString()); log() << status; return status; } @@ -416,9 +417,9 @@ StatusWith<std::set<NamespaceString>> RollbackImpl::_namespacesForOp(const Oplog // These commands do not need to be supported by rollback. 'convertToCapped' should // always be converted to lower level DDL operations, and 'emptycapped' is a // testing-only command. - std::string message = str::stream() << "Encountered unsupported command type '" - << firstElem.fieldName() - << "' during rollback."; + std::string message = str::stream() + << "Encountered unsupported command type '" << firstElem.fieldName() + << "' during rollback."; return Status(ErrorCodes::UnrecoverableRollbackError, message); } case OplogEntry::CommandType::kCreate: @@ -594,8 +595,7 @@ void RollbackImpl::_correctRecordStoreCounts(OperationContext* opCtx) { auto collToScan = autoCollToScan.getCollection(); invariant(coll == collToScan, str::stream() << "Catalog returned invalid collection: " << nss.ns() << " (" - << uuid.toString() - << ")"); + << uuid.toString() << ")"); auto exec = collToScan->makePlanExecutor( opCtx, PlanExecutor::INTERRUPT_ONLY, Collection::ScanDirection::kForward); long long countFromScan = 0; @@ -816,8 +816,7 @@ Status RollbackImpl::_processRollbackOp(OperationContext* opCtx, const OplogEntr const auto uuid = oplogEntry.getUuid().get(); invariant(_countDiffs.find(uuid) == _countDiffs.end(), str::stream() << "Unexpected existing count diff for " << uuid.toString() - << " op: " - << redact(oplogEntry.toBSON())); + << " op: " << redact(oplogEntry.toBSON())); if (auto countResult = _parseDroppedCollectionCount(oplogEntry)) { PendingDropInfo info; info.count = *countResult; @@ -843,10 +842,9 @@ Status RollbackImpl::_processRollbackOp(OperationContext* opCtx, const OplogEntr << "Oplog entry to roll back is unexpectedly missing dropTarget UUID: " << redact(oplogEntry.toBSON())); invariant(_countDiffs.find(dropTargetUUID) == _countDiffs.end(), - str::stream() << "Unexpected existing count diff for " - << dropTargetUUID.toString() - << " op: " - << redact(oplogEntry.toBSON())); + str::stream() + << "Unexpected existing count diff for " << dropTargetUUID.toString() + << " op: " << redact(oplogEntry.toBSON())); if (auto countResult = _parseDroppedCollectionCount(oplogEntry)) { PendingDropInfo info; info.count = *countResult; @@ -1012,9 +1010,7 @@ Status RollbackImpl::_checkAgainstTimeLimit( if (diff > timeLimit) { return Status(ErrorCodes::UnrecoverableRollbackError, str::stream() << "not willing to roll back more than " << timeLimit - << " seconds of data. Have: " - << diff - << " seconds."); + << " seconds of data. Have: " << diff << " seconds."); } } else { @@ -1044,8 +1040,7 @@ Timestamp RollbackImpl::_findTruncateTimestamp( invariant(commonPointTime.getStatus()); invariant(commonPointTime.getValue() == commonPointOpTime, str::stream() << "Common point: " << commonPointOpTime.toString() - << ", record found: " - << commonPointTime.getValue().toString()); + << ", record found: " << commonPointTime.getValue().toString()); // Get the next document, which will be the first document to truncate. auto truncatePointRecord = oplogCursor->next(); diff --git a/src/mongo/db/repl/rollback_impl.h b/src/mongo/db/repl/rollback_impl.h index 5343879c633..660231c4dbc 100644 --- a/src/mongo/db/repl/rollback_impl.h +++ b/src/mongo/db/repl/rollback_impl.h @@ -284,7 +284,7 @@ public: virtual const std::vector<BSONObj>& docsDeletedForNamespace_forTest(UUID uuid) const& { MONGO_UNREACHABLE; } - void docsDeletedForNamespace_forTest(UUID)&& = delete; + void docsDeletedForNamespace_forTest(UUID) && = delete; protected: /** diff --git a/src/mongo/db/repl/rollback_impl_test.cpp b/src/mongo/db/repl/rollback_impl_test.cpp index 927219c46db..98ac60952ca 100644 --- a/src/mongo/db/repl/rollback_impl_test.cpp +++ b/src/mongo/db/repl/rollback_impl_test.cpp @@ -69,37 +69,21 @@ std::string kGenericUUIDStr = "b4c66a44-c1ca-4d86-8d25-12e82fa2de5b"; BSONObj makeInsertOplogEntry(long long time, BSONObj obj, StringData ns, UUID uuid) { return BSON("ts" << Timestamp(time, time) << "t" << time << "op" << "i" - << "o" - << obj - << "ns" - << ns - << "ui" - << uuid); + << "o" << obj << "ns" << ns << "ui" << uuid); } BSONObj makeUpdateOplogEntry( long long time, BSONObj query, BSONObj update, StringData ns, UUID uuid) { return BSON("ts" << Timestamp(time, time) << "t" << time << "op" << "u" - << "ns" - << ns - << "ui" - << uuid - << "o2" - << query - << "o" + << "ns" << ns << "ui" << uuid << "o2" << query << "o" << BSON("$set" << update)); } BSONObj makeDeleteOplogEntry(long long time, BSONObj id, StringData ns, UUID uuid) { return BSON("ts" << Timestamp(time, time) << "t" << time << "op" << "d" - << "ns" - << ns - << "ui" - << uuid - << "o" - << id); + << "ns" << ns << "ui" << uuid << "o" << id); } class RollbackImplForTest final : public RollbackImpl { @@ -380,12 +364,7 @@ BSONObj makeOp(OpTime time) { auto kGenericUUID = unittest::assertGet(UUID::parse(kGenericUUIDStr)); return BSON("ts" << time.getTimestamp() << "t" << time.getTerm() << "op" << "n" - << "o" - << BSONObj() - << "ns" - << nss.ns() - << "ui" - << kGenericUUID); + << "o" << BSONObj() << "ns" << nss.ns() << "ui" << kGenericUUID); } BSONObj makeOp(int count) { @@ -400,13 +379,9 @@ auto makeOpWithWallClockTime(long count, long wallClockMillis) { auto kGenericUUID = unittest::assertGet(UUID::parse(kGenericUUIDStr)); return BSON("ts" << Timestamp(count, count) << "t" << (long long)count << "op" << "n" - << "o" - << BSONObj() - << "ns" + << "o" << BSONObj() << "ns" << "top" - << "ui" - << kGenericUUID - << "wall" + << "ui" << kGenericUUID << "wall" << Date_t::fromMillisSinceEpoch(wallClockMillis)); }; @@ -955,14 +930,10 @@ TEST_F(RollbackImplTest, RollbackDoesNotWriteRollbackFilesIfNoInsertsOrUpdatesAf const auto uuid = UUID::gen(); const auto nss = NamespaceString("db.coll"); const auto coll = _initializeCollection(_opCtx.get(), uuid, nss); - const auto oplogEntry = BSON("ts" << Timestamp(3, 3) << "t" << 3LL << "op" - << "c" - << "o" - << BSON("create" << nss.coll()) - << "ns" - << nss.ns() - << "ui" - << uuid); + const auto oplogEntry = + BSON("ts" << Timestamp(3, 3) << "t" << 3LL << "op" + << "c" + << "o" << BSON("create" << nss.coll()) << "ns" << nss.ns() << "ui" << uuid); ASSERT_OK(_insertOplogEntry(oplogEntry)); ASSERT_OK(_rollback->runRollback(_opCtx.get())); @@ -1183,12 +1154,7 @@ TEST_F(RollbackImplTest, RollbackProperlySavesFilesWhenInsertsAndDropOfCollectio const auto oplogEntry = BSON("ts" << dropOpTime.getTimestamp() << "t" << dropOpTime.getTerm() << "op" << "c" - << "o" - << BSON("drop" << nss.coll()) - << "ns" - << nss.ns() - << "ui" - << uuid); + << "o" << BSON("drop" << nss.coll()) << "ns" << nss.ns() << "ui" << uuid); ASSERT_OK(_insertOplogEntry(oplogEntry)); ASSERT_OK(_rollback->runRollback(_opCtx.get())); @@ -1213,14 +1179,10 @@ TEST_F(RollbackImplTest, RollbackProperlySavesFilesWhenCreateCollAndInsertsAreRo const auto nss = NamespaceString("db.people"); const auto uuid = UUID::gen(); const auto coll = _initializeCollection(_opCtx.get(), uuid, nss); - const auto oplogEntry = BSON("ts" << Timestamp(3, 3) << "t" << 3LL << "op" - << "c" - << "o" - << BSON("create" << nss.coll()) - << "ns" - << nss.ns() - << "ui" - << uuid); + const auto oplogEntry = + BSON("ts" << Timestamp(3, 3) << "t" << 3LL << "op" + << "c" + << "o" << BSON("create" << nss.coll()) << "ns" << nss.ns() << "ui" << uuid); ASSERT_OK(_insertOplogEntry(oplogEntry)); // Insert documents into the collection. @@ -1584,14 +1546,14 @@ public: void assertRollbackInfoContainsObjectForUUID(UUID uuid, BSONObj bson) { const auto& uuidToIdMap = _rbInfo.rollbackDeletedIdsMap; auto search = uuidToIdMap.find(uuid); - ASSERT(search != uuidToIdMap.end()) << "map is unexpectedly missing an entry for uuid " - << uuid.toString() << " containing object " - << bson.jsonString(); + ASSERT(search != uuidToIdMap.end()) + << "map is unexpectedly missing an entry for uuid " << uuid.toString() + << " containing object " << bson.jsonString(); const auto& idObjSet = search->second; const auto iter = idObjSet.find(bson); - ASSERT(iter != idObjSet.end()) << "_id object set is unexpectedly missing object " - << bson.jsonString() << " in namespace with uuid " - << uuid.toString(); + ASSERT(iter != idObjSet.end()) + << "_id object set is unexpectedly missing object " << bson.jsonString() + << " in namespace with uuid " << uuid.toString(); } @@ -1675,12 +1637,12 @@ TEST_F(RollbackImplObserverInfoTest, NamespacesForOpsExtractsNamespaceOfDropColl TEST_F(RollbackImplObserverInfoTest, NamespacesForOpsExtractsNamespaceOfCreateIndexOplogEntry) { auto nss = NamespaceString("test", "coll"); - auto indexObj = BSON("createIndexes" << nss.coll() << "ns" << nss.toString() << "v" - << static_cast<int>(IndexDescriptor::IndexVersion::kV2) - << "key" - << "x" - << "name" - << "x_1"); + auto indexObj = + BSON("createIndexes" << nss.coll() << "ns" << nss.toString() << "v" + << static_cast<int>(IndexDescriptor::IndexVersion::kV2) << "key" + << "x" + << "name" + << "x_1"); auto cmdOp = makeCommandOp(Timestamp(2, 2), UUID::gen(), nss.getCommandNS().toString(), indexObj, 2); diff --git a/src/mongo/db/repl/rollback_source_impl.cpp b/src/mongo/db/repl/rollback_source_impl.cpp index 2170ee1663d..9af1717b4ab 100644 --- a/src/mongo/db/repl/rollback_source_impl.cpp +++ b/src/mongo/db/repl/rollback_source_impl.cpp @@ -105,9 +105,7 @@ StatusWith<BSONObj> RollbackSourceImpl::getCollectionInfoByUUID(const std::strin return StatusWith<BSONObj>(ErrorCodes::NoSuchKey, str::stream() << "No collection info found for collection with uuid: " - << uuid.toString() - << " in db: " - << db); + << uuid.toString() << " in db: " << db); } invariant(info.size() == 1U); return info.front(); diff --git a/src/mongo/db/repl/rollback_test_fixture.cpp b/src/mongo/db/repl/rollback_test_fixture.cpp index 46baaac89be..b2afd664b94 100644 --- a/src/mongo/db/repl/rollback_test_fixture.cpp +++ b/src/mongo/db/repl/rollback_test_fixture.cpp @@ -295,12 +295,9 @@ void RollbackResyncsCollectionOptionsTest::resyncCollectionOptionsTest( auto commonOpUuid = unittest::assertGet(UUID::parse("f005ba11-cafe-bead-f00d-123456789abc")); auto commonOpBson = BSON("ts" << Timestamp(1, 1) << "t" << 1LL << "op" << "n" - << "o" - << BSONObj() - << "ns" + << "o" << BSONObj() << "ns" << "rollback_test.test" - << "ui" - << commonOpUuid); + << "ui" << commonOpUuid); auto commonOperation = std::make_pair(commonOpBson, RecordId(1)); diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp index 11ff4960681..2ef523e34b0 100644 --- a/src/mongo/db/repl/rs_rollback.cpp +++ b/src/mongo/db/repl/rs_rollback.cpp @@ -83,13 +83,13 @@ namespace mongo { -using std::shared_ptr; -using std::unique_ptr; using std::list; using std::map; +using std::pair; using std::set; +using std::shared_ptr; using std::string; -using std::pair; +using std::unique_ptr; namespace repl { @@ -199,10 +199,10 @@ Status FixUpInfo::recordDropTargetInfo(const BSONElement& dropTarget, OpTime opTime) { StatusWith<UUID> dropTargetUUIDStatus = UUID::parse(dropTarget); if (!dropTargetUUIDStatus.isOK()) { - std::string message = str::stream() << "Unable to roll back renameCollection. Cannot parse " - "dropTarget UUID. Returned status: " - << redact(dropTargetUUIDStatus.getStatus()) - << ", oplog entry: " << redact(obj); + std::string message = str::stream() + << "Unable to roll back renameCollection. Cannot parse " + "dropTarget UUID. Returned status: " + << redact(dropTargetUUIDStatus.getStatus()) << ", oplog entry: " << redact(obj); error() << message; return dropTargetUUIDStatus.getStatus(); } @@ -227,8 +227,8 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o // Checks that the oplog entry is smaller than 512 MB. We do not roll back if the // oplog entry is larger than 512 MB. if (ourObj.objsize() > 512 * 1024 * 1024) - throw RSFatalException(str::stream() << "Rollback too large, oplog size: " - << ourObj.objsize()); + throw RSFatalException(str::stream() + << "Rollback too large, oplog size: " << ourObj.objsize()); // If required fields are not present in the BSONObj for an applyOps entry, create these fields // and populate them with dummy values before parsing ourObj as an oplog entry. @@ -1235,8 +1235,9 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, // is rolled back upstream and we restart, we expect to still have the // collection. - log() << nss->ns() << " not found on remote host, so we do not roll back collmod " - "operation. Instead, we will drop the collection soon."; + log() << nss->ns() + << " not found on remote host, so we do not roll back collmod " + "operation. Instead, we will drop the collection soon."; continue; } @@ -1246,10 +1247,10 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, // Updates the collection flags. if (auto optionsField = info["options"]) { if (optionsField.type() != Object) { - throw RSFatalException(str::stream() << "Failed to parse options " << info - << ": expected 'options' to be an " - << "Object, got " - << typeName(optionsField.type())); + throw RSFatalException(str::stream() + << "Failed to parse options " << info + << ": expected 'options' to be an " + << "Object, got " << typeName(optionsField.type())); } // Removes the option.uuid field. We do not allow the options.uuid field @@ -1261,8 +1262,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, auto status = options.parse(optionsFieldObj, CollectionOptions::parseForCommand); if (!status.isOK()) { throw RSFatalException(str::stream() << "Failed to parse options " << info - << ": " - << status.toString()); + << ": " << status.toString()); } // TODO(SERVER-27992): Set options.uuid. @@ -1281,13 +1281,10 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, auto validatorStatus = collection->updateValidator( opCtx, options.validator, options.validationLevel, options.validationAction); if (!validatorStatus.isOK()) { - throw RSFatalException( - str::stream() << "Failed to update validator for " << nss->toString() << " (" - << uuid - << ") with " - << redact(info) - << ". Got: " - << validatorStatus.toString()); + throw RSFatalException(str::stream() + << "Failed to update validator for " << nss->toString() + << " (" << uuid << ") with " << redact(info) + << ". Got: " << validatorStatus.toString()); } wuow.commit(); @@ -1377,8 +1374,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, << " to archive file: " << redact(status); throw RSFatalException(str::stream() << "Rollback cannot write document in namespace " - << nss->ns() - << " to archive file."); + << nss->ns() << " to archive file."); } } else { error() << "Rollback cannot find object: " << pattern << " in namespace " diff --git a/src/mongo/db/repl/rs_rollback_test.cpp b/src/mongo/db/repl/rs_rollback_test.cpp index bfacdd849cb..991d0851afc 100644 --- a/src/mongo/db/repl/rs_rollback_test.cpp +++ b/src/mongo/db/repl/rs_rollback_test.cpp @@ -81,21 +81,16 @@ OplogInterfaceMock::Operation makeDropIndexOplogEntry(Collection* collection, BSONObj key, std::string indexName, int time) { - auto indexSpec = - BSON("ns" << collection->ns().ns() << "key" << key << "name" << indexName << "v" - << static_cast<int>(kIndexVersion)); + auto indexSpec = BSON("ns" << collection->ns().ns() << "key" << key << "name" << indexName + << "v" << static_cast<int>(kIndexVersion)); return std::make_pair( BSON("ts" << Timestamp(Seconds(time), 0) << "op" << "c" - << "ui" - << collection->uuid().get() - << "ns" + << "ui" << collection->uuid().get() << "ns" << "test.$cmd" - << "o" - << BSON("dropIndexes" << collection->ns().coll() << "index" << indexName) - << "o2" - << indexSpec), + << "o" << BSON("dropIndexes" << collection->ns().coll() << "index" << indexName) + << "o2" << indexSpec), RecordId(time)); } @@ -103,22 +98,15 @@ OplogInterfaceMock::Operation makeCreateIndexOplogEntry(Collection* collection, BSONObj key, std::string indexName, int time) { - auto indexSpec = - BSON("createIndexes" << collection->ns().coll() << "ns" << collection->ns().ns() << "v" - << static_cast<int>(kIndexVersion) - << "key" - << key - << "name" - << indexName); + auto indexSpec = BSON( + "createIndexes" << collection->ns().coll() << "ns" << collection->ns().ns() << "v" + << static_cast<int>(kIndexVersion) << "key" << key << "name" << indexName); return std::make_pair(BSON("ts" << Timestamp(Seconds(time), 0) << "op" << "c" << "ns" << "test.$cmd" - << "ui" - << collection->uuid().get() - << "o" - << indexSpec), + << "ui" << collection->uuid().get() << "o" << indexSpec), RecordId(time)); } @@ -140,11 +128,7 @@ OplogInterfaceMock::Operation makeRenameCollectionOplogEntry(const NamespaceStri } return std::make_pair(BSON("ts" << opTime.getTimestamp() << "t" << opTime.getTerm() << "op" << "c" - << "ui" - << collectionUUID - << "ns" - << renameFrom.ns() - << "o" + << "ui" << collectionUUID << "ns" << renameFrom.ns() << "o" << obj), RecordId(opTime.getTimestamp().getSecs())); } @@ -153,12 +137,9 @@ BSONObj makeOp(long long seconds) { auto uuid = unittest::assertGet(UUID::parse("f005ba11-cafe-bead-f00d-123456789abc")); return BSON("ts" << Timestamp(seconds, seconds) << "t" << seconds << "op" << "n" - << "o" - << BSONObj() - << "ns" + << "o" << BSONObj() << "ns" << "rs_rollback.test" - << "ui" - << uuid); + << "ui" << uuid); } int recordId = 0; @@ -294,12 +275,9 @@ int _testRollbackDelete(OperationContext* opCtx, auto commonOperation = makeOpAndRecordId(1); auto deleteOperation = std::make_pair(BSON("ts" << Timestamp(Seconds(2), 0) << "op" << "d" - << "ui" - << uuid - << "ns" + << "ui" << uuid << "ns" << "test.t" - << "o" - << BSON("_id" << 0)), + << "o" << BSON("_id" << 0)), RecordId(2)); class RollbackSourceLocal : public RollbackSourceMock { public: @@ -423,12 +401,9 @@ TEST_F(RSRollbackTest, RollbackInsertDocumentWithNoId) { auto commonOperation = makeOpAndRecordId(1); auto insertDocumentOperation = std::make_pair(BSON("ts" << Timestamp(Seconds(2), 0) << "op" << "i" - << "ui" - << UUID::gen() - << "ns" + << "ui" << UUID::gen() << "ns" << "test.t" - << "o" - << BSON("a" << 1)), + << "o" << BSON("a" << 1)), RecordId(2)); class RollbackSourceLocal : public RollbackSourceMock { public: @@ -467,8 +442,7 @@ TEST_F(RSRollbackTest, RollbackCreateIndexCommand) { NamespaceString nss("test", "coll"); auto collection = _createCollection(_opCtx.get(), nss.toString(), options); auto indexSpec = BSON("ns" << nss.toString() << "v" << static_cast<int>(kIndexVersion) << "key" - << BSON("a" << 1) - << "name" + << BSON("a" << 1) << "name" << "a_1"); int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), collection, nss, indexSpec); @@ -492,13 +466,11 @@ TEST_F(RSRollbackTest, RollbackCreateIndexCommand) { _coordinator, _replicationProcess.get())); stopCapturingLogMessages(); - ASSERT_EQUALS(1, - countLogLinesContaining(str::stream() - << "Dropped index in rollback for collection: " - << nss.toString() - << ", UUID: " - << options.uuid->toString() - << ", index: a_1")); + ASSERT_EQUALS( + 1, + countLogLinesContaining(str::stream() + << "Dropped index in rollback for collection: " << nss.toString() + << ", UUID: " << options.uuid->toString() << ", index: a_1")); { Lock::DBLock dbLock(_opCtx.get(), nss.db(), MODE_S); auto indexCatalog = collection->getIndexCatalog(); @@ -514,9 +486,7 @@ TEST_F(RSRollbackTest, RollbackCreateIndexCommandIndexNotInCatalog) { auto collection = _createCollection(_opCtx.get(), "test.t", options); auto indexSpec = BSON("ns" << "test.t" - << "key" - << BSON("a" << 1) - << "name" + << "key" << BSON("a" << 1) << "name" << "a_1"); // Skip index creation to trigger warning during rollback. { @@ -665,9 +635,7 @@ TEST_F(RSRollbackTest, RollingBackCreateIndexAndRenameWithLongName) { auto longName = std::string(115, 'a'); auto indexSpec = BSON("ns" << nss.toString() << "v" << static_cast<int>(kIndexVersion) << "key" - << BSON("b" << 1) - << "name" - << longName); + << BSON("b" << 1) << "name" << longName); int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), collection, nss, indexSpec); ASSERT_EQUALS(2, numIndexes); @@ -720,8 +688,7 @@ TEST_F(RSRollbackTest, RollingBackDropAndCreateOfSameIndexNameWithDifferentSpecs auto collection = _createCollection(_opCtx.get(), nss.toString(), options); auto indexSpec = BSON("ns" << nss.toString() << "v" << static_cast<int>(kIndexVersion) << "key" - << BSON("b" << 1) - << "name" + << BSON("b" << 1) << "name" << "a_1"); int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), collection, nss, indexSpec); @@ -752,19 +719,15 @@ TEST_F(RSRollbackTest, RollingBackDropAndCreateOfSameIndexNameWithDifferentSpecs ASSERT(indexCatalog); ASSERT_EQUALS(2, indexCatalog->numIndexesReady(_opCtx.get())); ASSERT_EQUALS(1, - countLogLinesContaining(str::stream() - << "Dropped index in rollback for collection: " - << nss.toString() - << ", UUID: " - << options.uuid->toString() - << ", index: a_1")); + countLogLinesContaining( + str::stream() + << "Dropped index in rollback for collection: " << nss.toString() + << ", UUID: " << options.uuid->toString() << ", index: a_1")); ASSERT_EQUALS(1, - countLogLinesContaining(str::stream() - << "Created index in rollback for collection: " - << nss.toString() - << ", UUID: " - << options.uuid->toString() - << ", index: a_1")); + countLogLinesContaining( + str::stream() + << "Created index in rollback for collection: " << nss.toString() + << ", UUID: " << options.uuid->toString() << ", index: a_1")); std::vector<const IndexDescriptor*> indexes; indexCatalog->findIndexesByKeyPattern(_opCtx.get(), BSON("a" << 1), false, &indexes); ASSERT(indexes.size() == 1); @@ -786,20 +749,15 @@ TEST_F(RSRollbackTest, RollbackCreateIndexCommandMissingIndexName) { << "t" << "ns" << "test.t" - << "v" - << static_cast<int>(kIndexVersion) - << "key" - << BSON("a" << 1)); - - auto createIndexOperation = std::make_pair(BSON("ts" << Timestamp(Seconds(2), 0) << "op" - << "c" - << "ns" - << "test.$cmd" - << "ui" - << collection->uuid().get() - << "o" - << command), - RecordId(2)); + << "v" << static_cast<int>(kIndexVersion) << "key" << BSON("a" << 1)); + + auto createIndexOperation = + std::make_pair(BSON("ts" << Timestamp(Seconds(2), 0) << "op" + << "c" + << "ns" + << "test.$cmd" + << "ui" << collection->uuid().get() << "o" << command), + RecordId(2)); RollbackSourceMock rollbackSource(std::unique_ptr<OplogInterface>(new OplogInterfaceMock({ commonOperation, }))); @@ -829,9 +787,7 @@ std::string idxName(std::string id) { // Create an index spec object given the namespace and the index 'id'. BSONObj idxSpec(NamespaceString nss, std::string id) { return BSON("ns" << nss.toString() << "v" << static_cast<int>(kIndexVersion) << "key" - << BSON(idxKey(id) << 1) - << "name" - << idxName(id)); + << BSON(idxKey(id) << 1) << "name" << idxName(id)); } // Returns the number of indexes that exist on the given collection. @@ -954,9 +910,7 @@ TEST_F(RSRollbackTest, RollbackCreateDropRecreateIndexOnCollection) { // Create the necessary indexes. Index 0 is created, dropped, and created again in the // sequence of ops, so we create that index. auto indexSpec = BSON("ns" << nss.toString() << "v" << static_cast<int>(kIndexVersion) << "key" - << BSON(idxKey("0") << 1) - << "name" - << idxName("0")); + << BSON(idxKey("0") << 1) << "name" << idxName("0")); int numIndexes = _createIndexOnEmptyCollection(_opCtx.get(), coll, nss, indexSpec); ASSERT_EQUALS(2, numIndexes); @@ -991,9 +945,7 @@ TEST_F(RSRollbackTest, RollbackUnknownCommand) { auto commonOperation = makeOpAndRecordId(1); auto unknownCommandOperation = std::make_pair(BSON("ts" << Timestamp(Seconds(2), 0) << "op" << "c" - << "ui" - << UUID::gen() - << "ns" + << "ui" << UUID::gen() << "ns" << "test.t" << "o" << BSON("convertToCapped" @@ -1027,9 +979,7 @@ TEST_F(RSRollbackTest, RollbackDropCollectionCommand) { auto dropCollectionOperation = std::make_pair(BSON("ts" << dropTime.getTimestamp() << "t" << dropTime.getTerm() << "op" << "c" - << "ui" - << coll->uuid().get() - << "ns" + << "ui" << coll->uuid().get() << "ns" << "test.t" << "o" << BSON("drop" @@ -1351,9 +1301,7 @@ TEST_F(RSRollbackTest, RollbackDropCollectionThenRenameCollectionToDroppedCollec auto dropCollectionOperation = std::make_pair(BSON("ts" << dropTime.getTimestamp() << "t" << dropTime.getTerm() << "op" << "c" - << "ui" - << droppedCollectionUUID - << "ns" + << "ui" << droppedCollectionUUID << "ns" << "test.x" << "o" << BSON("drop" @@ -1423,16 +1371,15 @@ TEST_F(RSRollbackTest, RollbackRenameCollectionThenCreateNewCollectionWithOldNam false, OpTime(Timestamp(2, 0), 5)); - auto createCollectionOperation = std::make_pair(BSON("ts" << Timestamp(Seconds(3), 0) << "op" - << "c" - << "ui" - << createdCollectionUUID - << "ns" - << "test.x" - << "o" - << BSON("create" - << "x")), - RecordId(3)); + auto createCollectionOperation = + std::make_pair(BSON("ts" << Timestamp(Seconds(3), 0) << "op" + << "c" + << "ui" << createdCollectionUUID << "ns" + << "test.x" + << "o" + << BSON("create" + << "x")), + RecordId(3)); RollbackSourceMock rollbackSource(std::unique_ptr<OplogInterface>(new OplogInterfaceMock({ @@ -1473,9 +1420,7 @@ TEST_F(RSRollbackTest, RollbackCollModCommandFailsIfRBIDChangesWhileSyncingColle auto commonOperation = makeOpAndRecordId(1); auto collModOperation = std::make_pair(BSON("ts" << Timestamp(Seconds(2), 0) << "op" << "c" - << "ui" - << coll->uuid().get() - << "ns" + << "ui" << coll->uuid().get() << "ns" << "test.t" << "o" << BSON("collMod" @@ -1519,8 +1464,7 @@ TEST_F(RSRollbackTest, RollbackDropDatabaseCommand) { << "c" << "ns" << "test.$cmd" - << "o" - << BSON("dropDatabase" << 1)), + << "o" << BSON("dropDatabase" << 1)), RecordId(2)); RollbackSourceMock rollbackSource(std::unique_ptr<OplogInterface>(new OplogInterfaceMock({ commonOperation, @@ -1588,93 +1532,47 @@ TEST_F(RSRollbackTest, RollbackApplyOpsCommand) { UUID uuid = coll->uuid().get(); const auto commonOperation = makeOpAndRecordId(1); const auto applyOpsOperation = - std::make_pair(makeApplyOpsOplogEntry(Timestamp(Seconds(2), 0), - {BSON("op" - << "u" - << "ui" - << uuid - << "ts" - << Timestamp(1, 1) - << "t" - << 1LL - << "ns" - << "test.t" - << "o2" - << BSON("_id" << 1) - << "o" - << BSON("_id" << 1 << "v" << 2)), - BSON("op" - << "u" - << "ui" - << uuid - << "ts" - << Timestamp(2, 1) - << "t" - << 1LL - << "ns" - << "test.t" - << "o2" - << BSON("_id" << 2) - << "o" - << BSON("_id" << 2 << "v" << 4)), - BSON("op" - << "d" - << "ui" - << uuid - << "ts" - << Timestamp(3, 1) - << "t" - << 1LL - << "ns" - << "test.t" - << "o" - << BSON("_id" << 3)), - BSON("op" - << "i" - << "ui" - << uuid - << "ts" - << Timestamp(4, 1) - << "t" - << 1LL - << "ns" - << "test.t" - << "o" - << BSON("_id" << 4)), - // applyOps internal oplog entries are not required - // to have a timestamp. - BSON("op" - << "i" - << "ui" - << uuid - << "ts" - << Timestamp(4, 1) - << "t" - << 1LL - << "ns" - << "test.t" - << "o" - << BSON("_id" << 4)), - BSON("op" - << "i" - << "ui" - << uuid - << "t" - << 1LL - << "ns" - << "test.t" - << "o" - << BSON("_id" << 4)), - BSON("op" - << "i" - << "ui" - << uuid - << "t" - << 1LL - << "ns" - << "test.t" - << "o" - << BSON("_id" << 4))}), + std::make_pair(makeApplyOpsOplogEntry( + Timestamp(Seconds(2), 0), + {BSON("op" + << "u" + << "ui" << uuid << "ts" << Timestamp(1, 1) << "t" << 1LL << "ns" + << "test.t" + << "o2" << BSON("_id" << 1) << "o" + << BSON("_id" << 1 << "v" << 2)), + BSON("op" + << "u" + << "ui" << uuid << "ts" << Timestamp(2, 1) << "t" << 1LL << "ns" + << "test.t" + << "o2" << BSON("_id" << 2) << "o" + << BSON("_id" << 2 << "v" << 4)), + BSON("op" + << "d" + << "ui" << uuid << "ts" << Timestamp(3, 1) << "t" << 1LL << "ns" + << "test.t" + << "o" << BSON("_id" << 3)), + BSON("op" + << "i" + << "ui" << uuid << "ts" << Timestamp(4, 1) << "t" << 1LL << "ns" + << "test.t" + << "o" << BSON("_id" << 4)), + // applyOps internal oplog entries are not required + // to have a timestamp. + BSON("op" + << "i" + << "ui" << uuid << "ts" << Timestamp(4, 1) << "t" << 1LL << "ns" + << "test.t" + << "o" << BSON("_id" << 4)), + BSON("op" + << "i" + << "ui" << uuid << "t" << 1LL << "ns" + << "test.t" + << "o" << BSON("_id" << 4)), + BSON("op" + << "i" + << "ui" << uuid << "t" << 1LL << "ns" + << "test.t" + << "o" << BSON("_id" << 4))}), RecordId(2)); class RollbackSourceLocal : public RollbackSourceMock { @@ -1742,9 +1640,7 @@ TEST_F(RSRollbackTest, RollbackCreateCollectionCommand) { auto commonOperation = makeOpAndRecordId(1); auto createCollectionOperation = std::make_pair(BSON("ts" << Timestamp(Seconds(2), 0) << "op" << "c" - << "ui" - << coll->uuid().get() - << "ns" + << "ui" << coll->uuid().get() << "ns" << "test.t" << "o" << BSON("create" @@ -1972,31 +1868,19 @@ TEST_F(RSRollbackTest, RollbackCollectionModificationCommandInvalidCollectionOpt TEST(RSRollbackTest, LocalEntryWithoutNsIsFatal) { const auto validOplogEntry = BSON("op" << "i" - << "ui" - << UUID::gen() - << "ts" - << Timestamp(1, 1) - << "t" - << 1LL - << "ns" + << "ui" << UUID::gen() << "ts" << Timestamp(1, 1) << "t" + << 1LL << "ns" << "test.t" - << "o" - << BSON("_id" << 1 << "a" << 1)); + << "o" << BSON("_id" << 1 << "a" << 1)); FixUpInfo fui; ASSERT_OK(updateFixUpInfoFromLocalOplogEntry( nullptr /* opCtx */, OplogInterfaceMock(), fui, validOplogEntry, false)); const auto invalidOplogEntry = BSON("op" << "i" - << "ui" - << UUID::gen() - << "ts" - << Timestamp(1, 1) - << "t" - << 1LL - << "ns" + << "ui" << UUID::gen() << "ts" << Timestamp(1, 1) << "t" + << 1LL << "ns" << "" - << "o" - << BSON("_id" << 1 << "a" << 1)); + << "o" << BSON("_id" << 1 << "a" << 1)); ASSERT_THROWS(updateFixUpInfoFromLocalOplogEntry( nullptr /* opCtx */, OplogInterfaceMock(), fui, invalidOplogEntry, false), RSFatalException); @@ -2005,31 +1889,19 @@ TEST(RSRollbackTest, LocalEntryWithoutNsIsFatal) { TEST(RSRollbackTest, LocalEntryWithoutOIsFatal) { const auto validOplogEntry = BSON("op" << "i" - << "ui" - << UUID::gen() - << "ts" - << Timestamp(1, 1) - << "t" - << 1LL - << "ns" + << "ui" << UUID::gen() << "ts" << Timestamp(1, 1) << "t" + << 1LL << "ns" << "test.t" - << "o" - << BSON("_id" << 1 << "a" << 1)); + << "o" << BSON("_id" << 1 << "a" << 1)); FixUpInfo fui; ASSERT_OK(updateFixUpInfoFromLocalOplogEntry( nullptr /* opCtx */, OplogInterfaceMock(), fui, validOplogEntry, false)); const auto invalidOplogEntry = BSON("op" << "i" - << "ui" - << UUID::gen() - << "ts" - << Timestamp(1, 1) - << "t" - << 1LL - << "ns" + << "ui" << UUID::gen() << "ts" << Timestamp(1, 1) << "t" + << 1LL << "ns" << "test.t" - << "o" - << BSONObj()); + << "o" << BSONObj()); ASSERT_THROWS(updateFixUpInfoFromLocalOplogEntry( nullptr /* opCtx */, OplogInterfaceMock(), fui, invalidOplogEntry, false), RSFatalException); @@ -2038,16 +1910,10 @@ TEST(RSRollbackTest, LocalEntryWithoutOIsFatal) { DEATH_TEST_F(RSRollbackTest, LocalUpdateEntryWithoutO2IsFatal, "Fatal Assertion") { const auto invalidOplogEntry = BSON("op" << "u" - << "ui" - << UUID::gen() - << "ts" - << Timestamp(1, 1) - << "t" - << 1LL - << "ns" + << "ui" << UUID::gen() << "ts" << Timestamp(1, 1) << "t" + << 1LL << "ns" << "test.t" - << "o" - << BSON("_id" << 1 << "a" << 1)); + << "o" << BSON("_id" << 1 << "a" << 1)); FixUpInfo fui; updateFixUpInfoFromLocalOplogEntry( nullptr /* opCtx */, OplogInterfaceMock(), fui, invalidOplogEntry, false) @@ -2057,34 +1923,20 @@ DEATH_TEST_F(RSRollbackTest, LocalUpdateEntryWithoutO2IsFatal, "Fatal Assertion" TEST(RSRollbackTest, LocalUpdateEntryWithEmptyO2IsFatal) { const auto validOplogEntry = BSON("op" << "u" - << "ui" - << UUID::gen() - << "ts" - << Timestamp(1, 1) - << "t" - << 1LL - << "ns" + << "ui" << UUID::gen() << "ts" << Timestamp(1, 1) << "t" + << 1LL << "ns" << "test.t" - << "o" - << BSON("_id" << 1 << "a" << 1) - << "o2" + << "o" << BSON("_id" << 1 << "a" << 1) << "o2" << BSON("_id" << 1)); FixUpInfo fui; ASSERT_OK(updateFixUpInfoFromLocalOplogEntry( nullptr /* opCtx */, OplogInterfaceMock(), fui, validOplogEntry, false)); const auto invalidOplogEntry = BSON("op" << "u" - << "ui" - << UUID::gen() - << "ts" - << Timestamp(1, 1) - << "t" - << 1LL - << "ns" + << "ui" << UUID::gen() << "ts" << Timestamp(1, 1) << "t" + << 1LL << "ns" << "test.t" - << "o" - << BSON("_id" << 1 << "a" << 1) - << "o2" + << "o" << BSON("_id" << 1 << "a" << 1) << "o2" << BSONObj()); ASSERT_THROWS(updateFixUpInfoFromLocalOplogEntry( nullptr /* opCtx */, OplogInterfaceMock(), fui, invalidOplogEntry, false), @@ -2094,12 +1946,9 @@ TEST(RSRollbackTest, LocalUpdateEntryWithEmptyO2IsFatal) { DEATH_TEST_F(RSRollbackTest, LocalEntryWithTxnNumberWithoutSessionIdIsFatal, "invariant") { auto validOplogEntry = BSON("ts" << Timestamp(Seconds(1), 0) << "t" << 1LL << "op" << "i" - << "ui" - << UUID::gen() - << "ns" + << "ui" << UUID::gen() << "ns" << "test.t" - << "o" - << BSON("_id" << 1 << "a" << 1)); + << "o" << BSON("_id" << 1 << "a" << 1)); FixUpInfo fui; ASSERT_OK(updateFixUpInfoFromLocalOplogEntry( nullptr /* opCtx */, OplogInterfaceMock(), fui, validOplogEntry, false)); @@ -2120,18 +1969,10 @@ TEST_F(RSRollbackTest, LocalEntryWithTxnNumberWithoutTxnTableUUIDIsFatal) { auto lsid = makeLogicalSessionIdForTest(); auto entryWithTxnNumber = BSON("ts" << Timestamp(Seconds(1), 0) << "t" << 1LL << "op" << "i" - << "ui" - << uuid - << "ns" + << "ui" << uuid << "ns" << "test.t" - << "o" - << BSON("_id" << 1 << "a" << 1) - << "txnNumber" - << 1LL - << "stmtId" - << 1 - << "lsid" - << lsid.toBSON()); + << "o" << BSON("_id" << 1 << "a" << 1) << "txnNumber" << 1LL + << "stmtId" << 1 << "lsid" << lsid.toBSON()); FixUpInfo fui; ASSERT_THROWS(updateFixUpInfoFromLocalOplogEntry( @@ -2145,12 +1986,9 @@ TEST_F(RSRollbackTest, LocalEntryWithTxnNumberAddsTransactionTableDocToBeRefetch // With no txnNumber present, no extra documents need to be refetched. auto entryWithoutTxnNumber = BSON("ts" << Timestamp(Seconds(1), 0) << "t" << 1LL << "op" << "i" - << "ui" - << UUID::gen() - << "ns" + << "ui" << UUID::gen() << "ns" << "test.t2" - << "o" - << BSON("_id" << 2 << "a" << 2)); + << "o" << BSON("_id" << 2 << "a" << 2)); ASSERT_OK(updateFixUpInfoFromLocalOplogEntry( nullptr /* opCtx */, OplogInterfaceMock(), fui, entryWithoutTxnNumber, false)); @@ -2163,18 +2001,10 @@ TEST_F(RSRollbackTest, LocalEntryWithTxnNumberAddsTransactionTableDocToBeRefetch auto lsid = makeLogicalSessionIdForTest(); auto entryWithTxnNumber = BSON("ts" << Timestamp(Seconds(1), 0) << "t" << 1LL << "op" << "i" - << "ui" - << uuid - << "ns" + << "ui" << uuid << "ns" << "test.t" - << "o" - << BSON("_id" << 1 << "a" << 1) - << "txnNumber" - << 1LL - << "stmtId" - << 1 - << "lsid" - << lsid.toBSON()); + << "o" << BSON("_id" << 1 << "a" << 1) << "txnNumber" << 1LL + << "stmtId" << 1 << "lsid" << lsid.toBSON()); UUID transactionTableUUID = UUID::gen(); fui.transactionTableUUID = transactionTableUUID; @@ -2204,20 +2034,11 @@ TEST_F(RSRollbackTest, LocalEntryWithPartialTxnAddsTransactionTableDocToBeRefetc << "o" << BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ui" - << uuid - << "ns" + << "ui" << uuid << "ns" << "test.t" - << "o" - << BSON("_id" << 1 << "a" << 1))) - << "partialTxn" - << true) - << "txnNumber" - << 1LL - << "stmtId" - << 1 - << "lsid" - << lsid.toBSON()); + << "o" << BSON("_id" << 1 << "a" << 1))) + << "partialTxn" << true) + << "txnNumber" << 1LL << "stmtId" << 1 << "lsid" << lsid.toBSON()); UUID transactionTableUUID = UUID::gen(); fui.transactionTableUUID = transactionTableUUID; @@ -2240,15 +2061,8 @@ TEST_F(RSRollbackTest, LocalAbortTxnRefetchesTransactionTableEntry) { << "c" << "ns" << "admin.$cmd" - << "o" - << BSON("abortTransaction" << 1) - << "txnNumber" - << 1LL - << "stmtId" - << 1 - << "lsid" - << lsid.toBSON() - << "prevOpTime" + << "o" << BSON("abortTransaction" << 1) << "txnNumber" << 1LL + << "stmtId" << 1 << "lsid" << lsid.toBSON() << "prevOpTime" << BSON("ts" << Timestamp(Seconds(1), 0) << "t" << 1LL)); UUID transactionTableUUID = UUID::gen(); @@ -2276,15 +2090,8 @@ TEST_F(RSRollbackTest, LocalEntryWithAbortedPartialTxnRefetchesOnlyTransactionTa << "c" << "ns" << "admin.$cmd" - << "o" - << BSON("abortTransaction" << 1) - << "txnNumber" - << 1LL - << "stmtId" - << 1 - << "lsid" - << lsid.toBSON() - << "prevOpTime" + << "o" << BSON("abortTransaction" << 1) << "txnNumber" << 1LL + << "stmtId" << 1 << "lsid" << lsid.toBSON() << "prevOpTime" << BSON("ts" << Timestamp(Seconds(1), 1) << "t" << 1LL)); auto entryWithTxnNumber = @@ -2295,20 +2102,11 @@ TEST_F(RSRollbackTest, LocalEntryWithAbortedPartialTxnRefetchesOnlyTransactionTa << "o" << BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ui" - << uuid - << "ns" + << "ui" << uuid << "ns" << "test.t" - << "o" - << BSON("_id" << 1 << "a" << 1))) - << "partialTxn" - << true) - << "txnNumber" - << 1LL - << "stmtId" - << 1 - << "lsid" - << lsid.toBSON()); + << "o" << BSON("_id" << 1 << "a" << 1))) + << "partialTxn" << true) + << "txnNumber" << 1LL << "stmtId" << 1 << "lsid" << lsid.toBSON()); UUID transactionTableUUID = UUID::gen(); fui.transactionTableUUID = transactionTableUUID; @@ -2335,21 +2133,11 @@ TEST_F(RSRollbackTest, LocalEntryWithCommittedTxnRefetchesDocsAndTransactionTabl << "o" << BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ui" - << uuid - << "ns" + << "ui" << uuid << "ns" << "test.t" - << "o" - << BSON("_id" << 2 << "a" << 2))) - << "count" - << 2) - << "txnNumber" - << 1LL - << "stmtId" - << 2 - << "lsid" - << lsid.toBSON() - << "prevOpTime" + << "o" << BSON("_id" << 2 << "a" << 2))) + << "count" << 2) + << "txnNumber" << 1LL << "stmtId" << 2 << "lsid" << lsid.toBSON() << "prevOpTime" << BSON("ts" << Timestamp(Seconds(1), 1) << "t" << 1LL)); auto commitTxnOperation = std::make_pair(commitTxnEntry, RecordId(2)); @@ -2361,21 +2149,11 @@ TEST_F(RSRollbackTest, LocalEntryWithCommittedTxnRefetchesDocsAndTransactionTabl << "o" << BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ui" - << uuid - << "ns" + << "ui" << uuid << "ns" << "test.t" - << "o" - << BSON("_id" << 1 << "a" << 1))) - << "partialTxn" - << true) - << "txnNumber" - << 1LL - << "stmtId" - << 1 - << "lsid" - << lsid.toBSON() - << "prevOpTime" + << "o" << BSON("_id" << 1 << "a" << 1))) + << "partialTxn" << true) + << "txnNumber" << 1LL << "stmtId" << 1 << "lsid" << lsid.toBSON() << "prevOpTime" << BSON("ts" << Timestamp(0, 0) << "t" << -1LL)); auto partialTxnOperation = std::make_pair(partialTxnEntry, RecordId(1)); @@ -2428,21 +2206,11 @@ TEST_F(RSRollbackTest, RollbackFetchesTransactionOperationBeforeCommonPoint) { << "o" << BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ui" - << uuid - << "ns" + << "ui" << uuid << "ns" << "test.t" - << "o" - << BSON("_id" << 0 << "a" << 0))) - << "count" - << 3) - << "txnNumber" - << 1LL - << "stmtId" - << 3 - << "lsid" - << lsid.toBSON() - << "prevOpTime" + << "o" << BSON("_id" << 0 << "a" << 0))) + << "count" << 3) + << "txnNumber" << 1LL << "stmtId" << 3 << "lsid" << lsid.toBSON() << "prevOpTime" << BSON("ts" << Timestamp(Seconds(10), 11) << "t" << 10LL)); auto commitTxnOperation = std::make_pair(commitTxnEntry, RecordId(12)); @@ -2454,21 +2222,11 @@ TEST_F(RSRollbackTest, RollbackFetchesTransactionOperationBeforeCommonPoint) { << "o" << BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ui" - << uuid - << "ns" + << "ui" << uuid << "ns" << "test.t" - << "o" - << BSON("_id" << 1 << "a" << 1))) - << "partialTxn" - << true) - << "txnNumber" - << 1LL - << "stmtId" - << 2 - << "lsid" - << lsid.toBSON() - << "prevOpTime" + << "o" << BSON("_id" << 1 << "a" << 1))) + << "partialTxn" << true) + << "txnNumber" << 1LL << "stmtId" << 2 << "lsid" << lsid.toBSON() << "prevOpTime" << BSON("ts" << Timestamp(Seconds(10), 9) << "t" << 10LL)); auto operationAfterCommonPoint = std::make_pair(entryAfterCommonPoint, RecordId(11)); @@ -2480,21 +2238,11 @@ TEST_F(RSRollbackTest, RollbackFetchesTransactionOperationBeforeCommonPoint) { << "o" << BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ui" - << uuid - << "ns" + << "ui" << uuid << "ns" << "test.t" - << "o" - << BSON("_id" << 2 << "a" << 2))) - << "partialTxn" - << true) - << "txnNumber" - << 1LL - << "stmtId" - << 1 - << "lsid" - << lsid.toBSON() - << "prevOpTime" + << "o" << BSON("_id" << 2 << "a" << 2))) + << "partialTxn" << true) + << "txnNumber" << 1LL << "stmtId" << 1 << "lsid" << lsid.toBSON() << "prevOpTime" << BSON("ts" << Timestamp(0, 0) << "t" << -1LL)); auto operationBeforeCommonPoint = std::make_pair(entryBeforeCommonPoint, RecordId(9)); @@ -2572,19 +2320,11 @@ TEST_F(RSRollbackTest, RollbackIncompleteTransactionReturnsUnrecoverableRollback << "o" << BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ui" - << uuid - << "ns" + << "ui" << uuid << "ns" << "test.t" - << "o" - << BSON("_id" << 0 << "a" << 0))) - << "count" - << 3) - << "stmtId" - << 3 - << "lsid" - << lsid.toBSON() - << "prevOpTime" + << "o" << BSON("_id" << 0 << "a" << 0))) + << "count" << 3) + << "stmtId" << 3 << "lsid" << lsid.toBSON() << "prevOpTime" << BSON("ts" << Timestamp(Seconds(10), 11) << "t" << 10LL)); auto commitTxnOperation = std::make_pair(commitTxnEntry, RecordId(12)); @@ -2596,21 +2336,11 @@ TEST_F(RSRollbackTest, RollbackIncompleteTransactionReturnsUnrecoverableRollback << "o" << BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ui" - << uuid - << "ns" + << "ui" << uuid << "ns" << "test.t" - << "o" - << BSON("_id" << 1 << "a" << 1))) - << "partialTxn" - << true) - << "txnNumber" - << 1LL - << "stmtId" - << 2 - << "lsid" - << lsid.toBSON() - << "prevOpTime" + << "o" << BSON("_id" << 1 << "a" << 1))) + << "partialTxn" << true) + << "txnNumber" << 1LL << "stmtId" << 2 << "lsid" << lsid.toBSON() << "prevOpTime" << BSON("ts" << Timestamp(Seconds(10), 9) << "t" << 10LL)); auto operationAfterCommonPoint = std::make_pair(entryAfterCommonPoint, RecordId(11)); @@ -2653,20 +2383,13 @@ TEST_F(RSRollbackTest, RollbackFailsIfTransactionDocumentRefetchReturnsDifferent // transaction number and session id. FixUpInfo fui; - auto entryWithTxnNumber = BSON("ts" << Timestamp(Seconds(2), 1) << "t" << 1LL << "op" - << "i" - << "ui" - << UUID::gen() - << "ns" - << "test.t" - << "o" - << BSON("_id" << 1 << "a" << 1) - << "txnNumber" - << 1LL - << "stmtId" - << 1 - << "lsid" - << makeLogicalSessionIdForTest().toBSON()); + auto entryWithTxnNumber = + BSON("ts" << Timestamp(Seconds(2), 1) << "t" << 1LL << "op" + << "i" + << "ui" << UUID::gen() << "ns" + << "test.t" + << "o" << BSON("_id" << 1 << "a" << 1) << "txnNumber" << 1LL << "stmtId" << 1 + << "lsid" << makeLogicalSessionIdForTest().toBSON()); UUID transactionTableUUID = UUID::gen(); fui.transactionTableUUID = transactionTableUUID; diff --git a/src/mongo/db/repl/split_horizon_test.cpp b/src/mongo/db/repl/split_horizon_test.cpp index 0a3a655ccaf..95b2df2ad36 100644 --- a/src/mongo/db/repl/split_horizon_test.cpp +++ b/src/mongo/db/repl/split_horizon_test.cpp @@ -300,8 +300,7 @@ TEST(SplitHorizonTesting, BSONConstruction) { // Two horizons with duplicate host and ports. {BSON("horizonWithDuplicateHost1" << matchingHostAndPort << "horizonWithDuplicateHost2" - << matchingHostAndPort - << "uniqueHorizon" + << matchingHostAndPort << "uniqueHorizon" << nonmatchingHost), defaultHostAndPort, {}, diff --git a/src/mongo/db/repl/storage_interface_impl.cpp b/src/mongo/db/repl/storage_interface_impl.cpp index 39d5c73b6e4..19e7c8840fa 100644 --- a/src/mongo/db/repl/storage_interface_impl.cpp +++ b/src/mongo/db/repl/storage_interface_impl.cpp @@ -501,20 +501,16 @@ Status StorageInterfaceImpl::renameCollection(OperationContext* opCtx, if (fromNS.db() != toNS.db()) { return Status(ErrorCodes::InvalidNamespace, str::stream() << "Cannot rename collection between databases. From NS: " - << fromNS.ns() - << "; to NS: " - << toNS.ns()); + << fromNS.ns() << "; to NS: " << toNS.ns()); } return writeConflictRetry(opCtx, "StorageInterfaceImpl::renameCollection", fromNS.ns(), [&] { AutoGetDb autoDB(opCtx, fromNS.db(), MODE_X); if (!autoDB.getDb()) { return Status(ErrorCodes::NamespaceNotFound, - str::stream() << "Cannot rename collection from " << fromNS.ns() << " to " - << toNS.ns() - << ". Database " - << fromNS.db() - << " not found."); + str::stream() + << "Cannot rename collection from " << fromNS.ns() << " to " + << toNS.ns() << ". Database " << fromNS.db() << " not found."); } WriteUnitOfWork wunit(opCtx); const auto status = autoDB.getDb()->renameCollection(opCtx, fromNS, toNS, stayTemp); @@ -557,8 +553,7 @@ Status StorageInterfaceImpl::setIndexIsMultikey(OperationContext* opCtx, if (!idx) { return Status(ErrorCodes::IndexNotFound, str::stream() << "Could not find index " << indexName << " in " - << nss.ns() - << " to set to multikey."); + << nss.ns() << " to set to multikey."); } collection->getIndexCatalog()->setMultikeyPaths(opCtx, idx, paths); wunit.commit(); @@ -646,16 +641,13 @@ StatusWith<std::vector<BSONObj>> _findOrDeleteDocuments( if (!indexDescriptor) { return Result(ErrorCodes::IndexNotFound, str::stream() << "Index not found, ns:" << nsOrUUID.toString() - << ", index: " - << *indexName); + << ", index: " << *indexName); } if (indexDescriptor->isPartial()) { return Result(ErrorCodes::IndexOptionsConflict, str::stream() << "Partial index is not allowed for this operation, ns:" - << nsOrUUID.toString() - << ", index: " - << *indexName); + << nsOrUUID.toString() << ", index: " << *indexName); } KeyPattern keyPattern(indexDescriptor->keyPattern()); @@ -855,11 +847,11 @@ Status _updateWithQuery(OperationContext* opCtx, } AutoGetCollection autoColl(opCtx, nss, MODE_IX); - auto collectionResult = getCollection( - autoColl, - nss, - str::stream() << "Unable to update documents in " << nss.ns() << " using query " - << request.getQuery()); + auto collectionResult = + getCollection(autoColl, + nss, + str::stream() << "Unable to update documents in " << nss.ns() + << " using query " << request.getQuery()); if (!collectionResult.isOK()) { return collectionResult.getStatus(); } @@ -988,11 +980,11 @@ Status StorageInterfaceImpl::deleteByFilter(OperationContext* opCtx, } AutoGetCollection autoColl(opCtx, nss, MODE_IX); - auto collectionResult = getCollection( - autoColl, - nss, - str::stream() << "Unable to delete documents in " << nss.ns() << " using filter " - << filter); + auto collectionResult = + getCollection(autoColl, + nss, + str::stream() << "Unable to delete documents in " << nss.ns() + << " using filter " << filter); if (!collectionResult.isOK()) { return collectionResult.getStatus(); } diff --git a/src/mongo/db/repl/storage_interface_impl_test.cpp b/src/mongo/db/repl/storage_interface_impl_test.cpp index 19d57312b19..8ade17d6efa 100644 --- a/src/mongo/db/repl/storage_interface_impl_test.cpp +++ b/src/mongo/db/repl/storage_interface_impl_test.cpp @@ -69,11 +69,7 @@ const auto kIndexVersion = IndexDescriptor::IndexVersion::kV2; BSONObj makeIdIndexSpec(const NamespaceString& nss) { return BSON("ns" << nss.toString() << "name" << "_id_" - << "key" - << BSON("_id" << 1) - << "unique" - << true - << "v" + << "key" << BSON("_id" << 1) << "unique" << true << "v" << static_cast<int>(kIndexVersion)); } @@ -299,8 +295,7 @@ void _assertRollbackIDDocument(OperationContext* opCtx, int id) { opCtx, NamespaceString(StorageInterfaceImpl::kDefaultRollbackIdNamespace), {BSON("_id" << StorageInterfaceImpl::kRollbackIdDocumentId - << StorageInterfaceImpl::kRollbackIdFieldName - << id)}); + << StorageInterfaceImpl::kRollbackIdFieldName << id)}); } TEST_F(StorageInterfaceImplTest, RollbackIdInitializesIncrementsAndReadsProperly) { @@ -380,8 +375,7 @@ TEST_F(StorageInterfaceImplTest, GetRollbackIDReturnsBadStatusIfRollbackIDIsNotI std::vector<TimestampedBSONObj> badDoc = { TimestampedBSONObj{BSON("_id" << StorageInterfaceImpl::kRollbackIdDocumentId - << StorageInterfaceImpl::kRollbackIdFieldName - << "bad id"), + << StorageInterfaceImpl::kRollbackIdFieldName << "bad id"), Timestamp::min()}}; ASSERT_OK(storage.insertDocuments(opCtx, nss, transformInserts(badDoc))); ASSERT_EQUALS(ErrorCodes::TypeMismatch, storage.getRollbackID(opCtx).getStatus()); @@ -625,8 +619,7 @@ TEST_F(StorageInterfaceImplTest, DestroyingUncommittedCollectionBulkLoaderDropsI auto nss = makeNamespace(_agent); std::vector<BSONObj> indexes = {BSON("v" << 1 << "key" << BSON("x" << 1) << "name" << "x_1" - << "ns" - << nss.ns())}; + << "ns" << nss.ns())}; auto destroyLoaderFn = [](std::unique_ptr<CollectionBulkLoader> loader) { // Destroy 'loader' by letting it go out of scope. }; @@ -650,8 +643,7 @@ TEST_F(StorageInterfaceImplTest, auto nss = makeNamespace(_agent); std::vector<BSONObj> indexes = {BSON("v" << 1 << "key" << BSON("x" << 1) << "name" << "x_1" - << "ns" - << nss.ns())}; + << "ns" << nss.ns())}; auto destroyLoaderFn = [](std::unique_ptr<CollectionBulkLoader> loader) { // Destroy 'loader' in a new thread that does not have a Client. stdx::thread([&loader]() { loader.reset(); }).join(); @@ -914,9 +906,7 @@ TEST_F(StorageInterfaceImplTest, FindDocumentsReturnsIndexOptionsConflictIfIndex auto nss = makeNamespace(_agent); std::vector<BSONObj> indexes = {BSON("v" << 1 << "key" << BSON("x" << 1) << "name" << "x_1" - << "ns" - << nss.ns() - << "partialFilterExpression" + << "ns" << nss.ns() << "partialFilterExpression" << BSON("y" << 1))}; auto loader = unittest::assertGet(storage.createCollectionForBulkLoading( nss, generateOptionsWithUuid(), makeIdIndexSpec(nss), indexes)); @@ -975,8 +965,8 @@ void _assertDocumentsEqual(const StatusWith<std::vector<BSONObj>>& statusWithDoc const std::vector<BSONObj>& expectedDocs) { const auto actualDocs = unittest::assertGet(statusWithDocs); auto iter = actualDocs.cbegin(); - std::string msg = str::stream() << "expected: " << _toString(expectedDocs) - << "; actual: " << _toString(actualDocs); + std::string msg = str::stream() + << "expected: " << _toString(expectedDocs) << "; actual: " << _toString(actualDocs); for (const auto& doc : expectedDocs) { ASSERT_TRUE(iter != actualDocs.cend()) << msg; ASSERT_BSONOBJ_EQ(doc, *(iter++)); @@ -2264,9 +2254,7 @@ TEST_F(StorageInterfaceImplTest, DeleteByFilterReturnsNamespaceNotFoundWhenDatab ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, status); ASSERT_EQUALS(std::string(str::stream() << "Database [nosuchdb] not found. Unable to delete documents in " - << nss.ns() - << " using filter " - << filter), + << nss.ns() << " using filter " << filter), status.reason()); } @@ -2362,9 +2350,7 @@ TEST_F(StorageInterfaceImplTest, DeleteByFilterReturnsNamespaceNotFoundWhenColle ASSERT_EQUALS(std::string( str::stream() << "Collection [mydb.wrongColl] not found. Unable to delete documents in " - << wrongColl.ns() - << " using filter " - << filter), + << wrongColl.ns() << " using filter " << filter), status.reason()); } @@ -2484,8 +2470,7 @@ TEST_F(StorageInterfaceImplTest, CollectionOptions options = generateOptionsWithUuid(); options.collation = BSON("locale" << "en_US" - << "strength" - << 2); + << "strength" << 2); ASSERT_OK(storage.createCollection(opCtx, nss, options)); auto doc1 = BSON("_id" << 1 << "x" @@ -2660,9 +2645,8 @@ TEST_F(StorageInterfaceImplTest, SetIndexIsMultikeySucceeds) { ASSERT_OK(storage.createCollection(opCtx, nss, CollectionOptions())); auto indexName = "a_b_1"; - auto indexSpec = - BSON("name" << indexName << "ns" << nss.ns() << "key" << BSON("a.b" << 1) << "v" - << static_cast<int>(kIndexVersion)); + auto indexSpec = BSON("name" << indexName << "ns" << nss.ns() << "key" << BSON("a.b" << 1) + << "v" << static_cast<int>(kIndexVersion)); ASSERT_EQUALS(_createIndexOnEmptyCollection(opCtx, nss, indexSpec), 2); MultikeyPaths paths = {{1}}; diff --git a/src/mongo/db/repl/storage_interface_mock.h b/src/mongo/db/repl/storage_interface_mock.h index 119f682fba9..cc031904cb8 100644 --- a/src/mongo/db/repl/storage_interface_mock.h +++ b/src/mongo/db/repl/storage_interface_mock.h @@ -352,8 +352,8 @@ public: [](const NamespaceString& nss, const CollectionOptions& options, const BSONObj idIndexSpec, - const std::vector<BSONObj>& - secondaryIndexSpecs) -> StatusWith<std::unique_ptr<CollectionBulkLoader>> { + const std::vector<BSONObj>& secondaryIndexSpecs) + -> StatusWith<std::unique_ptr<CollectionBulkLoader>> { return Status{ErrorCodes::IllegalOperation, "CreateCollectionForBulkFn not implemented."}; }; InsertDocumentFn insertDocumentFn = [](OperationContext* opCtx, @@ -404,8 +404,9 @@ public: IsAdminDbValidFn isAdminDbValidFn = [](OperationContext*) { return Status{ErrorCodes::IllegalOperation, "IsAdminDbValidFn not implemented."}; }; - GetCollectionUUIDFn getCollectionUUIDFn = []( - OperationContext* opCtx, const NamespaceString& nss) -> StatusWith<OptionalCollectionUUID> { + GetCollectionUUIDFn getCollectionUUIDFn = + [](OperationContext* opCtx, + const NamespaceString& nss) -> StatusWith<OptionalCollectionUUID> { return Status{ErrorCodes::IllegalOperation, "GetCollectionUUIDFn not implemented."}; }; UpgradeNonReplicatedUniqueIndexesFn upgradeNonReplicatedUniqueIndexesFn = diff --git a/src/mongo/db/repl/sync_source_resolver.cpp b/src/mongo/db/repl/sync_source_resolver.cpp index adfcc7b2f31..af82a940d35 100644 --- a/src/mongo/db/repl/sync_source_resolver.cpp +++ b/src/mongo/db/repl/sync_source_resolver.cpp @@ -74,8 +74,7 @@ SyncSourceResolver::SyncSourceResolver(executor::TaskExecutor* taskExecutor, str::stream() << "required optime (if provided) must be more recent than last " "fetched optime. requiredOpTime: " << requiredOpTime.toString() - << ", lastOpTimeFetched: " - << lastOpTimeFetched.toString(), + << ", lastOpTimeFetched: " << lastOpTimeFetched.toString(), requiredOpTime.isNull() || requiredOpTime > lastOpTimeFetched); uassert(ErrorCodes::BadValue, "callback function cannot be null", onCompletion); } @@ -171,9 +170,8 @@ std::unique_ptr<Fetcher> SyncSourceResolver::_makeFirstOplogEntryFetcher( kLocalOplogNss.db().toString(), BSON("find" << kLocalOplogNss.coll() << "limit" << 1 << "sort" << BSON("$natural" << 1) << "projection" - << BSON(OplogEntryBase::kTimestampFieldName << 1 - << OplogEntryBase::kTermFieldName - << 1)), + << BSON(OplogEntryBase::kTimestampFieldName + << 1 << OplogEntryBase::kTermFieldName << 1)), [=](const StatusWith<Fetcher::QueryResponse>& response, Fetcher::NextAction*, BSONObjBuilder*) { @@ -413,12 +411,11 @@ Status SyncSourceResolver::_compareRequiredOpTimeWithQueryResponse( const auto opTime = oplogEntry.getOpTime(); if (_requiredOpTime != opTime) { return Status(ErrorCodes::BadValue, - str::stream() << "remote oplog contain entry with matching timestamp " - << opTime.getTimestamp().toString() - << " but optime " - << opTime.toString() - << " does not " - "match our required optime"); + str::stream() + << "remote oplog contain entry with matching timestamp " + << opTime.getTimestamp().toString() << " but optime " << opTime.toString() + << " does not " + "match our required optime"); } if (_requiredOpTime.getTerm() != opTime.getTerm()) { return Status(ErrorCodes::BadValue, @@ -439,8 +436,7 @@ void SyncSourceResolver::_requiredOpTimeFetcherCallback( str::stream() << "sync source resolver shut down while looking for " "required optime " << _requiredOpTime.toString() - << " in candidate's oplog: " - << candidate)) + << " in candidate's oplog: " << candidate)) .transitional_ignore(); return; } diff --git a/src/mongo/db/repl/sync_source_selector.h b/src/mongo/db/repl/sync_source_selector.h index 0a620d691a2..c21a5e82a14 100644 --- a/src/mongo/db/repl/sync_source_selector.h +++ b/src/mongo/db/repl/sync_source_selector.h @@ -41,7 +41,7 @@ class Timestamp; namespace rpc { class ReplSetMetadata; class OplogQueryMetadata; -} +} // namespace rpc namespace repl { diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp index a21c1162829..4e7f6553e11 100644 --- a/src/mongo/db/repl/sync_tail.cpp +++ b/src/mongo/db/repl/sync_tail.cpp @@ -786,8 +786,7 @@ void SyncTail::_oplogApplication(ReplicationCoordinator* replCoord, str::stream() << "Attempted to apply an oplog entry (" << firstOpTimeInBatch.toString() << ") which is not greater than our last applied OpTime (" - << lastAppliedOpTimeAtStartOfBatch.toString() - << ").")); + << lastAppliedOpTimeAtStartOfBatch.toString() << ").")); } // Don't allow the fsync+lock thread to see intermediate states of batch application. @@ -817,8 +816,7 @@ void SyncTail::_oplogApplication(ReplicationCoordinator* replCoord, const auto lastAppliedOpTimeAtEndOfBatch = replCoord->getMyLastAppliedOpTime(); invariant(lastAppliedOpTimeAtStartOfBatch == lastAppliedOpTimeAtEndOfBatch, str::stream() << "the last known applied OpTime has changed from " - << lastAppliedOpTimeAtStartOfBatch.toString() - << " to " + << lastAppliedOpTimeAtStartOfBatch.toString() << " to " << lastAppliedOpTimeAtEndOfBatch.toString() << " in the middle of batch application"); @@ -1299,23 +1297,23 @@ void SyncTail::_applyOps(std::vector<MultiApplier::OperationPtrs>& writerVectors if (writerVectors[i].empty()) continue; - _writerPool->schedule([ - this, - &writer = writerVectors.at(i), - &status = statusVector->at(i), - &workerMultikeyPathInfo = workerMultikeyPathInfo->at(i) - ](auto scheduleStatus) { - invariant(scheduleStatus); + _writerPool->schedule( + [this, + &writer = writerVectors.at(i), + &status = statusVector->at(i), + &workerMultikeyPathInfo = workerMultikeyPathInfo->at(i)](auto scheduleStatus) { + invariant(scheduleStatus); - auto opCtx = cc().makeOperationContext(); + auto opCtx = cc().makeOperationContext(); - // This code path is only executed on secondaries and initial syncing nodes, so it is - // safe to exclude any writes from Flow Control. - opCtx->setShouldParticipateInFlowControl(false); + // This code path is only executed on secondaries and initial syncing nodes, so it + // is safe to exclude any writes from Flow Control. + opCtx->setShouldParticipateInFlowControl(false); - status = opCtx->runWithoutInterruptionExceptAtGlobalShutdown( - [&] { return _applyFunc(opCtx.get(), &writer, this, &workerMultikeyPathInfo); }); - }); + status = opCtx->runWithoutInterruptionExceptAtGlobalShutdown([&] { + return _applyFunc(opCtx.get(), &writer, this, &workerMultikeyPathInfo); + }); + }); } } diff --git a/src/mongo/db/repl/sync_tail_test.cpp b/src/mongo/db/repl/sync_tail_test.cpp index 33558e09a39..b5aeb361244 100644 --- a/src/mongo/db/repl/sync_tail_test.cpp +++ b/src/mongo/db/repl/sync_tail_test.cpp @@ -355,14 +355,8 @@ TEST_F(SyncTailTest, SyncApplyCommand) { NamespaceString nss("test.t"); auto op = BSON("op" << "c" - << "ns" - << nss.getCommandNS().ns() - << "o" - << BSON("create" << nss.coll()) - << "ts" - << Timestamp(1, 1) - << "ui" - << UUID::gen()); + << "ns" << nss.getCommandNS().ns() << "o" << BSON("create" << nss.coll()) << "ts" + << Timestamp(1, 1) << "ui" << UUID::gen()); bool applyCmdCalled = false; _opObserver->onCreateCollectionFn = [&](OperationContext* opCtx, Collection*, @@ -387,13 +381,10 @@ TEST_F(SyncTailTest, SyncApplyCommand) { TEST_F(SyncTailTest, SyncApplyCommandThrowsException) { const BSONObj op = BSON("op" << "c" - << "ns" - << 12345 - << "o" + << "ns" << 12345 << "o" << BSON("create" << "t") - << "ts" - << Timestamp(1, 1)); + << "ts" << Timestamp(1, 1)); // This test relies on the namespace type check of IDL. ASSERT_THROWS( SyncTail::syncApply(_opCtx.get(), op, OplogApplication::Mode::kInitialSync, boost::none), @@ -493,14 +484,9 @@ protected: cmdNss, BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ns" - << _nss1.ns() - << "ui" - << *_uuid1 - << "o" + << "ns" << _nss1.ns() << "ui" << *_uuid1 << "o" << BSON("_id" << 1))) - << "partialTxn" - << true), + << "partialTxn" << true), _lsid, _txnNum, StmtId(0), @@ -510,14 +496,9 @@ protected: cmdNss, BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ns" - << _nss2.ns() - << "ui" - << *_uuid2 - << "o" + << "ns" << _nss2.ns() << "ui" << *_uuid2 << "o" << BSON("_id" << 2))) - << "partialTxn" - << true), + << "partialTxn" << true), _lsid, _txnNum, StmtId(1), @@ -527,11 +508,7 @@ protected: cmdNss, BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ns" - << _nss2.ns() - << "ui" - << *_uuid2 - << "o" + << "ns" << _nss2.ns() << "ui" << *_uuid2 << "o" << BSON("_id" << 3)))), _lsid, _txnNum, @@ -683,14 +660,10 @@ TEST_F(MultiOplogEntrySyncTailTest, MultiApplyUnpreparedTransactionTwoBatches) { cmdNss, BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ns" - << (i == 1 ? _nss2.ns() : _nss1.ns()) - << "ui" - << (i == 1 ? *_uuid2 : *_uuid1) - << "o" + << "ns" << (i == 1 ? _nss2.ns() : _nss1.ns()) << "ui" + << (i == 1 ? *_uuid2 : *_uuid1) << "o" << insertDocs.back())) - << "partialTxn" - << true), + << "partialTxn" << true), _lsid, _txnNum, StmtId(i), @@ -757,14 +730,9 @@ TEST_F(MultiOplogEntrySyncTailTest, MultiApplyTwoTransactionsOneBatch) { cmdNss, BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ns" - << _nss1.ns() - << "ui" - << *_uuid1 - << "o" + << "ns" << _nss1.ns() << "ui" << *_uuid1 << "o" << BSON("_id" << 1))) - << "partialTxn" - << true), + << "partialTxn" << true), _lsid, txnNum1, StmtId(0), @@ -774,14 +742,9 @@ TEST_F(MultiOplogEntrySyncTailTest, MultiApplyTwoTransactionsOneBatch) { cmdNss, BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ns" - << _nss1.ns() - << "ui" - << *_uuid1 - << "o" + << "ns" << _nss1.ns() << "ui" << *_uuid1 << "o" << BSON("_id" << 2))) - << "partialTxn" - << true), + << "partialTxn" << true), _lsid, txnNum1, @@ -792,14 +755,9 @@ TEST_F(MultiOplogEntrySyncTailTest, MultiApplyTwoTransactionsOneBatch) { cmdNss, BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ns" - << _nss1.ns() - << "ui" - << *_uuid1 - << "o" + << "ns" << _nss1.ns() << "ui" << *_uuid1 << "o" << BSON("_id" << 3))) - << "partialTxn" - << true), + << "partialTxn" << true), _lsid, txnNum2, StmtId(0), @@ -809,14 +767,9 @@ TEST_F(MultiOplogEntrySyncTailTest, MultiApplyTwoTransactionsOneBatch) { cmdNss, BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ns" - << _nss1.ns() - << "ui" - << *_uuid1 - << "o" + << "ns" << _nss1.ns() << "ui" << *_uuid1 << "o" << BSON("_id" << 4))) - << "partialTxn" - << true), + << "partialTxn" << true), _lsid, txnNum2, StmtId(1), @@ -877,14 +830,9 @@ protected: _nss1, BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ns" - << _nss2.ns() - << "ui" - << *_uuid2 - << "o" + << "ns" << _nss2.ns() << "ui" << *_uuid2 << "o" << BSON("_id" << 3))) - << "prepare" - << true), + << "prepare" << true), _lsid, _txnNum, StmtId(2), @@ -894,14 +842,9 @@ protected: _nss1, BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ns" - << _nss1.ns() - << "ui" - << *_uuid1 - << "o" + << "ns" << _nss1.ns() << "ui" << *_uuid1 << "o" << BSON("_id" << 0))) - << "prepare" - << true), + << "prepare" << true), _lsid, _txnNum, StmtId(0), @@ -2190,28 +2133,18 @@ TEST_F(IdempotencyTest, CreateCollectionWithCollation) { auto insertOp2 = insert(fromjson("{ _id: 'Foo', x: 1 }")); auto updateOp = update("foo", BSON("$set" << BSON("x" << 2))); auto dropColl = makeCommandOplogEntry(nextOpTime(), nss, BSON("drop" << nss.coll())); - auto options = BSON("collation" << BSON("locale" - << "en" - << "caseLevel" - << false - << "caseFirst" - << "off" - << "strength" - << 1 - << "numericOrdering" - << false - << "alternate" - << "non-ignorable" - << "maxVariable" - << "punct" - << "normalization" - << false - << "backwards" - << false - << "version" - << "57.1") - << "uuid" - << uuid); + auto options = BSON("collation" + << BSON("locale" + << "en" + << "caseLevel" << false << "caseFirst" + << "off" + << "strength" << 1 << "numericOrdering" << false << "alternate" + << "non-ignorable" + << "maxVariable" + << "punct" + << "normalization" << false << "backwards" << false << "version" + << "57.1") + << "uuid" << uuid); auto createColl = makeCreateCollectionOplogEntry(nextOpTime(), nss, options); // We don't drop and re-create the collection since we don't have ways @@ -2235,12 +2168,8 @@ TEST_F(IdempotencyTest, CreateCollectionWithIdIndex) { auto options1 = BSON("idIndex" << BSON("key" << fromjson("{_id: 1}") << "name" << "_id_" - << "v" - << 2 - << "ns" - << nss.ns()) - << "uuid" - << uuid); + << "v" << 2 << "ns" << nss.ns()) + << "uuid" << uuid); auto createColl1 = makeCreateCollectionOplogEntry(nextOpTime(), nss, options1); ASSERT_OK(runOpInitialSync(createColl1)); @@ -2274,9 +2203,8 @@ TEST_F(IdempotencyTest, CreateCollectionWithView) { ASSERT_OK( runOpInitialSync(makeCreateCollectionOplogEntry(nextOpTime(), viewNss, options.toBSON()))); - auto viewDoc = - BSON("_id" << NamespaceString(nss.db(), "view").ns() << "viewOn" << nss.coll() << "pipeline" - << fromjson("[ { '$project' : { 'x' : 1 } } ]")); + auto viewDoc = BSON("_id" << NamespaceString(nss.db(), "view").ns() << "viewOn" << nss.coll() + << "pipeline" << fromjson("[ { '$project' : { 'x' : 1 } } ]")); auto insertViewOp = makeInsertDocumentOplogEntry(nextOpTime(), viewNss, viewDoc); auto dropColl = makeCommandOplogEntry(nextOpTime(), nss, BSON("drop" << nss.coll())); @@ -2698,14 +2626,9 @@ TEST_F(SyncTailTxnTableTest, RetryableWriteThenMultiStatementTxnWriteOnSameSessi cmdNss, BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ns" - << nss().ns() - << "ui" - << *uuid - << "o" + << "ns" << nss().ns() << "ui" << *uuid << "o" << BSON("_id" << 2))) - << "partialTxn" - << true), + << "partialTxn" << true), sessionId, *sessionInfo.getTxnNumber(), StmtId(0), @@ -2754,14 +2677,9 @@ TEST_F(SyncTailTxnTableTest, MultiStatementTxnWriteThenRetryableWriteOnSameSessi cmdNss, BSON("applyOps" << BSON_ARRAY(BSON("op" << "i" - << "ns" - << nss().ns() - << "ui" - << *uuid - << "o" + << "ns" << nss().ns() << "ui" << *uuid << "o" << BSON("_id" << 2))) - << "partialTxn" - << true), + << "partialTxn" << true), sessionId, *sessionInfo.getTxnNumber(), StmtId(0), diff --git a/src/mongo/db/repl/task_runner.cpp b/src/mongo/db/repl/task_runner.cpp index a79cdfa7faa..4c53b558aa1 100644 --- a/src/mongo/db/repl/task_runner.cpp +++ b/src/mongo/db/repl/task_runner.cpp @@ -182,7 +182,6 @@ void TaskRunner::_runTasks() { "this task has been canceled by a previously invoked task")); } tasks.clear(); - }; cancelTasks(); diff --git a/src/mongo/db/repl/topology_coordinator.cpp b/src/mongo/db/repl/topology_coordinator.cpp index 43b0a7a8605..81056086087 100644 --- a/src/mongo/db/repl/topology_coordinator.cpp +++ b/src/mongo/db/repl/topology_coordinator.cpp @@ -249,8 +249,8 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now, _syncSource = _rsConfig.getMemberAt(_forceSyncSourceIndex).getHostAndPort(); _forceSyncSourceIndex = -1; log() << "choosing sync source candidate by request: " << _syncSource; - std::string msg(str::stream() << "syncing from: " << _syncSource.toString() - << " by request"); + std::string msg(str::stream() + << "syncing from: " << _syncSource.toString() << " by request"); setMyHeartbeatMessage(now, msg); return _syncSource; } @@ -572,8 +572,7 @@ Status TopologyCoordinator::prepareHeartbeatResponseV1(Date_t now, << "; remote node's: " << rshb; return Status(ErrorCodes::InconsistentReplicaSetNames, str::stream() << "Our set name of " << ourSetName << " does not match name " - << rshb - << " reported by remote node"); + << rshb << " reported by remote node"); } const MemberState myState = getMemberState(); @@ -782,8 +781,9 @@ HeartbeatResponseAction TopologyCoordinator::processHeartbeatResponse( } const int memberIndex = _rsConfig.findMemberIndexByHostAndPort(target); if (memberIndex == -1) { - LOG(1) << "Could not find " << target << " in current config so ignoring --" - " current config: " + LOG(1) << "Could not find " << target + << " in current config so ignoring --" + " current config: " << _rsConfig.toBSON(); HeartbeatResponseAction nextAction = HeartbeatResponseAction::makeNoAction(); nextAction.setNextHeartbeatStartDate(nextHeartbeatStartDate); @@ -1131,8 +1131,9 @@ HeartbeatResponseAction TopologyCoordinator::_updatePrimaryFromHBDataV1( bool scheduleCatchupTakeover = false; bool schedulePriorityTakeover = false; - if (!catchupTakeoverDisabled && (_memberData.at(primaryIndex).getLastAppliedOpTime() < - _memberData.at(_selfIndex).getLastAppliedOpTime())) { + if (!catchupTakeoverDisabled && + (_memberData.at(primaryIndex).getLastAppliedOpTime() < + _memberData.at(_selfIndex).getLastAppliedOpTime())) { LOG_FOR_ELECTION(2) << "I can take over the primary due to fresher data." << " Current primary index: " << primaryIndex << " in term " << _memberData.at(primaryIndex).getTerm() << "." @@ -2711,38 +2712,30 @@ void TopologyCoordinator::processReplSetRequestVotes(const ReplSetRequestVotesAr if (args.getTerm() < _term) { response->setVoteGranted(false); response->setReason(str::stream() << "candidate's term (" << args.getTerm() - << ") is lower than mine (" - << _term - << ")"); + << ") is lower than mine (" << _term << ")"); } else if (args.getConfigVersion() != _rsConfig.getConfigVersion()) { response->setVoteGranted(false); - response->setReason(str::stream() << "candidate's config version (" - << args.getConfigVersion() - << ") differs from mine (" - << _rsConfig.getConfigVersion() - << ")"); + response->setReason(str::stream() + << "candidate's config version (" << args.getConfigVersion() + << ") differs from mine (" << _rsConfig.getConfigVersion() << ")"); } else if (args.getSetName() != _rsConfig.getReplSetName()) { response->setVoteGranted(false); - response->setReason(str::stream() << "candidate's set name (" << args.getSetName() - << ") differs from mine (" - << _rsConfig.getReplSetName() - << ")"); + response->setReason(str::stream() + << "candidate's set name (" << args.getSetName() + << ") differs from mine (" << _rsConfig.getReplSetName() << ")"); } else if (args.getLastDurableOpTime() < getMyLastAppliedOpTime()) { response->setVoteGranted(false); response ->setReason(str::stream() << "candidate's data is staler than mine. candidate's last applied OpTime: " << args.getLastDurableOpTime().toString() - << ", my last applied OpTime: " - << getMyLastAppliedOpTime().toString()); + << ", my last applied OpTime: " << getMyLastAppliedOpTime().toString()); } else if (!args.isADryRun() && _lastVote.getTerm() == args.getTerm()) { response->setVoteGranted(false); response->setReason(str::stream() << "already voted for another candidate (" << _rsConfig.getMemberAt(_lastVote.getCandidateIndex()).getHostAndPort() - << ") this term (" - << _lastVote.getTerm() - << ")"); + << ") this term (" << _lastVote.getTerm() << ")"); } else { int betterPrimary = _findHealthyPrimaryOfEqualOrGreaterPriority(args.getCandidateIndex()); if (_selfConfig().isArbiter() && betterPrimary >= 0) { diff --git a/src/mongo/db/repl/topology_coordinator.h b/src/mongo/db/repl/topology_coordinator.h index b07ef7deb3f..6a6a6af4652 100644 --- a/src/mongo/db/repl/topology_coordinator.h +++ b/src/mongo/db/repl/topology_coordinator.h @@ -1076,7 +1076,7 @@ public: /** * Gets the number of retries left for this heartbeat attempt. Invalid to call if the current * state is 'UNINITIALIZED'. - */ + */ int retriesLeft() const { return kMaxHeartbeatRetries - _numFailuresSinceLastStart; } diff --git a/src/mongo/db/repl/topology_coordinator_v1_test.cpp b/src/mongo/db/repl/topology_coordinator_v1_test.cpp index 73b2fd6bcf6..633c0220372 100644 --- a/src/mongo/db/repl/topology_coordinator_v1_test.cpp +++ b/src/mongo/db/repl/topology_coordinator_v1_test.cpp @@ -53,9 +53,9 @@ #define ASSERT_NO_ACTION(EXPRESSION) \ ASSERT_EQUALS(mongo::repl::HeartbeatResponseAction::NoAction, (EXPRESSION)) -using std::unique_ptr; -using mongo::rpc::ReplSetMetadata; using mongo::rpc::OplogQueryMetadata; +using mongo::rpc::ReplSetMetadata; +using std::unique_ptr; namespace mongo { namespace repl { @@ -326,9 +326,7 @@ TEST_F(TopoCoordTest, NodeReturnsSecondaryWithMostRecentDataAsSyncSource) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -399,44 +397,31 @@ TEST_F(TopoCoordTest, NodeReturnsSecondaryWithMostRecentDataAsSyncSource) { } TEST_F(TopoCoordTest, NodeReturnsClosestValidSyncSourceAsSyncSource) { - updateConfig(BSON("_id" - << "rs0" - << "version" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "hself") - << BSON("_id" << 10 << "host" - << "h1") - << BSON("_id" << 20 << "host" - << "h2" - << "buildIndexes" - << false - << "priority" - << 0) - << BSON("_id" << 30 << "host" - << "h3" - << "hidden" - << true - << "priority" - << 0 - << "votes" - << 0) - << BSON("_id" << 40 << "host" - << "h4" - << "arbiterOnly" - << true) - << BSON("_id" << 50 << "host" - << "h5" - << "slaveDelay" - << 1 - << "priority" - << 0) - << BSON("_id" << 60 << "host" - << "h6") - << BSON("_id" << 70 << "host" - << "hprimary"))), - 0); + updateConfig( + BSON("_id" + << "rs0" + << "version" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "hself") + << BSON("_id" << 10 << "host" + << "h1") + << BSON("_id" << 20 << "host" + << "h2" + << "buildIndexes" << false << "priority" << 0) + << BSON("_id" << 30 << "host" + << "h3" + << "hidden" << true << "priority" << 0 << "votes" << 0) + << BSON("_id" << 40 << "host" + << "h4" + << "arbiterOnly" << true) + << BSON("_id" << 50 << "host" + << "h5" + << "slaveDelay" << 1 << "priority" << 0) + << BSON("_id" << 60 << "host" + << "h6") + << BSON("_id" << 70 << "host" + << "hprimary"))), + 0); setSelfMemberState(MemberState::RS_SECONDARY); OpTime lastOpTimeWeApplied = OpTime(Timestamp(100, 0), 0); @@ -573,9 +558,7 @@ TEST_F(TopoCoordTest, NodeReturnsClosestValidSyncSourceAsSyncSource) { TEST_F(TopoCoordTest, NodeWontChooseSyncSourceFromOlderTerm) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "hself") << BSON("_id" << 10 << "host" @@ -625,10 +608,7 @@ TEST_F(TopoCoordTest, NodeWontChooseSyncSourceFromOlderTerm) { TEST_F(TopoCoordTest, ChooseOnlyPrimaryAsSyncSourceWhenChainingIsDisallowed) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "settings" - << BSON("chainingAllowed" << false) + << "version" << 1 << "settings" << BSON("chainingAllowed" << false) << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") @@ -752,9 +732,7 @@ TEST_F(TopoCoordTest, ChooseOnlyVotersAsSyncSourceWhenNodeIsAVoter) { TEST_F(TopoCoordTest, ChooseSameSyncSourceEvenWhenPrimary) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -809,9 +787,7 @@ TEST_F(TopoCoordTest, ChooseSameSyncSourceEvenWhenPrimary) { TEST_F(TopoCoordTest, ChooseRequestedSyncSourceOnlyTheFirstTimeAfterTheSyncSourceIsForciblySet) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -862,9 +838,7 @@ TEST_F(TopoCoordTest, ChooseRequestedSyncSourceOnlyTheFirstTimeAfterTheSyncSourc TEST_F(TopoCoordTest, NodeDoesNotChooseBlacklistedSyncSourceUntilBlacklistingExpires) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -917,10 +891,7 @@ TEST_F(TopoCoordTest, NodeDoesNotChooseBlacklistedSyncSourceUntilBlacklistingExp TEST_F(TopoCoordTest, ChooseNoSyncSourceWhenPrimaryIsBlacklistedAndChainingIsDisallowed) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "settings" - << BSON("chainingAllowed" << false) + << "version" << 1 << "settings" << BSON("chainingAllowed" << false) << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") @@ -975,9 +946,7 @@ TEST_F(TopoCoordTest, ChooseNoSyncSourceWhenPrimaryIsBlacklistedAndChainingIsDis TEST_F(TopoCoordTest, NodeChangesToRecoveringWhenOnlyUnauthorizedNodesAreUp) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -1050,9 +1019,7 @@ TEST_F(TopoCoordTest, NodeChangesToRecoveringWhenOnlyUnauthorizedNodesAreUp) { TEST_F(TopoCoordTest, NodeDoesNotActOnHeartbeatsWhenAbsentFromConfig) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "h1") << BSON("_id" << 20 << "host" @@ -1086,13 +1053,10 @@ TEST_F(TopoCoordTest, NodeReturnsNotSecondaryWhenSyncFromIsRunAgainstArbiter) { // Test trying to sync from another node when we are an arbiter updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 1 << "host" << "h1"))), 0); @@ -1108,21 +1072,15 @@ TEST_F(TopoCoordTest, NodeReturnsNotSecondaryWhenSyncFromIsRunAgainstPrimary) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 0 - << "buildIndexes" - << false) + << "priority" << 0 << "buildIndexes" << false) << BSON("_id" << 3 << "host" << "h3") << BSON("_id" << 4 << "host" @@ -1150,21 +1108,15 @@ TEST_F(TopoCoordTest, NodeReturnsNodeNotFoundWhenSyncFromRequestsANodeNotInConfi updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 0 - << "buildIndexes" - << false) + << "priority" << 0 << "buildIndexes" << false) << BSON("_id" << 3 << "host" << "h3") << BSON("_id" << 4 << "host" @@ -1187,21 +1139,15 @@ TEST_F(TopoCoordTest, NodeReturnsInvalidOptionsWhenSyncFromRequestsSelf) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 0 - << "buildIndexes" - << false) + << "priority" << 0 << "buildIndexes" << false) << BSON("_id" << 3 << "host" << "h3") << BSON("_id" << 4 << "host" @@ -1225,21 +1171,15 @@ TEST_F(TopoCoordTest, NodeReturnsInvalidOptionsWhenSyncFromRequestsArbiter) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 0 - << "buildIndexes" - << false) + << "priority" << 0 << "buildIndexes" << false) << BSON("_id" << 3 << "host" << "h3") << BSON("_id" << 4 << "host" @@ -1264,21 +1204,15 @@ TEST_F(TopoCoordTest, NodeReturnsInvalidOptionsWhenSyncFromRequestsAnIndexNonbui updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 0 - << "buildIndexes" - << false) + << "priority" << 0 << "buildIndexes" << false) << BSON("_id" << 3 << "host" << "h3") << BSON("_id" << 4 << "host" @@ -1303,21 +1237,15 @@ TEST_F(TopoCoordTest, NodeReturnsHostUnreachableWhenSyncFromRequestsADownNode) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 0 - << "buildIndexes" - << false) + << "priority" << 0 << "buildIndexes" << false) << BSON("_id" << 3 << "host" << "h3") << BSON("_id" << 4 << "host" @@ -1346,21 +1274,15 @@ TEST_F(TopoCoordTest, ChooseRequestedNodeWhenSyncFromRequestsAStaleNode) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 0 - << "buildIndexes" - << false) + << "priority" << 0 << "buildIndexes" << false) << BSON("_id" << 3 << "host" << "h3") << BSON("_id" << 4 << "host" @@ -1395,21 +1317,15 @@ TEST_F(TopoCoordTest, ChooseRequestedNodeWhenSyncFromRequestsAValidNode) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 0 - << "buildIndexes" - << false) + << "priority" << 0 << "buildIndexes" << false) << BSON("_id" << 3 << "host" << "h3") << BSON("_id" << 4 << "host" @@ -1445,21 +1361,15 @@ TEST_F(TopoCoordTest, updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 0 - << "buildIndexes" - << false) + << "priority" << 0 << "buildIndexes" << false) << BSON("_id" << 3 << "host" << "h3") << BSON("_id" << 4 << "host" @@ -1494,21 +1404,15 @@ TEST_F(TopoCoordTest, NodeReturnsUnauthorizedWhenSyncFromRequestsANodeWeAreNotAu updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 0 - << "buildIndexes" - << false) + << "priority" << 0 << "buildIndexes" << false) << BSON("_id" << 3 << "host" << "h3") << BSON("_id" << 4 << "host" @@ -1562,21 +1466,15 @@ TEST_F(TopoCoordTest, updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "h1" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 2 << "host" << "h2" - << "priority" - << 0 - << "buildIndexes" - << false) + << "priority" << 0 << "buildIndexes" << false) << BSON("_id" << 3 << "host" << "h3") << BSON("_id" << 4 << "host" @@ -1920,13 +1818,10 @@ TEST_F(TopoCoordTest, HeartbeatFrequencyShouldBeHalfElectionTimeoutWhenArbiter) TEST_F(TopoCoordTest, PrepareStepDownAttemptFailsIfNotLeader) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), 0); getTopoCoord().changeMemberState_forTest(MemberState::RS_SECONDARY); Status expectedStatus(ErrorCodes::NotMaster, "This node is not a primary. "); @@ -1940,17 +1835,14 @@ public: TopoCoordTest::setUp(); updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" << "h2") << BSON("_id" << 30 << "host" << "h3")) - << "settings" - << BSON("protocolVersion" << 1)), + << "settings" << BSON("protocolVersion" << 1)), 0); setSelfMemberState(MemberState::RS_SECONDARY); } @@ -1974,8 +1866,8 @@ TEST_F(PrepareHeartbeatResponseV1Test, prepareHeartbeatResponseV1(args, &response, &result); stopCapturingLogMessages(); ASSERT_EQUALS(ErrorCodes::InconsistentReplicaSetNames, result); - ASSERT(result.reason().find("repl set names do not match")) << "Actual string was \"" - << result.reason() << '"'; + ASSERT(result.reason().find("repl set names do not match")) + << "Actual string was \"" << result.reason() << '"'; ASSERT_EQUALS(1, countLogLinesContaining("replSet set names do not match, ours: rs0; remote " "node's: rs1")); @@ -1988,15 +1880,12 @@ TEST_F(PrepareHeartbeatResponseV1Test, // reconfig self out of set updateConfig(BSON("_id" << "rs0" - << "version" - << 3 - << "members" + << "version" << 3 << "members" << BSON_ARRAY(BSON("_id" << 20 << "host" << "h2") << BSON("_id" << 30 << "host" << "h3")) - << "settings" - << BSON("protocolVersion" << 1)), + << "settings" << BSON("protocolVersion" << 1)), -1); ReplSetHeartbeatArgsV1 args; args.setSetName("rs0"); @@ -2192,9 +2081,7 @@ TEST_F(TopoCoordTest, BecomeCandidateWhenBecomingSecondaryInSingleNodeSet) { ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "hself"))), 0); @@ -2212,9 +2099,7 @@ TEST_F(TopoCoordTest, DoNotBecomeCandidateWhenBecomingSecondaryInSingleNodeSetIf ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "hself"))), 0); @@ -2242,15 +2127,10 @@ TEST_F(TopoCoordTest, BecomeCandidateWhenReconfigToBeElectableInSingleNodeSet) { ReplSetConfig cfg; cfg.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "hself" - << "priority" - << 0)))) + << "priority" << 0)))) .transitional_ignore(); getTopoCoord().updateConfig(cfg, 0, now()++); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); @@ -2264,9 +2144,7 @@ TEST_F(TopoCoordTest, BecomeCandidateWhenReconfigToBeElectableInSingleNodeSet) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "hself"))), 0); @@ -2280,15 +2158,10 @@ TEST_F(TopoCoordTest, ReplSetConfig cfg; ASSERT_OK(cfg.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "hself" - << "priority" - << 0))))); + << "priority" << 0))))); getTopoCoord().updateConfig(cfg, 0, now()++); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); @@ -2302,9 +2175,7 @@ TEST_F(TopoCoordTest, getTopoCoord().adjustMaintenanceCountBy(1); updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "hself"))), 0); @@ -2317,13 +2188,10 @@ TEST_F(TopoCoordTest, NodeDoesNotBecomeCandidateWhenBecomingSecondaryInSingleNod ReplSetConfig cfg; cfg.initialize(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "hself" - << "priority" - << 0)))) + << "priority" << 0)))) .transitional_ignore(); getTopoCoord().updateConfig(cfg, 0, now()++); @@ -2342,9 +2210,7 @@ TEST_F(TopoCoordTest, NodeTransitionsFromRemovedToStartup2WhenAddedToConfig) { // config to be absent from the set updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" @@ -2357,9 +2223,7 @@ TEST_F(TopoCoordTest, NodeTransitionsFromRemovedToStartup2WhenAddedToConfig) { // reconfig to add to set updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" @@ -2377,9 +2241,7 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfig) { ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" @@ -2393,9 +2255,7 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfig) { // reconfig to remove self updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" @@ -2411,9 +2271,7 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfigEvenWhenPrima ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017"))), 0); @@ -2430,9 +2288,7 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfigEvenWhenPrima // reconfig to remove self updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" @@ -2448,11 +2304,7 @@ TEST_F(TopoCoordTest, NodeTransitionsToSecondaryWhenReconfiggingToBeUnelectable) ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017"))), 0); @@ -2469,13 +2321,10 @@ TEST_F(TopoCoordTest, NodeTransitionsToSecondaryWhenReconfiggingToBeUnelectable) // now lose primary due to loss of electability updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017" - << "priority" - << 0) + << "priority" << 0) << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" @@ -2490,9 +2339,7 @@ TEST_F(TopoCoordTest, NodeMaintainsPrimaryStateAcrossReconfigIfNodeRemainsElecta ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017"))), 0); @@ -2511,9 +2358,7 @@ TEST_F(TopoCoordTest, NodeMaintainsPrimaryStateAcrossReconfigIfNodeRemainsElecta // Add hosts updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" @@ -2528,18 +2373,13 @@ TEST_F(TopoCoordTest, NodeMaintainsPrimaryStateAcrossReconfigIfNodeRemainsElecta // Change priorities and tags updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017" - << "priority" - << 10) + << "priority" << 10) << BSON("_id" << 1 << "host" << "host2:27017" - << "priority" - << 5 - << "tags" + << "priority" << 5 << "tags" << BSON("dc" << "NA" << "rack" @@ -2553,9 +2393,7 @@ TEST_F(TopoCoordTest, NodeMaintainsPrimaryStateAcrossReconfigIfNodeRemainsElecta TEST_F(TopoCoordTest, NodeMaintainsSecondaryStateAcrossReconfig) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "host1:27017") << BSON("_id" << 2 << "host" @@ -2569,9 +2407,7 @@ TEST_F(TopoCoordTest, NodeMaintainsSecondaryStateAcrossReconfig) { // reconfig and stay secondary updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" @@ -2586,13 +2422,10 @@ TEST_F(TopoCoordTest, NodeMaintainsSecondaryStateAcrossReconfig) { TEST_F(TopoCoordTest, NodeReturnsArbiterWhenGetMemberStateRunsAgainstArbiter) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 20 << "host" << "h2") << BSON("_id" << 30 << "host" @@ -2611,9 +2444,7 @@ TEST_F(TopoCoordTest, ShouldNotStandForElectionWhileRemovedFromTheConfig) { TEST_F(TopoCoordTest, NodeDoesNotGrantVotesToTwoDifferentNodesInTheSameTerm) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -2626,13 +2457,8 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVotesToTwoDifferentNodesInTheSameTerm) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "term" - << 1LL - << "candidateIndex" - << 0LL - << "configVersion" - << 1LL - << "lastCommittedOp" + << "term" << 1LL << "candidateIndex" << 0LL + << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); ReplSetRequestVotesResponse response; @@ -2645,13 +2471,8 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVotesToTwoDifferentNodesInTheSameTerm) { args2 .initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "term" - << 1LL - << "candidateIndex" - << 1LL - << "configVersion" - << 1LL - << "lastCommittedOp" + << "term" << 1LL << "candidateIndex" << 1LL + << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); ReplSetRequestVotesResponse response2; @@ -2666,9 +2487,7 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVotesToTwoDifferentNodesInTheSameTerm) { TEST_F(TopoCoordTest, DryRunVoteRequestShouldNotPreventSubsequentDryRunsForThatTerm) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -2682,14 +2501,8 @@ TEST_F(TopoCoordTest, DryRunVoteRequestShouldNotPreventSubsequentDryRunsForThatT ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" - << true - << "term" - << 1LL - << "candidateIndex" - << 0LL - << "configVersion" - << 1LL + << "dryRun" << true << "term" << 1LL + << "candidateIndex" << 0LL << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); @@ -2704,14 +2517,8 @@ TEST_F(TopoCoordTest, DryRunVoteRequestShouldNotPreventSubsequentDryRunsForThatT args2 .initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" - << true - << "term" - << 1LL - << "candidateIndex" - << 0LL - << "configVersion" - << 1LL + << "dryRun" << true << "term" << 1LL + << "candidateIndex" << 0LL << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); @@ -2726,14 +2533,8 @@ TEST_F(TopoCoordTest, DryRunVoteRequestShouldNotPreventSubsequentDryRunsForThatT args3 .initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" - << false - << "term" - << 1LL - << "candidateIndex" - << 0LL - << "configVersion" - << 1LL + << "dryRun" << false << "term" << 1LL + << "candidateIndex" << 0LL << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); @@ -2748,14 +2549,8 @@ TEST_F(TopoCoordTest, DryRunVoteRequestShouldNotPreventSubsequentDryRunsForThatT args4 .initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" - << false - << "term" - << 1LL - << "candidateIndex" - << 0LL - << "configVersion" - << 1LL + << "dryRun" << false << "term" << 1LL + << "candidateIndex" << 0LL << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); @@ -2770,9 +2565,7 @@ TEST_F(TopoCoordTest, DryRunVoteRequestShouldNotPreventSubsequentDryRunsForThatT TEST_F(TopoCoordTest, VoteRequestShouldNotPreventDryRunsForThatTerm) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -2786,14 +2579,8 @@ TEST_F(TopoCoordTest, VoteRequestShouldNotPreventDryRunsForThatTerm) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" - << false - << "term" - << 1LL - << "candidateIndex" - << 0LL - << "configVersion" - << 1LL + << "dryRun" << false << "term" << 1LL + << "candidateIndex" << 0LL << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); @@ -2808,14 +2595,8 @@ TEST_F(TopoCoordTest, VoteRequestShouldNotPreventDryRunsForThatTerm) { args2 .initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" - << false - << "term" - << 1LL - << "candidateIndex" - << 0LL - << "configVersion" - << 1LL + << "dryRun" << false << "term" << 1LL + << "candidateIndex" << 0LL << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); @@ -2830,9 +2611,7 @@ TEST_F(TopoCoordTest, VoteRequestShouldNotPreventDryRunsForThatTerm) { TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenReplSetNameDoesNotMatch) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -2846,13 +2625,8 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenReplSetNameDoesNotMatch) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "wrongName" - << "term" - << 1LL - << "candidateIndex" - << 0LL - << "configVersion" - << 1LL - << "lastCommittedOp" + << "term" << 1LL << "candidateIndex" << 0LL + << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); ReplSetRequestVotesResponse response; @@ -2865,9 +2639,7 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenReplSetNameDoesNotMatch) { TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenConfigVersionDoesNotMatch) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -2881,13 +2653,8 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenConfigVersionDoesNotMatch) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "term" - << 1LL - << "candidateIndex" - << 1LL - << "configVersion" - << 0LL - << "lastCommittedOp" + << "term" << 1LL << "candidateIndex" << 1LL + << "configVersion" << 0LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); ReplSetRequestVotesResponse response; @@ -2900,9 +2667,7 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenConfigVersionDoesNotMatch) { TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenTermIsStale) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -2920,13 +2685,8 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenTermIsStale) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "term" - << 1LL - << "candidateIndex" - << 1LL - << "configVersion" - << 1LL - << "lastCommittedOp" + << "term" << 1LL << "candidateIndex" << 1LL + << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); ReplSetRequestVotesResponse response; @@ -2940,9 +2700,7 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenTermIsStale) { TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenOpTimeIsStale) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -2957,13 +2715,8 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenOpTimeIsStale) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "term" - << 3LL - << "candidateIndex" - << 1LL - << "configVersion" - << 1LL - << "lastCommittedOp" + << "term" << 3LL << "candidateIndex" << 1LL + << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); ReplSetRequestVotesResponse response; @@ -2973,8 +2726,7 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenOpTimeIsStale) { ASSERT_EQUALS( str::stream() << "candidate's data is staler than mine. candidate's last applied OpTime: " << OpTime().toString() - << ", my last applied OpTime: " - << OpTime(Timestamp(20, 0), 0).toString(), + << ", my last applied OpTime: " << OpTime(Timestamp(20, 0), 0).toString(), response.getReason()); ASSERT_FALSE(response.getVoteGranted()); } @@ -2982,9 +2734,7 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantVoteWhenOpTimeIsStale) { TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenReplSetNameDoesNotMatch) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -3001,13 +2751,8 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenReplSetNameDoesNotMatch) { argsForRealVote .initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "term" - << 1LL - << "candidateIndex" - << 0LL - << "configVersion" - << 1LL - << "lastCommittedOp" + << "term" << 1LL << "candidateIndex" << 0LL + << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); ReplSetRequestVotesResponse responseForRealVote; @@ -3021,14 +2766,8 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenReplSetNameDoesNotMatch) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "wrongName" - << "dryRun" - << true - << "term" - << 2LL - << "candidateIndex" - << 0LL - << "configVersion" - << 1LL + << "dryRun" << true << "term" << 2LL + << "candidateIndex" << 0LL << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); @@ -3043,9 +2782,7 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenReplSetNameDoesNotMatch) { TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenConfigVersionDoesNotMatch) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -3062,13 +2799,8 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenConfigVersionDoesNotMatch) { argsForRealVote .initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "term" - << 1LL - << "candidateIndex" - << 0LL - << "configVersion" - << 1LL - << "lastCommittedOp" + << "term" << 1LL << "candidateIndex" << 0LL + << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); ReplSetRequestVotesResponse responseForRealVote; @@ -3082,14 +2814,8 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenConfigVersionDoesNotMatch) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" - << true - << "term" - << 2LL - << "candidateIndex" - << 1LL - << "configVersion" - << 0LL + << "dryRun" << true << "term" << 2LL + << "candidateIndex" << 1LL << "configVersion" << 0LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); @@ -3104,9 +2830,7 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenConfigVersionDoesNotMatch) { TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenTermIsStale) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -3123,13 +2847,8 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenTermIsStale) { argsForRealVote .initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "term" - << 1LL - << "candidateIndex" - << 0LL - << "configVersion" - << 1LL - << "lastCommittedOp" + << "term" << 1LL << "candidateIndex" << 0LL + << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); ReplSetRequestVotesResponse responseForRealVote; @@ -3142,14 +2861,8 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenTermIsStale) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" - << true - << "term" - << 0LL - << "candidateIndex" - << 1LL - << "configVersion" - << 1LL + << "dryRun" << true << "term" << 0LL + << "candidateIndex" << 1LL << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); @@ -3164,9 +2877,7 @@ TEST_F(TopoCoordTest, NodeDoesNotGrantDryRunVoteWhenTermIsStale) { TEST_F(TopoCoordTest, GrantDryRunVoteEvenWhenTermHasBeenSeen) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -3183,13 +2894,8 @@ TEST_F(TopoCoordTest, GrantDryRunVoteEvenWhenTermHasBeenSeen) { argsForRealVote .initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "term" - << 1LL - << "candidateIndex" - << 0LL - << "configVersion" - << 1LL - << "lastCommittedOp" + << "term" << 1LL << "candidateIndex" << 0LL + << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); ReplSetRequestVotesResponse responseForRealVote; @@ -3203,14 +2909,8 @@ TEST_F(TopoCoordTest, GrantDryRunVoteEvenWhenTermHasBeenSeen) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" - << true - << "term" - << 1LL - << "candidateIndex" - << 1LL - << "configVersion" - << 1LL + << "dryRun" << true << "term" << 1LL + << "candidateIndex" << 1LL << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); @@ -3225,9 +2925,7 @@ TEST_F(TopoCoordTest, GrantDryRunVoteEvenWhenTermHasBeenSeen) { TEST_F(TopoCoordTest, DoNotGrantDryRunVoteWhenOpTimeIsStale) { updateConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "members" + << "version" << 1 << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") << BSON("_id" << 20 << "host" @@ -3244,13 +2942,8 @@ TEST_F(TopoCoordTest, DoNotGrantDryRunVoteWhenOpTimeIsStale) { argsForRealVote .initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "term" - << 1LL - << "candidateIndex" - << 0LL - << "configVersion" - << 1LL - << "lastCommittedOp" + << "term" << 1LL << "candidateIndex" << 0LL + << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); ReplSetRequestVotesResponse responseForRealVote; @@ -3264,14 +2957,8 @@ TEST_F(TopoCoordTest, DoNotGrantDryRunVoteWhenOpTimeIsStale) { ReplSetRequestVotesArgs args; args.initialize(BSON("replSetRequestVotes" << 1 << "setName" << "rs0" - << "dryRun" - << true - << "term" - << 3LL - << "candidateIndex" - << 1LL - << "configVersion" - << 1LL + << "dryRun" << true << "term" << 3LL + << "candidateIndex" << 1LL << "configVersion" << 1LL << "lastCommittedOp" << BSON("ts" << Timestamp(10, 0) << "term" << 0LL))) .transitional_ignore(); @@ -3282,8 +2969,7 @@ TEST_F(TopoCoordTest, DoNotGrantDryRunVoteWhenOpTimeIsStale) { ASSERT_EQUALS( str::stream() << "candidate's data is staler than mine. candidate's last applied OpTime: " << OpTime().toString() - << ", my last applied OpTime: " - << OpTime(Timestamp(20, 0), 0).toString(), + << ", my last applied OpTime: " << OpTime(Timestamp(20, 0), 0).toString(), response.getReason()); ASSERT_EQUALS(1, response.getTerm()); ASSERT_FALSE(response.getVoteGranted()); @@ -3299,12 +2985,7 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedIfCSRSButHaveNoReadCommittedSuppor updateConfig(BSON("_id" << "rs0" - << "protocolVersion" - << 1 - << "version" - << 1 - << "configsvr" - << true + << "protocolVersion" << 1 << "version" << 1 << "configsvr" << true << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") @@ -3326,12 +3007,7 @@ TEST_F(TopoCoordTest, NodeBecomesSecondaryAsNormalWhenReadCommittedSupportedAndC updateConfig(BSON("_id" << "rs0" - << "protocolVersion" - << 1 - << "version" - << 1 - << "configsvr" - << true + << "protocolVersion" << 1 << "version" << 1 << "configsvr" << true << "members" << BSON_ARRAY(BSON("_id" << 10 << "host" << "hself") @@ -3352,18 +3028,14 @@ public: TopoCoordTest::setUp(); updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); } @@ -3381,23 +3053,15 @@ TEST_F(HeartbeatResponseTestV1, updateConfig(BSON("_id" << "rs0" - << "version" - << 7 - << "members" + << "version" << 7 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself" - << "buildIndexes" - << false - << "priority" - << 0) + << "buildIndexes" << false << "priority" << 0) << BSON("_id" << 1 << "host" << "host2") << BSON("_id" << 2 << "host" << "host3" - << "buildIndexes" - << false - << "priority" - << 0))), + << "buildIndexes" << false << "priority" << 0))), 0); topoCoordSetMyLastAppliedOpTime(lastOpTimeApplied, Date_t(), false); HeartbeatResponseAction nextAction = receiveUpHeartbeat( @@ -3733,15 +3397,12 @@ TEST_F(HeartbeatResponseTestV1, ReconfigNodeRemovedBetweenHeartbeatRequestAndRep updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), 0); ReplSetHeartbeatResponse hb; @@ -3783,28 +3444,19 @@ TEST_F(HeartbeatResponseTestV1, ReconfigBetweenHeartbeatRequestAndRepsonse) { updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), 0); ReplSetHeartbeatResponse hb; hb.initialize(BSON("ok" << 1 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() - << "durableWallTime" - << Date_t() + Seconds(100) - << "opTime" - << OpTime(Timestamp(100, 0), 0).toBSON() - << "wallTime" - << Date_t() + Seconds(100) - << "v" - << 1 - << "state" + << "durableWallTime" << Date_t() + Seconds(100) << "opTime" + << OpTime(Timestamp(100, 0), 0).toBSON() << "wallTime" + << Date_t() + Seconds(100) << "v" << 1 << "state" << MemberState::RS_PRIMARY), 0, /*requireWallTime*/ true) @@ -3863,20 +3515,15 @@ TEST_F(HeartbeatResponseTestV1, ScheduleAPriorityTakeoverWhenElectableAndReceiveHeartbeatFromLowerPriorityPrimary) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017" - << "priority" - << 2) + << "priority" << 2) << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 6 << "host" << "host7:27017")) - << "protocolVersion" - << 1 - << "settings" + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); @@ -3897,21 +3544,16 @@ TEST_F(HeartbeatResponseTestV1, TEST_F(HeartbeatResponseTestV1, UpdateHeartbeatDataTermPreventsPriorityTakeover) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0:27017" - << "priority" - << 2) + << "priority" << 2) << BSON("_id" << 1 << "host" << "host1:27017" - << "priority" - << 3) + << "priority" << 3) << BSON("_id" << 2 << "host" << "host2:27017")) - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -3952,18 +3594,14 @@ TEST_F(HeartbeatResponseTestV1, UpdateHeartbeatDataTermPreventsPriorityTakeover) TEST_F(TopoCoordTest, FreshestNodeDoesCatchupTakeover) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "host1:27017") << BSON("_id" << 2 << "host" << "host2:27017") << BSON("_id" << 3 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); @@ -4009,18 +3647,14 @@ TEST_F(TopoCoordTest, FreshestNodeDoesCatchupTakeover) { TEST_F(TopoCoordTest, StaleNodeDoesntDoCatchupTakeover) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "host1:27017") << BSON("_id" << 2 << "host" << "host2:27017") << BSON("_id" << 3 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); @@ -4068,18 +3702,14 @@ TEST_F(TopoCoordTest, StaleNodeDoesntDoCatchupTakeover) { TEST_F(TopoCoordTest, NodeDoesntDoCatchupTakeoverHeartbeatSaysPrimaryCaughtUp) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "host1:27017") << BSON("_id" << 2 << "host" << "host2:27017") << BSON("_id" << 3 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); @@ -4124,18 +3754,14 @@ TEST_F(TopoCoordTest, NodeDoesntDoCatchupTakeoverHeartbeatSaysPrimaryCaughtUp) { TEST_F(TopoCoordTest, NodeDoesntDoCatchupTakeoverIfTermNumbersSayPrimaryCaughtUp) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "host1:27017") << BSON("_id" << 2 << "host" << "host2:27017") << BSON("_id" << 3 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); @@ -4185,19 +3811,14 @@ TEST_F(TopoCoordTest, NodeDoesntDoCatchupTakeoverIfTermNumbersSayPrimaryCaughtUp TEST_F(TopoCoordTest, StepDownAttemptFailsWhenNotPrimary) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); const auto term = getTopoCoord().getTerm(); Date_t curTime = now(); @@ -4214,19 +3835,14 @@ TEST_F(TopoCoordTest, StepDownAttemptFailsWhenNotPrimary) { TEST_F(TopoCoordTest, StepDownAttemptFailsWhenAlreadySteppingDown) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); const auto term = getTopoCoord().getTerm(); Date_t curTime = now(); @@ -4244,19 +3860,14 @@ TEST_F(TopoCoordTest, StepDownAttemptFailsWhenAlreadySteppingDown) { TEST_F(TopoCoordTest, StepDownAttemptFailsForDifferentTerm) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); const auto term = getTopoCoord().getTerm(); Date_t curTime = now(); @@ -4274,19 +3885,14 @@ TEST_F(TopoCoordTest, StepDownAttemptFailsForDifferentTerm) { TEST_F(TopoCoordTest, StepDownAttemptFailsIfPastStepDownUntil) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); const auto term = getTopoCoord().getTerm(); Date_t curTime = now(); @@ -4306,19 +3912,14 @@ TEST_F(TopoCoordTest, StepDownAttemptFailsIfPastStepDownUntil) { TEST_F(TopoCoordTest, StepDownAttemptFailsIfPastWaitUntil) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); const auto term = getTopoCoord().getTerm(); Date_t curTime = now(); @@ -4341,19 +3942,14 @@ TEST_F(TopoCoordTest, StepDownAttemptFailsIfPastWaitUntil) { TEST_F(TopoCoordTest, StepDownAttemptFailsIfNoSecondariesCaughtUp) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); const auto term = getTopoCoord().getTerm(); Date_t curTime = now(); @@ -4374,19 +3970,14 @@ TEST_F(TopoCoordTest, StepDownAttemptFailsIfNoSecondariesCaughtUp) { TEST_F(TopoCoordTest, StepDownAttemptFailsIfNoSecondariesCaughtUpForceIsTrueButNotPastWaitUntil) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); const auto term = getTopoCoord().getTerm(); Date_t curTime = now(); @@ -4407,19 +3998,14 @@ TEST_F(TopoCoordTest, StepDownAttemptFailsIfNoSecondariesCaughtUpForceIsTrueButN TEST_F(TopoCoordTest, StepDownAttemptSucceedsIfNoSecondariesCaughtUpForceIsTrueAndPastWaitUntil) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); const auto term = getTopoCoord().getTerm(); Date_t curTime = now(); @@ -4440,19 +4026,14 @@ TEST_F(TopoCoordTest, StepDownAttemptSucceedsIfNoSecondariesCaughtUpForceIsTrueA TEST_F(TopoCoordTest, StepDownAttemptSucceedsIfSecondariesCaughtUp) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); const auto term = getTopoCoord().getTerm(); Date_t curTime = now(); @@ -4473,23 +4054,15 @@ TEST_F(TopoCoordTest, StepDownAttemptSucceedsIfSecondariesCaughtUp) { TEST_F(TopoCoordTest, StepDownAttemptFailsIfSecondaryCaughtUpButNotElectable) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017" - << "priority" - << 0 - << "hidden" - << true) + << "priority" << 0 << "hidden" << true) << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); const auto term = getTopoCoord().getTerm(); Date_t curTime = now(); @@ -4519,15 +4092,12 @@ TEST_F(TopoCoordTest, ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0:27017") << BSON("_id" << 1 << "host" << "host1:27017")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), 0); { BSONObjBuilder statusBuilder; @@ -4576,15 +4146,12 @@ TEST_F(TopoCoordTest, ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0:27017") << BSON("_id" << 1 << "host" << "host1:27017")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), 0); ASSERT(getTopoCoord().getSyncSourceAddress().empty()); @@ -4649,10 +4216,7 @@ TEST_F(TopoCoordTest, replSetGetStatusForThreeMemberedReplicaSet) { ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "settings" - << BSON("chainingAllowed" << false) + << "version" << 5 << "settings" << BSON("chainingAllowed" << false) << "members" << BSON_ARRAY(BSON("_id" << 30 << "host" << "hself:27017") @@ -4660,8 +4224,7 @@ TEST_F(TopoCoordTest, replSetGetStatusForThreeMemberedReplicaSet) { << "hprimary:27017") << BSON("_id" << 10 << "host" << "h1:27017")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), 0); ASSERT(getTopoCoord().getSyncSourceAddress().empty()); @@ -4752,13 +4315,10 @@ TEST_F(TopoCoordTest, StatusResponseAlwaysIncludesStringStatusFieldsForNonMember ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0:27017")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), -1); // This node is no longer part of this replica set. BSONObjBuilder statusBuilder; @@ -4788,9 +4348,7 @@ TEST_F(TopoCoordTest, StatusResponseAlwaysIncludesStringStatusFieldsForNonMember TEST_F(TopoCoordTest, NoElectionHandoffCandidateInSingleNodeReplicaSet) { updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0:27017"))), 0); @@ -4805,9 +4363,7 @@ TEST_F(TopoCoordTest, NoElectionHandoffCandidateInSingleNodeReplicaSet) { TEST_F(TopoCoordTest, NoElectionHandoffCandidateWithOneLaggedNode) { updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0:27017") << BSON("_id" << 1 << "host" @@ -4828,15 +4384,12 @@ TEST_F(TopoCoordTest, NoElectionHandoffCandidateWithOneLaggedNode) { TEST_F(TopoCoordTest, NoElectionHandoffCandidateWithOneUnelectableNode) { updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0:27017") << BSON("_id" << 1 << "host" << "host1:27017" - << "priority" - << 0))), + << "priority" << 0))), 0); const auto term = getTopoCoord().getTerm(); @@ -4853,17 +4406,14 @@ TEST_F(TopoCoordTest, NoElectionHandoffCandidateWithOneUnelectableNode) { TEST_F(TopoCoordTest, NoElectionHandoffCandidateWithOneLaggedAndOneUnelectableNode) { updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0:27017") << BSON("_id" << 1 << "host" << "host1:27017") << BSON("_id" << 2 << "host" << "host2:27017" - << "priority" - << 0))), + << "priority" << 0))), 0); const auto term = getTopoCoord().getTerm(); @@ -4883,9 +4433,7 @@ TEST_F(TopoCoordTest, NoElectionHandoffCandidateWithOneLaggedAndOneUnelectableNo TEST_F(TopoCoordTest, ExactlyOneNodeEligibleForElectionHandoffOutOfOneSecondary) { updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0:27017") << BSON("_id" << 1 << "host" @@ -4906,15 +4454,12 @@ TEST_F(TopoCoordTest, ExactlyOneNodeEligibleForElectionHandoffOutOfOneSecondary) TEST_F(TopoCoordTest, ExactlyOneNodeEligibleForElectionHandoffOutOfThreeSecondaries) { updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0:27017") << BSON("_id" << 1 << "host" << "host1:27017" - << "priority" - << 0) + << "priority" << 0) << BSON("_id" << 2 << "host" << "host2:27017") << BSON("_id" << 3 << "host" @@ -4943,17 +4488,14 @@ TEST_F(TopoCoordTest, ExactlyOneNodeEligibleForElectionHandoffOutOfThreeSecondar TEST_F(TopoCoordTest, TwoNodesEligibleForElectionHandoffResolveByPriority) { updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0:27017") << BSON("_id" << 1 << "host" << "host1:27017") << BSON("_id" << 2 << "host" << "host2:27017" - << "priority" - << 5))), + << "priority" << 5))), 0); const auto term = getTopoCoord().getTerm(); @@ -4975,9 +4517,7 @@ TEST_F(TopoCoordTest, TwoNodesEligibleForElectionHandoffResolveByPriority) { TEST_F(TopoCoordTest, TwoNodesEligibleForElectionHandoffEqualPriorityResolveByMemberId) { updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0:27017") << BSON("_id" << 1 << "host" @@ -5006,23 +4546,17 @@ TEST_F(TopoCoordTest, ArbiterNotIncludedInW3WriteInPSSAReplSet) { // In a PSSA set, a w:3 write should only be acknowledged if both secondaries can satisfy it. updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0:27017") << BSON("_id" << 1 << "host" << "host1:27017") << BSON("_id" << 2 << "host" << "host2:27017" - << "priority" - << 0 - << "votes" - << 0) + << "priority" << 0 << "votes" << 0) << BSON("_id" << 3 << "host" << "host3:27017" - << "arbiterOnly" - << true))), + << "arbiterOnly" << true))), 0); const auto term = getTopoCoord().getTerm(); @@ -5051,31 +4585,21 @@ TEST_F(TopoCoordTest, ArbitersNotIncludedInW2WriteInPSSAAReplSet) { // can satisfy it. updateConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "members" + << "version" << 2 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0:27017") << BSON("_id" << 1 << "host" << "host1:27017" - << "priority" - << 0 - << "votes" - << 0) + << "priority" << 0 << "votes" << 0) << BSON("_id" << 2 << "host" << "host2:27017" - << "priority" - << 0 - << "votes" - << 0) + << "priority" << 0 << "votes" << 0) << BSON("_id" << 3 << "host" << "host3:27017" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 4 << "host" << "host4:27017" - << "arbiterOnly" - << true))), + << "arbiterOnly" << true))), 0); const auto term = getTopoCoord().getTerm(); @@ -5100,59 +4624,52 @@ TEST_F(TopoCoordTest, ArbitersNotIncludedInW2WriteInPSSAAReplSet) { TEST_F(TopoCoordTest, CheckIfCommitQuorumCanBeSatisfied) { ReplSetConfig configA; - ASSERT_OK(configA.initialize(BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "node0" - << "tags" - << BSON("dc" - << "NA" - << "rack" - << "rackNA1")) - << BSON("_id" << 1 << "host" - << "node1" - << "tags" - << BSON("dc" - << "NA" - << "rack" - << "rackNA2")) - << BSON("_id" << 2 << "host" - << "node2" - << "tags" - << BSON("dc" - << "NA" - << "rack" - << "rackNA3")) - << BSON("_id" << 3 << "host" - << "node3" - << "tags" - << BSON("dc" - << "EU" - << "rack" - << "rackEU1")) - << BSON("_id" << 4 << "host" - << "node4" - << "tags" - << BSON("dc" - << "EU" - << "rack" - << "rackEU2")) - << BSON("_id" << 5 << "host" - << "node5" - << "arbiterOnly" - << true)) - << "settings" - << BSON("getLastErrorModes" - << BSON("valid" << BSON("dc" << 2 << "rack" << 3) - << "invalidNotEnoughValues" - << BSON("dc" << 3) - << "invalidNotEnoughNodes" - << BSON("rack" << 6)))))); + ASSERT_OK(configA.initialize(BSON( + "_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "node0" + << "tags" + << BSON("dc" + << "NA" + << "rack" + << "rackNA1")) + << BSON("_id" << 1 << "host" + << "node1" + << "tags" + << BSON("dc" + << "NA" + << "rack" + << "rackNA2")) + << BSON("_id" << 2 << "host" + << "node2" + << "tags" + << BSON("dc" + << "NA" + << "rack" + << "rackNA3")) + << BSON("_id" << 3 << "host" + << "node3" + << "tags" + << BSON("dc" + << "EU" + << "rack" + << "rackEU1")) + << BSON("_id" << 4 << "host" + << "node4" + << "tags" + << BSON("dc" + << "EU" + << "rack" + << "rackEU2")) + << BSON("_id" << 5 << "host" + << "node5" + << "arbiterOnly" << true)) + << "settings" + << BSON("getLastErrorModes" << BSON( + "valid" << BSON("dc" << 2 << "rack" << 3) << "invalidNotEnoughValues" + << BSON("dc" << 3) << "invalidNotEnoughNodes" << BSON("rack" << 6)))))); getTopoCoord().updateConfig(configA, -1, Date_t()); std::vector<MemberConfig> memberConfig; @@ -5323,18 +4840,14 @@ TEST_F(HeartbeatResponseTestV1, ScheduleACatchupTakeoverWhenElectableAndReceiveHeartbeatFromPrimaryInCatchup) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 6 << "host" << "host7:27017")) - << "protocolVersion" - << 1 - << "settings" + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); @@ -5357,22 +4870,16 @@ TEST_F(HeartbeatResponseTestV1, ScheduleACatchupTakeoverWhenBothCatchupAndPriorityTakeoverPossible) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0:27017" - << "priority" - << 2) + << "priority" << 2) << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 6 << "host" << "host7:27017" - << "priority" - << 3)) - << "protocolVersion" - << 1 - << "settings" + << "priority" << 3)) + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); @@ -5395,43 +4902,26 @@ TEST_F(HeartbeatResponseTestV1, ScheduleElectionIfAMajorityOfVotersIsVisibleEvenThoughATrueMajorityIsNot) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017" - << "votes" - << 0 - << "priority" - << 0) + << "votes" << 0 << "priority" << 0) << BSON("_id" << 3 << "host" << "host4:27017" - << "votes" - << 0 - << "priority" - << 0) + << "votes" << 0 << "priority" << 0) << BSON("_id" << 4 << "host" << "host5:27017" - << "votes" - << 0 - << "priority" - << 0) + << "votes" << 0 << "priority" << 0) << BSON("_id" << 5 << "host" << "host6:27017" - << "votes" - << 0 - << "priority" - << 0) + << "votes" << 0 << "priority" << 0) << BSON("_id" << 6 << "host" << "host7:27017")) - << "protocolVersion" - << 1 - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -5500,19 +4990,15 @@ TEST_F(HeartbeatResponseTestV1, NodeDoesNotStandForElectionWhenPrimaryIsMarkedDownViaHeartbeatButWeAreAnArbiter) { updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017" - << "arbiterOnly" - << true) + << "arbiterOnly" << true) << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), 0); OpTime election = OpTime(Timestamp(400, 0), 0); @@ -5613,19 +5099,15 @@ TEST_F(HeartbeatResponseTestV1, updateConfig(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017" - << "priority" - << 0) + << "priority" << 0) << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" - << 1), + << "protocolVersion" << 1), 0); OpTime election = OpTime(Timestamp(400, 0), 0); @@ -5700,21 +5182,15 @@ TEST_F(HeartbeatResponseTestV1, // multiprimary states in PV1. updateConfig(BSON("_id" << "rs0" - << "version" - << 6 - << "members" + << "version" << 6 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017" - << "priority" - << 3)) - << "protocolVersion" - << 1 - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "priority" << 3)) + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -5739,21 +5215,15 @@ TEST_F(HeartbeatResponseTestV1, // multiprimary states in PV1. updateConfig(BSON("_id" << "rs0" - << "version" - << 6 - << "members" + << "version" << 6 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017" - << "priority" - << 3)) - << "protocolVersion" - << 1 - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "priority" << 3)) + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); OpTime election = OpTime(Timestamp(1000, 0), 0); OpTime staleTime = OpTime(); @@ -5775,21 +5245,15 @@ TEST_F(HeartbeatResponseTestV1, // multiprimary states in PV1. updateConfig(BSON("_id" << "rs0" - << "version" - << 6 - << "members" + << "version" << 6 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017" - << "priority" - << 3)) - << "protocolVersion" - << 1 - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "priority" << 3)) + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); OpTime election = OpTime(Timestamp(1000, 0), 0); @@ -5812,21 +5276,15 @@ TEST_F(HeartbeatResponseTestV1, // in all multiprimary states in PV1. updateConfig(BSON("_id" << "rs0" - << "version" - << 6 - << "members" + << "version" << 6 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017" - << "priority" - << 3)) - << "protocolVersion" - << 1 - << "settings" - << BSON("heartbeatTimeoutSecs" << 5)), + << "priority" << 3)) + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); setSelfMemberState(MemberState::RS_SECONDARY); @@ -5983,21 +5441,15 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenFresherMemberDoesNo updateConfig(BSON("_id" << "rs0" - << "version" - << 6 - << "members" + << "version" << 6 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "hself") << BSON("_id" << 1 << "host" << "host2") << BSON("_id" << 2 << "host" << "host3" - << "buildIndexes" - << false - << "priority" - << 0)) - << "protocolVersion" - << 1), + << "buildIndexes" << false << "priority" << 0)) + << "protocolVersion" << 1), 0); topoCoordSetMyLastAppliedOpTime(lastOpTimeApplied, Date_t(), false); HeartbeatResponseAction nextAction = receiveUpHeartbeat( @@ -6311,18 +5763,14 @@ TEST_F(HeartbeatResponseHighVerbosityTestV1, UpdateHeartbeatDataSameConfig) { originalConfig .initialize(BSON("_id" << "rs0" - << "version" - << 5 - << "members" + << "version" << 5 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017") << BSON("_id" << 1 << "host" << "host2:27017") << BSON("_id" << 2 << "host" << "host3:27017")) - << "protocolVersion" - << 1 - << "settings" + << "protocolVersion" << 1 << "settings" << BSON("heartbeatTimeoutSecs" << 5))) .transitional_ignore(); diff --git a/src/mongo/db/repl/vote_requester_test.cpp b/src/mongo/db/repl/vote_requester_test.cpp index ca0bc29844e..7d2dc73cf8c 100644 --- a/src/mongo/db/repl/vote_requester_test.cpp +++ b/src/mongo/db/repl/vote_requester_test.cpp @@ -59,31 +59,23 @@ class VoteRequesterTest : public mongo::unittest::Test { public: virtual void setUp() { ReplSetConfig config; - ASSERT_OK(config.initialize(BSON("_id" - << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host0") - << BSON("_id" << 1 << "host" - << "host1") - << BSON("_id" << 2 << "host" - << "host2") - << BSON("_id" << 3 << "host" - << "host3" - << "votes" - << 0 - << "priority" - << 0) - << BSON("_id" << 4 << "host" - << "host4" - << "votes" - << 0 - << "priority" - << 0))))); + ASSERT_OK( + config.initialize(BSON("_id" + << "rs0" + << "version" << 2 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host0") + << BSON("_id" << 1 << "host" + << "host1") + << BSON("_id" << 2 << "host" + << "host2") + << BSON("_id" << 3 << "host" + << "host3" + << "votes" << 0 << "priority" << 0) + << BSON("_id" << 4 << "host" + << "host4" + << "votes" << 0 << "priority" + << 0))))); ASSERT_OK(config.validate()); long long candidateId = 0; long long term = 2; @@ -216,31 +208,23 @@ class VoteRequesterDryRunTest : public VoteRequesterTest { public: virtual void setUp() { ReplSetConfig config; - ASSERT_OK(config.initialize(BSON("_id" - << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 0 << "host" - << "host0") - << BSON("_id" << 1 << "host" - << "host1") - << BSON("_id" << 2 << "host" - << "host2") - << BSON("_id" << 3 << "host" - << "host3" - << "votes" - << 0 - << "priority" - << 0) - << BSON("_id" << 4 << "host" - << "host4" - << "votes" - << 0 - << "priority" - << 0))))); + ASSERT_OK( + config.initialize(BSON("_id" + << "rs0" + << "version" << 2 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host0") + << BSON("_id" << 1 << "host" + << "host1") + << BSON("_id" << 2 << "host" + << "host2") + << BSON("_id" << 3 << "host" + << "host3" + << "votes" << 0 << "priority" << 0) + << BSON("_id" << 4 << "host" + << "host4" + << "votes" << 0 << "priority" + << 0))))); ASSERT_OK(config.validate()); long long candidateId = 0; long long term = 2; @@ -261,11 +245,7 @@ public: ReplSetConfig config; ASSERT_OK(config.initialize(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 0 << "host" << "host0") << BSON("_id" << 1 << "host" |