summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/set_cluster_parameter_fcv.js
blob: 3b9075e1d537d4c5ea745a536d09328baf114140 (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
// Test setClusterParameter command against FCV.
//
// @tags: [
//   creates_and_authenticates_user,
//   requires_auth,
//   requires_fcv_60,
//   requires_non_retryable_commands,
//   requires_persistence,
//   requires_replication,
//   disabled_for_fcv_6_1_upgrade,
// ]

load("jstests/noPassthrough/libs/user_write_blocking.js");

(function() {
'use strict';

const {
    WriteBlockState,
    ShardingFixture,
    ReplicaFixture,
    bypassUser,
    noBypassUser,
    password,
    keyfile
} = UserWriteBlockHelpers;

function mapToClusterParamsColl(db) {
    return db.getSiblingDB('config').clusterParameters;
}

function runTest(fixture) {
    // When the cluster is started at FCV 6.0, it is possible to run setClusterParameter.
    fixture.asAdmin(({admin}) => assert.commandWorked(admin.runCommand(
                        {setClusterParameter: {testIntClusterParameter: {intData: 102}}})));

    // Check that the config.clusterParameters collection has been created with a document for the
    // parameter.
    fixture.asAdmin(
        ({db}) => assert.eq(1, mapToClusterParamsColl(db).count({_id: "testIntClusterParameter"})));

    // When the cluster is at FCV 6.0 without an ongoing setClusterParameter operation in progress,
    // it should be possible to downgrade the cluster.
    fixture.asAdmin(({admin}) => assert.commandWorked(
                        admin.runCommand({setFeatureCompatibilityVersion: "5.0"})));

    // After downgrade, config.clusterParameters should not exist.
    fixture.asAdmin(({db}) => assert.isnull(mapToClusterParamsColl(db).exists()));
    fixture.asAdmin(
        ({db}) => assert.eq(
            0, mapToClusterParamsColl(db).count({_id: "testIntClusterParameter", intData: 102})));

    // While the cluster is downgraded, it should not be possible to run setClusterParameter.
    fixture.asAdmin(({admin}) => assert.commandFailed(admin.runCommand(
                        {setClusterParameter: {testIntClusterParameter: {intData: 102}}})));

    // Upgrading the cluster back to 6.0 should permit setClusterParameter to work again.
    fixture.asAdmin(({admin}) => assert.commandWorked(
                        admin.runCommand({setFeatureCompatibilityVersion: "6.0"})));
    fixture.asAdmin(({admin}) => assert.commandWorked(admin.runCommand(
                        {setClusterParameter: {testIntClusterParameter: {intData: 103}}})));

    // Set a failpoint to make setClusterParameter hang on a sharded cluster. FCV downgrade should
    // fail while setClusterParameter is in progress.
    if (fixture.hangTransition) {
        let hangWaiter =
            fixture.hangTransition({setClusterParameter: {testIntClusterParameter: {intData: 105}}},
                                   'hangInShardsvrSetClusterParameter');

        fixture.asAdmin(({admin}) => assert.commandFailedWithCode(
                            admin.runCommand({setFeatureCompatibilityVersion: "5.0"}),
                            ErrorCodes.CannotDowngrade));

        // Restart the config server primary and verify that FCV downgrade still fails.
        fixture.restartConfigPrimary();
        fixture.asAdmin(({admin}) => assert.commandFailedWithCode(
                            admin.runCommand({setFeatureCompatibilityVersion: "5.0"}),
                            ErrorCodes.CannotDowngrade));

        // Turn off the failpoint and wait for the hung setClusterParameter operation to drain.
        hangWaiter.failpoint.off();
        hangWaiter.waiter();

        // Verify that the updated value was successfully updated and is visible despite the restart
        // and failed FCV downgrade attempts.
        fixture.asAdmin(({admin}) => assert.eq(
                            105,
                            admin.runCommand({getClusterParameter: "testIntClusterParameter"})
                                .clusterParameters[0]
                                .intData));

        // Verify that FCV downgrade succeeds after the setClusterParameter operation has drained.
        fixture.asAdmin(({admin}) => assert.commandWorked(
                            admin.runCommand({setFeatureCompatibilityVersion: "5.0"})));
    }
}

{
    const rst = new ReplicaFixture();
    runTest(rst);
    rst.stop();
}

{
    const st = new ShardingFixture();
    runTest(st);
    st.stop();
}
}());