|
| 1 | +/** |
| 2 | + * Tests that the 'ns' field in index specs is removed during metadata changes when in FCV 4.4. |
| 3 | + * |
| 4 | + * Starting in 4.4, the 'ns' field for index specs is no longer generated. We want to ensure that |
| 5 | + * index specs created in prior server versions have their 'ns' field removed when running in FCV |
| 6 | + * 4.4. |
| 7 | + */ |
| 8 | +(function() { |
| 9 | +'use strict'; |
| 10 | +load('jstests/libs/feature_compatibility_version.js'); |
| 11 | + |
| 12 | +const dbName = 'test'; |
| 13 | +const collName = 'coll'; |
| 14 | + |
| 15 | +const dbpath = MongoRunner.dataPath + 'remove_ns_field_in_index_spec'; |
| 16 | +resetDbpath(dbpath); |
| 17 | + |
| 18 | +const mongodOptions42 = |
| 19 | + Object.extend({binVersion: 'last-stable'}, {dbpath: dbpath, cleanData: false}); |
| 20 | +const mongodOptions44 = Object.extend({binVersion: 'latest'}, {dbpath: dbpath, cleanData: false}); |
| 21 | + |
| 22 | +/** |
| 23 | + * Start up with the 4.2 binary and create a collection. The default '_id' index should have the |
| 24 | + * 'ns' field present in its index spec. |
| 25 | + */ |
| 26 | +let conn = MongoRunner.runMongod(mongodOptions42); |
| 27 | +assert.neq(null, conn, 'mongod was unable to start with version ' + tojson(mongodOptions42)); |
| 28 | + |
| 29 | +let testDb = conn.getDB(dbName); |
| 30 | +assert.commandWorked(testDb.adminCommand({setFeatureCompatibilityVersion: lastStableFCV})); |
| 31 | +assert.commandWorked(testDb.createCollection(collName)); |
| 32 | + |
| 33 | +let coll = testDb.getCollection(collName); |
| 34 | +let indexes = coll.getIndexes(); |
| 35 | + |
| 36 | +assert.eq(1, indexes.length); |
| 37 | +assert.eq(dbName + '.' + collName, indexes[0].ns); |
| 38 | + |
| 39 | +MongoRunner.stopMongod(conn); |
| 40 | + |
| 41 | +/** |
| 42 | + * Restart with the 4.4 binary while in FCV 4.2. The index should not lose its 'ns' field when doing |
| 43 | + * a disk modifying metadata change. |
| 44 | + */ |
| 45 | +let restartOpts44 = Object.extend(mongodOptions44, {restart: true}); |
| 46 | +conn = MongoRunner.runMongod(restartOpts44); |
| 47 | +assert.neq(null, conn, 'mongod was unable to start with version ' + tojson(restartOpts44)); |
| 48 | + |
| 49 | +testDb = conn.getDB(dbName); |
| 50 | +coll = testDb.getCollection(collName); |
| 51 | + |
| 52 | +// Run a metadata changing operation. |
| 53 | +assert.commandWorked(coll.createIndex({x: 1})); |
| 54 | +assert.commandWorked(coll.dropIndex({x: 1})); |
| 55 | + |
| 56 | +indexes = coll.getIndexes(); |
| 57 | + |
| 58 | +assert.eq(1, indexes.length); |
| 59 | +assert.eq(dbName + '.' + collName, indexes[0].ns); |
| 60 | + |
| 61 | +/** |
| 62 | + * Set the FCV to 4.4. The index should lose its 'ns' field when doing a disk modifying metadata |
| 63 | + * change. |
| 64 | + */ |
| 65 | +assert.commandWorked(testDb.adminCommand({setFeatureCompatibilityVersion: latestFCV})); |
| 66 | + |
| 67 | +// Run a metadata changing operation. |
| 68 | +assert.commandWorked(coll.createIndex({x: 1})); |
| 69 | +assert.commandWorked(coll.dropIndex({x: 1})); |
| 70 | + |
| 71 | +indexes = coll.getIndexes(); |
| 72 | + |
| 73 | +assert.eq(1, indexes.length); |
| 74 | +assert.eq(false, indexes[0].hasOwnProperty('ns')); |
| 75 | + |
| 76 | +MongoRunner.stopMongod(conn); |
| 77 | +})(); |
0 commit comments