@@ -50,10 +50,8 @@ namespace {
5050 * Calculates await data timeout based on the current replica set configuration.
5151 */
5252Milliseconds calculateAwaitDataTimeout (const ReplicaSetConfig& config) {
53- // Under protocol version 1, make the awaitData timeout (maxTimeMS) dependent
54- // on the election
55- // timeout. This enables the sync source to communicate liveness of the
56- // primary to secondaries.
53+ // Under protocol version 1, make the awaitData timeout (maxTimeMS) dependent on the election
54+ // timeout. This enables the sync source to communicate liveness of the primary to secondaries.
5755 // Under protocol version 0, use a default timeout of 2 seconds for awaitData.
5856 if (config.getProtocolVersion () == 1LL ) {
5957 return config.getElectionTimeoutPeriod () / 2 ;
@@ -111,19 +109,15 @@ StatusWith<BSONObj> makeMetadataObject(bool isV1ElectionProtocol) {
111109
112110/* *
113111 * Checks the first batch of results from query.
114- * 'documents' are the first batch of results returned from tailing the remote
115- * oplog.
116- * 'lastFetched' optime and hash should be consistent with the predicate in the
117- * query.
112+ * 'documents' are the first batch of results returned from tailing the remote oplog.
113+ * 'lastFetched' optime and hash should be consistent with the predicate in the query.
118114 * Returns RemoteOplogStale if the oplog query has no results.
119- * Returns OplogStartMissing if we cannot find the optime of the last fetched
120- * operation in
115+ * Returns OplogStartMissing if we cannot find the optime of the last fetched operation in
121116 * the remote oplog.
122117 */
123118Status checkRemoteOplogStart (const Fetcher::Documents& documents, OpTimeWithHash lastFetched) {
124119 if (documents.empty ()) {
125- // The GTE query from upstream returns nothing, so we're ahead of the
126- // upstream.
120+ // The GTE query from upstream returns nothing, so we're ahead of the upstream.
127121 return Status (ErrorCodes::RemoteOplogStale,
128122 str::stream () << " We are ahead of the sync source. Our last op time fetched: "
129123 << lastFetched.opTime .toString ());
@@ -176,8 +170,7 @@ StatusWith<OplogFetcher::DocumentsInfo> OplogFetcher::validateDocuments(
176170 info.networkDocumentBytes += doc.objsize ();
177171 ++info.networkDocumentCount ;
178172
179- // If this is the first response (to the $gte query) then we already applied
180- // the first doc.
173+ // If this is the first response (to the $gte query) then we already applied the first doc.
181174 if (first && info.networkDocumentCount == 1U ) {
182175 continue ;
183176 }
@@ -208,8 +201,7 @@ StatusWith<OplogFetcher::DocumentsInfo> OplogFetcher::validateDocuments(
208201 info.toApplyDocumentCount = documents.size ();
209202 info.toApplyDocumentBytes = info.networkDocumentBytes ;
210203 if (first) {
211- // The count is one less since the first document found was already applied
212- // ($gte $ts query)
204+ // The count is one less since the first document found was already applied ($gte $ts query)
213205 // and we will not apply it again.
214206 --info.toApplyDocumentCount ;
215207 auto alreadyAppliedDocument = documents.cbegin ();
@@ -302,11 +294,9 @@ void OplogFetcher::_callback(const Fetcher::QueryResponseStatus& result,
302294 }
303295
304296 const auto & queryResponse = result.getValue ();
305- OpTime sourcesLastOpTime;
306- bool syncSourceHasSyncSource = false ;
297+ rpc::ReplSetMetadata metadata;
307298
308- // Forward metadata (containing liveness information) to data replicator
309- // external state.
299+ // Forward metadata (containing liveness information) to data replicator external state.
310300 bool receivedMetadata =
311301 queryResponse.otherFields .metadata .hasElement (rpc::kReplSetMetadataFieldName );
312302 if (receivedMetadata) {
@@ -318,10 +308,8 @@ void OplogFetcher::_callback(const Fetcher::QueryResponseStatus& result,
318308 _onShutdown (metadataResult.getStatus ());
319309 return ;
320310 }
321- auto metadata = metadataResult.getValue ();
311+ metadata = metadataResult.getValue ();
322312 _dataReplicatorExternalState->processMetadata (metadata);
323- sourcesLastOpTime = metadata.getLastOpVisible ();
324- syncSourceHasSyncSource = metadata.getSyncSourceIndex () != -1 ;
325313 }
326314
327315 const auto & documents = queryResponse.documents ;
@@ -337,8 +325,7 @@ void OplogFetcher::_callback(const Fetcher::QueryResponseStatus& result,
337325
338326 auto opTimeWithHash = getLastOpTimeWithHashFetched ();
339327
340- // Check start of remote oplog and, if necessary, stop fetcher to execute
341- // rollback.
328+ // Check start of remote oplog and, if necessary, stop fetcher to execute rollback.
342329 if (queryResponse.first ) {
343330 auto status = checkRemoteOplogStart (documents, opTimeWithHash);
344331 if (!status.isOK ()) {
@@ -347,8 +334,7 @@ void OplogFetcher::_callback(const Fetcher::QueryResponseStatus& result,
347334 return ;
348335 }
349336
350- // If this is the first batch and no rollback is needed, skip the first
351- // document.
337+ // If this is the first batch and no rollback is needed, skip the first document.
352338 firstDocToApply++;
353339 }
354340
@@ -373,14 +359,15 @@ void OplogFetcher::_callback(const Fetcher::QueryResponseStatus& result,
373359 _lastFetched = opTimeWithHash;
374360 }
375361
376- if (_dataReplicatorExternalState->shouldStopFetching (
377- _fetcher.getSource (), sourcesLastOpTime, syncSourceHasSyncSource)) {
362+ if (_dataReplicatorExternalState->shouldStopFetching (_fetcher.getSource (), metadata)) {
378363 _onShutdown (Status (ErrorCodes::InvalidSyncSource,
379364 str::stream () << " sync source " << _fetcher.getSource ().toString ()
380365 << " (last optime: "
381- << sourcesLastOpTime.toString ()
382- << " ; has sync source: "
383- << syncSourceHasSyncSource
366+ << metadata.getLastOpVisible ().toString ()
367+ << " ; sync source index: "
368+ << metadata.getSyncSourceIndex ()
369+ << " ; primary index: "
370+ << metadata.getPrimaryIndex ()
384371 << " ) is no longer valid" ),
385372 opTimeWithHash);
386373 return ;
@@ -407,5 +394,6 @@ void OplogFetcher::_onShutdown(Status status, OpTimeWithHash opTimeWithHash) {
407394 _onShutdownCallbackFn (status, opTimeWithHash);
408395}
409396
397+
410398} // namespace repl
411399} // namespace mongo
0 commit comments