File: conc_update.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 (58 lines) | stat: -rw-r--r-- 1,670 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
load( "jstests/libs/slow_weekly_util.js" )
test = new SlowWeeklyMongod( "conc_update" )
db = test.getDB("concurrency")
db.dropDatabase();

NRECORDS=3*1024*1024 // this needs to be relatively big so that
                      // the update() will take a while, but it could
                      // probably be smaller.

print("loading "+NRECORDS+" documents (progress msg every 1024*1024 documents)")
for (i=0; i<(NRECORDS); i++) {
    db.conc.insert({x:i})
    if ((i%(1024*1024))==0)
	print("loaded " + i/(1024*1024) + " mibi-records")
}

print("making an index (this will take a while)")
db.conc.ensureIndex({x:1})

var c1=db.conc.count({x:{$lt:NRECORDS}})

updater=startParallelShell("db=db.getSisterDB('concurrency');\
                           db.concflag.insert( {inprog:true} );\
                           sleep(20);\
			   db.conc.update({}, {$inc:{x: "+NRECORDS+"}}, false, true);\
			   e=db.getLastError();\
			   print('update error: '+ e);\
			   db.concflag.update({},{inprog:false});\
			   assert.eq(e, null, 'update failed');");

assert.soon( function(){ var x = db.concflag.findOne(); return x && x.inprog; } , 
             "wait for fork" , 30000 , 1 );

querycount=0;
decrements=0;
misses=0

assert.soon( 
    function(){
	c2=db.conc.count({x:{$lt:NRECORDS}})
 	print(c2)
	querycount++;
	if (c2<c1)
	    decrements++;
	else
	    misses++;
	c1 = c2;        
        return ! db.concflag.findOne().inprog;
    } , 
    "update never finished" , 2 * 60 * 60 * 1000 , 10 );

print(querycount + " queries, " + decrements + " decrements, " + misses + " misses");

assert.eq( NRECORDS , db.conc.count() , "AT END 1" )

updater() // wait()

test.stop();