diff options
author | Dan Larkin-York <dan.larkin-york@mongodb.com> | 2021-05-26 14:34:52 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-05-26 15:07:24 +0000 |
commit | 01f22c5f2071ff338fefe256b8d81f0ddf09d88e (patch) | |
tree | 984342ab29730f29ccad93e83c6ef735d75fe637 /jstests | |
parent | 2af7ba48290bc0cbeecde0540282dbc7a8d4daab (diff) | |
download | mongo-01f22c5f2071ff338fefe256b8d81f0ddf09d88e.tar.gz |
SERVER-56797 Allow collMod to change time-series bucket granularity
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/timeseries/bucket_granularity.js | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/jstests/core/timeseries/bucket_granularity.js b/jstests/core/timeseries/bucket_granularity.js index 483ae312ef6..a090e7e5684 100644 --- a/jstests/core/timeseries/bucket_granularity.js +++ b/jstests/core/timeseries/bucket_granularity.js @@ -8,6 +8,8 @@ * # This test depends on certain writes ending up in the same bucket. Stepdowns may result in * # writes splitting between two primaries, and thus different buckets. * does_not_support_stepdowns, + * # Same goes for tenant migrations. + * tenant_migration_incompatible, * does_not_support_transactions, * requires_fcv_49, * requires_find_command, @@ -79,4 +81,98 @@ assert.commandWorked(coll.insert({t: ISODate("2021-05-22T00:00:00.000Z")})); assert.eq(2, db.system.buckets.granularityHours.find().itcount()); })(); + +(function testIncreasingSecondsToMinutes() { + let coll = db.granularitySecondsToMinutes; + coll.drop(); + + assert.commandWorked(db.createCollection( + coll.getName(), {timeseries: {timeField: 't', granularity: 'seconds'}})); + + // All measurements land in the same bucket. + assert.commandWorked(coll.insert({t: ISODate("2021-04-22T20:00:00.000Z")})); + assert.commandWorked(coll.insert({t: ISODate("2021-04-22T20:00:03.000Z")})); + assert.commandWorked(coll.insert({t: ISODate("2021-04-22T20:00:59.999Z")})); + assert.eq(1, db.system.buckets.granularitySecondsToMinutes.find().itcount()); + + // Expect bucket max span to be one hour. A new measurement outside of this range should create + // a new bucket. + assert.commandWorked(coll.insert({t: ISODate("2021-04-22T20:59:59.999Z")})); + assert.eq(1, db.system.buckets.granularitySecondsToMinutes.find().itcount()); + assert.commandWorked(coll.insert({t: ISODate("2021-04-22T21:00:00.000Z")})); + assert.eq(2, db.system.buckets.granularitySecondsToMinutes.find().itcount()); + + // Now let's bump to minutes and make sure we get the expected behavior + assert.commandWorked( + db.runCommand({collMod: coll.getName(), timeseries: {granularity: 'minutes'}})); + + // All measurements land in the same bucket. + assert.commandWorked(coll.insert({t: ISODate("2021-04-23T20:00:00.000Z")})); + assert.commandWorked(coll.insert({t: ISODate("2021-04-23T20:22:02.000Z")})); + assert.commandWorked(coll.insert({t: ISODate("2021-04-23T20:59:59.999Z")})); + assert.eq(2, db.system.buckets.granularitySecondsToMinutes.find().itcount()); + + // Expect bucket max span to be one day. A new measurement outside of this range should create + // a new bucket. + assert.commandWorked(coll.insert({t: ISODate("2021-04-23T21:00:00.000Z")})); + assert.eq(3, db.system.buckets.granularitySecondsToMinutes.find().itcount()); +})(); + +(function testIncreasingMinutesToHours() { + let coll = db.granularityMinutesToHours; + coll.drop(); + + assert.commandWorked(db.createCollection( + coll.getName(), {timeseries: {timeField: 't', granularity: 'minutes'}})); + + // All measurements land in the same bucket. + assert.commandWorked(coll.insert({t: ISODate("2021-04-22T20:00:00.000Z")})); + assert.commandWorked(coll.insert({t: ISODate("2021-04-22T20:22:02.000Z")})); + assert.commandWorked(coll.insert({t: ISODate("2021-04-22T20:59:59.999Z")})); + assert.eq(1, db.system.buckets.granularityMinutesToHours.find().itcount()); + + // Expect bucket max span to be one day. A new measurement outside of this range should create + // a new bucket. + assert.commandWorked(coll.insert({t: ISODate("2021-04-23T19:59:59.999Z")})); + assert.eq(1, db.system.buckets.granularityMinutesToHours.find().itcount()); + assert.commandWorked(coll.insert({t: ISODate("2021-04-23T20:00:00.000Z")})); + assert.eq(2, db.system.buckets.granularityMinutesToHours.find().itcount()); + + assert.commandWorked( + db.runCommand({collMod: coll.getName(), timeseries: {granularity: 'hours'}})); + + // All measurements land in the same bucket. + assert.commandWorked(coll.insert({t: ISODate("2021-05-23T00:00:00.000Z")})); + assert.commandWorked(coll.insert({t: ISODate("2021-05-23T18:11:03.000Z")})); + assert.commandWorked(coll.insert({t: ISODate("2021-05-23T19:59:59.999Z")})); + assert.eq(2, db.system.buckets.granularityMinutesToHours.find().itcount()); + + // Expect bucket max span to be 30 days. A new measurement outside of this range should create + // a new bucket. + assert.commandWorked(coll.insert({t: ISODate("2021-05-23T20:00:00.001Z")})); + assert.eq(3, db.system.buckets.granularityMinutesToHours.find().itcount()); +})(); + +(function testReducingGranularityFails() { + let coll = db.granularityMinutesToHours; + coll.drop(); + + assert.commandWorked(db.createCollection( + coll.getName(), {timeseries: {timeField: 't', granularity: 'minutes'}})); + + // Decreasing minutes -> seconds shouldn't work. + assert.commandFailed( + db.runCommand({collMod: coll.getName(), timeseries: {granularity: 'seconds'}})); + + // Increasing minutes -> hours should work fine. + assert.commandWorked( + db.runCommand({collMod: coll.getName(), timeseries: {granularity: 'hours'}})); + + // Decreasing hours -> minutes shouldn't work. + assert.commandFailed( + db.runCommand({collMod: coll.getName(), timeseries: {granularity: 'minutes'}})); + // Decreasing hours -> seconds shouldn't work either. + assert.commandFailed( + db.runCommand({collMod: coll.getName(), timeseries: {granularity: 'seconds'}})); +})(); })(); |