summaryrefslogtreecommitdiff
path: root/jstests/sharding/sharding_multiple_ns_rs.js
blob: f9ff596b87e722734e25f58b97cad89eea7b2e93 (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
// When checking UUID consistency, the shell attempts to run a command on the node it believes is
// primary in each shard. However, this test shuts down the primary of the shard. Since whether or
// not the shell detects the new primary before issuing the command is nondeterministic, skip the
// consistency check for this test.
TestData.skipCheckingUUIDsConsistentAcrossCluster = true;

(function() {
    'use strict';

    load("jstests/replsets/rslib.js");

    var s = new ShardingTest({shards: 1, mongos: 1, other: {rs: true, chunkSize: 1}});

    assert.commandWorked(s.s0.adminCommand({enablesharding: "test"}));
    assert.commandWorked(s.s0.adminCommand({shardcollection: "test.foo", key: {_id: 1}}));

    var db = s.getDB("test");

    var bulk = db.foo.initializeUnorderedBulkOp();
    var bulk2 = db.bar.initializeUnorderedBulkOp();
    for (var i = 0; i < 100; i++) {
        bulk.insert({_id: i, x: i});
        bulk2.insert({_id: i, x: i});
    }
    assert.writeOK(bulk.execute());
    assert.writeOK(bulk2.execute());

    s.splitAt("test.foo", {_id: 50});

    var other = new Mongo(s.s0.name);
    var dbother = other.getDB("test");

    assert.eq(5, db.foo.findOne({_id: 5}).x);
    assert.eq(5, dbother.foo.findOne({_id: 5}).x);

    assert.eq(5, db.bar.findOne({_id: 5}).x);
    assert.eq(5, dbother.bar.findOne({_id: 5}).x);

    s.rs0.awaitReplication();
    s.rs0.stopMaster(15);

    // Wait for mongos and the config server primary to recognize the new shard primary
    awaitRSClientHosts(db.getMongo(), s.rs0.getPrimary(), {ismaster: true});
    awaitRSClientHosts(db.getMongo(), s.configRS.getPrimary(), {ismaster: true});

    assert.eq(5, db.foo.findOne({_id: 5}).x);
    assert.eq(5, db.bar.findOne({_id: 5}).x);

    assert.commandWorked(s.s0.adminCommand({shardcollection: "test.bar", key: {_id: 1}}));
    s.splitAt("test.bar", {_id: 50});

    var yetagain = new Mongo(s.s.name);
    assert.eq(5, yetagain.getDB("test").bar.findOne({_id: 5}).x);
    assert.eq(5, yetagain.getDB("test").foo.findOne({_id: 5}).x);

    assert.eq(5, dbother.bar.findOne({_id: 5}).x);
    assert.eq(5, dbother.foo.findOne({_id: 5}).x);

    s.stop();
})();