summaryrefslogtreecommitdiff
path: root/jstests/multiVersion/explain.js
blob: 2579c12f164e04f83f13de6ad06926c3c4645151 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Multiversion scenarios for explain.

var explain, testDb, coll, options, st;

//
// Standalone
//

// Ensure that a 2.8 shell can explain .find() against a 2.6 mongod
var mongod26 = MongoRunner.runMongod({binVersion: "2.6"});

testDb = mongod26.getDB("explain-multiversion");
testDb.dropDatabase();
coll = testDb.standalone;
coll.drop();

coll.insert({_id: 1, a: 1});

// Make sure that we get the expected 2.6-style explain.
explain = coll.find().explain();
assert.eq(explain.cursor, "BasicCursor");
assert.eq(explain.n, 1);

// Also test the new .explain.find().finish() style.
explain = coll.explain().find().finish();
assert.eq(explain.cursor, "BasicCursor");
assert.eq(explain.n, 1);

MongoRunner.stopMongod(mongod26.port);

//
// Sharded cluster
//   --2.6 mongos
//   --2.6 config
//   --two shards, both version 2.6
//

options = {
    sync: true, // Old clusters can't use replsets for config servers
    mongosOptions: {binVersion: "2.6"},
    configOptions: {binVersion: "2.6"},
    shardOptions: {binVersion: "2.6"}
}

st = new ShardingTest({shards: 2, other: options});

testDb = st.s.getDB("explain-multiversion");
testDb.dropDatabase();
coll = testDb.standalone;
coll.drop();

assert.commandWorked(testDb.adminCommand({enableSharding: testDb.getName()}));
testDb.adminCommand({shardCollection: coll.getFullName(), key: {_id: 1}});

coll.insert({_id: 1, a: 1});

// Ensure that explain gives us 2.6-style sharded output.
explain = coll.find().explain();
assert("clusteredType" in explain);
assert("shards" in explain);
assert.eq(explain.n, 1);
assert.gte(explain.nscanned, 1);
assert.gte(explain.nscannedObjects, 1);

// Also test .explain().find().finish() syntax.
explain = coll.explain().find().finish();
assert("clusteredType" in explain);
assert("shards" in explain);
assert.eq(explain.n, 1);
assert.gte(explain.nscanned, 1);
assert.gte(explain.nscannedObjects, 1);

st.stop();

//
// Sharded cluster
//   --2.8 mongos
//   --2.8 config
//   --two shards, both 2.6
//

options = {
    sync: true, // Mixed version clusters can't use replsets for config servers
    mongosOptions: {binVersion: "2.8"},
    configOptions: {binVersion: "2.8"},
    shardOptions: {binVersion: "2.6"}
}

st = new ShardingTest({shards: 2, other: options});

testDb = st.s.getDB("explain-multiversion");
testDb.dropDatabase();
coll = testDb.standalone;
coll.drop();

assert.commandWorked(testDb.adminCommand({enableSharding: testDb.getName()}));
testDb.adminCommand({shardCollection: coll.getFullName(), key: {_id: 1}});

coll.insert({_id: 1, a: 1});

// Ensure that explain gives us 2.6-style sharded output.
explain = coll.find().explain();
assert("clusteredType" in explain);
assert("shards" in explain);
assert.eq(explain.n, 1);
assert.gte(explain.nscanned, 1);
assert.gte(explain.nscannedObjects, 1);

// Also test .explain().find().finish() syntax.
explain = coll.explain().find().finish();
assert("clusteredType" in explain);
assert("shards" in explain);
assert.eq(explain.n, 1);
assert.gte(explain.nscanned, 1);
assert.gte(explain.nscannedObjects, 1);

st.stop();

//
// Sharded cluster
//   --2.8 mongos
//   --2.8 config
//   --two shards, one 2.6 and one 2.8
//

options = {
    sync: true, // Mixed version clusters can't use replsets for config servers
    mongosOptions: {binVersion: "2.8"},
    configOptions: {binVersion: "2.8"},
    shardOptions: {binVersion: ["2.6", "2.8"]}
}

st = new ShardingTest({shards: 2, other: options});

testDb = st.s.getDB("explain-multiversion");
testDb.dropDatabase();
coll = testDb.standalone;
coll.drop();

assert.commandWorked(testDb.adminCommand({enableSharding: testDb.getName()}));
var res = testDb.adminCommand({movePrimary: testDb.getName(), to: 'shard0001'});
assert(res.ok || res.errmsg == "it is already the primary");
testDb.adminCommand({shardCollection: coll.getFullName(), key: {_id: 1}});

// Disable the balancer and pre-split in order to ensure chunks on both shards.
st.stopBalancer();
assert.commandWorked(testDb.adminCommand({split: coll.getFullName(), middle: {_id: 5}}));
assert.commandWorked(testDb.adminCommand({moveChunk: coll.getFullName(),
                                          find: {_id: 5},
                                          to: "shard0000"}));
coll.insert({_id: 1});
coll.insert({_id: 10});

// Explain should aggregate mixed-version output in a 2.6-style way.
explain = coll.find().explain();
assert("clusteredType" in explain);
assert("shards" in explain);
assert.eq(explain.n, 2);
assert.gte(explain.nscanned, 1);
assert.gte(explain.nscannedObjects, 1);

// Also test .explain().find().finish() syntax.
explain = coll.explain().find().finish();
assert("clusteredType" in explain);
assert("shards" in explain);
assert.eq(explain.n, 2);
assert.gte(explain.nscanned, 1);
assert.gte(explain.nscannedObjects, 1);

st.stop();