Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SERVER-56933 Return options to create an identical time-series collec…
…tion from listCollections
- Loading branch information
1 parent
a5caa67
commit 8d5547c
Showing
20 changed files
with
472 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/** | ||
* Tests the result of running listCollections when there are time-series collections present. | ||
* | ||
* @tags: [ | ||
* assumes_no_implicit_collection_creation_after_drop, | ||
* does_not_support_transactions, | ||
* requires_fcv_49, | ||
* requires_find_command, | ||
* requires_getmore, | ||
* ] | ||
*/ | ||
(function() { | ||
'use strict'; | ||
|
||
const testDB = db.getSiblingDB(jsTestName()); | ||
assert.commandWorked(testDB.dropDatabase()); | ||
|
||
const timeFieldName = 'time'; | ||
const metaFieldName = 'meta'; | ||
const coll = testDB.getCollection('t'); | ||
|
||
const getBucketMaxSpanSeconds = function(granularity) { | ||
switch (granularity) { | ||
case 'seconds': | ||
return 60 * 60; | ||
case 'minutes': | ||
return 60 * 60 * 24; | ||
case 'hours': | ||
return 60 * 60 * 24 * 30; | ||
default: | ||
assert(false, 'Invalid granularity: ' + granularity); | ||
} | ||
}; | ||
|
||
const testOptions = function(options) { | ||
coll.drop(); | ||
jsTestLog('Creating time-series collection with options: ' + tojson(options)); | ||
assert.commandWorked(testDB.createCollection(coll.getName(), options)); | ||
|
||
if (!options.timeseries.hasOwnProperty('granularity')) { | ||
Object.assign(options.timeseries, {granularity: 'seconds'}); | ||
} | ||
if (!options.timeseries.hasOwnProperty('bucketMaxSpanSeconds')) { | ||
Object.assign( | ||
options.timeseries, | ||
{bucketMaxSpanSeconds: getBucketMaxSpanSeconds(options.timeseries.granularity)}); | ||
} | ||
|
||
if (options.hasOwnProperty('collation')) { | ||
Object.assign(options.collation, { | ||
caseLevel: false, | ||
caseFirst: 'off', | ||
strength: 3, | ||
numericOrdering: false, | ||
alternate: 'non-ignorable', | ||
maxVariable: 'punct', | ||
normalization: false, | ||
backwards: false, | ||
version: '57.1', | ||
}); | ||
} | ||
|
||
const collections = | ||
assert.commandWorked(testDB.runCommand({listCollections: 1})).cursor.firstBatch; | ||
jsTestLog('Checking listCollections result: ' + tojson(collections)); | ||
assert.eq(collections.length, 3); | ||
assert(collections.find(entry => entry.name === 'system.views')); | ||
assert(collections.find(entry => entry.name === 'system.buckets.' + coll.getName())); | ||
assert.docEq( | ||
collections.find(entry => entry.name === coll.getName()), | ||
{name: coll.getName(), type: 'timeseries', options: options, info: {readOnly: false}}); | ||
}; | ||
|
||
testOptions({timeseries: {timeField: timeFieldName}}); | ||
testOptions({timeseries: {timeField: timeFieldName, metaField: metaFieldName}}); | ||
testOptions({ | ||
timeseries: { | ||
timeField: timeFieldName, | ||
granularity: 'minutes', | ||
} | ||
}); | ||
testOptions({ | ||
timeseries: { | ||
timeField: timeFieldName, | ||
granularity: 'minutes', | ||
bucketMaxSpanSeconds: 60 * 60 * 24, | ||
} | ||
}); | ||
testOptions({ | ||
timeseries: { | ||
timeField: timeFieldName, | ||
}, | ||
storageEngine: {wiredTiger: {}}, | ||
}); | ||
testOptions({ | ||
timeseries: { | ||
timeField: timeFieldName, | ||
}, | ||
indexOptionDefaults: {storageEngine: {wiredTiger: {}}}, | ||
}); | ||
testOptions({ | ||
timeseries: { | ||
timeField: timeFieldName, | ||
}, | ||
collation: {locale: 'ja'}, | ||
}); | ||
testOptions({timeseries: {timeField: timeFieldName}, expireAfterSeconds: NumberLong(100)}); | ||
testOptions({ | ||
timeseries: { | ||
timeField: timeFieldName, | ||
metaField: metaFieldName, | ||
granularity: 'minutes', | ||
bucketMaxSpanSeconds: 60 * 60 * 24, | ||
}, | ||
storageEngine: {wiredTiger: {}}, | ||
indexOptionDefaults: {storageEngine: {wiredTiger: {}}}, | ||
collation: {locale: 'ja'}, | ||
expireAfterSeconds: NumberLong(100), | ||
}); | ||
})(); |
37 changes: 37 additions & 0 deletions
37
jstests/core/timeseries/timeseries_list_collections_filter_name.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Tests that listCollections includes time-series collections and their options when filtering on | ||
* name. | ||
* | ||
* @tags: [ | ||
* assumes_no_implicit_collection_creation_after_drop, | ||
* does_not_support_transactions, | ||
* requires_fcv_49, | ||
* requires_find_command, | ||
* requires_getmore, | ||
* ] | ||
*/ | ||
(function() { | ||
'use strict'; | ||
|
||
const testDB = db.getSiblingDB(jsTestName()); | ||
assert.commandWorked(testDB.dropDatabase()); | ||
|
||
const timeFieldName = 'time'; | ||
const coll = testDB.getCollection('t'); | ||
|
||
assert.commandWorked( | ||
testDB.createCollection(coll.getName(), {timeseries: {timeField: timeFieldName}})); | ||
|
||
const collections = | ||
assert.commandWorked(testDB.runCommand({listCollections: 1, filter: {name: coll.getName()}})) | ||
.cursor.firstBatch; | ||
assert.eq(collections, [{ | ||
name: coll.getName(), | ||
type: 'timeseries', | ||
options: { | ||
timeseries: | ||
{timeField: timeFieldName, granularity: 'seconds', bucketMaxSpanSeconds: 3600} | ||
}, | ||
info: {readOnly: false}, | ||
}]); | ||
})(); |
51 changes: 51 additions & 0 deletions
51
jstests/core/timeseries/timeseries_list_collections_invalid_view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Tests the behavior of listCollections in the presence of both a time-series collection and an | ||
* invalid view definition. | ||
* | ||
* @tags: [ | ||
* assumes_against_mongod_not_mongos, | ||
* assumes_no_implicit_collection_creation_after_drop, | ||
* does_not_support_transactions, | ||
* requires_fcv_49, | ||
* requires_find_command, | ||
* requires_getmore, | ||
* ] | ||
*/ | ||
(function() { | ||
'use strict'; | ||
|
||
const testDB = db.getSiblingDB(jsTestName()); | ||
assert.commandWorked(testDB.dropDatabase()); | ||
|
||
const timeFieldName = 'time'; | ||
const coll = testDB.getCollection('t'); | ||
|
||
assert.commandWorked( | ||
testDB.createCollection(coll.getName(), {timeseries: {timeField: timeFieldName}})); | ||
assert.commandWorked(testDB.adminCommand({ | ||
applyOps: [ | ||
{op: 'i', ns: testDB.getName() + '.system.views', o: {_id: 'invalid', pipeline: 'invalid'}} | ||
] | ||
})); | ||
|
||
assert.commandFailedWithCode(testDB.runCommand({listCollections: 1}), | ||
ErrorCodes.InvalidViewDefinition); | ||
assert.commandFailedWithCode(testDB.runCommand({listCollections: 1, filter: {type: 'timeseries'}}), | ||
ErrorCodes.InvalidViewDefinition); | ||
assert.commandFailedWithCode( | ||
testDB.runCommand({listCollections: 1, filter: {name: coll.getName()}}), | ||
ErrorCodes.InvalidViewDefinition); | ||
|
||
// TODO (SERVER-25493): Change filter to {type: 'collection'}. | ||
const collections = | ||
assert | ||
.commandWorked(testDB.runCommand( | ||
{listCollections: 1, filter: {$or: [{type: 'collection'}, {type: {$exists: false}}]}})) | ||
.cursor.firstBatch; | ||
jsTestLog('Checking listCollections result: ' + tojson(collections)); | ||
assert.eq(collections.length, 2); | ||
assert(collections.find(entry => entry.name === 'system.views')); | ||
assert(collections.find(entry => entry.name === 'system.buckets.' + coll.getName())); | ||
|
||
assert(testDB.system.views.drop()); | ||
})(); |
39 changes: 39 additions & 0 deletions
39
jstests/core/timeseries/timeseries_list_collections_missing_buckets_collection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Tests that listCollections shows the time-series view, but not the buckets collection, if the | ||
* backing time-series buckets collection is missing. | ||
* | ||
* @tags: [ | ||
* assumes_no_implicit_collection_creation_after_drop, | ||
* does_not_support_transactions, | ||
* requires_fcv_49, | ||
* requires_find_command, | ||
* requires_getmore, | ||
* ] | ||
*/ | ||
(function() { | ||
'use strict'; | ||
|
||
const testDB = db.getSiblingDB(jsTestName()); | ||
assert.commandWorked(testDB.dropDatabase()); | ||
|
||
const timeFieldName = 'time'; | ||
const coll = testDB.getCollection('t'); | ||
const bucketsColl = testDB.getCollection('system.buckets.' + coll.getName()); | ||
|
||
assert.commandWorked( | ||
testDB.createCollection(coll.getName(), {timeseries: {timeField: timeFieldName}})); | ||
assert(bucketsColl.drop()); | ||
|
||
let collections = assert.commandWorked(testDB.runCommand({listCollections: 1})).cursor.firstBatch; | ||
jsTestLog('Checking listCollections result: ' + tojson(collections)); | ||
assert.eq(collections.length, 2); | ||
assert(collections.find(entry => entry.name === 'system.views')); | ||
assert.docEq(collections.find(entry => entry.name === coll.getName()), | ||
{name: coll.getName(), type: 'timeseries', options: {}, info: {readOnly: false}}); | ||
|
||
collections = | ||
assert.commandWorked(testDB.runCommand({listCollections: 1, filter: {name: coll.getName()}})) | ||
.cursor.firstBatch; | ||
assert.eq(collections, | ||
[{name: coll.getName(), type: 'timeseries', options: {}, info: {readOnly: false}}]); | ||
})(); |
30 changes: 30 additions & 0 deletions
30
jstests/core/timeseries/timeseries_list_collections_missing_view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Tests that listCollections shows the time-series buckets collection, but not the view, if the | ||
* time-series view is missing. | ||
* | ||
* @tags: [ | ||
* assumes_no_implicit_collection_creation_after_drop, | ||
* does_not_support_transactions, | ||
* requires_fcv_49, | ||
* requires_find_command, | ||
* requires_getmore, | ||
* ] | ||
*/ | ||
(function() { | ||
'use strict'; | ||
|
||
const testDB = db.getSiblingDB(jsTestName()); | ||
assert.commandWorked(testDB.dropDatabase()); | ||
|
||
const timeFieldName = 'time'; | ||
const coll = testDB.getCollection('t'); | ||
|
||
assert.commandWorked( | ||
testDB.createCollection(coll.getName(), {timeseries: {timeField: timeFieldName}})); | ||
assert(testDB.system.views.drop()); | ||
|
||
const collections = assert.commandWorked(testDB.runCommand({listCollections: 1})).cursor.firstBatch; | ||
jsTestLog('Checking listCollections result: ' + tojson(collections)); | ||
assert.eq(collections.length, 1); | ||
assert(collections.find(entry => entry.name === 'system.buckets.' + coll.getName())); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.