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
|
'use strict';
/**
* create_capped_collection_maxdocs.js
*
* Repeatedly creates a capped collection. Also verifies that truncation
* occurs once the collection reaches a certain size or contains a
* certain number of documents.
*
* As of SERVER-16049, capped deletes are replicated. This means that capped deletes can be rolled
* back without rolling back the insert that caused the capped collection to trigger the delete.
* This makes it possible for the capped collection to exceed its capped limit temporarily until
* the next insert is performed successfully without rolling back.
*
* @tags: [does_not_support_stepdowns, requires_capped]
*/
load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload
load('jstests/concurrency/fsm_workloads/create_capped_collection.js'); // for $config
var $config = extendWorkload($config, function($config, $super) {
// Use the workload name as a prefix for the collection name,
// since the workload name is assumed to be unique.
$config.data.prefix = 'create_capped_collection_maxdocs';
var options = {
capped: true,
size: 8192, // multiple of 256; larger than 4096 default
max: 3
};
function uniqueCollectionName(prefix, tid, num) {
return prefix + tid + '_' + num;
}
// TODO: how to avoid having too many files open?
function create(db, collName) {
var myCollName = uniqueCollectionName(this.prefix, this.tid, this.num++);
assertAlways.commandWorked(db.createCollection(myCollName, options));
// Define a small document to be an eighth the size of the capped collection.
var smallDocSize = Math.floor(options.size / 8) - 1;
// Verify size functionality still works as we expect
this.verifySizeTruncation(db, myCollName, options);
// Insert multiple small documents and verify that at least one truncation has occurred.
// There should never be more than 3 documents in the collection, regardless of the
// storage engine. They should always be the most recently inserted documents.
var insertedIds = [];
insertedIds.push(this.insert(db, myCollName, smallDocSize));
insertedIds.push(this.insert(db, myCollName, smallDocSize));
for (var i = 0; i < 50; i++) {
insertedIds.push(this.insert(db, myCollName, smallDocSize));
var foundIds = this.getObjectIds(db, myCollName);
var count = foundIds.length;
assertWhenOwnDB.eq(3, count, 'expected truncation to occur due to number of docs');
assertWhenOwnDB.eq(insertedIds.slice(insertedIds.length - count),
foundIds,
'expected truncation to remove the oldest documents');
}
}
$config.states.create = create;
return $config;
});
|