summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheahuychou Mao <cheahuychou.mao@mongodb.com>2020-09-03 16:18:01 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-09 19:09:10 +0000
commit2795d76c634e778a6d0bf672cd26c45c8193d2f4 (patch)
tree91526919c525358e4cf21a4b7ce877b763ff803b
parent067c84541cfced8abe0eca82b003ba02dd331ed6 (diff)
downloadmongo-2795d76c634e778a6d0bf672cd26c45c8193d2f4.tar.gz
SERVER-48318 Make snapshot window equal to max of minSnapshotHistoryWindowInSeconds and transactionLifetimeLimitSeconds
-rw-r--r--jstests/sharding/chunk_history_window.js28
-rw-r--r--src/mongo/db/s/SConscript1
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp6
3 files changed, 25 insertions, 10 deletions
diff --git a/jstests/sharding/chunk_history_window.js b/jstests/sharding/chunk_history_window.js
index 1be21395483..adc2ca7247a 100644
--- a/jstests/sharding/chunk_history_window.js
+++ b/jstests/sharding/chunk_history_window.js
@@ -21,17 +21,29 @@
load("jstests/sharding/libs/sharded_transactions_helpers.js");
-const configHistoryWindowSecs = 10;
+// The snapshot window is the max of minSnapshotHistoryWindowInSeconds and
+// transactionLifetimeLimitSeconds.
+const transactionLifetimeLimitSecs = 15;
+const minSnapshotHistoryWindowSecs = transactionLifetimeLimitSecs;
+const snapshotHistoryWindowSecs =
+ Math.max(minSnapshotHistoryWindowSecs, transactionLifetimeLimitSecs);
+
const st = new ShardingTest({
shards: {rs0: {nodes: 2}, rs1: {nodes: 2}},
other: {
configOptions: {
setParameter: {
- minSnapshotHistoryWindowInSeconds: configHistoryWindowSecs,
+ minSnapshotHistoryWindowInSeconds: minSnapshotHistoryWindowSecs,
+ transactionLifetimeLimitSeconds: transactionLifetimeLimitSecs,
logComponentVerbosity: tojson({sharding: {verbosity: 2}})
}
},
- rsOptions: {setParameter: {minSnapshotHistoryWindowInSeconds: 600}}
+ rsOptions: {
+ setParameter: {
+ minSnapshotHistoryWindowInSeconds: minSnapshotHistoryWindowSecs,
+ transactionLifetimeLimitSeconds: transactionLifetimeLimitSecs,
+ }
+ }
}
});
@@ -40,14 +52,14 @@ assert.eq(assert
.commandWorked(
primaryAdmin.runCommand({getParameter: 1, minSnapshotHistoryWindowInSeconds: 1}))
.minSnapshotHistoryWindowInSeconds,
- 600);
+ minSnapshotHistoryWindowSecs);
const configAdmin = st.configRS.getPrimary().getDB("admin");
assert.eq(assert
.commandWorked(
configAdmin.runCommand({getParameter: 1, minSnapshotHistoryWindowInSeconds: 1}))
.minSnapshotHistoryWindowInSeconds,
- 10);
+ minSnapshotHistoryWindowSecs);
const mongosDB = st.s.getDB(jsTestName());
const mongosColl = mongosDB.test;
@@ -81,9 +93,9 @@ assert.eq(2, chunk.history.length, tojson(chunk));
// Test history window with 1s margin.
const testMarginMS = 1000;
-// Test that reading from a snapshot at insertTS is valid for up to configHistoryWindowSecs
+// Test that reading from a snapshot at insertTS is valid for up to snapshotHistoryWindowSecs
// minus the testMarginMS (as a buffer).
-const testWindowMS = configHistoryWindowSecs * 1000 - testMarginMS;
+const testWindowMS = snapshotHistoryWindowSecs * 1000 - testMarginMS;
while (Date.now() - 1000 * insertTS.getTime() < testWindowMS) {
// Test that reading from a snapshot at insertTS is still valid.
assert.commandWorked(mongosDB.runCommand(
@@ -95,7 +107,7 @@ while (Date.now() - 1000 * insertTS.getTime() < testWindowMS) {
}
// Sleep until our most recent chunk move is before the oldest history in our window.
-const chunkExpirationTime = postMoveChunkTime + configHistoryWindowSecs * 1000;
+const chunkExpirationTime = postMoveChunkTime + snapshotHistoryWindowSecs * 1000;
sleep(chunkExpirationTime + testMarginMS - Date.now());
jsTestLog("Move chunk back to shard 0 to trigger history cleanup");
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index 4f97f81b966..f35bda25acc 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -263,6 +263,7 @@ env.Library(
'$BUILD_DIR/mongo/db/catalog_raii',
'$BUILD_DIR/mongo/db/repl/read_concern_args',
'$BUILD_DIR/mongo/db/rw_concern_d',
+ '$BUILD_DIR/mongo/db/transaction',
'$BUILD_DIR/mongo/executor/network_interface',
'$BUILD_DIR/mongo/s/catalog/sharding_catalog_client',
'$BUILD_DIR/mongo/s/client/sharding_client',
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp
index 204d8377764..3e2b4e0f8c7 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/s/sharding_logging.h"
#include "mongo/db/server_options.h"
#include "mongo/db/snapshot_window_options_gen.h"
+#include "mongo/db/transaction_participant_gen.h"
#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/catalog/sharding_catalog_client.h"
@@ -844,8 +845,9 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMigration(
// Drop old history. Keep at least 1 entry so ChunkInfo::getShardIdAt finds valid history for
// any query younger than the history window.
if (!MONGO_unlikely(skipExpiringOldChunkHistory.shouldFail())) {
- const int kHistorySecs = 10;
- auto windowInSeconds = std::max(minSnapshotHistoryWindowInSeconds.load(), kHistorySecs);
+ auto windowInSeconds = std::max(std::max(minSnapshotHistoryWindowInSeconds.load(),
+ gTransactionLifetimeLimitSeconds.load()),
+ 10);
int entriesDeleted = 0;
while (newHistory.size() > 1 &&
newHistory.back().getValidAfter().getSecs() + windowInSeconds <