summaryrefslogtreecommitdiff
path: root/jstests/sharding/writeback_bulk_insert.js
blob: 9f22875d046dd3a9b992741870f1e37d184856bf (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
//
// Tests whether a writeback error during bulk insert hangs GLE
//

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

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

st.stopBalancer()

var mongosA = st.s0
var mongosB = st.s1
var mongosC = st.s2

jsTest.log("Adding new collection...")

var collA = mongosA.getCollection(jsTestName() + ".coll")
collA.insert({hello : "world"})
assert.eq(null, collA.getDB().getLastError())

var collB = mongosB.getCollection("" + collA)
collB.insert({hello : "world"})
assert.eq(null, collB.getDB().getLastError())

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

printjson(mongosA.getDB("admin").runCommand({enableSharding : collA.getDB()
                                                              + ""}))
printjson(mongosA.getDB("admin").runCommand({shardCollection : collA + "",
                                             key : {_id : 1}}))

// MongoD doesn't know about the config shard version *until* MongoS tells it
collA.findOne()

jsTest.log("Preparing bulk insert...")

var data1MB = "x"
while (data1MB.length < 1024 * 1024)
    data1MB += data1MB;


var data7MB = ""
// Data now at 7MB
for ( var i = 0; i < 7; i++)
    data7MB += data1MB;

print("7MB object size is : " + Object.bsonsize({_id : 0,
                                                 d : data7MB}))

var dataCloseTo8MB = data7MB;
// WARNING - MAGIC NUMBERS HERE
// The idea is to just hit the 16MB limit so that the message gets passed in the
// shell, but adding additional writeback information could fail.
for ( var i = 0; i < 1024 * 1024 - 70; i++) {
    dataCloseTo8MB += "x"
}


var data8MB = "";
for ( var i = 0; i < 8; i++) {
    data8MB += data1MB;
}

print("Object size is: " + Object.bsonsize([{_id : 0,
                                             d : dataCloseTo8MB},
                                            {_id : 1,
                                             d : data8MB}]))

jsTest.log("Trigger wbl for mongosB...")

collB.insert([{_id : 0,
               d : dataCloseTo8MB},
              {_id : 1,
               d : data8MB}])

// Should succeed since our insert size is 16MB (plus very small overhead)
jsTest.log("Waiting for GLE...")

assert.eq(null, collB.getDB().getLastError())

print("GLE Successful...")

// Check that the counts via both mongoses are the same
assert.eq(4, collA.find().itcount())
assert.eq(4, collB.find().itcount())

st.stop()