@@ -338,7 +338,7 @@ Date_t ReplicationCoordinatorImpl::getPriorityTakeover_forTest() const {
338338 return _priorityTakeoverWhen;
339339}
340340
341- OpTime ReplicationCoordinatorImpl::getCurrentCommittedSnapshotOpTime () {
341+ OpTime ReplicationCoordinatorImpl::getCurrentCommittedSnapshotOpTime () const {
342342 stdx::lock_guard<stdx::mutex> lk (_mutex);
343343 if (_currentCommittedSnapshot) {
344344 return _currentCommittedSnapshot->opTime ;
@@ -1889,49 +1889,55 @@ int ReplicationCoordinatorImpl::_getMyId_inlock() const {
18891889
18901890StatusWith<BSONObj> ReplicationCoordinatorImpl::prepareReplSetUpdatePositionCommand (
18911891 ReplicationCoordinator::ReplSetUpdatePositionCommandStyle commandStyle) const {
1892- stdx::lock_guard<stdx::mutex> lock (_mutex);
1893- invariant (_rsConfig.isInitialized ());
1894- // Do not send updates if we have been removed from the config.
1895- if (_selfIndex == -1 ) {
1896- return Status (ErrorCodes::NodeNotFound,
1897- " This node is not in the current replset configuration." );
1898- }
18991892 BSONObjBuilder cmdBuilder;
1900- cmdBuilder.append (UpdatePositionArgs::kCommandFieldName , 1 );
1901- // Create an array containing objects each live member connected to us and for ourself.
1902- BSONArrayBuilder arrayBuilder (cmdBuilder.subarrayStart (" optimes" ));
1903- for (const auto & slaveInfo : _slaveInfo) {
1904- if (slaveInfo.lastAppliedOpTime .isNull ()) {
1905- // Don't include info on members we haven't heard from yet.
1906- continue ;
1907- }
1908- // Don't include members we think are down.
1909- if (!slaveInfo.self && slaveInfo.down ) {
1910- continue ;
1911- }
1893+ {
1894+ stdx::lock_guard<stdx::mutex> lock (_mutex);
1895+ invariant (_rsConfig.isInitialized ());
1896+ // Do not send updates if we have been removed from the config.
1897+ if (_selfIndex == -1 ) {
1898+ return Status (ErrorCodes::NodeNotFound,
1899+ " This node is not in the current replset configuration." );
1900+ }
1901+ cmdBuilder.append (UpdatePositionArgs::kCommandFieldName , 1 );
1902+ // Create an array containing objects each live member connected to us and for ourself.
1903+ BSONArrayBuilder arrayBuilder (cmdBuilder.subarrayStart (" optimes" ));
1904+ for (const auto & slaveInfo : _slaveInfo) {
1905+ if (slaveInfo.lastAppliedOpTime .isNull ()) {
1906+ // Don't include info on members we haven't heard from yet.
1907+ continue ;
1908+ }
1909+ // Don't include members we think are down.
1910+ if (!slaveInfo.self && slaveInfo.down ) {
1911+ continue ;
1912+ }
19121913
1913- BSONObjBuilder entry (arrayBuilder.subobjStart ());
1914- switch (commandStyle) {
1915- case ReplSetUpdatePositionCommandStyle::kNewStyle :
1916- slaveInfo.lastDurableOpTime .append (&entry,
1917- UpdatePositionArgs::kDurableOpTimeFieldName );
1918- slaveInfo.lastAppliedOpTime .append (&entry,
1919- UpdatePositionArgs::kAppliedOpTimeFieldName );
1920- break ;
1921- case ReplSetUpdatePositionCommandStyle::kOldStyle :
1922- entry.append (" _id" , slaveInfo.rid );
1923- if (isV1ElectionProtocol ()) {
1924- slaveInfo.lastDurableOpTime .append (&entry, " optime" );
1925- } else {
1926- entry.append (" optime" , slaveInfo.lastDurableOpTime .getTimestamp ());
1927- }
1928- break ;
1914+ BSONObjBuilder entry (arrayBuilder.subobjStart ());
1915+ switch (commandStyle) {
1916+ case ReplSetUpdatePositionCommandStyle::kNewStyle :
1917+ slaveInfo.lastDurableOpTime .append (&entry,
1918+ UpdatePositionArgs::kDurableOpTimeFieldName );
1919+ slaveInfo.lastAppliedOpTime .append (&entry,
1920+ UpdatePositionArgs::kAppliedOpTimeFieldName );
1921+ break ;
1922+ case ReplSetUpdatePositionCommandStyle::kOldStyle :
1923+ entry.append (" _id" , slaveInfo.rid );
1924+ if (isV1ElectionProtocol ()) {
1925+ slaveInfo.lastDurableOpTime .append (&entry, " optime" );
1926+ } else {
1927+ entry.append (" optime" , slaveInfo.lastDurableOpTime .getTimestamp ());
1928+ }
1929+ break ;
1930+ }
1931+ entry.append (UpdatePositionArgs::kMemberIdFieldName , slaveInfo.memberId );
1932+ entry.append (UpdatePositionArgs::kConfigVersionFieldName , _rsConfig.getConfigVersion ());
19291933 }
1930- entry.append (UpdatePositionArgs::kMemberIdFieldName , slaveInfo.memberId );
1931- entry.append (UpdatePositionArgs::kConfigVersionFieldName , _rsConfig.getConfigVersion ());
1934+ arrayBuilder.done ();
19321935 }
1933- arrayBuilder.done ();
19341936
1937+ // Add metadata to command. Old style parsing logic will reject the metadata.
1938+ if (commandStyle == ReplSetUpdatePositionCommandStyle::kNewStyle ) {
1939+ prepareReplMetadata (OpTime (), &cmdBuilder);
1940+ }
19351941 return cmdBuilder.obj ();
19361942}
19371943
@@ -3121,18 +3127,15 @@ Status ReplicationCoordinatorImpl::processReplSetRequestVotes(
31213127 return Status::OK ();
31223128}
31233129
3124- void ReplicationCoordinatorImpl::prepareReplResponseMetadata (const rpc::RequestInterface& request,
3125- const OpTime& lastOpTimeFromClient,
3126- BSONObjBuilder* builder) {
3127- if (request.getMetadata ().hasField (rpc::kReplSetMetadataFieldName )) {
3128- rpc::ReplSetMetadata metadata;
3129- LockGuard topoLock (_topoMutex);
3130+ void ReplicationCoordinatorImpl::prepareReplMetadata (const OpTime& lastOpTimeFromClient,
3131+ BSONObjBuilder* builder) const {
3132+ rpc::ReplSetMetadata metadata;
3133+ LockGuard topoLock (_topoMutex);
31303134
3131- OpTime lastReadableOpTime = getCurrentCommittedSnapshotOpTime ();
3132- OpTime lastVisibleOpTime = std::max (lastOpTimeFromClient, lastReadableOpTime);
3133- _topCoord->prepareReplResponseMetadata (&metadata, lastVisibleOpTime, _lastCommittedOpTime);
3134- metadata.writeToMetadata (builder);
3135- }
3135+ OpTime lastReadableOpTime = getCurrentCommittedSnapshotOpTime ();
3136+ OpTime lastVisibleOpTime = std::max (lastOpTimeFromClient, lastReadableOpTime);
3137+ _topCoord->prepareReplMetadata (&metadata, lastVisibleOpTime, _lastCommittedOpTime);
3138+ metadata.writeToMetadata (builder);
31363139}
31373140
31383141bool ReplicationCoordinatorImpl::isV1ElectionProtocol () const {
0 commit comments