summaryrefslogtreecommitdiff
path: root/jstests/multiVersion/wt_index_option_defaults_replset.js
blob: af17bd182b89b102b1b8e0eb9bc308435f824fa5 (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
/**
 * Creates a replica set with a 3.2 primary and a 3.0 secondary. Tests that the
 * "indexOptionDefaults" specified to collection creation are replicated by the 3.2 primary, but
 * ignored by the 3.0 secondary.
 */
(function() {
    'use strict';

    var replSetName = 'index_option_defaults';
    var nodes = [
        {binVersion: 'latest', storageEngine: 'wiredTiger'},
        {binVersion: '3.0', storageEngine: 'wiredTiger'},
    ];

    var rst = new ReplSetTest({name: replSetName, nodes: nodes});
    var conns = rst.startSet({startClean: true});

    // Use write commands in order to make assertions about success of operations based on the
    // response.
    conns.forEach(function(conn) {
        conn.forceWriteMode('commands');
    });

    // Rig the election so that the 3.2 node becomes the primary.
    var replSetConfig = rst.getReplSetConfig();
    replSetConfig.members[1].priority = 0;
    replSetConfig.protocolVersion = 0;

    rst.initiate(replSetConfig);

    var primary32 = conns[0].getDB('test');
    var secondary30 = conns[1].getDB('test');

    // Create a collection with "indexOptionDefaults" specified.
    var indexOptions = {storageEngine: {wiredTiger: {configString: 'prefix_compression=false'}}};
    assert.commandWorked(primary32.runCommand({create: 'coll', indexOptionDefaults: indexOptions}));

    // Verify that the "indexOptionDefaults" field is present in the corresponding oplog entry.
    var entry =
        primary32.getSiblingDB('local').oplog.rs.find().sort({$natural: -1}).limit(1).next();
    assert.docEq(indexOptions,
                 entry.o.indexOptionDefaults,
                 'indexOptionDefaults were not replicated: ' + tojson(entry));

    rst.awaitReplication();

    var collectionInfos = secondary30.getCollectionInfos({name: 'coll'});
    assert.eq(1,
              collectionInfos.length,
              'collection "coll" was not created on the secondary: ' + tojson(collectionInfos));

    assert(!collectionInfos[0].options.hasOwnProperty('indexOptionDefaults'),
           'indexOptionDefaults should not have been applied: ' + tojson(collectionInfos));

    rst.stopSet();
})();

/**
 * Creates a replica set with a 3.0 primary and a 3.2 secondary. Tests that the
 * "indexOptionDefaults" specified on a collection creation are ignored by the 3.0 primary, but
 * still replicated to the 3.2 secondary.
 */
(function() {
    'use strict';

    var replSetName = 'default_index_options';
    var nodes = [
        {binVersion: '3.0', storageEngine: 'wiredTiger'},
        {binVersion: 'latest', storageEngine: 'wiredTiger'},
    ];

    var rst = new ReplSetTest({name: replSetName, nodes: nodes});
    var conns = rst.startSet({startClean: true});

    // Use write commands in order to make assertions about success of operations based on the
    // response.
    conns.forEach(function(conn) {
        conn.forceWriteMode('commands');
    });

    // Rig the election so that the 3.0 node becomes the primary.
    var replSetConfig = rst.getReplSetConfig();
    replSetConfig.members[1].priority = 0;

    rst.initiate(replSetConfig);

    var primary30 = conns[0].getDB('test');
    var secondary32 = conns[1].getDB('test');

    // Create a collection with "indexOptionDefaults" specified.
    var indexOptions = {storageEngine: {wiredTiger: {configString: 'prefix_compression=false'}}};
    assert.commandWorked(primary30.runCommand({create: 'coll', indexOptionDefaults: indexOptions}));

    // Verify that the "indexOptionDefaults" field is present in the corresponding oplog entry.
    var entry =
        primary30.getSiblingDB('local').oplog.rs.find().sort({$natural: -1}).limit(1).next();
    assert.docEq(indexOptions,
                 entry.o.indexOptionDefaults,
                 'indexOptionDefaults were not replicated: ' + tojson(entry));

    rst.awaitReplication();

    var collectionInfos = secondary32.getCollectionInfos({name: 'coll'});
    assert.eq(1,
              collectionInfos.length,
              'collection "coll" was not created on the secondary: ' + tojson(collectionInfos));

    assert.docEq(indexOptions,
                 collectionInfos[0].options.indexOptionDefaults,
                 'indexOptionDefaults were not applied: ' + tojson(collectionInfos));

    rst.stopSet();
})();