summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/active_migrations_registry.h
diff options
context:
space:
mode:
authorAlex Taskov <alex.taskov@mongodb.com>2019-12-20 15:58:47 +0000
committerevergreen <evergreen@mongodb.com>2019-12-20 15:58:47 +0000
commitb1e7c36eb3af8ecbb9fe7fc02711fc2c38d8f2b2 (patch)
tree34c2beb08959382e9960aadec0abbc254f155574 /src/mongo/db/s/active_migrations_registry.h
parentc49f502693c6512784a7cb1a3238b68895e81d63 (diff)
downloadmongo-b1e7c36eb3af8ecbb9fe7fc02711fc2c38d8f2b2.tar.gz
SERVER-45047 Create multiVersion test to validate mixed FCV migrations
Diffstat (limited to 'src/mongo/db/s/active_migrations_registry.h')
-rw-r--r--src/mongo/db/s/active_migrations_registry.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/mongo/db/s/active_migrations_registry.h b/src/mongo/db/s/active_migrations_registry.h
index e885bc23b91..c0a8029c08b 100644
--- a/src/mongo/db/s/active_migrations_registry.h
+++ b/src/mongo/db/s/active_migrations_registry.h
@@ -61,6 +61,15 @@ public:
static ActiveMigrationsRegistry& get(OperationContext* opCtx);
/**
+ * These methods can be used to block migrations temporarily. The lock() method will block if
+ * there is a migration operation in progress and will return once it is completed. Any
+ * subsequent migration operations will return ConflictingOperationInProgress until the unlock()
+ * method is called.
+ */
+ void lock(OperationContext* opCtx);
+ void unlock();
+
+ /**
* If there are no migrations running on this shard, registers an active migration with the
* specified arguments. Returns a ScopedDonateChunk, which must be signaled by the
* caller before it goes out of scope.
@@ -153,6 +162,9 @@ private:
// Protects the state below
Mutex _mutex = MONGO_MAKE_LATCH("ActiveMigrationsRegistry::_mutex");
+ stdx::condition_variable _lockCond;
+
+ bool _migrationsBlocked{false};
// If there is an active moveChunk operation, this field contains the original request
boost::optional<ActiveMoveChunkState> _activeMoveChunkState;
@@ -161,6 +173,22 @@ private:
boost::optional<ActiveReceiveChunkState> _activeReceiveChunkState;
};
+class MigrationBlockingGuard {
+public:
+ MigrationBlockingGuard(OperationContext* opCtx, ActiveMigrationsRegistry& registry)
+ : _opCtx(opCtx), _registry(registry) {
+ _registry.lock(_opCtx);
+ }
+
+ ~MigrationBlockingGuard() {
+ _registry.unlock();
+ }
+
+private:
+ OperationContext* _opCtx{nullptr};
+ ActiveMigrationsRegistry& _registry;
+};
+
/**
* Object of this class is returned from the registerDonateChunk call of the active migrations
* registry. It can exist in two modes - 'execute' and 'join'. See the comments for