summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWilliam Schultz <william.schultz@mongodb.com>2018-01-25 17:37:52 -0500
committerWilliam Schultz <william.schultz@mongodb.com>2018-01-25 17:37:52 -0500
commit0ebed531c6506e8538858758a6af5b8eb9da7ed2 (patch)
treecfabef518d510a9ad80738d52d9a7bfd0bcd0452 /src
parenta917ca5b1691625d7a1e70e96672386bbf0a6243 (diff)
downloadmongo-0ebed531c6506e8538858758a6af5b8eb9da7ed2.tar.gz
Revert "SERVER-30818 Wait for all background index builds to complete before starting rollback to checkpoint"
This reverts commit 18eb990734653fc80f7d8c2916033e61ea7320e5.
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/background.cpp15
-rw-r--r--src/mongo/db/background.h11
-rw-r--r--src/mongo/db/catalog/index_create_impl.cpp13
-rw-r--r--src/mongo/db/repl/rollback_impl.cpp39
-rw-r--r--src/mongo/db/repl/rollback_impl.h15
5 files changed, 20 insertions, 73 deletions
diff --git a/src/mongo/db/background.cpp b/src/mongo/db/background.cpp
index d427c4db301..555062f7e63 100644
--- a/src/mongo/db/background.cpp
+++ b/src/mongo/db/background.cpp
@@ -124,14 +124,6 @@ bool BackgroundOperation::inProgForDb(StringData db) {
return dbsInProg.find(db) != dbsInProg.end();
}
-int BackgroundOperation::numInProgForDb(StringData db) {
- stdx::lock_guard<stdx::mutex> lk(m);
- std::shared_ptr<BgInfo> bgInfo = mapFindWithDefault(dbsInProg, db, std::shared_ptr<BgInfo>());
- if (!bgInfo)
- return 0;
- return bgInfo->getOpsInProgCount();
-}
-
bool BackgroundOperation::inProgForNs(StringData ns) {
stdx::lock_guard<stdx::mutex> lk(m);
return nsInProg.find(ns) != nsInProg.end();
@@ -155,6 +147,13 @@ void BackgroundOperation::assertNoBgOpInProgForNs(StringData ns) {
!inProgForNs(ns));
}
+void BackgroundOperation::awaitNoBgOpInProgForDbs(std::vector<StringData> dbs) {
+ stdx::unique_lock<stdx::mutex> lk(m);
+ for (auto db : dbs) {
+ awaitNoBgOps(lk, &dbsInProg, db);
+ }
+}
+
void BackgroundOperation::awaitNoBgOpInProgForDb(StringData db) {
stdx::unique_lock<stdx::mutex> lk(m);
awaitNoBgOps(lk, &dbsInProg, db);
diff --git a/src/mongo/db/background.h b/src/mongo/db/background.h
index acf0129efe7..1861e1b5f83 100644
--- a/src/mongo/db/background.h
+++ b/src/mongo/db/background.h
@@ -58,10 +58,19 @@ class BackgroundOperation {
public:
static bool inProgForDb(StringData db);
- static int numInProgForDb(StringData db);
static bool inProgForNs(StringData ns);
static void assertNoBgOpInProgForDb(StringData db);
static void assertNoBgOpInProgForNs(StringData ns);
+
+ /**
+ * Waits until there are no background operations in progress for all databases in the given
+ * list. This function assumes that while it is executing, no new background jobs are started on
+ * any of the given databases.
+ *
+ * @param dbs the list of all databases on which to wait for background operations to complete.
+ */
+ static void awaitNoBgOpInProgForDbs(std::vector<StringData> dbs);
+
static void awaitNoBgOpInProgForDb(StringData db);
static void awaitNoBgOpInProgForNs(StringData ns);
static void dump(std::ostream&);
diff --git a/src/mongo/db/catalog/index_create_impl.cpp b/src/mongo/db/catalog/index_create_impl.cpp
index 1b93f70d7bd..598fe9fa581 100644
--- a/src/mongo/db/catalog/index_create_impl.cpp
+++ b/src/mongo/db/catalog/index_create_impl.cpp
@@ -401,16 +401,9 @@ Status MultiIndexBlockImpl::insertAllDocumentsInCollection(std::set<RecordId>* d
"'hangAfterStartingIndexBuildUnlocked' failpoint";
sleepmillis(1000);
}
-
- if (_buildInBackground) {
- _opCtx->lockState()->restoreLockState(lockInfo);
- _opCtx->recoveryUnit()->abandonSnapshot();
- return Status(ErrorCodes::OperationFailed,
- "background index build aborted due to failpoint");
- } else {
- invariant(
- !"the hangAfterStartingIndexBuildUnlocked failpoint can't be turned off for foreground index builds");
- }
+ // If we want to support this, we'd need to regrab the lock and be sure that all callers are
+ // ok with us yielding. They should be for BG indexes, but not for foreground.
+ invariant(!"the hangAfterStartingIndexBuildUnlocked failpoint can't be turned off");
}
progress->finished();
diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp
index 63dfe97b02b..fa03b891526 100644
--- a/src/mongo/db/repl/rollback_impl.cpp
+++ b/src/mongo/db/repl/rollback_impl.cpp
@@ -32,7 +32,6 @@
#include "mongo/db/repl/rollback_impl.h"
-#include "mongo/db/background.h"
#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/logical_time_validator.h"
#include "mongo/db/operation_context.h"
@@ -92,13 +91,6 @@ Status RollbackImpl::runRollback(OperationContext* opCtx) {
}
_listener->onTransitionToRollback();
- // Wait for all background index builds to complete before starting the rollback process.
- status = _awaitBgIndexCompletion(opCtx);
- if (!status.isOK()) {
- return status;
- }
- _listener->onBgIndexesComplete();
-
auto commonPointSW = _findCommonPoint();
if (!commonPointSW.isOK()) {
return commonPointSW.getStatus();
@@ -188,37 +180,6 @@ Status RollbackImpl::_transitionToRollback(OperationContext* opCtx) {
return Status::OK();
}
-Status RollbackImpl::_awaitBgIndexCompletion(OperationContext* opCtx) {
- invariant(opCtx);
- if (_isInShutdown()) {
- return Status(ErrorCodes::ShutdownInProgress, "rollback shutting down");
- }
-
- // Get a list of all databases.
- StorageEngine* storageEngine = opCtx->getServiceContext()->getGlobalStorageEngine();
- std::vector<std::string> dbs;
- {
- Lock::GlobalLock lk(opCtx, MODE_IS, UINT_MAX);
- storageEngine->listDatabases(&dbs);
- }
-
- // Wait for all background operations to complete by waiting on each database.
- std::vector<StringData> dbNames(dbs.begin(), dbs.end());
- log() << "Waiting for all background operations to complete before starting rollback";
- for (auto db : dbNames) {
- LOG(1) << "Waiting for " << BackgroundOperation::numInProgForDb(db)
- << " background operations to complete on database '" << db << "'";
- BackgroundOperation::awaitNoBgOpInProgForDb(db);
- // Check for shutdown again.
- if (_isInShutdown()) {
- return Status(ErrorCodes::ShutdownInProgress, "rollback shutting down");
- }
- }
-
- log() << "Finished waiting for background operations to complete before rollback";
- return Status::OK();
-}
-
StatusWith<Timestamp> RollbackImpl::_findCommonPoint() {
if (_isInShutdown()) {
return Status(ErrorCodes::ShutdownInProgress, "rollback shutting down");
diff --git a/src/mongo/db/repl/rollback_impl.h b/src/mongo/db/repl/rollback_impl.h
index c88899e70b0..b8a6b5b04cf 100644
--- a/src/mongo/db/repl/rollback_impl.h
+++ b/src/mongo/db/repl/rollback_impl.h
@@ -100,11 +100,6 @@ public:
virtual void onTransitionToRollback() noexcept {}
/**
- * Function called after all background index builds have completed.
- */
- virtual void onBgIndexesComplete() noexcept {}
-
- /**
* Function called after we find the common point.
*/
virtual void onCommonPointFound(Timestamp commonPoint) noexcept {}
@@ -174,16 +169,6 @@ private:
Status _transitionToRollback(OperationContext* opCtx);
/**
- * Waits for any in-progress background index builds to complete. We do this before beginning
- * the rollback process to prevent any issues surrounding index builds pausing/resuming around a
- * call to 'recoverToStableTimestamp'. It's not clear that an index build, resumed in this way,
- * that continues until completion, would be consistent with the collection data. Waiting for
- * all background index builds to complete is a conservative approach, to avoid any of these
- * potential issues.
- */
- Status _awaitBgIndexCompletion(OperationContext* opCtx);
-
- /**
* Recovers to the stable timestamp while holding the global exclusive lock.
*/
Status _recoverToStableTimestamp(OperationContext* opCtx);