summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/shardsvr_move_range_command.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/s/shardsvr_move_range_command.cpp
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/s/shardsvr_move_range_command.cpp')
-rw-r--r--src/mongo/db/s/shardsvr_move_range_command.cpp46
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;
}
};