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
92
93
94
95
96
97
98
99
100
101
102
103
|
/**
* Tests that BucketCatalog bucket state management statistics are reported correctly in server
* status.
*
* @tags: [
* # State management statistics added as part of scalability improvements project.
* featureFlagTimeseriesScalabilityImprovements,
* requires_fcv_63,
* ]
*/
(function() {
"use strict";
const conn = MongoRunner.runMongod();
const dbName = jsTestName();
const db = conn.getDB(dbName);
assert.commandWorked(db.dropDatabase());
const coll = db.getCollection(jsTestName());
const timeFieldName = "tt";
const metaFieldName = "mm";
const resetCollection = () => {
coll.drop();
assert.commandWorked(db.createCollection(
jsTestName(), {timeseries: {timeField: timeFieldName, metaField: metaFieldName}}));
};
const dropUnrelatedCollection = () => {
const unrelated = db.getCollection(jsTestName() + "_foo");
assert.commandWorked(db.createCollection(
unrelated.getName(), {timeseries: {timeField: timeFieldName, metaField: metaFieldName}}));
unrelated.drop();
};
const expected = {
bucketsManaged: 0,
currentEra: 0,
erasWithRemainingBuckets: 0,
trackedClearOperations: 0
};
const checkServerStatus = function() {
const actual =
assert.commandWorked(db.runCommand({serverStatus: 1})).bucketCatalog.stateManagement;
assert.eq(expected.bucketsManaged, actual.bucketsManaged);
assert.eq(expected.currentEra, actual.currentEra);
assert.eq(expected.erasWithRemainingBuckets, actual.erasWithRemainingBuckets);
assert.eq(expected.trackedClearOperations, actual.trackedClearOperations);
};
resetCollection();
assert.commandWorked(coll.insert({[metaFieldName]: 1, [timeFieldName]: ISODate()}));
expected.bucketsManaged++;
expected.erasWithRemainingBuckets++;
checkServerStatus();
dropUnrelatedCollection();
expected.currentEra++;
expected.trackedClearOperations++;
checkServerStatus();
// Inserting into the existing bucket will update its era, which has no net effect on
// erasWithRemainingBuckets, but the previously tracked clear will get cleaned up.
assert.commandWorked(coll.insert({[metaFieldName]: 1, [timeFieldName]: ISODate()}));
expected.trackedClearOperations--;
checkServerStatus();
assert.commandWorked(coll.insert({[metaFieldName]: 2, [timeFieldName]: ISODate()}));
expected.bucketsManaged++;
checkServerStatus();
// Clearing the collection will not immediately remove the old bucket states.
resetCollection();
expected.currentEra++;
expected.trackedClearOperations++;
checkServerStatus();
// Inserting more measurements will check and remove the old bucket for that meta, and open a new
// one. The other meta value still has an old bucket.
assert.commandWorked(coll.insert({[metaFieldName]: 1, [timeFieldName]: ISODate()}));
expected.erasWithRemainingBuckets++;
checkServerStatus();
// If we clear an unrelated collection and add a third metadata value, we'll get a bucket in a third
// era.
dropUnrelatedCollection();
assert.commandWorked(coll.insert({[metaFieldName]: 3, [timeFieldName]: ISODate()}));
expected.bucketsManaged++;
expected.currentEra++;
expected.erasWithRemainingBuckets++;
expected.trackedClearOperations++;
checkServerStatus();
// If we access the oldest bucket, we'll clear it and garbage collect a tracked clear.
assert.commandWorked(coll.insert({[metaFieldName]: 2, [timeFieldName]: ISODate()}));
expected.erasWithRemainingBuckets--;
expected.trackedClearOperations--;
checkServerStatus();
MongoRunner.stopMongod(conn);
}());
|