blob: 2d666ebf6090f1224970035a1bf5814a06552626 (
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
/**
* Tests that buckets which need to be closed due to size (timeseriesBucketMaxSize) are kept open
* until the number of measurements reaches the threshold (timeseriesBucketMinCount).
*
* @tags: [
* requires_collstats,
* requires_fcv_61,
* ]
*/
(function() {
"use strict";
load("jstests/core/timeseries/libs/timeseries.js"); // For 'TimeseriesTest'.
const coll = db.getCollection(jsTestName());
const timeFieldName = "localTime";
const metaFieldName = "host";
const resetCollection = (() => {
coll.drop();
assert.commandWorked(db.createCollection(
jsTestName(), {timeseries: {timeField: timeFieldName, metaField: metaFieldName}}));
});
const areTimeseriesScalabilityImprovementsEnabled =
TimeseriesTest.timeseriesScalabilityImprovementsEnabled(db);
const numMeasurements = 50;
const checkBucketSize = (() => {
const timeseriesStats = assert.commandWorked(coll.stats()).timeseries;
if (areTimeseriesScalabilityImprovementsEnabled) {
// Need at least 10 measurements before closing buckets exceeding timeseriesBucketMaxSize.
assert.eq(numMeasurements / 10, timeseriesStats.bucketCount);
assert(timeseriesStats.hasOwnProperty("numBucketsKeptOpenDueToLargeMeasurements"));
assert.eq(numMeasurements / 10, timeseriesStats.numBucketsKeptOpenDueToLargeMeasurements);
} else {
// After accounting for the control.min and control.max summaries, one measurement of server
// status exceeds the bucket max size. Which means we'll only have one measurement per
// bucket.
assert.eq(numMeasurements, timeseriesStats.bucketCount);
assert(!timeseriesStats.hasOwnProperty("numBucketsKeptOpenDueToLargeMeasurements"));
}
});
jsTestLog("Testing single inserts");
resetCollection();
for (let i = 0; i < numMeasurements; i++) {
const doc = assert.commandWorked(db.runCommand({serverStatus: 1}));
assert.commandWorked(coll.insert(doc));
}
checkBucketSize();
jsTestLog("Testing batched inserts");
resetCollection();
let batch = [];
for (let i = 0; i < numMeasurements; i++) {
const doc = assert.commandWorked(db.runCommand({serverStatus: 1}));
batch.push(doc);
}
assert.commandWorked(coll.insertMany(batch));
checkBucketSize();
}());
|