summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/cluster_server_parameter_refresher.js
blob: 8edc13641eb62b52f93fd957471f645a918cdf39 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
 * Checks that the mongos cluster server parameter refresh job runs as expected.
 *
 * @tags: [
 *   # Requires all nodes to be running at least 6.1.
 *   requires_fcv_61,
 *   featureFlagClusterWideConfigM2,
 *   does_not_support_stepdowns,
 *   requires_replication,
 *   requires_sharding
 *  ]
 */
(function() {
'use strict';

function runTest(st, startupRefreshIntervalMS) {
    // First, check that the mongos logs a refresh attempt within the first refreshIntervalMS
    // milliseconds that finds no documents on the config servers.
    const conn = st.s0;
    const errorMarginMS = 5000;
    const startupRefreshIntervalRelaxedMS = startupRefreshIntervalMS + errorMarginMS;
    checkLog.containsRelaxedJson(
        conn, 6226403, {clusterParameterDocuments: []}, 1, startupRefreshIntervalRelaxedMS);

    // Set a cluster parameter to a different value and then wait.
    assert.commandWorked(
        conn.adminCommand({setClusterParameter: {testIntClusterParameter: {intData: 2022}}}));

    // Check that the newly set parameter is refreshed within the interval.
    checkLog.containsRelaxedJson(
        conn,
        6226403,
        {clusterParameterDocuments: [{_id: "testIntClusterParameter", intData: 2022}]},
        1,
        startupRefreshIntervalRelaxedMS);

    // Set another cluster parameter and check that only the updated parameter is refreshed within
    // the interval.
    assert.commandWorked(
        conn.adminCommand({setClusterParameter: {testStrClusterParameter: {strData: "welcome"}}}));
    checkLog.containsRelaxedJson(
        conn,
        6226403,
        {clusterParameterDocuments: [{_id: "testStrClusterParameter", strData: "welcome"}]},
        1,
        startupRefreshIntervalRelaxedMS);

    // Shorten the refresh interval by half and verify that the next setClusterParameter update
    // is seen within the new interval.
    const newRefreshIntervalMS = startupRefreshIntervalMS / 2;
    const newRefreshIntervalSecs = newRefreshIntervalMS / 1000;
    const newRefreshIntervalRelaxedMS = newRefreshIntervalMS + errorMarginMS;
    assert.commandWorked(conn.adminCommand(
        {setParameter: 1, clusterServerParameterRefreshIntervalSecs: newRefreshIntervalSecs}));
    assert.commandWorked(
        conn.adminCommand({setClusterParameter: {testIntClusterParameter: {intData: 2025}}}));
    checkLog.containsRelaxedJson(
        conn,
        6226403,
        {clusterParameterDocuments: [{_id: "testIntClusterParameter", intData: 2025}]},
        1,
        newRefreshIntervalRelaxedMS);

    // Restart the mongos and check that it refreshes both of the parameters that have documents on
    // the config server.
    st.restartMongos(0);
    checkLog.containsRelaxedJson(conn,
                                 6226403,
                                 {
                                     clusterParameterDocuments: [
                                         {_id: "testIntClusterParameter", intData: 2025},
                                         {_id: "testStrClusterParameter", strData: "welcome"}
                                     ]
                                 },
                                 1,
                                 newRefreshIntervalRelaxedMS);

    // Check that single parameter updates are caught as expected after restart. Note that the
    // startup refresh interval is used since runtime setParameter updates are not persisted.
    assert.commandWorked(
        conn.adminCommand({setClusterParameter: {testStrClusterParameter: {strData: "goodbye"}}}));
    checkLog.containsRelaxedJson(
        conn,
        6226403,
        {clusterParameterDocuments: [{_id: "testStrClusterParameter", strData: "goodbye"}]},
        1,
        startupRefreshIntervalRelaxedMS);

    // Finally, check that multiple setClusterParameter invocations within a single refresh cycle
    // are captured and updated.
    assert.commandWorked(
        conn.adminCommand({setClusterParameter: {testIntClusterParameter: {intData: 2028}}}));
    assert.commandWorked(
        conn.adminCommand({setClusterParameter: {testBoolClusterParameter: {boolData: true}}}));
    checkLog.containsRelaxedJson(conn,
                                 6226403,
                                 {
                                     clusterParameterDocuments: [
                                         {_id: "testIntClusterParameter", intData: 2028},
                                         {_id: "testBoolClusterParameter", boolData: true}
                                     ]
                                 },
                                 1,
                                 startupRefreshIntervalRelaxedMS);
}

// Test with default clusterServerParameterRefreshIntervalSecs at startup.
let options = {
    mongos: 1,
    config: 1,
    shards: 3,
    rs: {
        nodes: 3,
    },
    mongosOptions: {
        setParameter: {
            logLevel: 3,
        },
    },
};
let st = new ShardingTest(options);
runTest(st, 30000);
st.stop();

// Test with non-default clusterServerParameterRefreshIntervalSecs at startup.
options = {
    mongos: 1,
    config: 1,
    shards: 3,
    rs: {
        nodes: 3,
    },
    mongosOptions: {
        setParameter: {
            logLevel: 3,
            clusterServerParameterRefreshIntervalSecs: 20,
        },
    },
};
st = new ShardingTest(options);
runTest(st, 20000);
st.stop();
})();