File: cursor_timeout.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (64 lines) | stat: -rw-r--r-- 2,031 bytes parent folder | download | duplicates (3)
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
var st = new ShardingTest({ shards: 2, other: { chunkSize: 1 }});
st.stopBalancer();

var adminDB = st.admin;
var configDB = st.config;
var coll = st.s.getDB( 'test' ).user;

adminDB.runCommand({ enableSharding: coll.getDB().getName() });
adminDB.runCommand({ shardCollection: coll.getFullName(), key: { x: 1 }});

var data = 'c';
for( var x = 0; x < 18; x++ ){
    data += data;
}

for( x = 0; x < 200; x++ ){
    coll.insert({ x: x, v: data });
}

var chunkDoc = configDB.chunks.findOne();
var chunkOwner = chunkDoc.shard;
var toShard = configDB.shards.findOne({ _id: { $ne: chunkOwner }})._id;
var cmd = { moveChunk: coll.getFullName(), find: chunkDoc.min, to: toShard };
var res = adminDB.runCommand( cmd );

jsTest.log( 'move result: ' + tojson( res ));

var shardedCursorWithTimeout = coll.find();
var shardedCursorWithNoTimeout = coll.find();
shardedCursorWithNoTimeout.addOption( DBQuery.Option.noTimeout );

// Query directly to mongod
var shardHost = configDB.shards.findOne({ _id: chunkOwner }).host;
var mongod = new Mongo( shardHost );
var shardColl = mongod.getCollection( coll.getFullName() );

var cursorWithTimeout = shardColl.find();
var cursorWithNoTimeout = shardColl.find();
cursorWithNoTimeout.addOption( DBQuery.Option.noTimeout );

shardedCursorWithTimeout.next();
shardedCursorWithNoTimeout.next();

cursorWithTimeout.next();
cursorWithNoTimeout.next();

// Cursor cleanup is 10 minutes, but give a 8 min allowance --
// NOTE: Due to inaccurate timing on non-Linux platforms, mongos tries
// to timeout after 10 minutes but in fact is 15+ minutes;
// SERVER-8381
sleep( 1000 * 60 * 17 );

assert.throws( function(){ shardedCursorWithTimeout.itcount(); } );
assert.throws( function(){ cursorWithTimeout.itcount(); } );

var freshShardedItCount = coll.find().itcount();
// +1 because we already advanced once
assert.eq( freshShardedItCount, shardedCursorWithNoTimeout.itcount() + 1 );

var freshItCount = shardColl.find().itcount();
assert.eq( freshItCount, cursorWithNoTimeout.itcount() + 1 );

st.stop();