diff options
author | Benety Goh <benety@mongodb.com> | 2020-04-16 18:00:39 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-04-17 17:43:35 +0000 |
commit | 6d4ed7a8b959eed6a8b3d899fef971f80e1ecc07 (patch) | |
tree | 5cdc55cc4e9d499a5db41f35190818025906158d | |
parent | 91048cc39bdca1c92cb2f4626980924e5b949b2a (diff) | |
download | mongo-6d4ed7a8b959eed6a8b3d899fef971f80e1ecc07.tar.gz |
SERVER-45933 index builds support maxTimeMS through createIndexes interruptions
(cherry picked from commit f889e85da61e90586d032e8b706bf9506919f253)
-rw-r--r-- | jstests/noPassthrough/index_max_time_ms.js | 70 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod.cpp | 9 |
2 files changed, 70 insertions, 9 deletions
diff --git a/jstests/noPassthrough/index_max_time_ms.js b/jstests/noPassthrough/index_max_time_ms.js new file mode 100644 index 00000000000..484521cc3de --- /dev/null +++ b/jstests/noPassthrough/index_max_time_ms.js @@ -0,0 +1,70 @@ +/** + * Confirms that index builds on a primary are aborted when the createIndexes operation times out + * (based on expiration derived from maxTimeMS). + * @tags: [requires_replication] + */ +(function() { +"use strict"; + +load('jstests/noPassthrough/libs/index_build.js'); + +const rst = new ReplSetTest({ + nodes: [ + {}, + { + // Disallow elections on secondary. + rsConfig: { + priority: 0, + votes: 0, + }, + }, + ] +}); +const nodes = rst.startSet(); +rst.initiate(); + +const primary = rst.getPrimary(); +const testDB = primary.getDB('test'); +const coll = testDB.getCollection('test'); + +assert.commandWorked(coll.insert({a: 1})); + +IndexBuildTest.pauseIndexBuilds(primary); + +const createIndexesCmd = { + createIndexes: coll.getName(), + indexes: [ + { + name: 'a_1', + key: {a: 1}, + }, + ], + // This timeout value should be long enough for this test to locate the index build in the + // db.currentOp() output. + maxTimeMS: 10000, +}; + +const createIdx = + startParallelShell('assert.commandFailedWithCode(db.getSiblingDB("' + testDB.getName() + + '").runCommand(' + tojson(createIndexesCmd) + '), ' + + 'ErrorCodes.MaxTimeMSExpired' + + ');', + primary.port); + +try { + IndexBuildTest.waitForIndexBuildToScanCollection(testDB, coll.getName(), 'a_1'); + + // Index build will be interrupted when the createIndexes command times out. + IndexBuildTest.waitForIndexBuildToStop(testDB); +} finally { + IndexBuildTest.resumeIndexBuilds(primary); +} + +createIdx(); + +// Check that no new index has been created. This verifies that the index build was aborted +// rather than successfully completed. +IndexBuildTest.assertIndexes(coll, 1, ['_id_']); + +rst.stopSet(); +})(); diff --git a/src/mongo/db/index_builds_coordinator_mongod.cpp b/src/mongo/db/index_builds_coordinator_mongod.cpp index ecea42a5594..13e528ffd28 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod.cpp @@ -202,12 +202,6 @@ IndexBuildsCoordinatorMongod::startIndexBuild(OperationContext* opCtx, invariant(!opCtx->lockState()->isRSTLExclusive(), buildUUID.toString()); - // Copy over all necessary OperationContext state. - - // Task in thread pool should retain the caller's deadline. - const auto deadline = opCtx->getDeadline(); - const auto timeoutError = opCtx->getTimeoutError(); - const auto nss = CollectionCatalog::get(opCtx).resolveNamespaceStringOrUUID(opCtx, nssOrUuid); const auto& oss = OperationShardingState::get(opCtx); @@ -245,14 +239,12 @@ IndexBuildsCoordinatorMongod::startIndexBuild(OperationContext* opCtx, buildUUID, dbName, nss, - deadline, indexBuildOptions, logicalOp, opDesc, replState, startPromise = std::move(startPromise), startTimestamp, - timeoutError, shardVersion, dbVersion ](auto status) mutable noexcept { @@ -271,7 +263,6 @@ IndexBuildsCoordinatorMongod::startIndexBuild(OperationContext* opCtx, } auto opCtx = Client::getCurrent()->makeOperationContext(); - opCtx->setDeadlineByDate(deadline, timeoutError); auto& oss = OperationShardingState::get(opCtx.get()); oss.initializeClientRoutingVersions(nss, shardVersion, dbVersion); |