summaryrefslogtreecommitdiff
path: root/jstests/sharding/user_flags_sharded.js
blob: f629c3b759f6ed386f2f71c4c2761d8619255f21 (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
// Test that when user flags are set on a collection,
// then collection is sharded, flags get carried over.
(function() {

    if (jsTest.options().storageEngine === "mmapv1") {
        // the dbname and collection we'll be working with
        var dbname = "testDB";
        var coll = "userFlagsColl";
        var ns = dbname + "." + coll;

        // First create fresh collection on a new standalone mongod
        var newShardConn = MongoRunner.runMongod({});
        var db1 = newShardConn.getDB(dbname);
        var t = db1.getCollection(coll);
        print(t);
        db1.getCollection(coll).drop();  // in case collection already existed
        db1.createCollection(coll);

        // Then verify the new collection has userFlags set to 0
        var collstats = db1.getCollection(coll).stats();
        print("*************** Fresh Collection Stats ************");
        printjson(collstats);
        assert.eq(collstats.userFlags, 1, "fresh collection doesn't have userFlags = 1 ");

        // Now we modify the collection with the usePowerOf2Sizes flag
        var res = db1.runCommand({"collMod": coll, "usePowerOf2Sizes": false});
        assert.eq(res.ok, 1, "collMod failed");

        // and insert some stuff, for the hell of it
        var numdocs = 20;
        for (i = 0; i < numdocs; i++) {
            assert.writeOK(db1.getCollection(coll).insert({_id: i}));
        }

        // Next verify that userFlags has changed to 0
        collstats = db1.getCollection(coll).stats();
        print("*************** Collection Stats After CollMod ************");
        printjson(collstats);
        assert.eq(collstats.userFlags, 0, "modified collection should have userFlags = 0 ");

        // start up a new sharded cluster, and add previous mongod
        var s = new ShardingTest({name: "user_flags", shards: 1});
        assert(s.admin.runCommand({addshard: newShardConn.host, name: "myShard"}).ok,
               "did not accept new shard");

        // enable sharding of the collection. Only 1 chunk initially, so move it to
        // other shard to create the collection on that shard
        s.adminCommand({enablesharding: dbname});
        s.adminCommand({shardcollection: ns, key: {_id: 1}});
        s.adminCommand({moveChunk: ns, find: {_id: 1}, to: "shard0000", _waitForDelete: true});

        print("*************** Collection Stats On Other Shard ************");
        var shard2 = s._connections[0].getDB(dbname);
        shard2stats = shard2.getCollection(coll).stats();
        printjson(shard2stats);

        assert.eq(shard2stats.count, numdocs, "moveChunk didn't succeed");
        assert.eq(shard2stats.userFlags, 0, "new shard should also have userFlags = 0 ");

        MongoRunner.stopMongod(newShardConn);
        s.stop();
    }

})();