Skip to content

Commit 9867626

Browse files
mtrussottoevergreen
authored andcommitted
SERVER-43805 Create InitialSyncSharedData structure.
1 parent b3b494a commit 9867626

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright (C) 2019-present MongoDB, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the Server Side Public License, version 1,
6+
* as published by MongoDB, Inc.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* Server Side Public License for more details.
12+
*
13+
* You should have received a copy of the Server Side Public License
14+
* along with this program. If not, see
15+
* <http://www.mongodb.com/licensing/server-side-public-license>.
16+
*
17+
* As a special exception, the copyright holders give permission to link the
18+
* code of portions of this program with the OpenSSL library under certain
19+
* conditions as described in each individual source file and distribute
20+
* linked combinations including the program with the OpenSSL library. You
21+
* must comply with the Server Side Public License in all respects for
22+
* all of the code used other than as permitted herein. If you modify file(s)
23+
* with this exception, you may extend this exception to your version of the
24+
* file(s), but you are not obligated to do so. If you do not wish to do so,
25+
* delete this exception statement from your version. If you delete this
26+
* exception statement from all source files in the program, then also delete
27+
* it in the license file.
28+
*/
29+
30+
#pragma once
31+
32+
#include <mutex>
33+
34+
35+
#include "mongo/base/status.h"
36+
#include "mongo/base/string_data.h"
37+
#include "mongo/db/server_options.h"
38+
#include "mongo/platform/mutex.h"
39+
40+
namespace mongo {
41+
struct InitialSyncSharedData {
42+
InitialSyncSharedData(ServerGlobalParams::FeatureCompatibility::Version inFCV, int inRollbackId)
43+
: FCV(inFCV), rollBackId(inRollbackId) {}
44+
45+
// The const members above the mutex may be accessed without the mutex.
46+
47+
// Sync source FCV at start of initial sync.
48+
const ServerGlobalParams::FeatureCompatibility::Version FCV;
49+
50+
// Rollback ID at start of initial sync
51+
const int rollBackId;
52+
53+
// This mutex controls access to all members below it.
54+
mutable Mutex mutex = MONGO_MAKE_LATCH("InitialSyncSharedData::mutex"_sd);
55+
56+
// Status of the entire initial sync. All initial sync tasks should exit if this becomes
57+
// non-OK.
58+
Status initialSyncStatus = Status::OK();
59+
};
60+
} // namespace mongo

src/mongo/db/repl/initial_syncer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ void InitialSyncer::_cancelRemainingWork_inlock() {
271271
_cancelHandle_inlock(_getNextApplierBatchHandle);
272272

273273
_shutdownComponent_inlock(_oplogFetcher);
274+
if (_sharedData) {
275+
stdx::lock_guard<Latch>(_sharedData->mutex);
276+
if (_sharedData->initialSyncStatus.isOK()) {
277+
_sharedData->initialSyncStatus =
278+
Status{ErrorCodes::CallbackCanceled, "Initial sync attempt canceled"};
279+
}
280+
}
274281
if (_initialSyncState) {
275282
_shutdownComponent_inlock(_initialSyncState->dbsCloner);
276283
}
@@ -853,6 +860,7 @@ void InitialSyncer::_fcvFetcherCallback(const StatusWith<Fetcher::QueryResponse>
853860
// This is where the flow of control starts to split into two parallel tracks:
854861
// - oplog fetcher
855862
// - data cloning and applier
863+
_sharedData = std::make_unique<InitialSyncSharedData>(version, _rollbackChecker->getBaseRBID());
856864
auto listDatabasesFilter = [](BSONObj dbInfo) {
857865
std::string name;
858866
auto status = mongo::bsonExtractStringField(dbInfo, "name", &name);

src/mongo/db/repl/initial_syncer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "mongo/db/repl/collection_cloner.h"
4545
#include "mongo/db/repl/data_replicator_external_state.h"
4646
#include "mongo/db/repl/database_cloner.h"
47+
#include "mongo/db/repl/initial_sync_shared_data.h"
4748
#include "mongo/db/repl/multiapplier.h"
4849
#include "mongo/db/repl/oplog_applier.h"
4950
#include "mongo/db/repl/oplog_buffer.h"
@@ -640,6 +641,8 @@ class InitialSyncer {
640641
// Contains stats on the current initial sync request (includes all attempts).
641642
// To access these stats in a user-readable format, use getInitialSyncProgress().
642643
Stats _stats; // (M)
644+
// Data shared by cloners and fetcher. Follow InitialSyncSharedData synchronization rules.
645+
std::unique_ptr<InitialSyncSharedData> _sharedData; // (S)
643646
};
644647

645648
} // namespace repl

0 commit comments

Comments
 (0)