summaryrefslogtreecommitdiff
path: root/jstests/sharding/gle_error_message.js
blob: 757901b01142c5d329133f57e9ed338e93d398b2 (plain)
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
//
// Tests whether sharded GLE fails sanely and correctly reports failures.  
//

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" })

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" })

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" })

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)

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 : { goodbye : "world" } }, false, true)

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({ connPoolStats : true }) );
//printjson( admin.runCommand({ connPoolSync : true }) );
assert( admin.runCommand({ moveChunk : "" + coll, find : { _id : 0 }, to : shards[2]._id }).ok );

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()