From 84fd6eb9c0a700329dc0750261d05dd6741791cc Mon Sep 17 00:00:00 2001 From: Lingzhi Deng Date: Thu, 7 May 2020 16:21:38 -0400 Subject: SERVER-47997: Remove cachePressureThreshold and isCacheUnderPressure --- jstests/noPassthrough/snapshot_history_window.js | 6 ++ src/mongo/db/SConscript | 2 - src/mongo/db/service_entry_point_common.cpp | 16 +----- src/mongo/db/snapshot_window_options.cpp | 38 ------------- src/mongo/db/snapshot_window_options.h | 64 ---------------------- src/mongo/db/snapshot_window_options.idl | 14 +---- src/mongo/db/storage/biggie/SConscript | 1 - src/mongo/db/storage/biggie/biggie_kv_engine.cpp | 5 -- src/mongo/db/storage/biggie/biggie_kv_engine.h | 6 -- src/mongo/db/storage/devnull/SConscript | 3 - src/mongo/db/storage/devnull/devnull_kv_engine.cpp | 10 ---- src/mongo/db/storage/devnull/devnull_kv_engine.h | 4 -- src/mongo/db/storage/kv/kv_engine.h | 12 ---- src/mongo/db/storage/storage_engine.h | 15 ----- src/mongo/db/storage/storage_engine_impl.cpp | 8 --- src/mongo/db/storage/storage_engine_impl.h | 4 -- src/mongo/db/storage/storage_engine_mock.h | 5 +- .../db/storage/wiredtiger/wiredtiger_kv_engine.cpp | 24 +++----- .../db/storage/wiredtiger/wiredtiger_kv_engine.h | 2 - .../wiredtiger/wiredtiger_recovery_unit.cpp | 5 ++ .../storage/wiredtiger/wiredtiger_recovery_unit.h | 2 + .../wiredtiger/wiredtiger_recovery_unit_test.cpp | 42 -------------- .../db/storage/wiredtiger/wiredtiger_util.cpp | 12 +--- src/mongo/db/storage/wiredtiger/wiredtiger_util.h | 7 +-- 24 files changed, 30 insertions(+), 277 deletions(-) delete mode 100644 src/mongo/db/snapshot_window_options.cpp delete mode 100644 src/mongo/db/snapshot_window_options.h diff --git a/jstests/noPassthrough/snapshot_history_window.js b/jstests/noPassthrough/snapshot_history_window.js index 02e50fd622b..391af8b8372 100644 --- a/jstests/noPassthrough/snapshot_history_window.js +++ b/jstests/noPassthrough/snapshot_history_window.js @@ -60,5 +60,11 @@ assert.commandFailedWithCode( {find: collName, readConcern: {level: "snapshot", atClusterTime: insertTimestamp}}), ErrorCodes.SnapshotTooOld); +// Test that the SnapshotTooOld is recorded in serverStatus. +const serverStatusWT = assert.commandWorked(primaryDB.adminCommand({serverStatus: 1})).wiredTiger; +assert.eq(1, + serverStatusWT["snapshot-window-settings"]["total number of SnapshotTooOld errors"], + tojson(serverStatusWT)); + replSet.stopSet(); })(); diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 9519d1207f1..cbe71aab431 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -816,7 +816,6 @@ env.Library( 'introspect', 'lasterror', 'query_exec', - 'snapshot_window_options', 'transaction', '$BUILD_DIR/mongo/db/audit', '$BUILD_DIR/mongo/db/auth/auth', @@ -1467,7 +1466,6 @@ env.Library( env.Library( target='snapshot_window_options', source=[ - 'snapshot_window_options.cpp', env.Idlc('snapshot_window_options.idl')[0], ], LIBDEPS_PRIVATE=[ diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp index 0a3072214e9..9f0349a2f20 100644 --- a/src/mongo/db/service_entry_point_common.cpp +++ b/src/mongo/db/service_entry_point_common.cpp @@ -76,7 +76,6 @@ #include "mongo/db/s/transaction_coordinator_factory.h" #include "mongo/db/service_entry_point_common.h" #include "mongo/db/session_catalog_mongod.h" -#include "mongo/db/snapshot_window_options.h" #include "mongo/db/stats/counters.h" #include "mongo/db/stats/server_read_concern_metrics.h" #include "mongo/db/stats/top.h" @@ -1228,20 +1227,7 @@ void execCommandDatabase(OperationContext* opCtx, throw; } } catch (const DBException& e) { - if (e.code() == ErrorCodes::SnapshotTooOld) { - // SnapshotTooOld errors should never be thrown unless we are using a storage engine - // that supports snapshot read concern. - auto engine = opCtx->getServiceContext()->getStorageEngine(); - invariant(engine && engine->supportsReadConcernSnapshot()); - - // SnapshotTooOld errors indicate that PIT ops are failing to find an available - // snapshot at their specified atClusterTime. Therefore, we'll try to increase the - // snapshot history window that the storage engine maintains in order to increase - // the likelihood of successful future PIT atClusterTime requests. - snapshotWindowParams.snapshotTooOldErrorCount.addAndFetch(1); - } else { - behaviors.handleException(e, opCtx); - } + behaviors.handleException(e, opCtx); // Append the error labels for transient transaction errors. auto response = extraFieldsBuilder.asTempObj(); diff --git a/src/mongo/db/snapshot_window_options.cpp b/src/mongo/db/snapshot_window_options.cpp deleted file mode 100644 index 04814862e2c..00000000000 --- a/src/mongo/db/snapshot_window_options.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include "mongo/db/snapshot_window_options.h" - -namespace mongo { - -SnapshotWindowParams snapshotWindowParams; - -} // namespace mongo diff --git a/src/mongo/db/snapshot_window_options.h b/src/mongo/db/snapshot_window_options.h deleted file mode 100644 index dafeee5b28e..00000000000 --- a/src/mongo/db/snapshot_window_options.h +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#include "mongo/idl/mutable_observer_registry.h" -#include "mongo/platform/atomic_proxy.h" -#include "mongo/platform/atomic_word.h" - -namespace mongo { - -/** - * These are parameters that affect how much snapshot history the storage engine will keep to - * support snapshot reads. This is referred to as the snapshot window. The window is between the - * stable timestamp and the oldest timestamp. - */ -struct SnapshotWindowParams { - - // minSnapshotHistoryWindowInSeconds (startup & runtime server parameter, range 0+). - // - // Dictates the lag in seconds oldest_timestamp should be set behind stable_timestamp. - // - // Note that the window size can become greater than this if an ongoing operation is holding an - // older snapshot open. - AtomicWord minSnapshotHistoryWindowInSeconds{5}; - - // cachePressureThreshold (startup & runtime server parameter, range [0, 100]). - // - // Compares against a storage engine cache pressure indicator that ranges from 0 to 100. - // Currently, the only indicator is the WT lookaside score. - AtomicWord cachePressureThreshold{95}; - - AtomicWord snapshotTooOldErrorCount{0}; -}; - -extern SnapshotWindowParams snapshotWindowParams; - -} // namespace mongo diff --git a/src/mongo/db/snapshot_window_options.idl b/src/mongo/db/snapshot_window_options.idl index 97af09647a2..a5eae77268c 100644 --- a/src/mongo/db/snapshot_window_options.idl +++ b/src/mongo/db/snapshot_window_options.idl @@ -28,8 +28,6 @@ global: cpp_namespace: "mongo" - cpp_includes: - - "mongo/db/snapshot_window_options.h" imports: - "mongo/idl/basic_types.idl" @@ -38,13 +36,7 @@ server_parameters: minSnapshotHistoryWindowInSeconds: description: "Minimum snapshot history to keep, in seconds" set_at: [ startup, runtime ] - cpp_varname: "snapshotWindowParams.minSnapshotHistoryWindowInSeconds" + cpp_vartype: AtomicWord + cpp_varname: minSnapshotHistoryWindowInSeconds + default: 5 validator: { gte: 0 } - - cachePressureThreshold: - description: "Cache pressure threshold" - set_at: [ startup, runtime ] - cpp_varname: "snapshotWindowParams.cachePressureThreshold" - validator: - gte: 0 - lte: 100 diff --git a/src/mongo/db/storage/biggie/SConscript b/src/mongo/db/storage/biggie/SConscript index 11706d48971..f96f7e7c249 100644 --- a/src/mongo/db/storage/biggie/SConscript +++ b/src/mongo/db/storage/biggie/SConscript @@ -22,7 +22,6 @@ env.Library( ], LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/db/storage/key_string', - '$BUILD_DIR/mongo/db/snapshot_window_options', '$BUILD_DIR/mongo/db/storage/oplog_hack', '$BUILD_DIR/mongo/db/storage/write_unit_of_work', ], diff --git a/src/mongo/db/storage/biggie/biggie_kv_engine.cpp b/src/mongo/db/storage/biggie/biggie_kv_engine.cpp index 3e77b6a8cf3..7c83398126b 100644 --- a/src/mongo/db/storage/biggie/biggie_kv_engine.cpp +++ b/src/mongo/db/storage/biggie/biggie_kv_engine.cpp @@ -36,7 +36,6 @@ #include #include "mongo/db/index/index_descriptor.h" -#include "mongo/db/snapshot_window_options.h" #include "mongo/db/storage/biggie/biggie_recovery_unit.h" #include "mongo/db/storage/key_string.h" #include "mongo/db/storage/record_store.h" @@ -49,10 +48,6 @@ mongo::RecoveryUnit* KVEngine::newRecoveryUnit() { return new RecoveryUnit(this, nullptr); } -void KVEngine::setCachePressureForTest(int pressure) { - // TODO : implement. -} - Status KVEngine::createRecordStore(OperationContext* opCtx, StringData ns, StringData ident, diff --git a/src/mongo/db/storage/biggie/biggie_kv_engine.h b/src/mongo/db/storage/biggie/biggie_kv_engine.h index 2ce35d07cbf..63e89e8b579 100644 --- a/src/mongo/db/storage/biggie/biggie_kv_engine.h +++ b/src/mongo/db/storage/biggie/biggie_kv_engine.h @@ -105,12 +105,6 @@ public: return true; } - virtual bool isCacheUnderPressure(OperationContext* opCtx) const override { - return false; - } - - virtual void setCachePressureForTest(int pressure) override; - virtual int64_t getIdentSize(OperationContext* opCtx, StringData ident) { return 0; } diff --git a/src/mongo/db/storage/devnull/SConscript b/src/mongo/db/storage/devnull/SConscript index 66dcb6763a7..f2963e59380 100644 --- a/src/mongo/db/storage/devnull/SConscript +++ b/src/mongo/db/storage/devnull/SConscript @@ -13,9 +13,6 @@ env.Library( '$BUILD_DIR/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store', '$BUILD_DIR/mongo/db/storage/kv/kv_prefix', ], - LIBDEPS_PRIVATE=[ - '$BUILD_DIR/mongo/db/snapshot_window_options', - ], ) env.Library( diff --git a/src/mongo/db/storage/devnull/devnull_kv_engine.cpp b/src/mongo/db/storage/devnull/devnull_kv_engine.cpp index 4bbc0b9dc11..f70b7ad94fd 100644 --- a/src/mongo/db/storage/devnull/devnull_kv_engine.cpp +++ b/src/mongo/db/storage/devnull/devnull_kv_engine.cpp @@ -33,7 +33,6 @@ #include -#include "mongo/db/snapshot_window_options.h" #include "mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store.h" #include "mongo/db/storage/record_store.h" #include "mongo/db/storage/sorted_data_interface.h" @@ -244,15 +243,6 @@ std::unique_ptr DevNullKVEngine::getSortedDataInterface( return std::make_unique(); } -bool DevNullKVEngine::isCacheUnderPressure(OperationContext* opCtx) const { - return (_cachePressureForTest >= snapshotWindowParams.cachePressureThreshold.load()); -} - -void DevNullKVEngine::setCachePressureForTest(int pressure) { - invariant(pressure >= 0 && pressure <= 100); - _cachePressureForTest = pressure; -} - namespace { class StreamingCursorImpl : public StorageEngine::StreamingCursor { diff --git a/src/mongo/db/storage/devnull/devnull_kv_engine.h b/src/mongo/db/storage/devnull/devnull_kv_engine.h index f271ae0f0f8..dd1854e0256 100644 --- a/src/mongo/db/storage/devnull/devnull_kv_engine.h +++ b/src/mongo/db/storage/devnull/devnull_kv_engine.h @@ -97,10 +97,6 @@ public: return true; } - virtual bool isCacheUnderPressure(OperationContext* opCtx) const override; - - virtual void setCachePressureForTest(int pressure) override; - virtual int64_t getIdentSize(OperationContext* opCtx, StringData ident) { return 1; } diff --git a/src/mongo/db/storage/kv/kv_engine.h b/src/mongo/db/storage/kv/kv_engine.h index f20897f8be2..f5ceccc0b53 100644 --- a/src/mongo/db/storage/kv/kv_engine.h +++ b/src/mongo/db/storage/kv/kv_engine.h @@ -355,18 +355,6 @@ public: */ virtual void setOldestTimestamp(Timestamp newOldestTimestamp, bool force) {} - /** - * See `StorageEngine::isCacheUnderPressure()` - */ - virtual bool isCacheUnderPressure(OperationContext* opCtx) const { - return false; - } - - /** - * See 'StorageEngine::setCachePressureForTest()' - */ - virtual void setCachePressureForTest(int pressure) {} - /** * See `StorageEngine::supportsRecoverToStableTimestamp` */ diff --git a/src/mongo/db/storage/storage_engine.h b/src/mongo/db/storage/storage_engine.h index 98285ff0f30..8d7df601b5a 100644 --- a/src/mongo/db/storage/storage_engine.h +++ b/src/mongo/db/storage/storage_engine.h @@ -517,21 +517,6 @@ public: virtual void setOldestActiveTransactionTimestampCallback( OldestActiveTransactionTimestampCallback callback) = 0; - /** - * Indicates whether the storage engine cache is under pressure. - * - * Retrieves a cache pressure value in the range [0, 100] from the storage engine, and compares - * it against storageGlobalParams.cachePressureThreshold, a dynamic server parameter, to - * determine whether cache pressure is too high. - */ - virtual bool isCacheUnderPressure(OperationContext* opCtx) const = 0; - - /** - * For unit tests only. Sets the cache pressure value with which isCacheUnderPressure() - * evalutates to 'pressure'. - */ - virtual void setCachePressureForTest(int pressure) = 0; - struct IndexIdentifier { const RecordId catalogId; const NamespaceString nss; diff --git a/src/mongo/db/storage/storage_engine_impl.cpp b/src/mongo/db/storage/storage_engine_impl.cpp index 91ac87542c6..d45ccf93c22 100644 --- a/src/mongo/db/storage/storage_engine_impl.cpp +++ b/src/mongo/db/storage/storage_engine_impl.cpp @@ -783,14 +783,6 @@ void StorageEngineImpl::setOldestActiveTransactionTimestampCallback( _engine->setOldestActiveTransactionTimestampCallback(callback); } -bool StorageEngineImpl::isCacheUnderPressure(OperationContext* opCtx) const { - return _engine->isCacheUnderPressure(opCtx); -} - -void StorageEngineImpl::setCachePressureForTest(int pressure) { - return _engine->setCachePressureForTest(pressure); -} - bool StorageEngineImpl::supportsRecoverToStableTimestamp() const { return _engine->supportsRecoverToStableTimestamp(); } diff --git a/src/mongo/db/storage/storage_engine_impl.h b/src/mongo/db/storage/storage_engine_impl.h index 3fd3bab86d1..70bc31830c3 100644 --- a/src/mongo/db/storage/storage_engine_impl.h +++ b/src/mongo/db/storage/storage_engine_impl.h @@ -133,10 +133,6 @@ public: virtual void setOldestActiveTransactionTimestampCallback( StorageEngine::OldestActiveTransactionTimestampCallback) override; - virtual bool isCacheUnderPressure(OperationContext* opCtx) const override; - - virtual void setCachePressureForTest(int pressure) override; - virtual bool supportsRecoverToStableTimestamp() const override; virtual bool supportsRecoveryTimestamp() const override; diff --git a/src/mongo/db/storage/storage_engine_mock.h b/src/mongo/db/storage/storage_engine_mock.h index b8cb1cbde02..a4dfe3c677f 100644 --- a/src/mongo/db/storage/storage_engine_mock.h +++ b/src/mongo/db/storage/storage_engine_mock.h @@ -138,10 +138,7 @@ public: void setOldestTimestamp(Timestamp timestamp) final {} void setOldestActiveTransactionTimestampCallback( OldestActiveTransactionTimestampCallback callback) final {} - bool isCacheUnderPressure(OperationContext* opCtx) const final { - return false; - } - void setCachePressureForTest(int pressure) final {} + StatusWith reconcileCatalogAndIdents( OperationContext* opCtx) final { return ReconcileResult{}; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index 352699a9de8..b9749e79eab 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -69,7 +69,7 @@ #include "mongo/db/server_options.h" #include "mongo/db/server_recovery.h" #include "mongo/db/service_context.h" -#include "mongo/db/snapshot_window_options.h" +#include "mongo/db/snapshot_window_options_gen.h" #include "mongo/db/storage/journal_listener.h" #include "mongo/db/storage/storage_file_util.h" #include "mongo/db/storage/storage_options.h" @@ -681,7 +681,7 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, // We do not maintain any snapshot history for the ephemeral storage engine in production // because replication and sharded transactions do not currently run on the inMemory engine. // It is live in testing, however. - snapshotWindowParams.minSnapshotHistoryWindowInSeconds.store(0); + minSnapshotHistoryWindowInSeconds.store(0); } _sizeStorerUri = _uri("sizeStorer"); @@ -2017,20 +2017,20 @@ Timestamp WiredTigerKVEngine::_calculateHistoryLagFromStableTimestamp(Timestamp if (_ephemeral && !getTestCommandsEnabled()) { // No history should be maintained for the inMemory engine because it is not used yet. - invariant(snapshotWindowParams.minSnapshotHistoryWindowInSeconds.load() == 0); + invariant(minSnapshotHistoryWindowInSeconds.load() == 0); } if (stableTimestamp.getSecs() < - static_cast(snapshotWindowParams.minSnapshotHistoryWindowInSeconds.load())) { + static_cast(minSnapshotHistoryWindowInSeconds.load())) { // The history window is larger than the timestamp history thus far. We must wait for // the history to reach the window size before moving oldest_timestamp forward. This should // only happen in unit tests. return Timestamp(); } - Timestamp calculatedOldestTimestamp( - stableTimestamp.getSecs() - snapshotWindowParams.minSnapshotHistoryWindowInSeconds.load(), - stableTimestamp.getInc()); + Timestamp calculatedOldestTimestamp(stableTimestamp.getSecs() - + minSnapshotHistoryWindowInSeconds.load(), + stableTimestamp.getInc()); if (calculatedOldestTimestamp.asULL() <= _oldestTimestamp.load()) { // The stable_timestamp is not far enough ahead of the oldest_timestamp for the @@ -2285,16 +2285,6 @@ void WiredTigerKVEngine::haltOplogManager() { } } -bool WiredTigerKVEngine::isCacheUnderPressure(OperationContext* opCtx) const { - WiredTigerSession* session = WiredTigerRecoveryUnit::get(opCtx)->getSessionNoTxn(); - invariant(session); - - int64_t score = uassertStatusOK(WiredTigerUtil::getStatisticsValue( - session->getSession(), "statistics:", "", WT_STAT_CONN_CACHE_LOOKASIDE_SCORE)); - - return (score >= snapshotWindowParams.cachePressureThreshold.load()); -} - Timestamp WiredTigerKVEngine::getStableTimestamp() const { return Timestamp(_stableTimestamp.load()); } diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h index 4bebe95e99b..61b0589b617 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h @@ -273,8 +273,6 @@ public: bool supportsOplogStones() const final override; - bool isCacheUnderPressure(OperationContext* opCtx) const override; - bool supportsReadConcernMajority() const final; // wiredtiger specific diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp index f9d9751d464..8d6e087a86f 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp @@ -58,6 +58,8 @@ MONGO_FAIL_POINT_DEFINE(doUntimestampedWritesForIdempotencyTests); } // namespace +AtomicWord snapshotTooOldErrorCount{0}; + using Section = WiredTigerOperationStats::Section; std::map> WiredTigerOperationStats::_statNameMap = { @@ -531,6 +533,9 @@ void WiredTigerRecoveryUnit::_txnOpen() { auto status = txnOpen.setReadSnapshot(_readAtTimestamp); if (!status.isOK() && status.code() == ErrorCodes::BadValue) { + // SnapshotTooOld errors indicate that PIT ops are failing to find an available + // snapshot at their specified atClusterTime. + snapshotTooOldErrorCount.addAndFetch(1); uasserted(ErrorCodes::SnapshotTooOld, str::stream() << "Read timestamp " << _readAtTimestamp.toString() << " is older than the oldest available timestamp."); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h index 373794582a2..d2e599181de 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h @@ -51,6 +51,8 @@ namespace mongo { using RoundUpPreparedTimestamps = WiredTigerBeginTxnBlock::RoundUpPreparedTimestamps; using RoundUpReadTimestamp = WiredTigerBeginTxnBlock::RoundUpReadTimestamp; +extern AtomicWord snapshotTooOldErrorCount; + class BSONObjBuilder; class WiredTigerOperationStats final : public StorageStats { diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp index 1f440d319b7..b50d4b79889 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp @@ -263,48 +263,6 @@ TEST_F(WiredTigerRecoveryUnitTestFixture, NoOverlapReadSource) { ASSERT_TRUE(rs->findRecord(opCtx1, rid3, &unused)); } -TEST_F(WiredTigerRecoveryUnitTestFixture, CreateAndCheckForCachePressure) { - int time = 1; - - // Reconfigure the size of the cache to be very small so that building cache pressure is fast. - WiredTigerKVEngine* engine = harnessHelper->getEngine(); - std::string cacheSizeReconfig = "cache_size=1MB"; - ASSERT_EQ(engine->reconfigure(cacheSizeReconfig.c_str()), 0); - - OperationContext* opCtx = clientAndCtx1.second.get(); - std::unique_ptr rs(harnessHelper->createRecordStore(opCtx, "a.b")); - - // Insert one document so that we can then update it in a loop to create cache pressure. - // Note: inserts will not create cache pressure. - WriteUnitOfWork wu(opCtx); - ASSERT_OK(ru1->setTimestamp(Timestamp(time++))); - std::string str = str::stream() << "foobarbaz"; - StatusWith ress = rs->insertRecord(opCtx, str.c_str(), str.size() + 1, Timestamp()); - ASSERT_OK(ress.getStatus()); - auto recordId = ress.getValue(); - wu.commit(); - - for (int j = 0; j < 1000; ++j) { - // Once we hit the cache pressure threshold, i.e. have successfully created cache pressure - // that is detectable, we are done. - if (engine->isCacheUnderPressure(opCtx)) { - invariant(j != 0); - break; - } - - try { - WriteUnitOfWork wuow(opCtx); - ASSERT_OK(ru1->setTimestamp(Timestamp(time++))); - std::string s = str::stream() - << "abcbcdcdedefefgfghghihijijkjklklmlmnmnomopopqpqrqrsrststutuv" << j; - ASSERT_OK(rs->updateRecord(opCtx, recordId, s.c_str(), s.size() + 1)); - wuow.commit(); - } catch (const DBException& ex) { - invariant(ex.toStatus().code() == ErrorCodes::WriteConflict); - } - } -} - TEST_F(WiredTigerRecoveryUnitTestFixture, LocalReadOnADocumentBeingPreparedWithoutIgnoringPreparedTriggersPrepareConflict) { // Prepare but don't commit a transaction diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp index d2187782a2b..2b8f2d667fe 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp @@ -38,7 +38,7 @@ #include "mongo/base/simple_string_data_comparator.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/concurrency/write_conflict_exception.h" -#include "mongo/db/snapshot_window_options.h" +#include "mongo/db/snapshot_window_options_gen.h" #include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" #include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h" #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h" @@ -738,18 +738,12 @@ void WiredTigerUtil::appendSnapshotWindowSettings(WiredTigerKVEngine* engine, const unsigned currentAvailableSnapshotWindow = stableTimestamp.getSecs() - oldestTimestamp.getSecs(); - int64_t score = uassertStatusOK(WiredTigerUtil::getStatisticsValue( - session->getSession(), "statistics:", "", WT_STAT_CONN_CACHE_LOOKASIDE_SCORE)); - - auto totalNumberOfSnapshotTooOldErrors = snapshotWindowParams.snapshotTooOldErrorCount.load(); + auto totalNumberOfSnapshotTooOldErrors = snapshotTooOldErrorCount.load(); BSONObjBuilder settings(bob->subobjStart("snapshot-window-settings")); - settings.append("cache pressure percentage threshold", - snapshotWindowParams.cachePressureThreshold.load()); - settings.append("current cache pressure percentage", score); settings.append("total number of SnapshotTooOld errors", totalNumberOfSnapshotTooOldErrors); settings.append("minimum target snapshot window size in seconds", - snapshotWindowParams.minSnapshotHistoryWindowInSeconds.load()); + minSnapshotHistoryWindowInSeconds.load()); settings.append("current available snapshot window size in seconds", static_cast(currentAvailableSnapshotWindow)); settings.append("latest majority snapshot timestamp available", diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.h b/src/mongo/db/storage/wiredtiger/wiredtiger_util.h index 72ccee41b4f..e1e1a190b28 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.h @@ -158,12 +158,9 @@ public: * that affect that window of maintained history. * * "snapshot-window-settings" : { - * "cache pressure percentage threshold" : , - * "current cache pressure percentage" : , * "total number of SnapshotTooOld errors" : , - * "max target available snapshots window size in seconds" : , - * "target available snapshots window size in seconds" : , - * "current available snapshots window size in seconds" : , + * "minimum target snapshot window size in seconds" : , + * "current available snapshot window size in seconds" : , * "latest majority snapshot timestamp available" : , * "oldest majority snapshot timestamp available" : * } -- cgit v1.2.1