summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVesselina Ratcheva <vesselina.ratcheva@10gen.com>2017-12-13 13:27:01 -0500
committerVesselina Ratcheva <vesselina.ratcheva@10gen.com>2017-12-13 13:29:59 -0500
commitfcbce71b912723aac77ab1ec4efec8e15114a86c (patch)
tree3d3db6f4d7f2d3958f5c1246631e8d28e4115321
parent6796859387ba77a3556ed583a317681a288970e4 (diff)
downloadmongo-fcbce71b912723aac77ab1ec4efec8e15114a86c.tar.gz
SERVER-28895 Remove old form of replSetUpdatePosition command
-rw-r--r--src/mongo/db/repl/SConscript1
-rw-r--r--src/mongo/db/repl/old_update_position_args.cpp155
-rw-r--r--src/mongo/db/repl/old_update_position_args.h96
-rw-r--r--src/mongo/db/repl/repl_set_commands.cpp15
-rw-r--r--src/mongo/db/repl/replication_coordinator.h14
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp96
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.h11
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_test.cpp532
-rw-r--r--src/mongo/db/repl/replication_coordinator_mock.cpp9
-rw-r--r--src/mongo/db/repl/replication_coordinator_mock.h5
-rw-r--r--src/mongo/db/repl/reporter.cpp36
-rw-r--r--src/mongo/db/repl/reporter.h7
-rw-r--r--src/mongo/db/repl/reporter_test.cpp120
-rw-r--r--src/mongo/db/repl/sync_source_feedback.cpp5
-rw-r--r--src/mongo/db/repl/topology_coordinator.cpp31
-rw-r--r--src/mongo/db/repl/topology_coordinator.h1
16 files changed, 120 insertions, 1014 deletions
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript
index 92a5ee27814..75d416aef2f 100644
--- a/src/mongo/db/repl/SConscript
+++ b/src/mongo/db/repl/SConscript
@@ -1011,7 +1011,6 @@ env.Library('replica_set_messages',
'handshake_args.cpp',
'is_master_response.cpp',
'member_config.cpp',
- 'old_update_position_args.cpp',
'repl_set_heartbeat_args.cpp',
'repl_set_heartbeat_args_v1.cpp',
'repl_set_heartbeat_response.cpp',
diff --git a/src/mongo/db/repl/old_update_position_args.cpp b/src/mongo/db/repl/old_update_position_args.cpp
deleted file mode 100644
index e3c2f295d26..00000000000
--- a/src/mongo/db/repl/old_update_position_args.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-/**
- * Copyright 2014 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/db/repl/old_update_position_args.h"
-
-#include "mongo/base/status.h"
-#include "mongo/bson/util/bson_check.h"
-#include "mongo/bson/util/bson_extract.h"
-#include "mongo/db/jsobj.h"
-#include "mongo/db/repl/bson_extract_optime.h"
-
-namespace mongo {
-namespace repl {
-
-const char OldUpdatePositionArgs::kCommandFieldName[] = "replSetUpdatePosition";
-const char OldUpdatePositionArgs::kUpdateArrayFieldName[] = "optimes";
-const char OldUpdatePositionArgs::kMemberRIDFieldName[] = "_id";
-const char OldUpdatePositionArgs::kMemberConfigFieldName[] = "config";
-const char OldUpdatePositionArgs::kOpTimeFieldName[] = "optime";
-const char OldUpdatePositionArgs::kMemberIdFieldName[] = "memberId";
-const char OldUpdatePositionArgs::kConfigVersionFieldName[] = "cfgver";
-
-OldUpdatePositionArgs::UpdateInfo::UpdateInfo(const OID& anRid,
- const OpTime& aTs,
- long long aCfgver,
- long long aMemberId)
- : rid(anRid), ts(aTs), cfgver(aCfgver), memberId(aMemberId) {}
-
-namespace {
-
-const std::string kLegalUpdatePositionFieldNames[] = {
- OldUpdatePositionArgs::kCommandFieldName, OldUpdatePositionArgs::kUpdateArrayFieldName,
-};
-
-const std::string kLegalUpdateInfoFieldNames[] = {
- OldUpdatePositionArgs::kMemberConfigFieldName,
- OldUpdatePositionArgs::kMemberRIDFieldName,
- OldUpdatePositionArgs::kOpTimeFieldName,
- OldUpdatePositionArgs::kMemberIdFieldName,
- OldUpdatePositionArgs::kConfigVersionFieldName,
-};
-
-} // namespace
-
-Status OldUpdatePositionArgs::initialize(const BSONObj& argsObj) {
- Status status = bsonCheckOnlyHasFieldsForCommand(
- "OldUpdatePositionArgs", argsObj, kLegalUpdatePositionFieldNames);
-
- if (!status.isOK())
- return status;
-
- // grab the array of changes
- BSONElement updateArray;
- status = bsonExtractTypedField(argsObj, kUpdateArrayFieldName, Array, &updateArray);
- if (!status.isOK())
- return status;
-
- // now parse each array entry into an update
- BSONObjIterator i(updateArray.Obj());
- while (i.more()) {
- BSONObj entry = i.next().Obj();
- status = bsonCheckOnlyHasFields("UpdateInfoArgs", entry, kLegalUpdateInfoFieldNames);
- if (!status.isOK())
- return status;
-
- OpTime opTime;
- if (entry[kOpTimeFieldName].isABSONObj()) {
- // In protocol version 1, { ts: <timestamp>, t: term }
- Status status = bsonExtractOpTimeField(entry, kOpTimeFieldName, &opTime);
- if (!status.isOK())
- return status;
- } else {
- Timestamp ts;
- status = bsonExtractTimestampField(entry, kOpTimeFieldName, &ts);
- if (!status.isOK())
- return status;
- opTime = OpTime(ts, OpTime::kUninitializedTerm);
- }
- if (!status.isOK())
- return status;
-
- // TODO(spencer): The following three fields are optional in 3.0, but should be made
- // required or ignored in 3.0
- long long cfgver;
- status = bsonExtractIntegerFieldWithDefault(entry, kConfigVersionFieldName, -1, &cfgver);
- if (!status.isOK())
- return status;
-
- OID rid;
- status = bsonExtractOIDFieldWithDefault(entry, kMemberRIDFieldName, OID(), &rid);
- if (!status.isOK())
- return status;
-
- long long memberID;
- status = bsonExtractIntegerFieldWithDefault(entry, kMemberIdFieldName, -1, &memberID);
- if (!status.isOK())
- return status;
-
- _updates.push_back(UpdateInfo(rid, opTime, cfgver, memberID));
- }
-
- return Status::OK();
-}
-
-BSONObj OldUpdatePositionArgs::toBSON() const {
- BSONObjBuilder builder;
- // add command name
- builder.append(kCommandFieldName, 1);
-
- // build array of updates
- if (!_updates.empty()) {
- BSONArrayBuilder updateArray(builder.subarrayStart(kUpdateArrayFieldName));
- for (OldUpdatePositionArgs::UpdateIterator update = updatesBegin(); update != updatesEnd();
- ++update) {
- updateArray.append(BSON(kMemberRIDFieldName << update->rid << kOpTimeFieldName
- << update->ts.getTimestamp()
- << kConfigVersionFieldName
- << update->cfgver
- << kMemberIdFieldName
- << update->memberId));
- }
- updateArray.doneFast();
- }
- return builder.obj();
-}
-
-} // namespace repl
-} // namespace mongo
diff --git a/src/mongo/db/repl/old_update_position_args.h b/src/mongo/db/repl/old_update_position_args.h
deleted file mode 100644
index 01a7b52bdc4..00000000000
--- a/src/mongo/db/repl/old_update_position_args.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * Copyright (C) 2014 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-#include <vector>
-
-#include "mongo/db/jsobj.h"
-#include "mongo/db/repl/optime.h"
-
-namespace mongo {
-
-class Status;
-
-namespace repl {
-
-/**
- * Arguments to the handshake command.
- */
-class OldUpdatePositionArgs {
-public:
- static const char kCommandFieldName[];
- static const char kUpdateArrayFieldName[];
- static const char kMemberRIDFieldName[];
- static const char kMemberConfigFieldName[];
- static const char kOpTimeFieldName[];
- static const char kMemberIdFieldName[];
- static const char kConfigVersionFieldName[];
-
- struct UpdateInfo {
- UpdateInfo(const OID& anRid, const OpTime& aTs, long long aCfgver, long long aMemberId);
-
- OID rid;
- OpTime ts;
- long long cfgver;
- long long memberId;
- };
-
- typedef std::vector<UpdateInfo>::const_iterator UpdateIterator;
-
- /**
- * Initializes this OldUpdatePositionArgs from the contents of "argsObj".
- */
- Status initialize(const BSONObj& argsObj);
-
- /**
- * Gets a begin iterator over the UpdateInfos stored in this OldUpdatePositionArgs.
- */
- UpdateIterator updatesBegin() const {
- return _updates.begin();
- }
-
- /**
- * Gets an end iterator over the UpdateInfos stored in this OldUpdatePositionArgs.
- */
- UpdateIterator updatesEnd() const {
- return _updates.end();
- }
-
- /**
- * Returns a BSONified version of the object.
- * _updates is only included if it is not empty.
- */
- BSONObj toBSON() const;
-
-private:
- std::vector<UpdateInfo> _updates;
-};
-
-} // namespace repl
-} // namespace mongo
diff --git a/src/mongo/db/repl/repl_set_commands.cpp b/src/mongo/db/repl/repl_set_commands.cpp
index 5bc28841697..ebee2285b3e 100644
--- a/src/mongo/db/repl/repl_set_commands.cpp
+++ b/src/mongo/db/repl/repl_set_commands.cpp
@@ -49,7 +49,6 @@
#include "mongo/db/lasterror.h"
#include "mongo/db/op_observer.h"
#include "mongo/db/repl/drop_pending_collection_reaper.h"
-#include "mongo/db/repl/old_update_position_args.h"
#include "mongo/db/repl/oplog.h"
#include "mongo/db/repl/repl_set_heartbeat_args.h"
#include "mongo/db/repl/repl_set_heartbeat_args_v1.h"
@@ -657,26 +656,12 @@ public:
status = args.initialize(cmdObj);
if (status.isOK()) {
- // v3.2.4+ style replSetUpdatePosition command.
status = replCoord->processReplSetUpdatePosition(args, &configVersion);
if (status == ErrorCodes::InvalidReplicaSetConfig) {
result.append("configVersion", configVersion);
}
return appendCommandStatus(result, status);
- } else if (status == ErrorCodes::NoSuchKey) {
- // Pre-3.2.4 style replSetUpdatePosition command.
- OldUpdatePositionArgs oldArgs;
- status = oldArgs.initialize(cmdObj);
- if (!status.isOK())
- return appendCommandStatus(result, status);
-
- status = replCoord->processReplSetUpdatePosition(oldArgs, &configVersion);
-
- if (status == ErrorCodes::InvalidReplicaSetConfig) {
- result.append("configVersion", configVersion);
- }
- return appendCommandStatus(result, status);
} else {
// Parsing error from UpdatePositionArgs.
return appendCommandStatus(result, status);
diff --git a/src/mongo/db/repl/replication_coordinator.h b/src/mongo/db/repl/replication_coordinator.h
index bb2d725b6e8..3fa44e8a026 100644
--- a/src/mongo/db/repl/replication_coordinator.h
+++ b/src/mongo/db/repl/replication_coordinator.h
@@ -67,7 +67,6 @@ namespace repl {
class BackgroundSync;
class HandshakeArgs;
class IsMasterResponse;
-class OldUpdatePositionArgs;
class OplogReader;
class OpTime;
class ReadConcernArgs;
@@ -521,17 +520,11 @@ public:
*/
virtual void signalUpstreamUpdater() = 0;
- enum class ReplSetUpdatePositionCommandStyle {
- kNewStyle,
- kOldStyle // Pre-3.2.4 servers.
- };
-
/**
* Prepares a BSONObj describing an invocation of the replSetUpdatePosition command that can
* be sent to this node's sync source to update it about our progress in replication.
*/
- virtual StatusWith<BSONObj> prepareReplSetUpdatePositionCommand(
- ReplSetUpdatePositionCommandStyle commandStyle) const = 0;
+ virtual StatusWith<BSONObj> prepareReplSetUpdatePositionCommand() const = 0;
enum class ReplSetGetStatusResponseStyle { kBasic, kInitialSync };
@@ -700,12 +693,7 @@ public:
* were applied.
* "configVersion" will be populated with our config version if and only if we return
* InvalidReplicaSetConfig.
- *
- * The OldUpdatePositionArgs version provides support for the pre-3.2.4 format of
- * UpdatePositionArgs.
*/
- virtual Status processReplSetUpdatePosition(const OldUpdatePositionArgs& updates,
- long long* configVersion) = 0;
virtual Status processReplSetUpdatePosition(const UpdatePositionArgs& updates,
long long* configVersion) = 0;
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp
index bc178dc9ecf..3dd9826e018 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -52,7 +52,6 @@
#include "mongo/db/repl/is_master_response.h"
#include "mongo/db/repl/last_vote.h"
#include "mongo/db/repl/member_data.h"
-#include "mongo/db/repl/old_update_position_args.h"
#include "mongo/db/repl/read_concern_args.h"
#include "mongo/db/repl/repl_client_info.h"
#include "mongo/db/repl/repl_set_config_checks.h"
@@ -1374,73 +1373,6 @@ Status ReplicationCoordinatorImpl::setLastAppliedOptime_forTest(long long cfgVer
return status;
}
-Status ReplicationCoordinatorImpl::_setLastOptime_inlock(
- const OldUpdatePositionArgs::UpdateInfo& args, long long* configVersion) {
- if (_selfIndex == -1) {
- // Ignore updates when we're in state REMOVED
- return Status(ErrorCodes::NotMasterOrSecondary,
- "Received replSetUpdatePosition command but we are in state REMOVED");
- }
- invariant(getReplicationMode() == modeReplSet);
-
- if (args.memberId < 0) {
- std::string errmsg = str::stream()
- << "Received replSetUpdatePosition for node with memberId " << args.memberId
- << " which is negative and therefore invalid";
- LOG(1) << errmsg;
- return Status(ErrorCodes::NodeNotFound, errmsg);
- }
-
- if (args.memberId == _rsConfig.getMemberAt(_selfIndex).getId()) {
- // Do not let remote nodes tell us what our optime is.
- return Status::OK();
- }
-
- LOG(2) << "received notification that node with memberID " << args.memberId
- << " in config with version " << args.cfgver
- << " has durably reached optime: " << args.ts;
-
- if (args.cfgver != _rsConfig.getConfigVersion()) {
- std::string errmsg = str::stream()
- << "Received replSetUpdatePosition for node with memberId " << args.memberId
- << " whose config version of " << args.cfgver << " doesn't match our config version of "
- << _rsConfig.getConfigVersion();
- LOG(1) << errmsg;
- *configVersion = _rsConfig.getConfigVersion();
- return Status(ErrorCodes::InvalidReplicaSetConfig, errmsg);
- }
-
- auto* memberData = _topCoord->findMemberDataByMemberId(args.memberId);
- if (!memberData) {
- invariant(!_rsConfig.findMemberByID(args.memberId));
-
- std::string errmsg = str::stream()
- << "Received replSetUpdatePosition for node with memberId " << args.memberId
- << " which doesn't exist in our config";
- LOG(1) << errmsg;
- return Status(ErrorCodes::NodeNotFound, errmsg);
- }
-
- invariant(args.memberId == memberData->getMemberId());
-
- LOG(3) << "Node with memberID " << args.memberId << " has durably applied operations through "
- << memberData->getLastDurableOpTime() << " and has applied operations through "
- << memberData->getLastAppliedOpTime()
- << "; updating to new durable operation with timestamp " << args.ts;
-
- auto now(_replExecutor->now());
- bool advancedOpTime = memberData->advanceLastAppliedOpTime(args.ts, now);
- advancedOpTime = memberData->advanceLastDurableOpTime(args.ts, now) || advancedOpTime;
-
- // Only update committed optime if the remote optimes increased.
- if (advancedOpTime) {
- _updateLastCommittedOpTime_inlock();
- }
-
- _cancelAndRescheduleLivenessUpdate_inlock(args.memberId);
- return Status::OK();
-}
-
Status ReplicationCoordinatorImpl::_setLastOptime_inlock(const UpdatePositionArgs::UpdateInfo& args,
long long* configVersion) {
if (_selfIndex == -1) {
@@ -2060,11 +1992,10 @@ Status ReplicationCoordinatorImpl::resyncData(OperationContext* opCtx, bool wait
return Status::OK();
}
-StatusWith<BSONObj> ReplicationCoordinatorImpl::prepareReplSetUpdatePositionCommand(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle commandStyle) const {
+StatusWith<BSONObj> ReplicationCoordinatorImpl::prepareReplSetUpdatePositionCommand() const {
stdx::lock_guard<stdx::mutex> lock(_mutex);
return _topCoord->prepareReplSetUpdatePositionCommand(
- commandStyle, _getCurrentCommittedSnapshotOpTime_inlock());
+ _getCurrentCommittedSnapshotOpTime_inlock());
}
Status ReplicationCoordinatorImpl::processReplSetGetStatus(
@@ -2981,29 +2912,6 @@ void ReplicationCoordinatorImpl::_wakeReadyWaiters_inlock() {
});
}
-Status ReplicationCoordinatorImpl::processReplSetUpdatePosition(
- const OldUpdatePositionArgs& updates, long long* configVersion) {
- stdx::unique_lock<stdx::mutex> lock(_mutex);
- Status status = Status::OK();
- bool somethingChanged = false;
- for (OldUpdatePositionArgs::UpdateIterator update = updates.updatesBegin();
- update != updates.updatesEnd();
- ++update) {
- status = _setLastOptime_inlock(*update, configVersion);
- if (!status.isOK()) {
- break;
- }
- somethingChanged = true;
- }
-
- if (somethingChanged && !_getMemberState_inlock().primary()) {
- lock.unlock();
- // Must do this outside _mutex
- _externalState->forwardSlaveProgress();
- }
- return status;
-}
-
Status ReplicationCoordinatorImpl::processReplSetUpdatePosition(const UpdatePositionArgs& updates,
long long* configVersion) {
stdx::unique_lock<stdx::mutex> lock(_mutex);
diff --git a/src/mongo/db/repl/replication_coordinator_impl.h b/src/mongo/db/repl/replication_coordinator_impl.h
index 1e97a82db0f..ab3873868e6 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.h
+++ b/src/mongo/db/repl/replication_coordinator_impl.h
@@ -37,7 +37,6 @@
#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/repl/initial_syncer.h"
#include "mongo/db/repl/member_state.h"
-#include "mongo/db/repl/old_update_position_args.h"
#include "mongo/db/repl/optime.h"
#include "mongo/db/repl/repl_set_config.h"
#include "mongo/db/repl/replication_coordinator.h"
@@ -192,8 +191,7 @@ public:
virtual Status resyncData(OperationContext* opCtx, bool waitUntilCompleted) override;
- virtual StatusWith<BSONObj> prepareReplSetUpdatePositionCommand(
- ReplSetUpdatePositionCommandStyle commandStyle) const override;
+ virtual StatusWith<BSONObj> prepareReplSetUpdatePositionCommand() const override;
virtual Status processReplSetGetStatus(BSONObjBuilder* result,
ReplSetGetStatusResponseStyle responseStyle) override;
@@ -239,8 +237,6 @@ public:
virtual Status processReplSetElect(const ReplSetElectArgs& args,
BSONObjBuilder* response) override;
- virtual Status processReplSetUpdatePosition(const OldUpdatePositionArgs& updates,
- long long* configVersion) override;
virtual Status processReplSetUpdatePosition(const UpdatePositionArgs& updates,
long long* configVersion) override;
@@ -658,12 +654,7 @@ private:
* This is only valid to call on replica sets.
* "configVersion" will be populated with our config version if it and the configVersion
* of "args" differ.
- *
- * The OldUpdatePositionArgs version provides support for the pre-3.2.4 format of
- * UpdatePositionArgs.
*/
- Status _setLastOptime_inlock(const OldUpdatePositionArgs::UpdateInfo& args,
- long long* configVersion);
Status _setLastOptime_inlock(const UpdatePositionArgs::UpdateInfo& args,
long long* configVersion);
diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
index c8058823ab8..3cf40cda0d4 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
@@ -41,7 +41,6 @@
#include "mongo/db/repl/bson_extract_optime.h"
#include "mongo/db/repl/handshake_args.h"
#include "mongo/db/repl/is_master_response.h"
-#include "mongo/db/repl/old_update_position_args.h"
#include "mongo/db/repl/optime.h"
#include "mongo/db/repl/read_concern_args.h"
#include "mongo/db/repl/repl_client_info.h"
@@ -2270,8 +2269,7 @@ TEST_F(ReplCoordTest, NodeIncludesOtherMembersProgressInUpdatePositionCommand) {
ASSERT_OK(getReplCoord()->setLastDurableOptime_forTest(1, 3, optime1));
// Check that the proper BSON is generated for the replSetUpdatePositionCommand
- BSONObj cmd = unittest::assertGet(getReplCoord()->prepareReplSetUpdatePositionCommand(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kNewStyle));
+ BSONObj cmd = unittest::assertGet(getReplCoord()->prepareReplSetUpdatePositionCommand());
ASSERT_EQUALS(3, cmd.nFields());
ASSERT_EQUALS(UpdatePositionArgs::kCommandFieldName, cmd.firstElement().fieldNameStringData());
@@ -2321,60 +2319,6 @@ TEST_F(ReplCoordTest, NodeIncludesOtherMembersProgressInUpdatePositionCommand) {
ASSERT_EQUALS(4U, memberIds.size()); // Make sure we saw all 4 nodes
}
-TEST_F(ReplCoordTest, NodeIncludesOtherMembersProgressInOldUpdatePositionCommand) {
- init("mySet/test1:1234,test2:1234,test3:1234");
- assertStartSuccess(BSON("_id"
- << "mySet"
- << "version"
- << 1
- << "members"
- << BSON_ARRAY(BSON("_id" << 0 << "host"
- << "test1:1234")
- << BSON("_id" << 1 << "host"
- << "test2:1234")
- << BSON("_id" << 2 << "host"
- << "test3:1234"))),
- HostAndPort("test1", 1234));
- OpTimeWithTermOne optime1(100, 1);
- OpTimeWithTermOne optime2(100, 2);
- OpTimeWithTermOne optime3(2, 1);
- getReplCoord()->setMyLastAppliedOpTime(optime1);
- getReplCoord()->setMyLastDurableOpTime(optime1);
- ASSERT_OK(getReplCoord()->setLastAppliedOptime_forTest(1, 1, optime2));
- ASSERT_OK(getReplCoord()->setLastDurableOptime_forTest(1, 1, optime2));
- ASSERT_OK(getReplCoord()->setLastAppliedOptime_forTest(1, 2, optime3));
- ASSERT_OK(getReplCoord()->setLastDurableOptime_forTest(1, 2, optime3));
-
- // Check that the proper BSON is generated for the replSetUpdatePositionCommand
- BSONObj cmd = unittest::assertGet(getReplCoord()->prepareReplSetUpdatePositionCommand(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kOldStyle));
-
- ASSERT_EQUALS(2, cmd.nFields());
- ASSERT_EQUALS(OldUpdatePositionArgs::kCommandFieldName,
- cmd.firstElement().fieldNameStringData());
-
- std::set<long long> memberIds;
- BSONForEach(entryElement, cmd[OldUpdatePositionArgs::kUpdateArrayFieldName].Obj()) {
- BSONObj entry = entryElement.Obj();
- long long memberId = entry[OldUpdatePositionArgs::kMemberIdFieldName].Number();
- memberIds.insert(memberId);
- if (memberId == 0) {
- // TODO(siyuan) Update when we change replSetUpdatePosition format
- ASSERT_EQUALS(optime1.timestamp,
- entry[OldUpdatePositionArgs::kOpTimeFieldName]["ts"].timestamp());
- } else if (memberId == 1) {
- ASSERT_EQUALS(optime2.timestamp,
- entry[OldUpdatePositionArgs::kOpTimeFieldName]["ts"].timestamp());
- } else {
- ASSERT_EQUALS(2, memberId);
- ASSERT_EQUALS(optime3.timestamp,
- entry[OldUpdatePositionArgs::kOpTimeFieldName]["ts"].timestamp());
- }
- ASSERT_EQUALS(1, entry[OldUpdatePositionArgs::kOpTimeFieldName]["t"].Number());
- }
- ASSERT_EQUALS(3U, memberIds.size()); // Make sure we saw all 3 nodes
-}
-
TEST_F(ReplCoordTest,
NodeReturnsOperationFailedWhenSettingMaintenanceModeFalseWhenItHasNotBeenSetTrue) {
init("mySet/test1:1234,test2:1234,test3:1234");
@@ -2947,63 +2891,6 @@ TEST_F(ReplCoordTest, DoNotProcessSelfWhenUpdatePositionContainsInfoAboutSelf) {
getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern).status);
}
-TEST_F(ReplCoordTest, DoNotProcessSelfWhenOldUpdatePositionContainsInfoAboutSelf) {
- assertStartSuccess(BSON("_id"
- << "mySet"
- << "version"
- << 2
- << "members"
- << BSON_ARRAY(BSON("host"
- << "node1:12345"
- << "_id"
- << 0)
- << BSON("host"
- << "node2:12345"
- << "_id"
- << 1)
- << BSON("host"
- << "node3:12345"
- << "_id"
- << 2))),
- HostAndPort("node1", 12345));
- ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY));
- getReplCoord()->setMyLastAppliedOpTime(OpTimeWithTermOne(100, 0));
- getReplCoord()->setMyLastDurableOpTime(OpTimeWithTermOne(100, 0));
- simulateSuccessfulV1Election();
-
- OpTimeWithTermOne time1(100, 1);
- OpTimeWithTermOne time2(100, 2);
- OpTimeWithTermOne staleTime(10, 0);
- getReplCoord()->setMyLastAppliedOpTime(time1);
- getReplCoord()->setMyLastDurableOpTime(time1);
-
- WriteConcernOptions writeConcern;
- writeConcern.wTimeout = WriteConcernOptions::kNoWaiting;
- writeConcern.wNumNodes = 1;
-
- auto opCtx = makeOperationContext();
-
-
- ASSERT_EQUALS(ErrorCodes::WriteConcernFailed,
- getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern).status);
-
- // receive updatePosition containing ourself, should not process the update for self
- OldUpdatePositionArgs args;
- ASSERT_OK(args.initialize(BSON(OldUpdatePositionArgs::kCommandFieldName
- << 1
- << OldUpdatePositionArgs::kUpdateArrayFieldName
- << BSON_ARRAY(BSON(OldUpdatePositionArgs::kConfigVersionFieldName
- << 2
- << OldUpdatePositionArgs::kMemberIdFieldName
- << 0
- << OldUpdatePositionArgs::kOpTimeFieldName
- << time2.timestamp)))));
-
- ASSERT_OK(getReplCoord()->processReplSetUpdatePosition(args, 0));
- ASSERT_EQUALS(ErrorCodes::WriteConcernFailed,
- getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern).status);
-}
-
TEST_F(ReplCoordTest, DoNotProcessUpdatePositionWhenItsConfigVersionIsIncorrect) {
assertStartSuccess(BSON("_id"
<< "mySet"
@@ -3061,62 +2948,6 @@ TEST_F(ReplCoordTest, DoNotProcessUpdatePositionWhenItsConfigVersionIsIncorrect)
getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern).status);
}
-TEST_F(ReplCoordTest, DoNotProcessOldUpdatePositionWhenItsConfigVersionIsIncorrect) {
- assertStartSuccess(BSON("_id"
- << "mySet"
- << "version"
- << 2
- << "members"
- << BSON_ARRAY(BSON("host"
- << "node1:12345"
- << "_id"
- << 0)
- << BSON("host"
- << "node2:12345"
- << "_id"
- << 1)
- << BSON("host"
- << "node3:12345"
- << "_id"
- << 2))),
- HostAndPort("node1", 12345));
- ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY));
- getReplCoord()->setMyLastAppliedOpTime(OpTimeWithTermOne(100, 0));
- getReplCoord()->setMyLastDurableOpTime(OpTimeWithTermOne(100, 0));
- simulateSuccessfulV1Election();
-
- OpTimeWithTermOne time1(100, 1);
- OpTimeWithTermOne time2(100, 2);
- OpTimeWithTermOne staleTime(10, 0);
- getReplCoord()->setMyLastAppliedOpTime(time1);
- getReplCoord()->setMyLastDurableOpTime(time1);
-
- WriteConcernOptions writeConcern;
- writeConcern.wTimeout = WriteConcernOptions::kNoWaiting;
- writeConcern.wNumNodes = 1;
-
- // receive updatePosition with incorrect config version
- OldUpdatePositionArgs args;
- ASSERT_OK(args.initialize(BSON(OldUpdatePositionArgs::kCommandFieldName
- << 1
- << OldUpdatePositionArgs::kUpdateArrayFieldName
- << BSON_ARRAY(BSON(OldUpdatePositionArgs::kConfigVersionFieldName
- << 3
- << OldUpdatePositionArgs::kMemberIdFieldName
- << 1
- << OldUpdatePositionArgs::kOpTimeFieldName
- << time2.timestamp)))));
-
- auto opCtx = makeOperationContext();
-
-
- long long cfgver;
- ASSERT_EQUALS(ErrorCodes::InvalidReplicaSetConfig,
- getReplCoord()->processReplSetUpdatePosition(args, &cfgver));
- ASSERT_EQUALS(ErrorCodes::WriteConcernFailed,
- getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern).status);
-}
-
TEST_F(ReplCoordTest, DoNotProcessUpdatePositionOfMembersWhoseIdsAreNotInTheConfig) {
assertStartSuccess(BSON("_id"
<< "mySet"
@@ -3172,60 +3003,6 @@ TEST_F(ReplCoordTest, DoNotProcessUpdatePositionOfMembersWhoseIdsAreNotInTheConf
getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern).status);
}
-TEST_F(ReplCoordTest, DoNotProcessOldUpdatePositionOfMembersWhoseIdsAreNotInTheConfig) {
- assertStartSuccess(BSON("_id"
- << "mySet"
- << "version"
- << 2
- << "members"
- << BSON_ARRAY(BSON("host"
- << "node1:12345"
- << "_id"
- << 0)
- << BSON("host"
- << "node2:12345"
- << "_id"
- << 1)
- << BSON("host"
- << "node3:12345"
- << "_id"
- << 2))),
- HostAndPort("node1", 12345));
- ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY));
- getReplCoord()->setMyLastAppliedOpTime(OpTimeWithTermOne(100, 0));
- getReplCoord()->setMyLastDurableOpTime(OpTimeWithTermOne(100, 0));
- simulateSuccessfulV1Election();
-
- OpTimeWithTermOne time1(100, 1);
- OpTimeWithTermOne time2(100, 2);
- OpTimeWithTermOne staleTime(10, 0);
- getReplCoord()->setMyLastAppliedOpTime(time1);
- getReplCoord()->setMyLastDurableOpTime(time1);
-
- WriteConcernOptions writeConcern;
- writeConcern.wTimeout = WriteConcernOptions::kNoWaiting;
- writeConcern.wNumNodes = 1;
-
- // receive updatePosition with nonexistent member id
- OldUpdatePositionArgs args;
- ASSERT_OK(args.initialize(BSON(OldUpdatePositionArgs::kCommandFieldName
- << 1
- << OldUpdatePositionArgs::kUpdateArrayFieldName
- << BSON_ARRAY(BSON(OldUpdatePositionArgs::kConfigVersionFieldName
- << 2
- << OldUpdatePositionArgs::kMemberIdFieldName
- << 9
- << OldUpdatePositionArgs::kOpTimeFieldName
- << time2.timestamp)))));
-
- auto opCtx = makeOperationContext();
-
-
- ASSERT_EQUALS(ErrorCodes::NodeNotFound, getReplCoord()->processReplSetUpdatePosition(args, 0));
- ASSERT_EQUALS(ErrorCodes::WriteConcernFailed,
- getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern).status);
-}
-
TEST_F(ReplCoordTest,
ProcessUpdateWhenUpdatePositionContainsOnlyConfigVersionAndMemberIdsWithoutRIDs) {
assertStartSuccess(BSON("_id"
@@ -3264,23 +3041,27 @@ TEST_F(ReplCoordTest,
// receive a good update position
getReplCoord()->setMyLastAppliedOpTime(time2);
getReplCoord()->setMyLastDurableOpTime(time2);
- OldUpdatePositionArgs args;
+ UpdatePositionArgs args;
ASSERT_OK(
- args.initialize(BSON(OldUpdatePositionArgs::kCommandFieldName
+ args.initialize(BSON(UpdatePositionArgs::kCommandFieldName
<< 1
- << OldUpdatePositionArgs::kUpdateArrayFieldName
- << BSON_ARRAY(BSON(OldUpdatePositionArgs::kConfigVersionFieldName
+ << UpdatePositionArgs::kUpdateArrayFieldName
+ << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName
<< 2
- << OldUpdatePositionArgs::kMemberIdFieldName
+ << UpdatePositionArgs::kMemberIdFieldName
<< 1
- << OldUpdatePositionArgs::kOpTimeFieldName
- << time2.timestamp)
- << BSON(OldUpdatePositionArgs::kConfigVersionFieldName
+ << UpdatePositionArgs::kAppliedOpTimeFieldName
+ << time2.asOpTime().toBSON()
+ << UpdatePositionArgs::kDurableOpTimeFieldName
+ << time2.asOpTime().toBSON())
+ << BSON(UpdatePositionArgs::kConfigVersionFieldName
<< 2
- << OldUpdatePositionArgs::kMemberIdFieldName
+ << UpdatePositionArgs::kMemberIdFieldName
<< 2
- << OldUpdatePositionArgs::kOpTimeFieldName
- << time2.timestamp)))));
+ << UpdatePositionArgs::kAppliedOpTimeFieldName
+ << time2.asOpTime().toBSON()
+ << UpdatePositionArgs::kDurableOpTimeFieldName
+ << time2.asOpTime().toBSON())))));
auto opCtx = makeOperationContext();
@@ -5198,8 +4979,7 @@ TEST_F(ReplCoordTest, OnlyForwardSyncProgressForOtherNodesWhenTheNodesAreBelieve
ASSERT_OK(getReplCoord()->setLastDurableOptime_forTest(1, 1, optime));
// Check that we have two entries in our UpdatePosition (us and node 1).
- BSONObj cmd = unittest::assertGet(getReplCoord()->prepareReplSetUpdatePositionCommand(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kNewStyle));
+ BSONObj cmd = unittest::assertGet(getReplCoord()->prepareReplSetUpdatePositionCommand());
std::set<long long> memberIds;
BSONForEach(entryElement, cmd[UpdatePositionArgs::kUpdateArrayFieldName].Obj()) {
BSONObj entry = entryElement.Obj();
@@ -5216,21 +4996,6 @@ TEST_F(ReplCoordTest, OnlyForwardSyncProgressForOtherNodesWhenTheNodesAreBelieve
}
ASSERT_EQUALS(2U, memberIds.size());
- // Check that this true for old style (pre-3.2.4) UpdatePosition as well.
- BSONObj cmd2 = unittest::assertGet(getReplCoord()->prepareReplSetUpdatePositionCommand(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kOldStyle));
- std::set<long long> memberIds2;
- BSONForEach(entryElement, cmd2[OldUpdatePositionArgs::kUpdateArrayFieldName].Obj()) {
- BSONObj entry = entryElement.Obj();
- long long memberId = entry[OldUpdatePositionArgs::kMemberIdFieldName].Number();
- memberIds2.insert(memberId);
- OpTime entryOpTime;
- bsonExtractOpTimeField(entry, OldUpdatePositionArgs::kOpTimeFieldName, &entryOpTime)
- .transitional_ignore();
- ASSERT_EQUALS(optime, entryOpTime);
- }
- ASSERT_EQUALS(2U, memberIds2.size());
-
// Advance the clock far enough to cause the other node to be marked as DOWN.
const Date_t startDate = getNet()->now();
const Date_t endDate = startDate + Milliseconds(2000);
@@ -5245,13 +5010,12 @@ TEST_F(ReplCoordTest, OnlyForwardSyncProgressForOtherNodesWhenTheNodesAreBelieve
// Check there is one entry in our UpdatePosition, since we shouldn't forward for a
// DOWN node.
- BSONObj cmd3 = unittest::assertGet(getReplCoord()->prepareReplSetUpdatePositionCommand(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kNewStyle));
- std::set<long long> memberIds3;
- BSONForEach(entryElement, cmd3[UpdatePositionArgs::kUpdateArrayFieldName].Obj()) {
+ BSONObj cmd2 = unittest::assertGet(getReplCoord()->prepareReplSetUpdatePositionCommand());
+ std::set<long long> memberIds2;
+ BSONForEach(entryElement, cmd2[UpdatePositionArgs::kUpdateArrayFieldName].Obj()) {
BSONObj entry = entryElement.Obj();
long long memberId = entry[UpdatePositionArgs::kMemberIdFieldName].Number();
- memberIds3.insert(memberId);
+ memberIds2.insert(memberId);
OpTime appliedOpTime;
OpTime durableOpTime;
bsonExtractOpTimeField(entry, UpdatePositionArgs::kAppliedOpTimeFieldName, &appliedOpTime)
@@ -5261,25 +5025,10 @@ TEST_F(ReplCoordTest, OnlyForwardSyncProgressForOtherNodesWhenTheNodesAreBelieve
.transitional_ignore();
ASSERT_EQUALS(optime, durableOpTime);
}
- ASSERT_EQUALS(1U, memberIds3.size());
-
- // Check that this true for old style (pre-3.2.4) UpdatePosition as well.
- BSONObj cmd4 = unittest::assertGet(getReplCoord()->prepareReplSetUpdatePositionCommand(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kOldStyle));
- std::set<long long> memberIds4;
- BSONForEach(entryElement, cmd4[OldUpdatePositionArgs::kUpdateArrayFieldName].Obj()) {
- BSONObj entry = entryElement.Obj();
- long long memberId = entry[OldUpdatePositionArgs::kMemberIdFieldName].Number();
- memberIds4.insert(memberId);
- OpTime entryOpTime;
- bsonExtractOpTimeField(entry, OldUpdatePositionArgs::kOpTimeFieldName, &entryOpTime)
- .transitional_ignore();
- ASSERT_EQUALS(optime, entryOpTime);
- }
- ASSERT_EQUALS(1U, memberIds4.size());
+ ASSERT_EQUALS(1U, memberIds2.size());
}
-TEST_F(ReplCoordTest, NewStyleUpdatePositionCmdHasMetadata) {
+TEST_F(ReplCoordTest, UpdatePositionCmdHasMetadata) {
assertStartSuccess(
BSON("_id"
<< "mySet"
@@ -5307,8 +5056,7 @@ TEST_F(ReplCoordTest, NewStyleUpdatePositionCmdHasMetadata) {
getReplCoord()->processReplSetMetadata(syncSourceMetadata);
getReplCoord()->advanceCommitPoint(optime);
- BSONObj cmd = unittest::assertGet(getReplCoord()->prepareReplSetUpdatePositionCommand(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kNewStyle));
+ BSONObj cmd = unittest::assertGet(getReplCoord()->prepareReplSetUpdatePositionCommand());
auto metadata = unittest::assertGet(rpc::ReplSetMetadata::readFromMetadata(cmd));
ASSERT_EQUALS(metadata.getTerm(), getReplCoord()->getTerm());
ASSERT_EQUALS(metadata.getLastOpVisible(), optime);
@@ -5355,58 +5103,70 @@ TEST_F(ReplCoordTest, StepDownWhenHandleLivenessTimeoutMarksAMajorityOfVotingNod
getReplCoord()->setMyLastDurableOpTime(startingOpTime);
// Receive notification that every node is up.
- OldUpdatePositionArgs args;
+ UpdatePositionArgs args;
ASSERT_OK(
- args.initialize(BSON(OldUpdatePositionArgs::kCommandFieldName
+ args.initialize(BSON(UpdatePositionArgs::kCommandFieldName
<< 1
- << OldUpdatePositionArgs::kUpdateArrayFieldName
- << BSON_ARRAY(BSON(OldUpdatePositionArgs::kConfigVersionFieldName
+ << UpdatePositionArgs::kUpdateArrayFieldName
+ << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName
<< 2
- << OldUpdatePositionArgs::kMemberIdFieldName
+ << UpdatePositionArgs::kMemberIdFieldName
<< 1
- << OldUpdatePositionArgs::kOpTimeFieldName
- << startingOpTime.getTimestamp())
- << BSON(OldUpdatePositionArgs::kConfigVersionFieldName
+ << UpdatePositionArgs::kAppliedOpTimeFieldName
+ << startingOpTime.toBSON()
+ << UpdatePositionArgs::kDurableOpTimeFieldName
+ << startingOpTime.toBSON())
+ << BSON(UpdatePositionArgs::kConfigVersionFieldName
<< 2
- << OldUpdatePositionArgs::kMemberIdFieldName
+ << UpdatePositionArgs::kMemberIdFieldName
<< 2
- << OldUpdatePositionArgs::kOpTimeFieldName
- << startingOpTime.getTimestamp())
- << BSON(OldUpdatePositionArgs::kConfigVersionFieldName
+ << UpdatePositionArgs::kAppliedOpTimeFieldName
+ << startingOpTime.toBSON()
+ << UpdatePositionArgs::kDurableOpTimeFieldName
+ << startingOpTime.toBSON())
+ << BSON(UpdatePositionArgs::kConfigVersionFieldName
<< 2
- << OldUpdatePositionArgs::kMemberIdFieldName
+ << UpdatePositionArgs::kMemberIdFieldName
<< 3
- << OldUpdatePositionArgs::kOpTimeFieldName
- << startingOpTime.getTimestamp())
- << BSON(OldUpdatePositionArgs::kConfigVersionFieldName
+ << UpdatePositionArgs::kAppliedOpTimeFieldName
+ << startingOpTime.toBSON()
+ << UpdatePositionArgs::kDurableOpTimeFieldName
+ << startingOpTime.toBSON())
+ << BSON(UpdatePositionArgs::kConfigVersionFieldName
<< 2
- << OldUpdatePositionArgs::kMemberIdFieldName
+ << UpdatePositionArgs::kMemberIdFieldName
<< 4
- << OldUpdatePositionArgs::kOpTimeFieldName
- << startingOpTime.getTimestamp())))));
+ << UpdatePositionArgs::kAppliedOpTimeFieldName
+ << startingOpTime.toBSON()
+ << UpdatePositionArgs::kDurableOpTimeFieldName
+ << startingOpTime.toBSON())))));
ASSERT_OK(getReplCoord()->processReplSetUpdatePosition(args, 0));
// Become PRIMARY.
simulateSuccessfulV1Election();
// Keep two nodes alive.
- OldUpdatePositionArgs args1;
+ UpdatePositionArgs args1;
ASSERT_OK(
- args1.initialize(BSON(OldUpdatePositionArgs::kCommandFieldName
+ args1.initialize(BSON(UpdatePositionArgs::kCommandFieldName
<< 1
- << OldUpdatePositionArgs::kUpdateArrayFieldName
- << BSON_ARRAY(BSON(OldUpdatePositionArgs::kConfigVersionFieldName
+ << UpdatePositionArgs::kUpdateArrayFieldName
+ << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName
<< 2
- << OldUpdatePositionArgs::kMemberIdFieldName
+ << UpdatePositionArgs::kMemberIdFieldName
<< 1
- << OldUpdatePositionArgs::kOpTimeFieldName
- << startingOpTime.getTimestamp())
- << BSON(OldUpdatePositionArgs::kConfigVersionFieldName
+ << UpdatePositionArgs::kAppliedOpTimeFieldName
+ << startingOpTime.toBSON()
+ << UpdatePositionArgs::kDurableOpTimeFieldName
+ << startingOpTime.toBSON())
+ << BSON(UpdatePositionArgs::kConfigVersionFieldName
<< 2
- << OldUpdatePositionArgs::kMemberIdFieldName
+ << UpdatePositionArgs::kMemberIdFieldName
<< 2
- << OldUpdatePositionArgs::kOpTimeFieldName
- << startingOpTime.getTimestamp())))));
+ << UpdatePositionArgs::kAppliedOpTimeFieldName
+ << startingOpTime.toBSON()
+ << UpdatePositionArgs::kDurableOpTimeFieldName
+ << startingOpTime.toBSON())))));
ASSERT_OK(getReplCoord()->processReplSetUpdatePosition(args1, 0));
// Confirm that the node remains PRIMARY after the other two nodes are marked DOWN.
@@ -5417,17 +5177,19 @@ TEST_F(ReplCoordTest, StepDownWhenHandleLivenessTimeoutMarksAMajorityOfVotingNod
ASSERT_EQUALS(MemberState::RS_PRIMARY, getReplCoord()->getMemberState().s);
// Keep one node alive via two methods (UpdatePosition and requestHeartbeat).
- OldUpdatePositionArgs args2;
+ UpdatePositionArgs args2;
ASSERT_OK(
- args2.initialize(BSON(OldUpdatePositionArgs::kCommandFieldName
+ args2.initialize(BSON(UpdatePositionArgs::kCommandFieldName
<< 1
- << OldUpdatePositionArgs::kUpdateArrayFieldName
- << BSON_ARRAY(BSON(OldUpdatePositionArgs::kConfigVersionFieldName
+ << UpdatePositionArgs::kUpdateArrayFieldName
+ << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName
<< 2
- << OldUpdatePositionArgs::kMemberIdFieldName
+ << UpdatePositionArgs::kMemberIdFieldName
<< 1
- << OldUpdatePositionArgs::kOpTimeFieldName
- << startingOpTime.getTimestamp())))));
+ << UpdatePositionArgs::kDurableOpTimeFieldName
+ << startingOpTime.toBSON()
+ << UpdatePositionArgs::kAppliedOpTimeFieldName
+ << startingOpTime.toBSON())))));
ASSERT_OK(getReplCoord()->processReplSetUpdatePosition(args2, 0));
ReplSetHeartbeatArgsV1 hbArgs;
@@ -5530,150 +5292,6 @@ TEST_F(ReplCoordTest, WaitForDrainFinish) {
ASSERT_OK(replCoord->waitForDrainFinish(Milliseconds(0)));
}
-TEST_F(ReplCoordTest, UpdatePositionArgsReturnsNoSuchKeyWhenParsingOldUpdatePositionArgs) {
- OldUpdatePositionArgs args;
- UpdatePositionArgs args2;
- OpTime opTime = OpTime(Timestamp(100, 1), 0);
- ASSERT_EQUALS(
- ErrorCodes::NoSuchKey,
- args2.initialize(BSON(OldUpdatePositionArgs::kCommandFieldName
- << 1
- << OldUpdatePositionArgs::kUpdateArrayFieldName
- << BSON_ARRAY(BSON(OldUpdatePositionArgs::kConfigVersionFieldName
- << 2
- << OldUpdatePositionArgs::kMemberIdFieldName
- << 1
- << OldUpdatePositionArgs::kOpTimeFieldName
- << opTime.getTimestamp())
- << BSON(OldUpdatePositionArgs::kConfigVersionFieldName
- << 2
- << OldUpdatePositionArgs::kMemberIdFieldName
- << 2
- << OldUpdatePositionArgs::kOpTimeFieldName
- << opTime.getTimestamp())
- << BSON(OldUpdatePositionArgs::kConfigVersionFieldName
- << 2
- << OldUpdatePositionArgs::kMemberIdFieldName
- << 3
- << OldUpdatePositionArgs::kOpTimeFieldName
- << opTime.getTimestamp())
- << BSON(OldUpdatePositionArgs::kConfigVersionFieldName
- << 2
- << OldUpdatePositionArgs::kMemberIdFieldName
- << 4
- << OldUpdatePositionArgs::kOpTimeFieldName
- << opTime.getTimestamp())))));
-
- ASSERT_OK(
- args.initialize(BSON(OldUpdatePositionArgs::kCommandFieldName
- << 1
- << OldUpdatePositionArgs::kUpdateArrayFieldName
- << BSON_ARRAY(BSON(OldUpdatePositionArgs::kConfigVersionFieldName
- << 2
- << OldUpdatePositionArgs::kMemberIdFieldName
- << 1
- << OldUpdatePositionArgs::kOpTimeFieldName
- << opTime.getTimestamp())
- << BSON(OldUpdatePositionArgs::kConfigVersionFieldName
- << 2
- << OldUpdatePositionArgs::kMemberIdFieldName
- << 2
- << OldUpdatePositionArgs::kOpTimeFieldName
- << opTime.getTimestamp())
- << BSON(OldUpdatePositionArgs::kConfigVersionFieldName
- << 2
- << OldUpdatePositionArgs::kMemberIdFieldName
- << 3
- << OldUpdatePositionArgs::kOpTimeFieldName
- << opTime.getTimestamp())
- << BSON(OldUpdatePositionArgs::kConfigVersionFieldName
- << 2
- << OldUpdatePositionArgs::kMemberIdFieldName
- << 4
- << OldUpdatePositionArgs::kOpTimeFieldName
- << opTime.getTimestamp())))));
-}
-
-
-TEST_F(ReplCoordTest, OldUpdatePositionArgsReturnsBadValueWhenParsingUpdatePositionArgs) {
- OldUpdatePositionArgs args;
- UpdatePositionArgs args2;
- OpTime opTime = OpTime(Timestamp(100, 1), 0);
- ASSERT_EQUALS(ErrorCodes::BadValue,
- args.initialize(BSON(
- UpdatePositionArgs::kCommandFieldName
- << 1
- << UpdatePositionArgs::kUpdateArrayFieldName
- << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName
- << 2
- << UpdatePositionArgs::kMemberIdFieldName
- << 1
- << UpdatePositionArgs::kDurableOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3)
- << UpdatePositionArgs::kAppliedOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3))
- << BSON(UpdatePositionArgs::kConfigVersionFieldName
- << 2
- << UpdatePositionArgs::kMemberIdFieldName
- << 2
- << UpdatePositionArgs::kDurableOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3)
- << UpdatePositionArgs::kAppliedOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3))
- << BSON(UpdatePositionArgs::kConfigVersionFieldName
- << 2
- << UpdatePositionArgs::kMemberIdFieldName
- << 3
- << UpdatePositionArgs::kDurableOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3)
- << UpdatePositionArgs::kAppliedOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3))
- << BSON(UpdatePositionArgs::kConfigVersionFieldName
- << 2
- << UpdatePositionArgs::kMemberIdFieldName
- << 4
- << UpdatePositionArgs::kDurableOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3)
- << UpdatePositionArgs::kAppliedOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3))))));
- ASSERT_OK(args2.initialize(
- BSON(UpdatePositionArgs::kCommandFieldName
- << 1
- << UpdatePositionArgs::kUpdateArrayFieldName
- << BSON_ARRAY(BSON(UpdatePositionArgs::kConfigVersionFieldName
- << 2
- << UpdatePositionArgs::kMemberIdFieldName
- << 1
- << UpdatePositionArgs::kDurableOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3)
- << UpdatePositionArgs::kAppliedOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3))
- << BSON(UpdatePositionArgs::kConfigVersionFieldName
- << 2
- << UpdatePositionArgs::kMemberIdFieldName
- << 2
- << UpdatePositionArgs::kDurableOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3)
- << UpdatePositionArgs::kAppliedOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3))
- << BSON(UpdatePositionArgs::kConfigVersionFieldName
- << 2
- << UpdatePositionArgs::kMemberIdFieldName
- << 3
- << UpdatePositionArgs::kDurableOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3)
- << UpdatePositionArgs::kAppliedOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3))
- << BSON(UpdatePositionArgs::kConfigVersionFieldName
- << 2
- << UpdatePositionArgs::kMemberIdFieldName
- << 4
- << UpdatePositionArgs::kDurableOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3)
- << UpdatePositionArgs::kAppliedOpTimeFieldName
- << BSON("ts" << opTime.getTimestamp() << "t" << 3))))));
-}
-
TEST_F(
ReplCoordTest,
PopulateUnsetWriteConcernOptionsSyncModeReturnsInputWithSyncModeNoneIfUnsetAndWriteConcernMajorityJournalDefaultIsFalse) {
diff --git a/src/mongo/db/repl/replication_coordinator_mock.cpp b/src/mongo/db/repl/replication_coordinator_mock.cpp
index 41f44d944e7..3ea5c3d7717 100644
--- a/src/mongo/db/repl/replication_coordinator_mock.cpp
+++ b/src/mongo/db/repl/replication_coordinator_mock.cpp
@@ -271,8 +271,7 @@ Status ReplicationCoordinatorMock::resyncData(OperationContext* opCtx, bool wait
return Status::OK();
}
-StatusWith<BSONObj> ReplicationCoordinatorMock::prepareReplSetUpdatePositionCommand(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle commandStyle) const {
+StatusWith<BSONObj> ReplicationCoordinatorMock::prepareReplSetUpdatePositionCommand() const {
BSONObjBuilder cmdBuilder;
cmdBuilder.append("replSetUpdatePosition", 1);
return cmdBuilder.obj();
@@ -362,12 +361,6 @@ Status ReplicationCoordinatorMock::processReplSetElect(const ReplSetElectArgs& a
return Status::OK();
}
-Status ReplicationCoordinatorMock::processReplSetUpdatePosition(
- const OldUpdatePositionArgs& updates, long long* configVersion) {
- // TODO
- return Status::OK();
-}
-
Status ReplicationCoordinatorMock::processReplSetUpdatePosition(const UpdatePositionArgs& updates,
long long* configVersion) {
// TODO
diff --git a/src/mongo/db/repl/replication_coordinator_mock.h b/src/mongo/db/repl/replication_coordinator_mock.h
index 42e79009920..8f3e208d90f 100644
--- a/src/mongo/db/repl/replication_coordinator_mock.h
+++ b/src/mongo/db/repl/replication_coordinator_mock.h
@@ -153,8 +153,7 @@ public:
virtual Status resyncData(OperationContext* opCtx, bool waitUntilCompleted) override;
- virtual StatusWith<BSONObj> prepareReplSetUpdatePositionCommand(
- ReplSetUpdatePositionCommandStyle commandStyle) const override;
+ virtual StatusWith<BSONObj> prepareReplSetUpdatePositionCommand() const override;
virtual Status processReplSetGetStatus(BSONObjBuilder*, ReplSetGetStatusResponseStyle);
@@ -199,8 +198,6 @@ public:
virtual Status processReplSetElect(const ReplSetElectArgs& args, BSONObjBuilder* resultObj);
- virtual Status processReplSetUpdatePosition(const OldUpdatePositionArgs& updates,
- long long* configVersion);
virtual Status processReplSetUpdatePosition(const UpdatePositionArgs& updates,
long long* configVersion);
diff --git a/src/mongo/db/repl/reporter.cpp b/src/mongo/db/repl/reporter.cpp
index b22c180bb7c..b1fe3d50e36 100644
--- a/src/mongo/db/repl/reporter.cpp
+++ b/src/mongo/db/repl/reporter.cpp
@@ -33,7 +33,6 @@
#include "mongo/db/repl/reporter.h"
#include "mongo/bson/util/bson_extract.h"
-#include "mongo/db/repl/old_update_position_args.h"
#include "mongo/db/repl/update_position_args.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/util/assert_util.h"
@@ -68,10 +67,7 @@ long long _parseCommandRequestConfigVersion(const BSONObj& commandRequest) {
* locally generated update command request object.
* Returns false if config version is missing in either document.
*/
-bool _isTargetConfigNewerThanRequest(
- const BSONObj& commandResult,
- const BSONObj& commandRequest,
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle commandStyle) {
+bool _isTargetConfigNewerThanRequest(const BSONObj& commandResult, const BSONObj& commandRequest) {
long long targetConfigVersion;
if (!bsonExtractIntegerField(commandResult, kConfigVersionFieldName, &targetConfigVersion)
.isOK()) {
@@ -79,9 +75,7 @@ bool _isTargetConfigNewerThanRequest(
}
const long long localConfigVersion =
- commandStyle == ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kNewStyle
- ? _parseCommandRequestConfigVersion<UpdatePositionArgs>(commandRequest)
- : _parseCommandRequestConfigVersion<OldUpdatePositionArgs>(commandRequest);
+ _parseCommandRequestConfigVersion<UpdatePositionArgs>(commandRequest);
if (localConfigVersion == -1) {
return false;
}
@@ -192,19 +186,7 @@ Status Reporter::trigger() {
}
StatusWith<BSONObj> Reporter::_prepareCommand() {
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle commandStyle =
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kNewStyle;
- {
- stdx::lock_guard<stdx::mutex> lk(_mutex);
- invariant(_isActive_inlock());
- if (!_status.isOK()) {
- return _status;
- }
-
- commandStyle = _commandStyle;
- }
-
- auto prepareResult = _prepareReplSetUpdatePositionCommandFn(commandStyle);
+ auto prepareResult = _prepareReplSetUpdatePositionCommandFn();
stdx::lock_guard<stdx::mutex> lk(_mutex);
@@ -269,16 +251,8 @@ void Reporter::_processResponseCallback(
// Some error types are OK and should not cause the reporter to stop sending updates to the
// sync target.
- if (_status == ErrorCodes::BadValue &&
- _commandStyle == ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kNewStyle) {
- LOG(1) << "Reporter falling back to old style UpdatePosition command for sync source: "
- << _target;
- _status = Status::OK();
- _commandStyle = ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kOldStyle;
- _isWaitingToSendReporter = true;
- } else if (_status == ErrorCodes::InvalidReplicaSetConfig &&
- _isTargetConfigNewerThanRequest(
- commandResult, rcbd.request.cmdObj, _commandStyle)) {
+ if (_status == ErrorCodes::InvalidReplicaSetConfig &&
+ _isTargetConfigNewerThanRequest(commandResult, rcbd.request.cmdObj)) {
LOG(1) << "Reporter found newer configuration on sync source: " << _target
<< ". Retrying.";
_status = Status::OK();
diff --git a/src/mongo/db/repl/reporter.h b/src/mongo/db/repl/reporter.h
index cabf6536328..353f3391db6 100644
--- a/src/mongo/db/repl/reporter.h
+++ b/src/mongo/db/repl/reporter.h
@@ -71,8 +71,7 @@ public:
*
* The returned status indicates whether or not the command was created.
*/
- using PrepareReplSetUpdatePositionCommandFn = stdx::function<StatusWith<BSONObj>(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle)>;
+ using PrepareReplSetUpdatePositionCommandFn = stdx::function<StatusWith<BSONObj>()>;
Reporter(executor::TaskExecutor* executor,
PrepareReplSetUpdatePositionCommandFn prepareReplSetUpdatePositionCommandFn,
@@ -188,10 +187,6 @@ private:
// Stores the most recent Status returned from the executor.
Status _status = Status::OK();
- // Stores style of the most recent update command object.
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle _commandStyle =
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kNewStyle;
-
// _isWaitingToSendReporter is true when Reporter is scheduled to be run by the executor and
// subsequent updates have come in.
bool _isWaitingToSendReporter = false;
diff --git a/src/mongo/db/repl/reporter_test.cpp b/src/mongo/db/repl/reporter_test.cpp
index 97485f030e5..aec94c02387 100644
--- a/src/mongo/db/repl/reporter_test.cpp
+++ b/src/mongo/db/repl/reporter_test.cpp
@@ -28,8 +28,6 @@
#include "mongo/platform/basic.h"
-#include "mongo/db/repl/old_update_position_args.h"
-#include "mongo/db/repl/optime.h"
#include "mongo/db/repl/reporter.h"
#include "mongo/db/repl/update_position_args.h"
#include "mongo/executor/network_interface_mock.h"
@@ -64,27 +62,17 @@ public:
_configVersion = configVersion;
}
- StatusWith<BSONObj> prepareReplSetUpdatePositionCommand(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle commandStyle) {
+ StatusWith<BSONObj> prepareReplSetUpdatePositionCommand() {
BSONObjBuilder cmdBuilder;
cmdBuilder.append(UpdatePositionArgs::kCommandFieldName, 1);
BSONArrayBuilder arrayBuilder(
cmdBuilder.subarrayStart(UpdatePositionArgs::kUpdateArrayFieldName));
for (auto&& itr : _progressMap) {
BSONObjBuilder entry(arrayBuilder.subobjStart());
- switch (commandStyle) {
- case ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kNewStyle:
- itr.second.lastDurableOpTime.append(
- &entry, UpdatePositionArgs::kDurableOpTimeFieldName);
- itr.second.lastAppliedOpTime.append(
- &entry, UpdatePositionArgs::kAppliedOpTimeFieldName);
- break;
- case ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kOldStyle:
- // Assume protocol version 1.
- itr.second.lastDurableOpTime.append(&entry,
- OldUpdatePositionArgs::kOpTimeFieldName);
- break;
- }
+ itr.second.lastDurableOpTime.append(&entry,
+ UpdatePositionArgs::kDurableOpTimeFieldName);
+ itr.second.lastAppliedOpTime.append(&entry,
+ UpdatePositionArgs::kAppliedOpTimeFieldName);
entry.append(UpdatePositionArgs::kMemberIdFieldName, itr.first);
if (_configVersion != -1) {
entry.append(UpdatePositionArgs::kConfigVersionFieldName, _configVersion);
@@ -159,17 +147,13 @@ void ReporterTest::setUp() {
posUpdater->updateMap(0, OpTime({3, 0}, 1), OpTime({3, 0}, 1));
prepareReplSetUpdatePositionCommandFn =
- stdx::bind(&MockProgressManager::prepareReplSetUpdatePositionCommand,
- posUpdater.get(),
- stdx::placeholders::_1);
-
- reporter = stdx::make_unique<Reporter>(
- _executorProxy.get(),
- [this](ReplicationCoordinator::ReplSetUpdatePositionCommandStyle commandStyle) {
- return prepareReplSetUpdatePositionCommandFn(commandStyle);
- },
- HostAndPort("h1"),
- Milliseconds(1000));
+ stdx::bind(&MockProgressManager::prepareReplSetUpdatePositionCommand, posUpdater.get());
+
+ reporter =
+ stdx::make_unique<Reporter>(_executorProxy.get(),
+ [this]() { return prepareReplSetUpdatePositionCommandFn(); },
+ HostAndPort("h1"),
+ Milliseconds(1000));
launchExecutorThread();
if (triggerAtSetUp()) {
@@ -369,9 +353,8 @@ TEST_F(ReporterTest, InvalidReplicaSetResponseWithSameConfigVersionOnSyncTargetS
assertReporterDone();
}
-TEST_F(
- ReporterTest,
- InvalidReplicaSetResponseWithNewerConfigVersionOnSyncTargetToAnNewCommandStyleRequestDoesNotStopTheReporter) {
+TEST_F(ReporterTest,
+ InvalidReplicaSetResponseWithNewerConfigVersionOnSyncTargetDoesNotStopTheReporter) {
// Reporter should not retry update command on sync source immediately after seeing newer
// configuration.
ASSERT_OK(reporter->trigger());
@@ -386,32 +369,6 @@ TEST_F(
ASSERT_TRUE(reporter->isActive());
}
-TEST_F(
- ReporterTest,
- InvalidReplicaSetResponseWithNewerConfigVersionOnSyncTargetToAnOldCommandStyleRequestDoesNotStopTheReporter) {
- auto expectedNewStyleCommandRequest = unittest::assertGet(prepareReplSetUpdatePositionCommandFn(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kNewStyle));
-
- auto commandRequest =
- processNetworkResponse(BSON("ok" << 0 << "code" << int(ErrorCodes::BadValue) << "errmsg"
- << "Unexpected field durableOpTime in UpdateInfoArgs"),
- true);
- ASSERT_BSONOBJ_EQ(expectedNewStyleCommandRequest, commandRequest);
-
- // Update command object should match old style (pre-3.2.4).
- auto expectedOldStyleCommandRequest = unittest::assertGet(prepareReplSetUpdatePositionCommandFn(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kOldStyle));
-
- commandRequest = processNetworkResponse(
- BSON("ok" << 0 << "code" << int(ErrorCodes::InvalidReplicaSetConfig) << "errmsg"
- << "newer config"
- << "configVersion"
- << posUpdater->getConfigVersion() + 1));
- ASSERT_BSONOBJ_EQ(expectedOldStyleCommandRequest, commandRequest);
-
- ASSERT_TRUE(reporter->isActive());
-}
-
// Schedule while we are already scheduled, it should set "isWaitingToSendReport", then
// automatically
// schedule itself after finishing.
@@ -500,9 +457,9 @@ TEST_F(ReporterTest, ShuttingReporterDownWhileSecondCommandRequestIsInProgressSt
TEST_F(ReporterTestNoTriggerAtSetUp, CommandPreparationFailureStopsTheReporter) {
Status expectedStatus(ErrorCodes::UnknownError, "unknown error");
- prepareReplSetUpdatePositionCommandFn =
- [expectedStatus](ReplicationCoordinator::ReplSetUpdatePositionCommandStyle commandStyle)
- -> StatusWith<BSONObj> { return expectedStatus; };
+ prepareReplSetUpdatePositionCommandFn = [expectedStatus]() -> StatusWith<BSONObj> {
+ return expectedStatus;
+ };
ASSERT_OK(reporter->trigger());
ASSERT_EQUALS(expectedStatus, reporter->join());
@@ -518,9 +475,9 @@ TEST_F(ReporterTest, CommandPreparationFailureDuringRescheduleStopsTheReporter)
// This will cause command preparation to fail for the subsequent request.
Status expectedStatus(ErrorCodes::UnknownError, "unknown error");
- prepareReplSetUpdatePositionCommandFn =
- [expectedStatus](ReplicationCoordinator::ReplSetUpdatePositionCommandStyle commandStyle)
- -> StatusWith<BSONObj> { return expectedStatus; };
+ prepareReplSetUpdatePositionCommandFn = [expectedStatus]() -> StatusWith<BSONObj> {
+ return expectedStatus;
+ };
processNetworkResponse(BSON("ok" << 1));
@@ -528,37 +485,6 @@ TEST_F(ReporterTest, CommandPreparationFailureDuringRescheduleStopsTheReporter)
assertReporterDone();
}
-// If a remote server (most likely running with version before 3.2.4) returns ErrorCodes::BadValue
-// on a new style replSetUpdateCommand command object, we should regenerate the command with
-// pre-3.2.4 style arguments and retry the remote command.
-TEST_F(ReporterTest,
- BadValueErrorOnNewStyleCommandShouldCauseRescheduleImmediatelyWithOldStyleCommand) {
- runReadyScheduledTasks();
-
- auto expectedNewStyleCommandRequest = unittest::assertGet(prepareReplSetUpdatePositionCommandFn(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kNewStyle));
-
- auto commandRequest =
- processNetworkResponse(BSON("ok" << 0 << "code" << int(ErrorCodes::BadValue) << "errmsg"
- << "Unexpected field durableOpTime in UpdateInfoArgs"),
- true);
- ASSERT_BSONOBJ_EQ(expectedNewStyleCommandRequest, commandRequest);
-
- auto expectedOldStyleCommandRequest = unittest::assertGet(prepareReplSetUpdatePositionCommandFn(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kOldStyle));
-
- commandRequest = processNetworkResponse(BSON("ok" << 1));
-
- // Update command object should match old style (pre-3.2.2).
- ASSERT_BSONOBJ_NE(expectedNewStyleCommandRequest, expectedOldStyleCommandRequest);
- ASSERT_BSONOBJ_EQ(expectedOldStyleCommandRequest, commandRequest);
-
- reporter->shutdown();
-
- ASSERT_EQUALS(ErrorCodes::CallbackCanceled, reporter->join());
- assertReporterDone();
-}
-
TEST_F(ReporterTest, FailedUpdateShouldNotRescheduleUpdate) {
processNetworkResponse({ErrorCodes::OperationFailed, "update failed", Milliseconds(0)});
@@ -678,9 +604,9 @@ TEST_F(ReporterTest, KeepAliveTimeoutFailingToScheduleRemoteCommandShouldMakeRep
ASSERT_TRUE(reporter->isActive());
Status expectedStatus(ErrorCodes::UnknownError, "failed to prepare update command");
- prepareReplSetUpdatePositionCommandFn =
- [expectedStatus](ReplicationCoordinator::ReplSetUpdatePositionCommandStyle commandStyle)
- -> StatusWith<BSONObj> { return expectedStatus; };
+ prepareReplSetUpdatePositionCommandFn = [expectedStatus]() -> StatusWith<BSONObj> {
+ return expectedStatus;
+ };
runUntil(until);
diff --git a/src/mongo/db/repl/sync_source_feedback.cpp b/src/mongo/db/repl/sync_source_feedback.cpp
index 8fd1e66d6a5..4bd190ff14e 100644
--- a/src/mongo/db/repl/sync_source_feedback.cpp
+++ b/src/mongo/db/repl/sync_source_feedback.cpp
@@ -61,8 +61,7 @@ Milliseconds calculateKeepAliveInterval(const ReplSetConfig& rsConfig) {
*/
Reporter::PrepareReplSetUpdatePositionCommandFn makePrepareReplSetUpdatePositionCommandFn(
ReplicationCoordinator* replCoord, const HostAndPort& syncTarget, BackgroundSync* bgsync) {
- return [syncTarget, replCoord, bgsync](ReplicationCoordinator::ReplSetUpdatePositionCommandStyle
- commandStyle) -> StatusWith<BSONObj> {
+ return [syncTarget, replCoord, bgsync]() -> StatusWith<BSONObj> {
auto currentSyncTarget = bgsync->getSyncTarget();
if (currentSyncTarget != syncTarget) {
if (currentSyncTarget.empty()) {
@@ -84,7 +83,7 @@ Reporter::PrepareReplSetUpdatePositionCommandFn makePrepareReplSetUpdatePosition
"Currently primary - no one to send updates to");
}
- return replCoord->prepareReplSetUpdatePositionCommand(commandStyle);
+ return replCoord->prepareReplSetUpdatePositionCommand();
};
}
diff --git a/src/mongo/db/repl/topology_coordinator.cpp b/src/mongo/db/repl/topology_coordinator.cpp
index 3607128a2c2..29cce45feca 100644
--- a/src/mongo/db/repl/topology_coordinator.cpp
+++ b/src/mongo/db/repl/topology_coordinator.cpp
@@ -2049,7 +2049,6 @@ void TopologyCoordinator::prepareStatusResponse(const ReplSetStatusArgs& rsStatu
}
StatusWith<BSONObj> TopologyCoordinator::prepareReplSetUpdatePositionCommand(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle commandStyle,
OpTime currentCommittedSnapshotOpTime) const {
BSONObjBuilder cmdBuilder;
invariant(_rsConfig.isInitialized());
@@ -2072,33 +2071,19 @@ StatusWith<BSONObj> TopologyCoordinator::prepareReplSetUpdatePositionCommand(
}
BSONObjBuilder entry(arrayBuilder.subobjStart());
- switch (commandStyle) {
- case ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kNewStyle:
- memberData.getLastDurableOpTime().append(
- &entry, UpdatePositionArgs::kDurableOpTimeFieldName);
- memberData.getLastAppliedOpTime().append(
- &entry, UpdatePositionArgs::kAppliedOpTimeFieldName);
- break;
- case ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kOldStyle:
- entry.append("_id", memberData.getRid());
- if (_rsConfig.getProtocolVersion() == 1) {
- memberData.getLastDurableOpTime().append(&entry, "optime");
- } else {
- entry.append("optime", memberData.getLastDurableOpTime().getTimestamp());
- }
- break;
- }
+ memberData.getLastDurableOpTime().append(&entry,
+ UpdatePositionArgs::kDurableOpTimeFieldName);
+ memberData.getLastAppliedOpTime().append(&entry,
+ UpdatePositionArgs::kAppliedOpTimeFieldName);
entry.append(UpdatePositionArgs::kMemberIdFieldName, memberData.getMemberId());
entry.append(UpdatePositionArgs::kConfigVersionFieldName, _rsConfig.getConfigVersion());
}
arrayBuilder.done();
- // Add metadata to command. Old style parsing logic will reject the metadata.
- if (commandStyle == ReplicationCoordinator::ReplSetUpdatePositionCommandStyle::kNewStyle) {
- prepareReplSetMetadata(currentCommittedSnapshotOpTime)
- .writeToMetadata(&cmdBuilder)
- .transitional_ignore();
- }
+ // Add metadata to command
+ prepareReplSetMetadata(currentCommittedSnapshotOpTime)
+ .writeToMetadata(&cmdBuilder)
+ .transitional_ignore();
return cmdBuilder.obj();
}
diff --git a/src/mongo/db/repl/topology_coordinator.h b/src/mongo/db/repl/topology_coordinator.h
index 34ca9906d05..44f5abcead0 100644
--- a/src/mongo/db/repl/topology_coordinator.h
+++ b/src/mongo/db/repl/topology_coordinator.h
@@ -360,7 +360,6 @@ public:
// Produce a replSetUpdatePosition command to be sent to the node's sync source.
StatusWith<BSONObj> prepareReplSetUpdatePositionCommand(
- ReplicationCoordinator::ReplSetUpdatePositionCommandStyle commandStyle,
OpTime currentCommittedSnapshotOpTime) const;
// produce a reply to an ismaster request. It is only valid to call this if we are a