|
| 1 | +/** |
| 2 | + * Tests validating a time-series collection with mixed schema buckets when the mixed-schema flag |
| 3 | + * in the top-level catalog metadata, but not in the collection options (WiredTiger config string). |
| 4 | + * |
| 5 | + * This replicates the scenario where a time series collection has been created in MongoDB <5.2, |
| 6 | + * (i.e. before SERVER-60565) then later upgraded to MongoDB <6.0.17 (i.e. before SERVER-91195), |
| 7 | + * then all the way up to the current version (see SERVER-98399 for more details). |
| 8 | + * |
| 9 | + * As having the mixed-schema flag set only in the top-level catalog metadata is a precarious state, |
| 10 | + * as its value may be lost, direct manipulation of mixed-schema buckets is prevented, and |
| 11 | + * validation will flag the collection as needing manual intervention for SERVER-91194. |
| 12 | + */ |
| 13 | +(function() { |
| 14 | +"use strict"; |
| 15 | + |
| 16 | +load("jstests/libs/fail_point_util.js"); // For configureFailPoint |
| 17 | + |
| 18 | +const conn = MongoRunner.runMongod(); |
| 19 | +const testDB = conn.getDB(jsTestName()); |
| 20 | + |
| 21 | +const collName = "ts"; |
| 22 | + |
| 23 | +// Create a time-series collection containing a mixed-schema bucket |
| 24 | +assert.commandWorked(testDB.runCommand({drop: collName})); |
| 25 | +assert.commandWorked( |
| 26 | + testDB.createCollection(collName, {timeseries: {timeField: 't', metaField: 'm'}})); |
| 27 | +const coll = testDB[collName]; |
| 28 | +const bucketsColl = testDB["system.buckets." + collName]; |
| 29 | + |
| 30 | +const bucket = { |
| 31 | + _id: ObjectId("65a6eb806ffc9fa4280ecac4"), |
| 32 | + control: { |
| 33 | + version: NumberInt(1), |
| 34 | + min: { |
| 35 | + _id: ObjectId("65a6eba7e6d2e848e08c3750"), |
| 36 | + t: ISODate("2024-01-16T20:48:00Z"), |
| 37 | + a: 1, |
| 38 | + }, |
| 39 | + max: { |
| 40 | + _id: ObjectId("65a6eba7e6d2e848e08c3751"), |
| 41 | + t: ISODate("2024-01-16T20:48:39.448Z"), |
| 42 | + a: "a", |
| 43 | + }, |
| 44 | + }, |
| 45 | + meta: 0, |
| 46 | + data: { |
| 47 | + _id: { |
| 48 | + 0: ObjectId("65a6eba7e6d2e848e08c3750"), |
| 49 | + 1: ObjectId("65a6eba7e6d2e848e08c3751"), |
| 50 | + }, |
| 51 | + t: { |
| 52 | + 0: ISODate("2024-01-16T20:48:39.448Z"), |
| 53 | + 1: ISODate("2024-01-16T20:48:39.448Z"), |
| 54 | + }, |
| 55 | + a: { |
| 56 | + 0: "a", |
| 57 | + 1: 1, |
| 58 | + }, |
| 59 | + }, |
| 60 | +}; |
| 61 | + |
| 62 | +assert.commandWorked( |
| 63 | + testDB.runCommand({collMod: collName, timeseriesBucketsMayHaveMixedSchemaData: true})); |
| 64 | +assert.commandWorked(bucketsColl.insert(bucket)); |
| 65 | + |
| 66 | +// Set the mixed-schema flag only set on the top-level catalog metadata field |
| 67 | +// (md.timeseriesBucketsMayHaveMixedSchemaData), but not on the collection options |
| 68 | +// (inside md.options.storageEngine.wiredTiger.configString). |
| 69 | +const fpsimulateLegacyTimeseriesMixedSchemaFlag = |
| 70 | + configureFailPoint(conn, "simulateLegacyTimeseriesMixedSchemaFlag"); |
| 71 | +assert.commandWorked( |
| 72 | + testDB.runCommand({collMod: collName, timeseriesBucketsMayHaveMixedSchemaData: true})); |
| 73 | +fpsimulateLegacyTimeseriesMixedSchemaFlag.off(); |
| 74 | + |
| 75 | +const bucketsCatalogEntry = bucketsColl.aggregate([{$listCatalog: {}}]).toArray()[0]; |
| 76 | +const wtConfigStr = bucketsCatalogEntry.md.options.storageEngine?.wiredTiger?.configString ?? ''; |
| 77 | +assert.eq(true, bucketsCatalogEntry.md.timeseriesBucketsMayHaveMixedSchemaData); |
| 78 | +assert(!wtConfigStr.includes("timeseriesBucketsMayHaveMixedSchemaData")); |
| 79 | + |
| 80 | +// Validation of the collection returns the error asking for SERVER-91194 manual intervention |
| 81 | +const res = assert.commandWorked(coll.validate()); |
| 82 | +assert(!res.valid); |
| 83 | +assert.eq(res.warnings.length, 0); |
| 84 | +assert.gt(res.errors.length, 0, "Validation should return at least one error."); |
| 85 | +assert.containsPrefix( |
| 86 | + "Detected a time-series bucket with mixed schema data", |
| 87 | + res.errors, |
| 88 | + "Validation of mixed schema buckets when they are not allowed should return an error stating such"); |
| 89 | + |
| 90 | +assert.commandWorked(bucketsColl.deleteOne({_id: bucket._id})); // Clean up for shutdown validation |
| 91 | +MongoRunner.stopMongod(conn); |
| 92 | +})(); |
0 commit comments