Skip to content

Commit 164e785

Browse files
author
Dianna Hohensee
committed
SERVER-41560 default the snapshot window size to 0 when running with the WT inMemory storage engine
1 parent b919815 commit 164e785

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

src/mongo/db/SConscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,7 @@ env.Library(
14021402
],
14031403
LIBDEPS_PRIVATE=[
14041404
'snapshot_window_options',
1405+
'$BUILD_DIR/mongo/db/commands/test_commands_enabled',
14051406
'$BUILD_DIR/mongo/db/service_context',
14061407
],
14071408
)

src/mongo/db/db.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,11 @@ ExitCode _initAndListen(int listenPort) {
611611
// release periodically in order to avoid storage cache pressure build up.
612612
if (storageEngine->supportsReadConcernSnapshot()) {
613613
PeriodicThreadToAbortExpiredTransactions::get(serviceContext)->start();
614-
PeriodicThreadToDecreaseSnapshotHistoryCachePressure::get(serviceContext)->start();
614+
// The inMemory engine is not yet used for replica or sharded transactions in production so
615+
// it does not currently maintain snapshot history. It is live in testing, however.
616+
if (!storageEngine->isEphemeral() || getTestCommandsEnabled()) {
617+
PeriodicThreadToDecreaseSnapshotHistoryCachePressure::get(serviceContext)->start();
618+
}
615619
}
616620

617621
// Set up the logical session cache

src/mongo/db/snapshot_window_util.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include "mongo/db/snapshot_window_util.h"
3535

36+
#include "mongo/db/commands/test_commands_enabled.h"
3637
#include "mongo/db/operation_context.h"
3738
#include "mongo/db/service_context.h"
3839
#include "mongo/db/snapshot_window_options.h"
@@ -109,6 +110,7 @@ void increaseTargetSnapshotWindowSize(OperationContext* opCtx) {
109110
// the window size.
110111
StorageEngine* engine = opCtx->getServiceContext()->getStorageEngine();
111112
if (engine && engine->isCacheUnderPressure(opCtx)) {
113+
invariant(!engine->isEphemeral() || getTestCommandsEnabled());
112114
warning() << "Attempted to increase the time window of available snapshots for "
113115
"point-in-time operations (readConcern level 'snapshot' or transactions), but "
114116
"the storage engine cache pressure, per the cachePressureThreshold setting of "
@@ -152,6 +154,7 @@ void decreaseTargetSnapshotWindowSize(OperationContext* opCtx) {
152154

153155
StorageEngine* engine = opCtx->getServiceContext()->getStorageEngine();
154156
if (engine && engine->isCacheUnderPressure(opCtx)) {
157+
invariant(!engine->isEphemeral() || getTestCommandsEnabled());
155158
_decreaseTargetSnapshotWindowSize(lock, opCtx);
156159
}
157160
}

src/mongo/db/snapshot_window_util_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "mongo/db/snapshot_window_util.h"
3333

3434
#include "mongo/db/client.h"
35+
#include "mongo/db/commands/test_commands_enabled.h"
3536
#include "mongo/db/service_context.h"
3637
#include "mongo/db/service_context_devnull_test_fixture.h"
3738
#include "mongo/db/snapshot_window_options.h"
@@ -51,6 +52,7 @@ class SnapshotWindowTest : public ServiceContextDevnullTestFixture {
5152
void setUp() override {
5253
ServiceContextDevnullTestFixture::setUp();
5354
_opCtx = cc().makeOperationContext();
55+
setTestCommandsEnabled(true);
5456
}
5557

5658
void tearDown() override {

src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,13 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName,
684684
_checkpointThread->go();
685685
}
686686

687+
if (_ephemeral && !getTestCommandsEnabled()) {
688+
// We do not maintain any snapshot history for the ephemeral storage engine in production
689+
// because replication and sharded transactions do not currently run on the inMemory engine.
690+
// It is live in testing, however.
691+
snapshotWindowParams.targetSnapshotHistoryWindowInSeconds.store(0);
692+
}
693+
687694
_sizeStorerUri = _uri("sizeStorer");
688695
WiredTigerSession session(_conn);
689696
if (!_readOnly && repair && _hasUri(session.getSession(), _sizeStorerUri)) {
@@ -1675,6 +1682,11 @@ Timestamp WiredTigerKVEngine::_calculateHistoryLagFromStableTimestamp(Timestamp
16751682
// The oldest_timestamp should lag behind the stable_timestamp by
16761683
// 'targetSnapshotHistoryWindowInSeconds' seconds.
16771684

1685+
if (_ephemeral && !getTestCommandsEnabled()) {
1686+
// No history should be maintained for the inMemory engine because it is not used yet.
1687+
invariant(snapshotWindowParams.targetSnapshotHistoryWindowInSeconds.load() == 0);
1688+
}
1689+
16781690
if (stableTimestamp.getSecs() <
16791691
static_cast<unsigned>(snapshotWindowParams.targetSnapshotHistoryWindowInSeconds.load())) {
16801692
// The history window is larger than the timestamp history thus far. We must wait for

0 commit comments

Comments
 (0)