File: gle_error_message.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 (154 lines) | stat: -rw-r--r-- 4,085 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
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
//
// Tests whether sharded GLE fails sanely and correctly reports failures.  
//

function waitForWrite(shardIndex, query, count) {
    var searchText = tojson(query) + " on shard " + shardIndex;
    jsTest.log( "Waiting for " + count + " document(s) with " + searchText );
    var shardDB = connect(shards[shardIndex].host + "/" + jsTestName());
    assert.soon( function() { return shardDB.coll.find( query ).count() == count; },
                 "Failed to find document with " + searchText,
                 /* timeout */ 10 * 1000,
                 /*interval*/ 10 );
}

jsTest.log( "Starting sharded cluster..." )

var st = new ShardingTest({ shards : 3,
                            mongos : 2,
                            verbose : 3,
                            other : { separateConfig : true } })

st.stopBalancer()

var mongos = st.s0
var admin = mongos.getDB( "admin" )
var config = mongos.getDB( "config" )
var coll = mongos.getCollection( jsTestName() + ".coll" )
var shards = config.shards.find().toArray()

jsTest.log( "Enabling sharding..." )

printjson( admin.runCommand({ enableSharding : "" + coll.getDB() }) )
printjson( admin.runCommand({ movePrimary : "" + coll.getDB(), to : shards[0]._id }) )
printjson( admin.runCommand({ shardCollection : "" + coll, key : { _id : 1 } }) )
printjson( admin.runCommand({ split : "" + coll, middle : { _id : 0 } }) )
printjson( admin.runCommand({ moveChunk : "" + coll, find : { _id : 0 }, to : shards[1]._id }) )

st.printShardingStatus()



jsTest.log( "Testing GLE...")

// insert to two diff shards
coll.insert({ _id : -1, hello : "world" })
coll.insert({ _id : 1, hello : "world" })

waitForWrite(0, {_id: -1}, 1);
waitForWrite(1, {_id:  1}, 1);

jsTest.log( "GLE : " + tojson( coll.getDB().getLastErrorObj() ) )



jsTest.log( "Testing GLE when writeback host goes down..." )

// insert to two diff shards
coll.insert({ _id : -2, hello : "world" })
coll.insert({ _id : 2, hello : "world" })

waitForWrite(0, {_id: -2}, 1);
waitForWrite(1, {_id:  2}, 1);

MongoRunner.stopMongod( st.shard0 )

jsTest.log( "GLE : " + tojson( coll.getDB().getLastErrorObj() ) )

st.shard0 = MongoRunner.runMongod( st.shard0 )



jsTest.log( "Testing GLE when main host goes down..." )

// insert to two diff shards
coll.insert({ _id : -3, hello : "world" })
coll.insert({ _id : 3, hello : "world" })

waitForWrite(0, {_id: -3}, 1);
waitForWrite(1, {_id:  3}, 1);

MongoRunner.stopMongod( st.shard1 )

try{ 
    jsTest.log( "Calling GLE! " ) 
    coll.getDB().getLastErrorObj()
    assert( false )
}
catch( e ){
    jsTest.log( "GLE : " + e )
    
    // Stupid string exceptions
    assert( /could not get last error/.test( e + "") )
}

st.shard1 = MongoRunner.runMongod( st.shard1 )



jsTest.log( "Testing multi GLE for multi-host writes..." )

coll.update({ hello : "world" }, { $set : { goodbye : "world" } }, false, true)

waitForWrite(0, {goodbye: "world"}, 3);
waitForWrite(1, {goodbye: "world"}, 3);

jsTest.log( "GLE : " + tojson( coll.getDB().getLastErrorObj() ) )

jsTest.log( "Testing multi GLE when host goes down..." )

// insert to two diff shards
coll.update({ hello : "world" }, { $set : { goodnight : "moon" } }, false, true)

waitForWrite(0, {goodnight: "moon"}, 3);
waitForWrite(1, {goodnight: "moon"}, 3);

MongoRunner.stopMongod( st.shard0 )

try{ 
    jsTest.log( "Calling GLE! " ) 
    coll.getDB().getLastErrorObj()
    assert( false )
}
catch( e ){
    jsTest.log( "GLE : " + e )
    
    // Stupid string exceptions
    assert( /could not get last error/.test( e + "") )
}

st.shard0 = MongoRunner.runMongod( st.shard0 )



jsTest.log( "Testing stale version GLE when host goes down..." )

var staleColl = st.s1.getCollection( coll + "" )
staleColl.findOne()

printjson( admin.runCommand({ moveChunk : "" + coll, find : { _id : 0 }, to : shards[2]._id }) )

waitForWrite(2, {goodnight: "moon"}, 3);

MongoRunner.stopMongod( st.shard2 )

jsTest.log( "Sending stale write..." )

staleColl.insert({ _id : 4, hello : "world" })

assert.neq( null, staleColl.getDB().getLastError() )


jsTest.log( "Done!" )

st.stop()