summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/write_local.js
blob: 252baf3d87171f9fc9d7a12fffc0194d45dc5466 (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
// SERVER-22011: Deadlock in ticket distribution
// @tags: [requires_replication, requires_capped]
(function() {
'use strict';

// Limit concurrent WiredTiger transactions to maximize locking issues, harmless for other SEs.
var options = {verbose: 1};

// Create a new single node replicaSet
var replTest = new ReplSetTest({name: "write_local", nodes: 1, oplogSize: 1, nodeOptions: options});
replTest.startSet();
replTest.initiate();
var mongod = replTest.getPrimary();
mongod.adminCommand({setParameter: 1, wiredTigerConcurrentWriteTransactions: 1});

var local = mongod.getDB('local');

// Start inserting documents in test.capped and local.capped capped collections.
var shells = ['test', 'local'].map(function(dbname) {
    var mydb = local.getSiblingDB(dbname);
    mydb.capped.drop();
    mydb.createCollection('capped', {capped: true, size: 20 * 1000});
    return startParallelShell('var mydb=db.getSiblingDB("' + dbname + '"); ' +
                                  '(function() { ' +
                                  '    for(var i=0; i < 10*1000; i++) { ' +
                                  '        mydb.capped.insert({ x: i }); ' +
                                  '    } ' +
                                  '})();',
                              mongod.port);
});

// The following causes inconsistent locking order in the ticket system, depending on
// timeouts to avoid deadlock.
var oldObjects = 0;
for (var i = 0; i < 1000; i++) {
    print(local.stats().objects);
    sleep(1);
}

// Wait for parallel shells to terminate and stop our replset.
shells.forEach((function(f) {
    f();
}));
replTest.stopSet();
}());