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
|
/**
* Tests that bucketing parameters are disallowed after downgrading to versions where the parameters
* are not supported.
*/
(function() {
'use strict';
load("jstests/core/timeseries/libs/timeseries.js");
load("jstests/libs/fail_point_util.js");
const dbName = 'testDB';
const collName = 'testColl';
const timeField = 'tm';
const metaField = 'mt';
const st = new ShardingTest({shards: 2});
const mongos = st.s0;
function useBucketingParametersOnLowerFCV() {
const db = mongos.getDB(dbName);
if (!TimeseriesTest.timeseriesScalabilityImprovementsEnabled(db)) {
jsTestLog(
"Skipped test as the featureFlagTimeseriesScalabilityImprovements feature flag is not enabled.");
return;
}
assert.commandWorked(db.adminCommand({setFeatureCompatibilityVersion: latestFCV}));
let coll = db.getCollection(collName);
coll.drop();
assert.commandWorked(db.createCollection(collName, {
timeseries: {
timeField: timeField,
metaField: metaField,
bucketMaxSpanSeconds: 60,
bucketRoundingSeconds: 60
}
}));
// On the latestFCV, we should not be able to use collMod with incomplete bucketing parameters.
assert.commandFailedWithCode(
db.runCommand({collMod: collName, timeseries: {bucketMaxSpanSeconds: 3600}}),
ErrorCodes.InvalidOptions);
// We should fail to downgrade if we have a collection with custom bucketing parameters set.
assert.commandFailedWithCode(db.adminCommand({setFeatureCompatibilityVersion: lastLTSFCV}),
ErrorCodes.CannotDowngrade);
coll = db.getCollection(collName);
coll.drop();
// Successfully downgrade to latest FCV.
assert.commandWorked(db.adminCommand({setFeatureCompatibilityVersion: lastLTSFCV}));
// On the latest FCV, we should not be able to create a collection with bucketing parameters.
assert.commandFailedWithCode(db.createCollection(collName, {
timeseries: {
timeField: timeField,
metaField: metaField,
bucketMaxSpanSeconds: 60,
bucketRoundingSeconds: 60
}
}),
ErrorCodes.InvalidOptions);
assert.commandWorked(
db.createCollection(collName, {timeseries: {timeField: timeField, metaField: metaField}}));
// On the latest FCV we should not be able to use collMod with the bucketing parameters.
assert.commandFailedWithCode(db.runCommand({
collMod: collName,
timeseries: {bucketMaxSpanSeconds: 3600, bucketRoundingSeconds: 3600}
}),
ErrorCodes.InvalidOptions);
assert.commandFailedWithCode(
db.runCommand({collMod: collName, timeseries: {bucketMaxSpanSeconds: 3600}}),
ErrorCodes.InvalidOptions);
assert.commandFailedWithCode(
db.runCommand({collMod: collName, timeseries: {bucketRoundingSeconds: 3600}}),
ErrorCodes.InvalidOptions);
// Verify the time-series options are valid.
let collections = assert.commandWorked(db.runCommand({listCollections: 1})).cursor.firstBatch;
let collectionEntry = collections.find(entry => entry.name === 'system.buckets.' + collName);
assert(collectionEntry);
assert.eq(collectionEntry.options.timeseries.granularity, "seconds");
// Downgrading does not remove the 'bucketMaxSpanSeconds' parameter. It should correspond with
// the "seconds" granularity.
assert.eq(collectionEntry.options.timeseries.bucketMaxSpanSeconds, 3600);
assert.isnull(collectionEntry.options.timeseries.bucketRoundingSeconds);
}
useBucketingParametersOnLowerFCV();
st.stop();
})();
|