summaryrefslogtreecommitdiff
path: root/jstests/sharding/shard_config_db_collections.js
blob: 8f8f324957b49ab2584456607f58bf285cd99a50 (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
(function() {
'use strict';

// Database-level tests
{
    var st = new ShardingTest({shards: 2});
    var config = st.s.getDB('config');
    var admin = st.s.getDB('admin');

    // At first, there should not be an entry for config
    assert.eq(0, config.databases.count({"_id": "config"}));

    // Test that we can enable sharding on the config db
    assert.commandWorked(admin.runCommand({enableSharding: 'config'}));

    // We should never have a metadata doc for config, it is generated in-mem
    assert.eq(0, config.databases.count({"_id": "config"}));

    // Test that you cannot set the primary shard for config (not even to 'config')
    assert.commandFailed(admin.runCommand({movePrimary: 'config', to: st.shard0.shardName}));
    assert.commandFailed(admin.runCommand({movePrimary: 'config', to: 'config'}));

    st.stop();
}

// Test that only system.sessions may be sharded.
{
    var st = new ShardingTest({shards: 2});
    var admin = st.s.getDB('admin');

    assert.commandWorked(
        admin.runCommand({shardCollection: "config.system.sessions", key: {_id: 1}}));
    assert.eq(0, st.s.getDB('config').chunks.count({"shard": "config"}));

    assert.commandFailed(admin.runCommand({shardCollection: "config.anythingelse", key: {_id: 1}}));

    st.stop();
}

// Cannot shard things in config without shards.
{
    var st = new ShardingTest({shards: 0});
    var admin = st.s.getDB('admin');

    assert.commandFailed(
        admin.runCommand({shardCollection: "config.system.sessions", key: {_id: 1}}));

    st.stop();
}
})();