summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/sharding/analyze_shard_key/libs/monotonicity_common.js15
-rw-r--r--jstests/sharding/analyze_shard_key/monotonicity_hashed_sharding_compound.js13
-rw-r--r--jstests/sharding/analyze_shard_key/monotonicity_hashed_sharding_non_compound.js13
-rw-r--r--jstests/sharding/analyze_shard_key/monotonicity_range_sharding_compound.js13
-rw-r--r--jstests/sharding/analyze_shard_key/monotonicity_range_sharding_non_compound.js13
5 files changed, 46 insertions, 21 deletions
diff --git a/jstests/sharding/analyze_shard_key/libs/monotonicity_common.js b/jstests/sharding/analyze_shard_key/libs/monotonicity_common.js
index 50f858206b3..f771625cc67 100644
--- a/jstests/sharding/analyze_shard_key/libs/monotonicity_common.js
+++ b/jstests/sharding/analyze_shard_key/libs/monotonicity_common.js
@@ -202,16 +202,13 @@ function makeDocuments(numDocs, fieldOpts) {
return docs;
}
-const minNumDocs = 2500;
-const maxNumDocs = 5000;
-
-function testMonotonicity(conn, dbName, collName, currentShardKey, testCases) {
+function testMonotonicity(conn, dbName, collName, currentShardKey, testCases, numDocsRange) {
const ns = dbName + "." + collName;
const db = conn.getDB(dbName);
const coll = db.getCollection(collName);
testCases.forEach(testCase => {
- const numDocs = AnalyzeShardKeyUtil.getRandInteger(minNumDocs, maxNumDocs);
+ const numDocs = AnalyzeShardKeyUtil.getRandInteger(numDocsRange.min, numDocsRange.max);
for (let i = 0; i < testCase.fieldOpts.length; i++) {
const order = testCase.fieldOpts[i].order;
if (order == "increasing" || order == "decreasing") {
@@ -251,7 +248,7 @@ function testMonotonicity(conn, dbName, collName, currentShardKey, testCases) {
});
}
-function testAnalyzeShardKeysUnshardedCollection(conn, testCases) {
+function testAnalyzeShardKeysUnshardedCollection(conn, testCases, numDocsRange) {
const dbName = "testDbCandidateUnsharded";
const collName = "testColl";
const db = conn.getDB(dbName);
@@ -259,11 +256,11 @@ function testAnalyzeShardKeysUnshardedCollection(conn, testCases) {
jsTest.log(`Testing analyzing a shard key for an unsharded collection: ${
tojsononeline({dbName, collName})}`);
- testMonotonicity(conn, dbName, collName, null /* currentShardKey */, testCases);
+ testMonotonicity(conn, dbName, collName, null /* currentShardKey */, testCases, numDocsRange);
assert.commandWorked(db.dropDatabase());
}
-function testAnalyzeShardKeysShardedCollection(st, testCases) {
+function testAnalyzeShardKeysShardedCollection(st, testCases, numDocsRange) {
const dbName = "testDbCandidateSharded";
const collName = "testColl";
const ns = dbName + "." + collName;
@@ -280,6 +277,6 @@ function testAnalyzeShardKeysShardedCollection(st, testCases) {
assert.commandWorked(st.s.adminCommand({split: ns, middle: currentShardKeySplitPoint}));
assert.commandWorked(st.s.adminCommand(
{moveChunk: ns, find: currentShardKeySplitPoint, to: st.shard1.shardName}));
- testMonotonicity(st.s, dbName, collName, currentShardKey, testCases);
+ testMonotonicity(st.s, dbName, collName, currentShardKey, testCases, numDocsRange);
assert.commandWorked(db.dropDatabase());
}
diff --git a/jstests/sharding/analyze_shard_key/monotonicity_hashed_sharding_compound.js b/jstests/sharding/analyze_shard_key/monotonicity_hashed_sharding_compound.js
index 42f3b22fb7e..3d7a430d8f5 100644
--- a/jstests/sharding/analyze_shard_key/monotonicity_hashed_sharding_compound.js
+++ b/jstests/sharding/analyze_shard_key/monotonicity_hashed_sharding_compound.js
@@ -53,11 +53,18 @@ for (let orderType0 of kOrderTypes) {
}
}
+// This test requires the collection to contain at least a few thousands of documents to smooth out
+// the noise in the insertion order caused by the oplog application batching on secondaries.
+const numDocsRange = {
+ min: 2500,
+ max: 5000
+};
+
{
const st = new ShardingTest({shards: 2, rs: {nodes: 2}});
- testAnalyzeShardKeysUnshardedCollection(st.s, testCases);
- testAnalyzeShardKeysShardedCollection(st, testCases);
+ testAnalyzeShardKeysUnshardedCollection(st.s, testCases, numDocsRange);
+ testAnalyzeShardKeysShardedCollection(st, testCases, numDocsRange);
st.stop();
}
@@ -68,7 +75,7 @@ for (let orderType0 of kOrderTypes) {
rst.initiate();
const primary = rst.getPrimary();
- testAnalyzeShardKeysUnshardedCollection(primary, testCases);
+ testAnalyzeShardKeysUnshardedCollection(primary, testCases, numDocsRange);
rst.stopSet();
}
diff --git a/jstests/sharding/analyze_shard_key/monotonicity_hashed_sharding_non_compound.js b/jstests/sharding/analyze_shard_key/monotonicity_hashed_sharding_non_compound.js
index ae0bbfe4c27..d08d7336595 100644
--- a/jstests/sharding/analyze_shard_key/monotonicity_hashed_sharding_non_compound.js
+++ b/jstests/sharding/analyze_shard_key/monotonicity_hashed_sharding_non_compound.js
@@ -48,11 +48,18 @@ for (let orderType0 of kOrderTypes) {
}
}
+// This test requires the collection to contain at least a few thousands of documents to smooth out
+// the noise in the insertion order caused by the oplog application batching on secondaries.
+const numDocsRange = {
+ min: 2500,
+ max: 5000
+};
+
{
const st = new ShardingTest({shards: 2, rs: {nodes: 2}});
- testAnalyzeShardKeysUnshardedCollection(st.s, testCases);
- testAnalyzeShardKeysShardedCollection(st, testCases);
+ testAnalyzeShardKeysUnshardedCollection(st.s, testCases, numDocsRange);
+ testAnalyzeShardKeysShardedCollection(st, testCases, numDocsRange);
st.stop();
}
@@ -63,7 +70,7 @@ for (let orderType0 of kOrderTypes) {
rst.initiate();
const primary = rst.getPrimary();
- testAnalyzeShardKeysUnshardedCollection(primary, testCases);
+ testAnalyzeShardKeysUnshardedCollection(primary, testCases, numDocsRange);
rst.stopSet();
}
diff --git a/jstests/sharding/analyze_shard_key/monotonicity_range_sharding_compound.js b/jstests/sharding/analyze_shard_key/monotonicity_range_sharding_compound.js
index f16166da462..8d903f49e97 100644
--- a/jstests/sharding/analyze_shard_key/monotonicity_range_sharding_compound.js
+++ b/jstests/sharding/analyze_shard_key/monotonicity_range_sharding_compound.js
@@ -60,11 +60,18 @@ for (let orderType0 of kOrderTypes) {
}
}
+// This test requires the collection to contain at least a few thousands of documents to smooth out
+// the noise in the insertion order caused by the oplog application batching on secondaries.
+const numDocsRange = {
+ min: 2500,
+ max: 5000
+};
+
{
const st = new ShardingTest({shards: 2, rs: {nodes: 2}});
- testAnalyzeShardKeysUnshardedCollection(st.s, testCases);
- testAnalyzeShardKeysShardedCollection(st, testCases);
+ testAnalyzeShardKeysUnshardedCollection(st.s, testCases, numDocsRange);
+ testAnalyzeShardKeysShardedCollection(st, testCases, numDocsRange);
st.stop();
}
@@ -75,7 +82,7 @@ for (let orderType0 of kOrderTypes) {
rst.initiate();
const primary = rst.getPrimary();
- testAnalyzeShardKeysUnshardedCollection(primary, testCases);
+ testAnalyzeShardKeysUnshardedCollection(primary, testCases, numDocsRange);
rst.stopSet();
}
diff --git a/jstests/sharding/analyze_shard_key/monotonicity_range_sharding_non_compound.js b/jstests/sharding/analyze_shard_key/monotonicity_range_sharding_non_compound.js
index 526f920a68b..dbfa1c992d3 100644
--- a/jstests/sharding/analyze_shard_key/monotonicity_range_sharding_non_compound.js
+++ b/jstests/sharding/analyze_shard_key/monotonicity_range_sharding_non_compound.js
@@ -48,11 +48,18 @@ for (let orderType0 of kOrderTypes) {
}
}
+// This test requires the collection to contain at least a few thousands of documents to smooth out
+// the noise in the insertion order caused by the oplog application batching on secondaries.
+const numDocsRange = {
+ min: 5000,
+ max: 10000
+};
+
{
const st = new ShardingTest({shards: 2, rs: {nodes: 2}});
- testAnalyzeShardKeysUnshardedCollection(st.s, testCases);
- testAnalyzeShardKeysShardedCollection(st, testCases);
+ testAnalyzeShardKeysUnshardedCollection(st.s, testCases, numDocsRange);
+ testAnalyzeShardKeysShardedCollection(st, testCases, numDocsRange);
st.stop();
}
@@ -63,7 +70,7 @@ for (let orderType0 of kOrderTypes) {
rst.initiate();
const primary = rst.getPrimary();
- testAnalyzeShardKeysUnshardedCollection(primary, testCases);
+ testAnalyzeShardKeysUnshardedCollection(primary, testCases, numDocsRange);
rst.stopSet();
}