summaryrefslogtreecommitdiff
path: root/jstests/sharding/unique_index_on_shardservers.js
blob: 1776aa44260251fbae762b58276d083c20590ab1 (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
// SERVER-34954 This test ensures a node started with --shardsvr and added to a replica set has
// the correct version of unique indexes upon re-initiation.
(function() {
    "use strict";
    load("jstests/libs/check_unique_indexes.js");

    let st = new ShardingTest({shards: 1, rs: {nodes: 1}, mongos: 1});
    let mongos = st.s;
    let rs = st.rs0;

    // Create `test.coll` and add some indexes on it:
    // with index versions as default, v=1 and v=2; both unique and standard types
    assert.writeOK(mongos.getDB("test").coll.insert({_id: 1, a: 1, b: 1, c: 1, d: 1, e: 1, f: 1}));
    assert.commandWorked(mongos.getDB("test").coll.createIndex({a: 1}, {"v": 1}));
    assert.commandWorked(mongos.getDB("test").coll.createIndex({b: 1}, {"v": 1, "unique": true}));
    assert.commandWorked(mongos.getDB("test").coll.createIndex({c: 1}, {"v": 2}));
    assert.commandWorked(mongos.getDB("test").coll.createIndex({d: 1}, {"v": 2, "unique": true}));
    assert.commandWorked(mongos.getDB("test").coll.createIndex({e: 1}));
    assert.commandWorked(mongos.getDB("test").coll.createIndex({f: 1}, {"unique": true}));

    // Add a node with --shardsvr to the replica set.
    let newNode = rs.add({'shardsvr': '', rsConfig: {priority: 0, votes: 0}});
    rs.reInitiate();
    rs.awaitSecondaryNodes();

    // After adding a new node as a ShardServer ensure the new node has unique indexes
    // in the correct version
    checkUniqueIndexFormatVersion(newNode.getDB("admin"));
    st.stop();
})();