Skip to content

Commit b31482d

Browse files
wh5aMongoDB Bot
authored andcommitted
SERVER-103934 FCBIS should shutdown storage engine without leaking memory (#37853)
GitOrigin-RevId: f673992c06e5bb331e0c4ccc4c700b6ed3101ae8
1 parent 41e6943 commit b31482d

24 files changed

+111
-69
lines changed

src/mongo/db/mongod_main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2073,7 +2073,8 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
20732073
"Shut down the storage engine",
20742074
&shutdownTimeElapsedBuilder);
20752075
LOGV2(4784930, "Shutting down the storage engine");
2076-
shutdownGlobalStorageEngineCleanly(serviceContext);
2076+
// Allow memory leak for faster shutdown.
2077+
shutdownGlobalStorageEngineCleanly(serviceContext, true /* memLeakAllowed */);
20772078
}
20782079

20792080
{

src/mongo/db/op_msg_fuzzer_fixture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ OpMsgFuzzerFixture::~OpMsgFuzzerFixture() {
160160
databaseHolder->closeAll(opCtx.get());
161161
}
162162

163-
shutdownGlobalStorageEngineCleanly(_serviceContext);
163+
shutdownGlobalStorageEngineCleanly(_serviceContext, true /* memLeakAllowed */);
164164
}
165165

166166
int OpMsgFuzzerFixture::testOneInput(const char* Data, size_t Size) {

src/mongo/db/repl/oplog_application_bm.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
#include "mongo/util/clock_source_mock.h"
111111
#include "mongo/util/concurrency/thread_pool.h"
112112
#include "mongo/util/duration.h"
113-
#include "mongo/util/fail_point.h"
114113
#include "mongo/util/periodic_runner.h"
115114
#include "mongo/util/periodic_runner_factory.h"
116115
#include "mongo/util/time_support.h"
@@ -179,9 +178,6 @@ class TestServiceContext {
179178
repl::ReplicationCoordinator::set(
180179
_svcCtx, std::unique_ptr<repl::ReplicationCoordinator>(_replCoord));
181180

182-
// Disable fast shutdown so that WT can free memory.
183-
globalFailPointRegistry().find("WTDisableFastShutDown")->setMode(FailPoint::alwaysOn);
184-
185181
{
186182
auto initializeStorageEngineOpCtx = _svcCtx->makeOperationContext(&cc());
187183
shard_role_details::setRecoveryUnit(
@@ -259,8 +255,8 @@ class TestServiceContext {
259255
auto databaseHolder = DatabaseHolder::get(opCtx);
260256
databaseHolder->closeAll(opCtx);
261257

262-
// Shut down storage engine.
263-
shutdownGlobalStorageEngineCleanly(_svcCtx);
258+
// Shut down storage engine and free memory.
259+
shutdownGlobalStorageEngineCleanly(_svcCtx, false /* memLeakAllowed */);
264260
}
265261

266262
// Shut down the storage engine, clear the dbpath, and restart the storage engine with empty

src/mongo/db/repl/oplog_write_bm.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
#include "mongo/util/clock_source_mock.h"
113113
#include "mongo/util/concurrency/thread_pool.h"
114114
#include "mongo/util/duration.h"
115-
#include "mongo/util/fail_point.h"
116115
#include "mongo/util/periodic_runner.h"
117116
#include "mongo/util/periodic_runner_factory.h"
118117
#include "mongo/util/time_support.h"
@@ -180,9 +179,6 @@ class TestServiceContext {
180179
repl::ReplicationCoordinator::set(
181180
_svcCtx, std::unique_ptr<repl::ReplicationCoordinator>(_replCoord));
182181

183-
// Disable fast shutdown so that WT can free memory.
184-
globalFailPointRegistry().find("WTDisableFastShutDown")->setMode(FailPoint::alwaysOn);
185-
186182
auto startupOpCtx = _svcCtx->makeOperationContext(&cc());
187183
initializeStorageEngine(startupOpCtx.get(),
188184
StorageEngineInitFlags::kAllowNoLockFile |
@@ -250,8 +246,8 @@ class TestServiceContext {
250246
auto databaseHolder = DatabaseHolder::get(opCtx);
251247
databaseHolder->closeAll(opCtx);
252248

253-
// Shut down storage engine.
254-
shutdownGlobalStorageEngineCleanly(_svcCtx);
249+
// Shut down storage engine and free memory.
250+
shutdownGlobalStorageEngineCleanly(_svcCtx, false /* memLeakAllowed */);
255251
}
256252

257253
// Shut down the storage engine, clear the dbpath, and restart the storage engine with empty

src/mongo/db/service_context_d_test_fixture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ ServiceContextMongoDTest::~ServiceContextMongoDTest() {
204204
databaseHolder->closeAll(opCtx);
205205
}
206206

207-
shutdownGlobalStorageEngineCleanly(getServiceContext());
207+
shutdownGlobalStorageEngineCleanly(getServiceContext(), true /* memLeakAllowed */);
208208

209209
std::swap(storageGlobalParams.engine, _stashedStorageParams.engine);
210210
std::swap(storageGlobalParams.engineSetByUser, _stashedStorageParams.engineSetByUser);

src/mongo/db/storage/SConscript

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# -*- mode: python -*-
2-
Import("env")
2+
Import([
3+
"env",
4+
"use_system_version_of_library",
5+
])
36

47
env = env.Clone()
58

@@ -654,6 +657,9 @@ env.Library(
654657
],
655658
)
656659

660+
if not use_system_version_of_library('valgrind'):
661+
env.InjectThirdParty('valgrind')
662+
657663
env.Library(
658664
target='storage_engine_impl',
659665
source=[

src/mongo/db/storage/devnull/devnull_kv_engine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class DevNullKVEngine : public KVEngine {
165165
return std::vector<std::string>();
166166
}
167167

168-
void cleanShutdown() override {}
168+
void cleanShutdown(bool memLeakAllowed) override {}
169169

170170
void setJournalListener(JournalListener* jl) override {}
171171

src/mongo/db/storage/kv/kv_drop_pending_ident_reaper_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class KVEngineMock : public KVEngine {
160160
std::vector<std::string> getAllIdents(OperationContext* opCtx) const override {
161161
return {};
162162
}
163-
void cleanShutdown() override {}
163+
void cleanShutdown(bool memLeakAllowed) override {}
164164
void setJournalListener(JournalListener* jl) override {}
165165
Timestamp getAllDurableTimestamp() const override {
166166
return {};

src/mongo/db/storage/kv/kv_engine.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,12 @@ class KVEngine {
321321
* override this method if they have clean-up to do that is different from unclean shutdown.
322322
* MongoDB will not call into the storage subsystem after calling this function.
323323
*
324+
* The storage engine is allowed to leak memory for faster shutdown, except when the process is
325+
* not exiting or when running tools to look for memory leaks.
326+
*
324327
* There is intentionally no uncleanShutdown().
325328
*/
326-
virtual void cleanShutdown() = 0;
329+
virtual void cleanShutdown(bool memLeakAllowed) = 0;
327330

328331
/**
329332
* Return the SnapshotManager for this KVEngine or NULL if not supported.

src/mongo/db/storage/kv/storage_engine_test.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,12 @@ class TimestampKVEngineTest : public ServiceContextTest {
656656
}
657657

658658
void tearDown() override {
659-
_storageEngine->cleanShutdown(getServiceContext());
659+
#if __has_feature(address_sanitizer)
660+
constexpr bool memLeakAllowed = false;
661+
#else
662+
constexpr bool memLeakAllowed = true;
663+
#endif
664+
_storageEngine->cleanShutdown(getServiceContext(), memLeakAllowed);
660665
_storageEngine.reset();
661666

662667
ServiceContextTest::tearDown();

0 commit comments

Comments
 (0)