~ubuntu-branches/ubuntu/wily/juju-mongodb/wily-proposed

« back to all changes in this revision

Viewing changes to jstests/sharding/mongos_rs_shard_failure_tolerance.js

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-22 14:52:36 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140122145236-exgvx1pxk4fu9o4c
Tags: 2.4.9-0ubuntu1
* New upstream point release.
* d/p/0003-SERVER-12064-Use-gcc-atomic-builtins-if-available.patch:
  Dropped - not really needed for this version on mongodb.
* d/install: Don't ship mongo binary, its broken without a JS engine
  (LP: #1270098).
* d/p/0005-disable-jstests.patch: Dropped in preference to updates to
  d/p/0001-Add-option-to-disable-javascript.patch - rebased on revised
  upstream pull request.
* d/rules: Don't strip binaries during build so we get a ddeb.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Tests mongos's failure tolerance for replica set shards and read preference queries
 
3
//
 
4
// Sets up a cluster with three shards, the first shard of which has an unsharded collection and
 
5
// half a sharded collection.  The second shard has the second half of the sharded collection, and
 
6
// the third shard has nothing.  Progressively shuts down the primary of each shard to see the
 
7
// impact on the cluster.
 
8
//
 
9
// Three different connection states are tested - active (connection is active through whole
 
10
// sequence), idle (connection is connected but not used before a shard change), and new
 
11
// (connection connected after shard change).
 
12
//
 
13
 
 
14
var options = {separateConfig : true,
 
15
               rs : true,
 
16
               rsOptions : { nodes : 2 }};
 
17
 
 
18
var st = new ShardingTest({shards : 3, mongos : 1, other : options});
 
19
st.stopBalancer();
 
20
 
 
21
var mongos = st.s0;
 
22
var admin = mongos.getDB( "admin" );
 
23
var shards = mongos.getDB( "config" ).shards.find().toArray();
 
24
 
 
25
assert.commandWorked( admin.runCommand({ setParameter : 1, traceExceptions : true }) );
 
26
assert.commandWorked( admin.runCommand({ setParameter : 1, ignoreInitialVersionFailure : true }) );
 
27
assert.commandWorked( admin.runCommand({ setParameter : 1, authOnPrimaryOnly : false }) );
 
28
 
 
29
var collSharded = mongos.getCollection( "fooSharded.barSharded" );
 
30
var collUnsharded = mongos.getCollection( "fooUnsharded.barUnsharded" );
 
31
 
 
32
// Create the unsharded database
 
33
collUnsharded.insert({ some : "doc" });
 
34
assert.eq( null, collUnsharded.getDB().getLastError() );
 
35
collUnsharded.remove({});
 
36
assert.eq( null, collUnsharded.getDB().getLastError() );
 
37
printjson( admin.runCommand({ movePrimary : collUnsharded.getDB().toString(),
 
38
                              to : shards[0]._id }) );
 
39
 
 
40
// Create the sharded database
 
41
assert.commandWorked( admin.runCommand({ enableSharding : collSharded.getDB().toString() }) );
 
42
printjson( admin.runCommand({ movePrimary : collSharded.getDB().toString(), to : shards[0]._id }) );
 
43
assert.commandWorked( admin.runCommand({ shardCollection : collSharded.toString(),
 
44
                                         key : { _id : 1 } }) );
 
45
assert.commandWorked( admin.runCommand({ split : collSharded.toString(), middle : { _id : 0 } }) );
 
46
assert.commandWorked( admin.runCommand({ moveChunk : collSharded.toString(),
 
47
                                         find : { _id : 0 },
 
48
                                         to : shards[1]._id }) );
 
49
 
 
50
st.printShardingStatus();
 
51
 
 
52
// Needed b/c the GLE command itself can fail if the shard is down ("write result unknown") - we
 
53
// don't care if this happens in this test, we only care that we did not get "write succeeded".
 
54
// Depending on the connection pool state, we could get either.
 
55
function gleErrorOrThrow(database, msg) {
 
56
    var gle;
 
57
    try {
 
58
        gle = database.getLastErrorObj();
 
59
    }
 
60
    catch (ex) {
 
61
        return;
 
62
    }
 
63
    if (!gle.err) doassert("getLastError is null: " + tojson(gle) + " :" + msg);
 
64
    return;
 
65
};
 
66
 
 
67
//
 
68
// Setup is complete
 
69
//
 
70
 
 
71
jsTest.log("Inserting initial data...");
 
72
 
 
73
var mongosConnActive = new Mongo( mongos.host );
 
74
var mongosConnIdle = null;
 
75
var mongosConnNew = null;
 
76
 
 
77
mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : -1 });
 
78
mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : 1 });
 
79
assert.eq(null, mongosConnActive.getCollection( collSharded.toString() ).getDB().getLastError());
 
80
 
 
81
mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 1 });
 
82
assert.eq(null, mongosConnActive.getCollection( collUnsharded.toString() ).getDB().getLastError());
 
83
 
 
84
jsTest.log("Stopping primary of third shard...");
 
85
 
 
86
mongosConnIdle = new Mongo( mongos.host );
 
87
 
 
88
st.rs2.stop(st.rs2.getPrimary(), true /*wait for stop*/ );
 
89
 
 
90
jsTest.log("Testing active connection with third primary down...");
 
91
 
 
92
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
93
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : 1 }));
 
94
assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
95
 
 
96
mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : -2 });
 
97
assert.gleSuccess(mongosConnActive.getCollection( collSharded.toString() ).getDB());
 
98
mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : 2 });
 
99
assert.gleSuccess(mongosConnActive.getCollection( collSharded.toString() ).getDB());
 
100
mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 2 });
 
101
assert.gleSuccess(mongosConnActive.getCollection( collUnsharded.toString() ).getDB());
 
102
 
 
103
jsTest.log("Testing idle connection with third primary down...");
 
104
 
 
105
mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : -3 });
 
106
assert.gleSuccess(mongosConnIdle.getCollection( collSharded.toString() ).getDB());
 
107
mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : 3 });
 
108
assert.gleSuccess(mongosConnIdle.getCollection( collSharded.toString() ).getDB());
 
109
mongosConnIdle.getCollection( collUnsharded.toString() ).insert({ _id : 3 });
 
110
assert.gleSuccess(mongosConnIdle.getCollection( collUnsharded.toString() ).getDB());
 
111
 
 
112
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : -1 }) );
 
113
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : 1 }) );
 
114
assert.neq(null, mongosConnIdle.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }) );
 
115
 
 
116
jsTest.log("Testing new connections with third primary down...");
 
117
 
 
118
mongosConnNew = new Mongo( mongos.host );
 
119
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : -1 }) );
 
120
mongosConnNew = new Mongo( mongos.host );
 
121
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : 1 }) );
 
122
mongosConnNew = new Mongo( mongos.host );
 
123
assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }) );
 
124
 
 
125
mongosConnNew = new Mongo( mongos.host );
 
126
mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : -4 });
 
127
assert.gleSuccess(mongosConnNew.getCollection( collSharded.toString() ).getDB());
 
128
mongosConnNew = new Mongo( mongos.host );
 
129
mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : 4 });
 
130
assert.gleSuccess(mongosConnNew.getCollection( collSharded.toString() ).getDB());
 
131
mongosConnNew = new Mongo( mongos.host );
 
132
mongosConnNew.getCollection( collUnsharded.toString() ).insert({ _id : 4 });
 
133
assert.gleSuccess(mongosConnNew.getCollection( collUnsharded.toString() ).getDB());
 
134
 
 
135
gc(); // Clean up new connections
 
136
 
 
137
jsTest.log("Stopping primary of second shard...");
 
138
 
 
139
mongosConnIdle = new Mongo( mongos.host );
 
140
 
 
141
// Need to save this node for later
 
142
var rs1Secondary = st.rs1.getSecondary();
 
143
 
 
144
st.rs1.stop(st.rs1.getPrimary(), true /* wait for stop */);
 
145
 
 
146
jsTest.log("Testing active connection with second primary down...");
 
147
 
 
148
// Reads with read prefs
 
149
mongosConnActive.setSlaveOk();
 
150
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
151
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : 1 }));
 
152
assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
153
mongosConnActive.setSlaveOk(false);
 
154
 
 
155
mongosConnActive.setReadPref("primary");
 
156
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
157
assert.throws(function() {
 
158
    mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : 1 });
 
159
});
 
160
assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
161
 
 
162
//Ensure read prefs override slaveOK
 
163
mongosConnActive.setSlaveOk();
 
164
mongosConnActive.setReadPref("primary");
 
165
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
166
assert.throws(function() {
 
167
    mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : 1 });
 
168
});
 
169
assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
170
mongosConnActive.setSlaveOk(false);
 
171
 
 
172
mongosConnActive.setReadPref("secondary");
 
173
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
174
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : 1 }));
 
175
assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
176
 
 
177
mongosConnActive.setReadPref("primaryPreferred");
 
178
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
179
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : 1 }));
 
180
assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
181
 
 
182
mongosConnActive.setReadPref("secondaryPreferred");
 
183
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
184
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : 1 }));
 
185
assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
186
 
 
187
mongosConnActive.setReadPref("nearest");
 
188
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
189
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : 1 }));
 
190
assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
191
 
 
192
// Writes
 
193
mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : -5 });
 
194
assert.gleSuccess(mongosConnActive.getCollection( collSharded.toString() ).getDB());
 
195
mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : 5 });
 
196
gleErrorOrThrow(mongosConnActive.getCollection( collSharded.toString() ).getDB());
 
197
mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 5 });
 
198
assert.gleSuccess(mongosConnActive.getCollection( collUnsharded.toString() ).getDB());
 
199
 
 
200
jsTest.log("Testing idle connection with second primary down...");
 
201
 
 
202
// Writes
 
203
mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : -6 });
 
204
assert.gleSuccess(mongosConnIdle.getCollection( collSharded.toString() ).getDB());
 
205
mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : 6 });
 
206
gleErrorOrThrow(mongosConnIdle.getCollection( collSharded.toString() ).getDB());
 
207
mongosConnIdle.getCollection( collUnsharded.toString() ).insert({ _id : 6 });
 
208
assert.gleSuccess(mongosConnIdle.getCollection( collUnsharded.toString() ).getDB());
 
209
 
 
210
// Reads with read prefs
 
211
mongosConnIdle.setSlaveOk();
 
212
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : -1 }) );
 
213
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : 1 }) );
 
214
assert.neq(null, mongosConnIdle.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }) );
 
215
mongosConnIdle.setSlaveOk(false);
 
216
 
 
217
mongosConnIdle.setReadPref("primary");
 
218
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
219
assert.throws(function() {
 
220
    mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : 1 });
 
221
});
 
222
assert.neq(null, mongosConnIdle.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
223
 
 
224
// Ensure read prefs override slaveOK
 
225
mongosConnIdle.setSlaveOk();
 
226
mongosConnIdle.setReadPref("primary");
 
227
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
228
assert.throws(function() {
 
229
    mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : 1 });
 
230
});
 
231
assert.neq(null, mongosConnIdle.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
232
mongosConnIdle.setSlaveOk(false);
 
233
 
 
234
mongosConnIdle.setReadPref("secondary");
 
235
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
236
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : 1 }));
 
237
assert.neq(null, mongosConnIdle.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
238
 
 
239
mongosConnIdle.setReadPref("primaryPreferred");
 
240
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
241
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : 1 }));
 
242
assert.neq(null, mongosConnIdle.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
243
 
 
244
mongosConnIdle.setReadPref("secondaryPreferred");
 
245
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
246
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : 1 }));
 
247
assert.neq(null, mongosConnIdle.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
248
 
 
249
mongosConnIdle.setReadPref("nearest");
 
250
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
251
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : 1 }));
 
252
assert.neq(null, mongosConnIdle.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
253
 
 
254
jsTest.log("Testing new connections with second primary down...");
 
255
 
 
256
// Reads with read prefs
 
257
mongosConnNew = new Mongo( mongos.host );
 
258
mongosConnNew.setSlaveOk();
 
259
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : -1 }) );
 
260
mongosConnNew = new Mongo( mongos.host );
 
261
mongosConnNew.setSlaveOk();
 
262
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : 1 }) );
 
263
mongosConnNew = new Mongo( mongos.host );
 
264
mongosConnNew.setSlaveOk();
 
265
assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }) );
 
266
 
 
267
mongosConnNew = new Mongo( mongos.host );
 
268
mongosConnNew.setReadPref("primary");
 
269
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
270
mongosConnNew = new Mongo( mongos.host );
 
271
mongosConnNew.setReadPref("primary");
 
272
assert.throws(function() {
 
273
    mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : 1 });
 
274
});
 
275
mongosConnNew = new Mongo( mongos.host );
 
276
mongosConnNew.setReadPref("primary");
 
277
assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
278
 
 
279
// Ensure read prefs override slaveok
 
280
mongosConnNew = new Mongo( mongos.host );
 
281
mongosConnNew.setSlaveOk();
 
282
mongosConnNew.setReadPref("primary");
 
283
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
284
mongosConnNew = new Mongo( mongos.host );
 
285
mongosConnNew.setSlaveOk();
 
286
mongosConnNew.setReadPref("primary");
 
287
assert.throws(function() {
 
288
    mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : 1 });
 
289
});
 
290
mongosConnNew = new Mongo( mongos.host );
 
291
mongosConnNew.setSlaveOk();
 
292
mongosConnNew.setReadPref("primary");
 
293
assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
294
 
 
295
mongosConnNew = new Mongo( mongos.host );
 
296
mongosConnNew.setReadPref("secondary");
 
297
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
298
mongosConnNew = new Mongo( mongos.host );
 
299
mongosConnNew.setReadPref("secondary");
 
300
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : 1 }));
 
301
mongosConnNew = new Mongo( mongos.host );
 
302
mongosConnNew.setReadPref("secondary");
 
303
assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
304
 
 
305
mongosConnNew = new Mongo( mongos.host );
 
306
mongosConnNew.setReadPref("primaryPreferred");
 
307
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
308
mongosConnNew = new Mongo( mongos.host );
 
309
mongosConnNew.setReadPref("primaryPreferred");
 
310
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : 1 }));
 
311
mongosConnNew = new Mongo( mongos.host );
 
312
mongosConnNew.setReadPref("primaryPreferred");
 
313
assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
314
 
 
315
mongosConnNew = new Mongo( mongos.host );
 
316
mongosConnNew.setReadPref("secondaryPreferred");
 
317
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
318
mongosConnNew = new Mongo( mongos.host );
 
319
mongosConnNew.setReadPref("secondaryPreferred");
 
320
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : 1 }));
 
321
mongosConnNew = new Mongo( mongos.host );
 
322
mongosConnNew.setReadPref("secondaryPreferred");
 
323
assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
324
 
 
325
mongosConnNew = new Mongo( mongos.host );
 
326
mongosConnNew.setReadPref("nearest");
 
327
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
328
mongosConnNew = new Mongo( mongos.host );
 
329
mongosConnNew.setReadPref("nearest");
 
330
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : 1 }));
 
331
mongosConnNew = new Mongo( mongos.host );
 
332
mongosConnNew.setReadPref("nearest");
 
333
assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
334
 
 
335
// Writes
 
336
mongosConnNew = new Mongo( mongos.host );
 
337
mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : -7 });
 
338
assert.gleSuccess(mongosConnNew.getCollection( collSharded.toString() ).getDB());
 
339
mongosConnNew = new Mongo( mongos.host );
 
340
mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : 7 });
 
341
gleErrorOrThrow(mongosConnNew.getCollection( collSharded.toString() ).getDB());
 
342
mongosConnNew = new Mongo( mongos.host );
 
343
mongosConnNew.getCollection( collUnsharded.toString() ).insert({ _id : 7 });
 
344
assert.gleSuccess(mongosConnNew.getCollection( collUnsharded.toString() ).getDB());
 
345
 
 
346
gc(); // Clean up new connections
 
347
 
 
348
jsTest.log("Stopping primary of first shard...");
 
349
 
 
350
mongosConnIdle = new Mongo( mongos.host );
 
351
 
 
352
st.rs0.stop(st.rs0.getPrimary(), true /*wait for stop*/ );
 
353
 
 
354
jsTest.log("Testing active connection with first primary down...");
 
355
 
 
356
mongosConnActive.setSlaveOk();
 
357
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
358
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : 1 }));
 
359
assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
360
 
 
361
mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : -8 });
 
362
gleErrorOrThrow(mongosConnActive.getCollection( collSharded.toString() ).getDB());
 
363
mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : 8 });
 
364
gleErrorOrThrow(mongosConnActive.getCollection( collSharded.toString() ).getDB());
 
365
mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 8 });
 
366
gleErrorOrThrow(mongosConnActive.getCollection( collUnsharded.toString() ).getDB());
 
367
 
 
368
jsTest.log("Testing idle connection with first primary down...");
 
369
 
 
370
mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : -9 });
 
371
gleErrorOrThrow(mongosConnIdle.getCollection( collSharded.toString() ).getDB());
 
372
mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : 9 });
 
373
gleErrorOrThrow(mongosConnIdle.getCollection( collSharded.toString() ).getDB());
 
374
mongosConnIdle.getCollection( collUnsharded.toString() ).insert({ _id : 9 });
 
375
gleErrorOrThrow(mongosConnIdle.getCollection( collUnsharded.toString() ).getDB());
 
376
 
 
377
mongosConnIdle.setSlaveOk();
 
378
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : -1 }) );
 
379
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : 1 }) );
 
380
assert.neq(null, mongosConnIdle.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }) );
 
381
 
 
382
jsTest.log("Testing new connections with first primary down...");
 
383
 
 
384
mongosConnNew = new Mongo( mongos.host );
 
385
mongosConnNew.setSlaveOk();
 
386
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : -1 }) );
 
387
mongosConnNew = new Mongo( mongos.host );
 
388
mongosConnNew.setSlaveOk();
 
389
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : 1 }) );
 
390
mongosConnNew = new Mongo( mongos.host );
 
391
mongosConnNew.setSlaveOk();
 
392
assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }) );
 
393
 
 
394
mongosConnNew = new Mongo( mongos.host );
 
395
mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : -10 });
 
396
gleErrorOrThrow(mongosConnNew.getCollection( collSharded.toString() ).getDB());
 
397
mongosConnNew = new Mongo( mongos.host );
 
398
mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : 10 });
 
399
gleErrorOrThrow(mongosConnNew.getCollection( collSharded.toString() ).getDB());
 
400
mongosConnNew = new Mongo( mongos.host );
 
401
mongosConnNew.getCollection( collUnsharded.toString() ).insert({ _id : 10 });
 
402
gleErrorOrThrow(mongosConnNew.getCollection( collUnsharded.toString() ).getDB());
 
403
 
 
404
gc(); // Clean up new connections
 
405
 
 
406
jsTest.log("Stopping second shard...");
 
407
 
 
408
mongosConnIdle = new Mongo( mongos.host );
 
409
 
 
410
st.rs1.stop(rs1Secondary, true /* wait for stop */);
 
411
 
 
412
jsTest.log("Testing active connection with second shard down...");
 
413
 
 
414
mongosConnActive.setSlaveOk();
 
415
assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : -1 }));
 
416
assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
 
417
 
 
418
mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : -11 });
 
419
gleErrorOrThrow(mongosConnActive.getCollection( collSharded.toString() ).getDB());
 
420
mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : 11 });
 
421
gleErrorOrThrow(mongosConnActive.getCollection( collSharded.toString() ).getDB());
 
422
mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 11 });
 
423
gleErrorOrThrow(mongosConnActive.getCollection( collUnsharded.toString() ).getDB());
 
424
 
 
425
jsTest.log("Testing idle connection with second shard down...");
 
426
 
 
427
mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : -12 });
 
428
gleErrorOrThrow(mongosConnIdle.getCollection( collSharded.toString() ).getDB());
 
429
mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : 12 });
 
430
gleErrorOrThrow(mongosConnIdle.getCollection( collSharded.toString() ).getDB());
 
431
mongosConnIdle.getCollection( collUnsharded.toString() ).insert({ _id : 12 });
 
432
gleErrorOrThrow(mongosConnIdle.getCollection( collUnsharded.toString() ).getDB());
 
433
 
 
434
mongosConnIdle.setSlaveOk();
 
435
assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : -1 }) );
 
436
assert.neq(null, mongosConnIdle.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }) );
 
437
 
 
438
jsTest.log("Testing new connections with second shard down...");
 
439
 
 
440
mongosConnNew = new Mongo( mongos.host );
 
441
mongosConnNew.setSlaveOk();
 
442
assert.neq(null, mongosConnNew.getCollection( collSharded.toString() ).findOne({ _id : -1 }) );
 
443
mongosConnNew = new Mongo( mongos.host );
 
444
mongosConnNew.setSlaveOk();
 
445
assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }) );
 
446
 
 
447
mongosConnNew = new Mongo( mongos.host );
 
448
mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : -13 });
 
449
gleErrorOrThrow(mongosConnNew.getCollection( collSharded.toString() ).getDB());
 
450
mongosConnNew = new Mongo( mongos.host );
 
451
mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : 13 });
 
452
gleErrorOrThrow(mongosConnNew.getCollection( collSharded.toString() ).getDB());
 
453
mongosConnNew = new Mongo( mongos.host );
 
454
mongosConnNew.getCollection( collUnsharded.toString() ).insert({ _id : 13 });
 
455
gleErrorOrThrow(mongosConnNew.getCollection( collUnsharded.toString() ).getDB());
 
456
 
 
457
gc(); // Clean up new connections
 
458
 
 
459
jsTest.log("DONE!");
 
460
st.stop();