diff options
Diffstat (limited to 'src/mongo/db/s/shardsvr_move_range_command.cpp')
| -rw-r--r-- | src/mongo/db/s/shardsvr_move_range_command.cpp | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/src/mongo/db/s/shardsvr_move_range_command.cpp b/src/mongo/db/s/shardsvr_move_range_command.cpp index dab2d3ab073..df6d900aa3c 100644 --- a/src/mongo/db/s/shardsvr_move_range_command.cpp +++ b/src/mongo/db/s/shardsvr_move_range_command.cpp @@ -97,7 +97,7 @@ public: // Check if there is an existing migration running and if so, join it if (scopedMigration.mustExecute()) { auto moveChunkComplete = - ExecutorFuture<void>(Grid::get(opCtx)->getExecutorPool()->getFixedExecutor()) + ExecutorFuture<void>(_getExecutor()) .then([req = request(), writeConcern = opCtx->getWriteConcern(), scopedMigration = std::move(scopedMigration), @@ -215,13 +215,6 @@ public: opCtx, ReadPreferenceSetting{ReadPreference::PrimaryOnly}); }()); - long long totalDocsCloned = - ShardingStatistics::get(opCtx).countDocsClonedOnDonor.load(); - long long totalBytesCloned = - ShardingStatistics::get(opCtx).countBytesClonedOnDonor.load(); - long long totalCloneTime = - ShardingStatistics::get(opCtx).totalDonorChunkCloneTimeMillis.load(); - MigrationSourceManager migrationSourceManager( opCtx, std::move(request), std::move(writeConcern), donorConnStr, recipientHost); @@ -230,23 +223,28 @@ public: migrationSourceManager.enterCriticalSection(); migrationSourceManager.commitChunkOnRecipient(); migrationSourceManager.commitChunkMetadataOnConfig(); + } + + // Returns a single-threaded executor to be used to run moveChunk commands. The executor is + // initialized on the first call to this function. Uses a shared_ptr because a shared_ptr is + // required to work with ExecutorFutures. + static std::shared_ptr<ThreadPool> _getExecutor() { + static Mutex mutex = MONGO_MAKE_LATCH("MoveChunkExecutor::_mutex"); + static std::shared_ptr<ThreadPool> executor; + + stdx::lock_guard<Latch> lg(mutex); + if (!executor) { + ThreadPool::Options options; + options.poolName = "MoveChunk"; + options.minThreads = 0; + // We limit the size of the thread pool to a single thread because currently there + // can only be one moveRange operation on a shard at a time. + options.maxThreads = 1; + executor = std::make_shared<ThreadPool>(std::move(options)); + executor->startup(); + } - long long docsCloned = - ShardingStatistics::get(opCtx).countDocsClonedOnDonor.load() - totalDocsCloned; - long long bytesCloned = - ShardingStatistics::get(opCtx).countBytesClonedOnDonor.load() - totalBytesCloned; - long long cloneTime = - ShardingStatistics::get(opCtx).totalDonorChunkCloneTimeMillis.load() - - totalCloneTime; - auto migrationId = migrationSourceManager.getMigrationId(); - - LOGV2(7627801, - "Migration finished", - "migrationId"_attr = migrationId ? migrationId->toString() : "", - "totalTimeMillis"_attr = migrationSourceManager.getOpTimeMillis(), - "docsCloned"_attr = docsCloned, - "bytesCloned"_attr = bytesCloned, - "cloneTime"_attr = cloneTime); + return executor; } }; |
