2
// Tests mongos's failure tolerance for replica set shards and read preference queries
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.
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).
14
var options = {separateConfig : true,
16
rsOptions : { nodes : 2 }};
18
var st = new ShardingTest({shards : 3, mongos : 1, other : options});
22
var admin = mongos.getDB( "admin" );
23
var shards = mongos.getDB( "config" ).shards.find().toArray();
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 }) );
29
var collSharded = mongos.getCollection( "fooSharded.barSharded" );
30
var collUnsharded = mongos.getCollection( "fooUnsharded.barUnsharded" );
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 }) );
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(),
48
to : shards[1]._id }) );
50
st.printShardingStatus();
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) {
58
gle = database.getLastErrorObj();
63
if (!gle.err) doassert("getLastError is null: " + tojson(gle) + " :" + msg);
71
jsTest.log("Inserting initial data...");
73
var mongosConnActive = new Mongo( mongos.host );
74
var mongosConnIdle = null;
75
var mongosConnNew = null;
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());
81
mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 1 });
82
assert.eq(null, mongosConnActive.getCollection( collUnsharded.toString() ).getDB().getLastError());
84
jsTest.log("Stopping primary of third shard...");
86
mongosConnIdle = new Mongo( mongos.host );
88
st.rs2.stop(st.rs2.getPrimary(), true /*wait for stop*/ );
90
jsTest.log("Testing active connection with third primary down...");
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 }));
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());
103
jsTest.log("Testing idle connection with third primary down...");
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());
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 }) );
116
jsTest.log("Testing new connections with third primary down...");
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 }) );
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());
135
gc(); // Clean up new connections
137
jsTest.log("Stopping primary of second shard...");
139
mongosConnIdle = new Mongo( mongos.host );
141
// Need to save this node for later
142
var rs1Secondary = st.rs1.getSecondary();
144
st.rs1.stop(st.rs1.getPrimary(), true /* wait for stop */);
146
jsTest.log("Testing active connection with second primary down...");
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);
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 });
160
assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
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 });
169
assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
170
mongosConnActive.setSlaveOk(false);
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 }));
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 }));
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 }));
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 }));
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());
200
jsTest.log("Testing idle connection with second primary down...");
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());
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);
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 });
222
assert.neq(null, mongosConnIdle.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
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 });
231
assert.neq(null, mongosConnIdle.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
232
mongosConnIdle.setSlaveOk(false);
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 }));
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 }));
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 }));
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 }));
254
jsTest.log("Testing new connections with second primary down...");
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 }) );
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 });
275
mongosConnNew = new Mongo( mongos.host );
276
mongosConnNew.setReadPref("primary");
277
assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
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 });
290
mongosConnNew = new Mongo( mongos.host );
291
mongosConnNew.setSlaveOk();
292
mongosConnNew.setReadPref("primary");
293
assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }));
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 }));
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 }));
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 }));
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 }));
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());
346
gc(); // Clean up new connections
348
jsTest.log("Stopping primary of first shard...");
350
mongosConnIdle = new Mongo( mongos.host );
352
st.rs0.stop(st.rs0.getPrimary(), true /*wait for stop*/ );
354
jsTest.log("Testing active connection with first primary down...");
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 }));
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());
368
jsTest.log("Testing idle connection with first primary down...");
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());
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 }) );
382
jsTest.log("Testing new connections with first primary down...");
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 }) );
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());
404
gc(); // Clean up new connections
406
jsTest.log("Stopping second shard...");
408
mongosConnIdle = new Mongo( mongos.host );
410
st.rs1.stop(rs1Secondary, true /* wait for stop */);
412
jsTest.log("Testing active connection with second shard down...");
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 }));
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());
425
jsTest.log("Testing idle connection with second shard down...");
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());
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 }) );
438
jsTest.log("Testing new connections with second shard down...");
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 }) );
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());
457
gc(); // Clean up new connections