summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/index_builds_coordinator.cpp49
-rw-r--r--src/mongo/db/index_builds_coordinator.h18
-rw-r--r--src/mongo/db/repl/SConscript2
-rw-r--r--src/mongo/db/repl/bgsync.cpp3
-rw-r--r--src/mongo/db/repl/replication_coordinator_external_state_impl.cpp3
5 files changed, 75 insertions, 0 deletions
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp
index 5f356c81111..295df777f6e 100644
--- a/src/mongo/db/index_builds_coordinator.cpp
+++ b/src/mongo/db/index_builds_coordinator.cpp
@@ -160,6 +160,29 @@ void logFailure(Status status,
<< replState->collectionUUID << " ): " << status;
}
+/**
+ * Iterates over index builds with the provided function.
+ */
+void forEachIndexBuild(
+ const std::vector<std::shared_ptr<ReplIndexBuildState>>& indexBuilds,
+ StringData logPrefix,
+ std::function<void(std::shared_ptr<ReplIndexBuildState> replState)> onIndexBuild) {
+ if (indexBuilds.empty()) {
+ return;
+ }
+
+ log() << logPrefix << "active index builds: " << indexBuilds.size();
+
+ for (auto replState : indexBuilds) {
+ std::string indexNamesStr;
+ str::joinStringDelim(replState->indexNames, &indexNamesStr, ',');
+ log() << logPrefix << replState->buildUUID << ": collection: " << replState->collectionUUID
+ << "; indexes: " << replState->indexNames.size() << " [" << indexNamesStr << "]";
+
+ onIndexBuild(replState);
+ }
+}
+
} // namespace
const auto getIndexBuildsCoord =
@@ -398,6 +421,21 @@ void IndexBuildsCoordinator::abortIndexBuildByBuildUUID(OperationContext* opCtx,
}
}
+void IndexBuildsCoordinator::onStepUp(OperationContext* opCtx) {
+ log() << "IndexBuildsCoordinator::onStepUp - this node is stepping up to primary";
+
+ auto indexBuilds = _getIndexBuilds();
+ auto onIndexBuild = [](std::shared_ptr<ReplIndexBuildState> replState) {};
+ forEachIndexBuild(indexBuilds, "IndexBuildsCoordinator::onStepUp - "_sd, onIndexBuild);
+}
+
+void IndexBuildsCoordinator::onRollback(OperationContext* opCtx) {
+ log() << "IndexBuildsCoordinator::onRollback - this node is entering the rollback state";
+ auto indexBuilds = _getIndexBuilds();
+ auto onIndexBuild = [](std::shared_ptr<ReplIndexBuildState> replState) {};
+ forEachIndexBuild(indexBuilds, "IndexBuildsCoordinator::onRollback - "_sd, onIndexBuild);
+}
+
void IndexBuildsCoordinator::recoverIndexBuilds() {
// TODO: not yet implemented.
}
@@ -1305,6 +1343,17 @@ StatusWith<std::shared_ptr<ReplIndexBuildState>> IndexBuildsCoordinator::_getInd
return it->second;
}
+std::vector<std::shared_ptr<ReplIndexBuildState>> IndexBuildsCoordinator::_getIndexBuilds() const {
+ std::vector<std::shared_ptr<ReplIndexBuildState>> indexBuilds;
+ {
+ stdx::unique_lock<Latch> lk(_mutex);
+ for (auto pair : _allIndexBuilds) {
+ indexBuilds.push_back(pair.second);
+ }
+ }
+ return indexBuilds;
+}
+
ScopedStopNewDatabaseIndexBuilds::ScopedStopNewDatabaseIndexBuilds(
IndexBuildsCoordinator* indexBuildsCoordinator, StringData dbName)
: _indexBuildsCoordinatorPtr(indexBuildsCoordinator), _dbName(dbName.toString()) {
diff --git a/src/mongo/db/index_builds_coordinator.h b/src/mongo/db/index_builds_coordinator.h
index 175c6bbad95..1c22bf9fec9 100644
--- a/src/mongo/db/index_builds_coordinator.h
+++ b/src/mongo/db/index_builds_coordinator.h
@@ -211,6 +211,18 @@ public:
const std::string& reason);
/**
+ * Invoked when the node enters the primary state.
+ * Unblocks index builds that have been waiting to commit/abort during the secondary state.
+ */
+ void onStepUp(OperationContext* opCtx);
+
+ /**
+ * Invoked when the node enters the rollback state.
+ * Unblocks index builds that have been waiting to commit/abort during the secondary state.
+ */
+ void onRollback(OperationContext* opCtx);
+
+ /**
* TODO: This is not yet implemented.
*/
virtual Status voteCommitIndexBuild(const UUID& buildUUID, const HostAndPort& hostAndPort) = 0;
@@ -418,6 +430,12 @@ protected:
*/
StatusWith<std::shared_ptr<ReplIndexBuildState>> _getIndexBuild(const UUID& buildUUID) const;
+ /**
+ * Returns a snapshot of active index builds. Since each index build state is reference counted,
+ * it is fine to examine the returned index builds without re-locking 'mutex'.
+ */
+ std::vector<std::shared_ptr<ReplIndexBuildState>> _getIndexBuilds() const;
+
// Protects the below state.
mutable Mutex _mutex = MONGO_MAKE_LATCH("IndexBuildsCoordinator::_mutex");
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript
index cc60be2e808..5069a772f10 100644
--- a/src/mongo/db/repl/SConscript
+++ b/src/mongo/db/repl/SConscript
@@ -128,6 +128,7 @@ env.Library(
'$BUILD_DIR/mongo/client/connection_pool',
'$BUILD_DIR/mongo/client/fetcher',
'$BUILD_DIR/mongo/db/concurrency/write_conflict_exception',
+ '$BUILD_DIR/mongo/db/index_builds_coordinator_interface',
'$BUILD_DIR/mongo/db/service_context',
'$BUILD_DIR/mongo/util/concurrency/thread_pool',
],
@@ -1197,6 +1198,7 @@ env.Library(
'repl_server_parameters',
'$BUILD_DIR/mongo/db/commands/mongod_fcv',
'$BUILD_DIR/mongo/db/commands/test_commands_enabled',
+ '$BUILD_DIR/mongo/db/index_builds_coordinator_interface',
],
)
diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp
index 497a0fefca9..39cb42f86f7 100644
--- a/src/mongo/db/repl/bgsync.cpp
+++ b/src/mongo/db/repl/bgsync.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/concurrency/replication_state_transition_lock_guard.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/dbhelpers.h"
+#include "mongo/db/index_builds_coordinator.h"
#include "mongo/db/repl/data_replicator_external_state_impl.h"
#include "mongo/db/repl/oplog.h"
#include "mongo/db/repl/oplog_interface_local.h"
@@ -633,6 +634,8 @@ void BackgroundSync::_runRollback(OperationContext* opCtx,
// are visible before potentially truncating the oplog.
storageInterface->waitForAllEarlierOplogWritesToBeVisible(opCtx);
+ IndexBuildsCoordinator::get(opCtx)->onRollback(opCtx);
+
auto storageEngine = opCtx->getServiceContext()->getStorageEngine();
if (!forceRollbackViaRefetch.load() && storageEngine->supportsRecoverToStableTimestamp()) {
log() << "Rollback using 'recoverToStableTimestamp' method.";
diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp
index e7489542f40..23611a79206 100644
--- a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp
@@ -53,6 +53,7 @@
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/free_mon/free_mon_mongod.h"
+#include "mongo/db/index_builds_coordinator.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/kill_sessions_local.h"
#include "mongo/db/logical_clock.h"
@@ -468,6 +469,8 @@ OpTime ReplicationCoordinatorExternalStateImpl::onTransitionToPrimary(OperationC
_dropAllTempCollections(opCtx);
+ IndexBuildsCoordinator::get(opCtx)->onStepUp(opCtx);
+
notifyFreeMonitoringOnTransitionToPrimary();
// It is only necessary to check the system indexes on the first transition to master.