summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/active_migrations_registry.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/s/active_migrations_registry.h')
-rw-r--r--src/mongo/db/s/active_migrations_registry.h101
1 files changed, 52 insertions, 49 deletions
diff --git a/src/mongo/db/s/active_migrations_registry.h b/src/mongo/db/s/active_migrations_registry.h
index a36699d09cf..6acd4678927 100644
--- a/src/mongo/db/s/active_migrations_registry.h
+++ b/src/mongo/db/s/active_migrations_registry.h
@@ -40,14 +40,14 @@
namespace mongo {
class OperationContext;
-class ScopedRegisterDonateChunk;
-class ScopedRegisterReceiveChunk;
+class ScopedDonateChunk;
+class ScopedReceiveChunk;
template <typename T>
class StatusWith;
/**
- * Thread-safe object, which keeps track of the active migrations running on a node and limits them
- * to only one per-shard. There is only one instance of this object per shard.
+ * Thread-safe object that keeps track of the active migrations running on a node and limits them
+ * to only one per shard. There is only one instance of this object per shard.
*/
class ActiveMigrationsRegistry {
MONGO_DISALLOW_COPYING(ActiveMigrationsRegistry);
@@ -58,30 +58,30 @@ public:
/**
* If there are no migrations running on this shard, registers an active migration with the
- * specified arguments and returns a ScopedRegisterDonateChunk, which must be signaled by the
+ * specified arguments. Returns a ScopedDonateChunk, which must be signaled by the
* caller before it goes out of scope.
*
* If there is an active migration already running on this shard and it has the exact same
- * arguments, returns a ScopedRegisterDonateChunk, which can be used to join the already running
- * migration.
+ * arguments, returns a ScopedDonateChunk. The ScopedDonateChunk can be used to join the
+ * already running migration.
*
* Otherwise returns a ConflictingOperationInProgress error.
*/
- StatusWith<ScopedRegisterDonateChunk> registerDonateChunk(const MoveChunkRequest& args);
+ StatusWith<ScopedDonateChunk> registerDonateChunk(const MoveChunkRequest& args);
/**
* If there are no migrations running on this shard, registers an active receive operation with
- * the specified session id and returns a ScopedRegisterReceiveChunk, which will unregister it
- * when it goes out of scope.
+ * the specified session id and returns a ScopedReceiveChunk. The ScopedReceiveChunk will
+ * unregister the migration when the ScopedReceiveChunk goes out of scope.
*
* Otherwise returns a ConflictingOperationInProgress error.
*/
- StatusWith<ScopedRegisterReceiveChunk> registerReceiveChunk(const NamespaceString& nss,
- const ChunkRange& chunkRange,
- const ShardId& fromShardId);
+ StatusWith<ScopedReceiveChunk> registerReceiveChunk(const NamespaceString& nss,
+ const ChunkRange& chunkRange,
+ const ShardId& fromShardId);
/**
- * If a migration has been previously registered through a call to registerDonateChunk returns
+ * If a migration has been previously registered through a call to registerDonateChunk, returns
* that namespace. Otherwise returns boost::none.
*/
boost::optional<NamespaceString> getActiveDonateChunkNss();
@@ -95,8 +95,8 @@ public:
BSONObj getActiveMigrationStatusReport(OperationContext* opCtx);
private:
- friend class ScopedRegisterDonateChunk;
- friend class ScopedRegisterReceiveChunk;
+ friend class ScopedDonateChunk;
+ friend class ScopedReceiveChunk;
// Describes the state of a currently active moveChunk operation
struct ActiveMoveChunkState {
@@ -111,7 +111,7 @@ private:
// Exact arguments of the currently active operation
MoveChunkRequest args;
- // Notification event, which will be signaled when the currently active operation completes
+ // Notification event that will be signaled when the currently active operation completes
std::shared_ptr<Notification<Status>> notification;
};
@@ -125,7 +125,7 @@ private:
*/
Status constructErrorStatus() const;
- // Namesspace for which a chunk is being received
+ // Namespace for which a chunk is being received
NamespaceString nss;
// Bounds of the chunk being migrated
@@ -136,8 +136,8 @@ private:
};
/**
- * Unregisters a previously registered namespace with ongoing migration. Must only be called if
- * a previous call to registerDonateChunk has succeeded.
+ * Unregisters a previously registered namespace with an ongoing migration. Must only be called
+ * if a previous call to registerDonateChunk has succeeded.
*/
void _clearDonateChunk();
@@ -150,49 +150,49 @@ private:
// Protects the state below
stdx::mutex _mutex;
- // If there is an active moveChunk operation going on, this field contains the request, which
- // initiated it
+ // If there is an active moveChunk operation, this field contains the original request
boost::optional<ActiveMoveChunkState> _activeMoveChunkState;
- // If there is an active receive of a chunk going on, this field contains the session id, which
- // initiated it
+ // If there is an active chunk receive operation, this field contains the original session id
boost::optional<ActiveReceiveChunkState> _activeReceiveChunkState;
};
/**
* Object of this class is returned from the registerDonateChunk call of the active migrations
- * registry. It can exist in two modes - 'unregister' and 'join'. See the comments for
+ * registry. It can exist in two modes - 'execute' and 'join'. See the comments for
* registerDonateChunk method for more details.
*/
-class ScopedRegisterDonateChunk {
- MONGO_DISALLOW_COPYING(ScopedRegisterDonateChunk);
+class ScopedDonateChunk {
+ MONGO_DISALLOW_COPYING(ScopedDonateChunk);
public:
- ScopedRegisterDonateChunk(ActiveMigrationsRegistry* registry,
- bool forUnregister,
- std::shared_ptr<Notification<Status>> completionNotification);
- ~ScopedRegisterDonateChunk();
+ ScopedDonateChunk(ActiveMigrationsRegistry* registry,
+ bool shouldExecute,
+ std::shared_ptr<Notification<Status>> completionNotification);
+ ~ScopedDonateChunk();
- ScopedRegisterDonateChunk(ScopedRegisterDonateChunk&&);
- ScopedRegisterDonateChunk& operator=(ScopedRegisterDonateChunk&&);
+ ScopedDonateChunk(ScopedDonateChunk&&);
+ ScopedDonateChunk& operator=(ScopedDonateChunk&&);
/**
- * Returns true if the migration object is in the 'unregister' mode, which means that the holder
- * must execute the moveChunk command and complete with a status.
+ * Returns true if the migration object is in the 'execute' mode. This means that the migration
+ * object holder is next in line to execute the moveChunk command. The holder must execute the
+ * command and call signalComplete with a status.
*/
bool mustExecute() const {
- return _forUnregister;
+ return _shouldExecute;
}
/**
- * Must only be called if the object is in the 'unregister' mode. Signals any callers, which
- * might be blocked in waitForCompletion.
+ * Must only be called if the object is in the 'execute' mode when the moveChunk command was
+ * invoked (the command immediately executed). Signals any callers that might be blocked in
+ * waitForCompletion.
*/
- void complete(Status status);
+ void signalComplete(Status status);
/**
* Must only be called if the object is in the 'join' mode. Blocks until the main executor of
- * the moveChunk command calls complete.
+ * the moveChunk command calls signalComplete.
*/
Status waitForCompletion(OperationContext* opCtx);
@@ -200,9 +200,12 @@ private:
// Registry from which to unregister the migration. Not owned.
ActiveMigrationsRegistry* _registry;
- // Whether this is a newly started migration (in which case the destructor must unregister) or
- // joining an existing one (in which case the caller must wait for completion).
- bool _forUnregister;
+ /**
+ * Whether the holder is the first in line for a newly started migration (in which case the
+ * destructor must unregister) or the caller is joining on an already-running migration
+ * (in which case the caller must block and wait for completion).
+ */
+ bool _shouldExecute;
// This is the future, which will be signaled at the end of a migration
std::shared_ptr<Notification<Status>> _completionNotification;
@@ -212,15 +215,15 @@ private:
* Object of this class is returned from the registerReceiveChunk call of the active migrations
* registry.
*/
-class ScopedRegisterReceiveChunk {
- MONGO_DISALLOW_COPYING(ScopedRegisterReceiveChunk);
+class ScopedReceiveChunk {
+ MONGO_DISALLOW_COPYING(ScopedReceiveChunk);
public:
- ScopedRegisterReceiveChunk(ActiveMigrationsRegistry* registry);
- ~ScopedRegisterReceiveChunk();
+ ScopedReceiveChunk(ActiveMigrationsRegistry* registry);
+ ~ScopedReceiveChunk();
- ScopedRegisterReceiveChunk(ScopedRegisterReceiveChunk&&);
- ScopedRegisterReceiveChunk& operator=(ScopedRegisterReceiveChunk&&);
+ ScopedReceiveChunk(ScopedReceiveChunk&&);
+ ScopedReceiveChunk& operator=(ScopedReceiveChunk&&);
private:
// Registry from which to unregister the migration. Not owned.