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
|
/**
* convert_to_capped_collection.js
*
* Creates a non-capped collection. Converts it to a
* capped collection. After each iteration, truncates the
* collection, ensuring that the storage size of the
* collection is still a multiple of 256.
*
* MongoDB raises the storage size of a capped collection
* to an integer multiple of 256.
*
* @tags: [requires_collstats, requires_capped]
*/
var $config = (function() {
load("jstests/libs/feature_flag_util.js");
// TODO: This workload may fail if an iteration multiplier is specified.
var data = {prefix: 'convert_to_capped_collection'};
var states = (function() {
function uniqueCollectionName(prefix, tid) {
return prefix + '_' + tid;
}
function init(db, collName) {
this.threadCollName = uniqueCollectionName(this.prefix, this.tid);
var bulk = db[this.threadCollName].initializeUnorderedBulkOp();
for (var i = 0; i < (this.tid + 1) * 200; i++) {
bulk.insert({i: i, rand: Random.rand()});
}
var res = bulk.execute();
assertAlways.commandWorked(res);
assertAlways.eq((this.tid + 1) * 200, res.nInserted);
assertWhenOwnDB(!db[this.threadCollName].isCapped());
assertWhenOwnDB.commandWorked(db[this.threadCollName].convertToCapped(this.size));
assertWhenOwnDB(db[this.threadCollName].isCapped());
}
function convertToCapped(db, collName) {
// divide size by 1.5 so that the resulting size
// is not a multiple of 256
this.size /= 1.5;
assertWhenOwnDB.commandWorked(db[this.threadCollName].convertToCapped(this.size));
assertWhenOwnDB(db[this.threadCollName].isCapped());
// only the _id index should remain after running convertToCapped
var indexKeys = db[this.threadCollName].getIndexKeys();
assertWhenOwnDB.eq(1, indexKeys.length);
assertWhenOwnDB(function() {
assertWhenOwnDB.docEq({_id: 1}, indexKeys[0]);
});
}
return {init: init, convertToCapped: convertToCapped};
})();
var transitions = {init: {convertToCapped: 1}, convertToCapped: {convertToCapped: 1}};
function setup(db, collName, cluster) {
// Initial size should not be a power of 256.
this.size = Math.pow(2, this.iterations + 5) + 1;
}
return {
threadCount: 10,
iterations: 20,
data: data,
states: states,
transitions: transitions,
setup: setup,
};
})();
|