summaryrefslogtreecommitdiff
path: root/src/mongo/db/snapshot_window_util.cpp
diff options
context:
space:
mode:
authorDianna <dianna.hohensee@10gen.com>2019-05-15 08:41:20 -0400
committerDianna <dianna.hohensee@10gen.com>2019-05-17 17:31:45 -0400
commit8899b34e1044b08aec7ad9f8546652456472702c (patch)
treed7aecc9bc566326ed9ecc9b6b093bbe5797a1d36 /src/mongo/db/snapshot_window_util.cpp
parent278e1936f837c260e037ce7e56ac93586247fa61 (diff)
downloadmongo-8899b34e1044b08aec7ad9f8546652456472702c.tar.gz
SERVER-36956 SnapshotTooOld errors will always increase the snapshot history window size
Diffstat (limited to 'src/mongo/db/snapshot_window_util.cpp')
-rw-r--r--src/mongo/db/snapshot_window_util.cpp58
1 files changed, 22 insertions, 36 deletions
diff --git a/src/mongo/db/snapshot_window_util.cpp b/src/mongo/db/snapshot_window_util.cpp
index 1ed27ca417b..eaaf84adc5b 100644
--- a/src/mongo/db/snapshot_window_util.cpp
+++ b/src/mongo/db/snapshot_window_util.cpp
@@ -52,25 +52,12 @@ namespace SnapshotWindowUtil {
// Adds concurrency control to increaseTargetSnapshotWindowSize() and
// decreaseTargetSnapshotWindowSize(). They should not run concurrently with themselves or one
// another, since they act on and modify the same storage parameters. Further guards the static
-// variables "_snapshotWindowLastDecreasedAt" and "_snapshotWindowLastIncreasedAt" used in
-// increaseTargetSnapshotWindowSize() and decreaseSnapshowWindow().
+// variable "_snapshotWindowLastIncreasedAt" used in increaseTargetSnapshotWindowSize().
stdx::mutex snapshotWindowMutex;
namespace {
-void _decreaseTargetSnapshotWindowSize(WithLock lock, OperationContext* opCtx) {
- // Tracks the last time that the snapshot window was decreased so that it does not go down so
- // fast that the system does not have time to react and reduce snapshot availability.
- static Date_t _snapshotWindowLastDecreasedAt{Date_t::min()};
-
- if (_snapshotWindowLastDecreasedAt >
- (Date_t::now() -
- Milliseconds(snapshotWindowParams.minMillisBetweenSnapshotWindowDec.load()))) {
- // We have already decreased the window size in the last minMillisBetweenSnapshotWindowDec
- // milliseconds.
- return;
- }
-
+void _decreaseTargetSnapshotWindowSize(WithLock, OperationContext* opCtx) {
snapshotWindowParams.targetSnapshotHistoryWindowInSeconds.store(
snapshotWindowParams.targetSnapshotHistoryWindowInSeconds.load() *
snapshotWindowParams.snapshotWindowMultiplicativeDecrease.load());
@@ -80,8 +67,6 @@ void _decreaseTargetSnapshotWindowSize(WithLock lock, OperationContext* opCtx) {
StorageEngine* engine = opCtx->getServiceContext()->getStorageEngine();
invariant(engine);
engine->setOldestTimestampFromStable();
-
- _snapshotWindowLastDecreasedAt = Date_t::now();
}
} // namespace
@@ -105,23 +90,6 @@ void increaseTargetSnapshotWindowSize(OperationContext* opCtx) {
return;
}
- // If the cache pressure is already too high, we will not put more pressure on it by increasing
- // the window size.
- StorageEngine* engine = opCtx->getServiceContext()->getStorageEngine();
- if (engine && engine->isCacheUnderPressure(opCtx)) {
- warning() << "Attempted to increase the time window of available snapshots for "
- "point-in-time operations (readConcern level 'snapshot' or transactions), but "
- "the storage engine cache pressure, per the cachePressureThreshold setting of "
- "'"
- << snapshotWindowParams.cachePressureThreshold.load()
- << "', is too high to allow it to increase. If this happens frequently, consider "
- "either increasing the cache pressure threshold or increasing the memory "
- "available to the storage engine cache, in order to improve the success rate "
- "or speed of point-in-time requests.";
- _decreaseTargetSnapshotWindowSize(lock, opCtx);
- return;
- }
-
if (snapshotWindowParams.targetSnapshotHistoryWindowInSeconds.load() ==
snapshotWindowParams.maxTargetSnapshotHistoryWindowInSeconds.load()) {
warning() << "Attempted to increase the time window of available snapshots for "
@@ -151,10 +119,28 @@ void decreaseTargetSnapshotWindowSize(OperationContext* opCtx) {
stdx::unique_lock<stdx::mutex> lock(snapshotWindowMutex);
StorageEngine* engine = opCtx->getServiceContext()->getStorageEngine();
- if (engine && engine->isCacheUnderPressure(opCtx)) {
- _decreaseTargetSnapshotWindowSize(lock, opCtx);
+ if (engine) {
+ static auto lastInsertsCount = 0;
+ static auto lastSnapshotErrorCount = 0;
+
+ auto currentInsertsCount = engine->getCacheOverflowTableInsertCount(opCtx);
+ auto currentSnapshotErrorCount = snapshotWindowParams.snapshotTooOldErrorCount.load();
+
+ // Only decrease the snapshot window size if there were writes to the cache overflow table
+ // and there has been no new SnapshotTooOld errors in the same time period.
+ if (currentInsertsCount > lastInsertsCount &&
+ currentSnapshotErrorCount == lastSnapshotErrorCount) {
+ _decreaseTargetSnapshotWindowSize(lock, opCtx);
+ }
+
+ lastInsertsCount = currentInsertsCount;
+ lastSnapshotErrorCount = currentSnapshotErrorCount;
}
}
+void incrementSnapshotTooOldErrorCount() {
+ snapshotWindowParams.snapshotTooOldErrorCount.addAndFetch(1);
+}
+
} // namespace SnapshotWindowUtil
} // namespace mongo