summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthew Russotto <matthew.russotto@mongodb.com>2019-10-16 19:33:35 +0000
committerevergreen <evergreen@mongodb.com>2019-10-16 19:33:35 +0000
commit98676262fd8ae528f63fd4f299a2fc4d90d449e4 (patch)
tree749d66e30b0965ce86591f2c56ad7595eed19ef5 /src
parentb3b494a72f0e19d7556bee627da7ae9b79e26a03 (diff)
downloadmongo-98676262fd8ae528f63fd4f299a2fc4d90d449e4.tar.gz
SERVER-43805 Create InitialSyncSharedData structure.
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/repl/initial_sync_shared_data.h60
-rw-r--r--src/mongo/db/repl/initial_syncer.cpp8
-rw-r--r--src/mongo/db/repl/initial_syncer.h3
3 files changed, 71 insertions, 0 deletions
diff --git a/src/mongo/db/repl/initial_sync_shared_data.h b/src/mongo/db/repl/initial_sync_shared_data.h
new file mode 100644
index 00000000000..841b83ba82b
--- /dev/null
+++ b/src/mongo/db/repl/initial_sync_shared_data.h
@@ -0,0 +1,60 @@
+/**
+ * Copyright (C) 2019-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * 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
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * 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 Server Side 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 <mutex>
+
+
+#include "mongo/base/status.h"
+#include "mongo/base/string_data.h"
+#include "mongo/db/server_options.h"
+#include "mongo/platform/mutex.h"
+
+namespace mongo {
+struct InitialSyncSharedData {
+ InitialSyncSharedData(ServerGlobalParams::FeatureCompatibility::Version inFCV, int inRollbackId)
+ : FCV(inFCV), rollBackId(inRollbackId) {}
+
+ // The const members above the mutex may be accessed without the mutex.
+
+ // Sync source FCV at start of initial sync.
+ const ServerGlobalParams::FeatureCompatibility::Version FCV;
+
+ // Rollback ID at start of initial sync
+ const int rollBackId;
+
+ // This mutex controls access to all members below it.
+ mutable Mutex mutex = MONGO_MAKE_LATCH("InitialSyncSharedData::mutex"_sd);
+
+ // Status of the entire initial sync. All initial sync tasks should exit if this becomes
+ // non-OK.
+ Status initialSyncStatus = Status::OK();
+};
+} // namespace mongo
diff --git a/src/mongo/db/repl/initial_syncer.cpp b/src/mongo/db/repl/initial_syncer.cpp
index 6f1c1615e9a..48ef80f92b6 100644
--- a/src/mongo/db/repl/initial_syncer.cpp
+++ b/src/mongo/db/repl/initial_syncer.cpp
@@ -271,6 +271,13 @@ void InitialSyncer::_cancelRemainingWork_inlock() {
_cancelHandle_inlock(_getNextApplierBatchHandle);
_shutdownComponent_inlock(_oplogFetcher);
+ if (_sharedData) {
+ stdx::lock_guard<Latch>(_sharedData->mutex);
+ if (_sharedData->initialSyncStatus.isOK()) {
+ _sharedData->initialSyncStatus =
+ Status{ErrorCodes::CallbackCanceled, "Initial sync attempt canceled"};
+ }
+ }
if (_initialSyncState) {
_shutdownComponent_inlock(_initialSyncState->dbsCloner);
}
@@ -853,6 +860,7 @@ void InitialSyncer::_fcvFetcherCallback(const StatusWith<Fetcher::QueryResponse>
// This is where the flow of control starts to split into two parallel tracks:
// - oplog fetcher
// - data cloning and applier
+ _sharedData = std::make_unique<InitialSyncSharedData>(version, _rollbackChecker->getBaseRBID());
auto listDatabasesFilter = [](BSONObj dbInfo) {
std::string name;
auto status = mongo::bsonExtractStringField(dbInfo, "name", &name);
diff --git a/src/mongo/db/repl/initial_syncer.h b/src/mongo/db/repl/initial_syncer.h
index 80c702cde7f..406c89352bb 100644
--- a/src/mongo/db/repl/initial_syncer.h
+++ b/src/mongo/db/repl/initial_syncer.h
@@ -44,6 +44,7 @@
#include "mongo/db/repl/collection_cloner.h"
#include "mongo/db/repl/data_replicator_external_state.h"
#include "mongo/db/repl/database_cloner.h"
+#include "mongo/db/repl/initial_sync_shared_data.h"
#include "mongo/db/repl/multiapplier.h"
#include "mongo/db/repl/oplog_applier.h"
#include "mongo/db/repl/oplog_buffer.h"
@@ -640,6 +641,8 @@ private:
// Contains stats on the current initial sync request (includes all attempts).
// To access these stats in a user-readable format, use getInitialSyncProgress().
Stats _stats; // (M)
+ // Data shared by cloners and fetcher. Follow InitialSyncSharedData synchronization rules.
+ std::unique_ptr<InitialSyncSharedData> _sharedData; // (S)
};
} // namespace repl