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
|
'use strict';
/**
* indexed_insert_ttl.js
*
* Creates a TTL index with a short expireAfterSeconds value (5 seconds). Each
* thread does an insert on each iteration. The first insert done by each
* thread is marked with an extra field. At the end, we assert that the first
* doc inserted by each thread is no longer in the collection.
* @tags: [uses_ttl]
*/
load('jstests/concurrency/fsm_workload_helpers/balancer.js');
var $config = (function() {
var states = {
init: function init(db, collName) {
var res = db[collName].insert({indexed_insert_ttl: new ISODate(), first: true});
assertAlways.commandWorked(res);
assertWhenOwnColl.eq(1, res.nInserted, tojson(res));
},
insert: function insert(db, collName) {
var res = db[collName].insert({indexed_insert_ttl: new ISODate()});
assertAlways.commandWorked(res);
assertWhenOwnColl.eq(1, res.nInserted, tojson(res));
}
};
var transitions = {init: {insert: 1}, insert: {insert: 1}};
function setup(db, collName, cluster) {
var res = db[collName].createIndex({indexed_insert_ttl: 1},
{expireAfterSeconds: this.ttlSeconds});
assertAlways.commandWorked(res);
}
function teardown(db, collName, cluster) {
if (TestData.runningWithBalancer) {
// Disallow balancing 'ns' so that it does not cause the TTLMonitor to fail rounds due
// to ongoing migration critical sections. TTLMonitor will retry on the next round, but
// it might not converge in time for the following assertion to pass.
BalancerHelper.disableBalancerForCollection(db, db[collName].getFullName());
BalancerHelper.joinBalancerRound(db);
}
// By default, the TTL monitor thread runs every 60 seconds.
var defaultTTLSecs = 60;
// We need to wait for the initial documents to expire. It's possible for this code to run
// right after the TTL thread has started to sleep, which requires us to wait at least ~60
// seconds for it to wake up and delete the expired documents. We wait at least another
// minute just to avoid race-prone tests on overloaded test hosts.
var timeoutMS =
(TestData.inEvergreen ? 10 : 2) * Math.max(defaultTTLSecs, this.ttlSeconds) * 1000;
assertWhenOwnColl.soon(function checkTTLCount() {
// All initial documents should be removed by the end of the workload.
var count = db[collName].find({first: true}).itcount();
return count === 0;
}, 'Expected oldest documents with TTL fields to be removed', timeoutMS);
}
return {
threadCount: 20,
iterations: 200,
states: states,
transitions: transitions,
setup: setup,
data: {ttlSeconds: 5},
teardown: teardown
};
})();
|