summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2020-08-25 23:02:06 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-07 15:22:30 +0000
commit10859d92a95d27a86a5b216e7db3d3c6cacb31a6 (patch)
tree2dc648be7cc683a990c5ead0b29c65d019608342 /src/mongo/db/storage
parent3de4ca147e62d806bfc73852a8e1cd1fa65359d0 (diff)
downloadmongo-10859d92a95d27a86a5b216e7db3d3c6cacb31a6.tar.gz
SERVER-50045 JournalFlusher doesn't return ShutdownInProgress during rollback
(cherry picked from commit a751610b2eb005c0b47f6ad637f009f8aa9c8346)
Diffstat (limited to 'src/mongo/db/storage')
-rw-r--r--src/mongo/db/storage/control/journal_flusher.cpp7
-rw-r--r--src/mongo/db/storage/control/journal_flusher.h6
-rw-r--r--src/mongo/db/storage/control/storage_control.cpp4
-rw-r--r--src/mongo/db/storage/control/storage_control.h5
-rw-r--r--src/mongo/db/storage/storage_engine_init.cpp3
5 files changed, 15 insertions, 10 deletions
diff --git a/src/mongo/db/storage/control/journal_flusher.cpp b/src/mongo/db/storage/control/journal_flusher.cpp
index be9e993f2a0..00e225d426d 100644
--- a/src/mongo/db/storage/control/journal_flusher.cpp
+++ b/src/mongo/db/storage/control/journal_flusher.cpp
@@ -146,8 +146,8 @@ void JournalFlusher::run() {
if (_shuttingDown) {
LOGV2_DEBUG(4584702, 1, "stopping {name} thread", "name"_attr = name());
- _nextSharedPromise->setError(
- Status(ErrorCodes::ShutdownInProgress, "The storage catalog is being closed."));
+ invariant(!_shutdownReason.isOK());
+ _nextSharedPromise->setError(_shutdownReason);
stdx::lock_guard<Latch> lk(_opCtxMutex);
_uniqueCtx.reset();
return;
@@ -159,11 +159,12 @@ void JournalFlusher::run() {
}
}
-void JournalFlusher::shutdown() {
+void JournalFlusher::shutdown(const Status& reason) {
LOGV2(22320, "Shutting down journal flusher thread");
{
stdx::lock_guard<Latch> lk(_stateMutex);
_shuttingDown = true;
+ _shutdownReason = reason;
_flushJournalNowCV.notify_one();
}
wait();
diff --git a/src/mongo/db/storage/control/journal_flusher.h b/src/mongo/db/storage/control/journal_flusher.h
index f7b22f5cac2..4d1058b60e9 100644
--- a/src/mongo/db/storage/control/journal_flusher.h
+++ b/src/mongo/db/storage/control/journal_flusher.h
@@ -81,9 +81,10 @@ public:
void run();
/**
- * Signals the thread to quit and then waits until it does.
+ * Signals the thread to quit and then waits until it does. The given 'reason' is returned to
+ * any operations that were waiting for the journal to flush.
*/
- void shutdown();
+ void shutdown(const Status& reason);
/**
* Signals an immediate journal flush and leaves.
@@ -129,6 +130,7 @@ private:
bool _flushJournalNow = false;
bool _shuttingDown = false;
+ Status _shutdownReason = Status::OK();
// New callers get a future from nextSharedPromise. The JournalFlusher thread will swap that to
// currentSharedPromise at the start of every round of flushing, and reset nextSharedPromise
diff --git a/src/mongo/db/storage/control/storage_control.cpp b/src/mongo/db/storage/control/storage_control.cpp
index 5bb76bf327d..f0b7e7d825f 100644
--- a/src/mongo/db/storage/control/storage_control.cpp
+++ b/src/mongo/db/storage/control/storage_control.cpp
@@ -76,9 +76,9 @@ void startStorageControls(ServiceContext* serviceContext, bool forTestOnly) {
areControlsStarted = true;
}
-void stopStorageControls(ServiceContext* serviceContext) {
+void stopStorageControls(ServiceContext* serviceContext, const Status& reason) {
if (areControlsStarted) {
- JournalFlusher::get(serviceContext)->shutdown();
+ JournalFlusher::get(serviceContext)->shutdown(reason);
}
}
diff --git a/src/mongo/db/storage/control/storage_control.h b/src/mongo/db/storage/control/storage_control.h
index 83c62960151..ea868466d81 100644
--- a/src/mongo/db/storage/control/storage_control.h
+++ b/src/mongo/db/storage/control/storage_control.h
@@ -33,6 +33,7 @@ namespace mongo {
class OperationContext;
class ServiceContext;
+class Status;
/**
* Helper functions to manipulate independent processes that perform actions against the storage
@@ -54,13 +55,13 @@ namespace StorageControl {
void startStorageControls(ServiceContext* serviceContext, bool forTestOnly = false);
/**
- * Stops the processes begun by startStorageControls().
+ * Stops the processes begun by startStorageControls() and relays the reason to them.
*
* The JournalFlusher is shut down.
*
* Safe to call multiple times, whether or not startStorageControls() has been called.
*/
-void stopStorageControls(ServiceContext* serviceContext);
+void stopStorageControls(ServiceContext* serviceContext, const Status& reason);
} // namespace StorageControl
diff --git a/src/mongo/db/storage/storage_engine_init.cpp b/src/mongo/db/storage/storage_engine_init.cpp
index 5ee9d4a10ac..0d2a2940428 100644
--- a/src/mongo/db/storage/storage_engine_init.cpp
+++ b/src/mongo/db/storage/storage_engine_init.cpp
@@ -185,7 +185,8 @@ LastStorageEngineShutdownState initializeStorageEngine(ServiceContext* service,
void shutdownGlobalStorageEngineCleanly(ServiceContext* service) {
invariant(service->getStorageEngine());
- StorageControl::stopStorageControls(service);
+ StorageControl::stopStorageControls(
+ service, {ErrorCodes::ShutdownInProgress, "The storage catalog is being closed."});
service->getStorageEngine()->cleanShutdown();
auto& lockFile = StorageEngineLockFile::get(service);
if (lockFile) {