1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/*
* Intergration test for the server parameters for hedged reads. The more comprehensive
* unit test can be found in executor/remote_command_request_test.cpp.
*
* TODO (SERVER-45432): test that hedging is performed as expected.
*
* @tags: [requires_fcv_44]
*/
(function() {
const st = new ShardingTest({
shards: 2,
mongosOptions: {setParameter: {maxTimeMSThresholdForHedging: 1500, hedgingDelayPercentage: 50}}
});
const dbName = "foo";
const collName = "bar";
const ns = dbName + "." + collName;
const testDB = st.s.getDB(dbName);
assert.commandWorked(st.s.adminCommand({enableSharding: dbName}));
st.ensurePrimaryShard(dbName, st.shard0.shardName);
assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {x: 1}}));
// With maxTimeMS.
assert.commandWorked(st.s.getDB(dbName).runCommand(
{query: {find: collName, maxTimeMS: 1000}, $readPreference: {mode: "nearest", hedge: {}}}));
// Without maxTimeMS.
st.restartMongos(0, {
restart: true,
setParameter: {defaultHedgingDelayMS: 800},
});
assert.commandWorked(st.s.getDB(dbName).runCommand(
{query: {count: collName}, $readPreference: {mode: "secondaryPreferred", hedge: {}}}));
// readHedgingMode "off".
st.restartMongos(0, {
restart: true,
setParameter: {readHedgingMode: "off"},
});
assert.commandWorked(st.s.getDB(dbName).runCommand({
query: {distinct: collName, key: "x"},
$readPreference: {mode: "primaryPreferred", hedge: {}}
}));
st.stop();
})();
|