summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/resharding/resharding_metrics.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/s/resharding/resharding_metrics.h')
-rw-r--r--src/mongo/db/s/resharding/resharding_metrics.h46
1 files changed, 27 insertions, 19 deletions
diff --git a/src/mongo/db/s/resharding/resharding_metrics.h b/src/mongo/db/s/resharding/resharding_metrics.h
index aeb3ddf11e1..1cdc1f88766 100644
--- a/src/mongo/db/s/resharding/resharding_metrics.h
+++ b/src/mongo/db/s/resharding/resharding_metrics.h
@@ -49,6 +49,8 @@ namespace mongo {
*/
class ReshardingMetrics final {
public:
+ enum Role { kCoordinator, kDonor, kRecipient };
+
ReshardingMetrics(const ReshardingMetrics&) = delete;
ReshardingMetrics(ReshardingMetrics&&) = delete;
@@ -57,13 +59,13 @@ public:
static ReshardingMetrics* get(ServiceContext*) noexcept;
- // Marks the beginning of a resharding operation. Not that only one resharding operation may run
- // at any time.
- void onStart(Date_t runningOperationStartTime) noexcept;
+ // Marks the beginning of a resharding operation for a particular role. Note that:
+ // * Only one resharding operation may run at any time.
+ // * The only valid co-existing roles on a process are kDonor and kRecipient.
+ void onStart(Role role, Date_t runningOperationStartTime) noexcept;
- // Marks the resumption of a resharding operation. Note that only one resharding operation may
- // run at any time.
- void onStepUp() noexcept;
+ // Marks the resumption of a resharding operation for a particular role.
+ void onStepUp(Role role) noexcept;
// So long as a resharding operation is in progress, the following may be used to update the
// state of a donor, a recipient, and a coordinator, respectively.
@@ -94,17 +96,21 @@ public:
// "donating-oplog-entries" or "blocking-writes".
void onWriteDuringCriticalSection(int64_t writes) noexcept;
- // Tears down the currentOp variable so that the node that is stepping up may continue the
- // resharding operation from disk.
- void onStepDown() noexcept;
-
- // Marks the completion of the current (active) resharding operation. Aborts the process if no
- // resharding operation is in progress.
- void onCompletion(ReshardingOperationStatusEnum status,
+ // Indicates that a role on this node is stepping down. If the role being stepped down is the
+ // last active role on this process, the function tears down the currentOp variable. The
+ // replica set primary that is stepping up continues the resharding operation from disk.
+ void onStepDown(Role role) noexcept;
+
+ // Marks the completion of the current (active) resharding operation for a particular role. If
+ // the role being completed is the last active role on this process, the function tears down
+ // the currentOp variable, indicating completion for the resharding operation on this process.
+ //
+ // Aborts the process if no resharding operation is in progress.
+ void onCompletion(Role role,
+ ReshardingOperationStatusEnum status,
Date_t runningOperationEndTime) noexcept;
struct ReporterOptions {
- enum class Role { kDonor, kRecipient, kCoordinator };
ReporterOptions(Role role, UUID id, NamespaceString nss, BSONObj shardKey, bool unique)
: role(role),
id(std::move(id)),
@@ -121,7 +127,7 @@ public:
BSONObj reportForCurrentOp(const ReporterOptions& options) const noexcept;
// Append metrics to the builder in CurrentOp format for the given `role`.
- void serializeCurrentOpMetrics(BSONObjBuilder*, ReporterOptions::Role role) const;
+ void serializeCurrentOpMetrics(BSONObjBuilder*, Role role) const;
// Append metrics to the builder in CumulativeOp (ServerStatus) format.
void serializeCumulativeOpMetrics(BSONObjBuilder*) const;
@@ -137,6 +143,9 @@ private:
mutable Mutex _mutex = MONGO_MAKE_LATCH("ReshardingMetrics::_mutex");
+ void _emplaceCurrentOpForRole(Role role,
+ boost::optional<Date_t> runningOperationStartTime) noexcept;
+
// The following maintain the number of resharding operations that have started, succeeded,
// failed with an unrecoverable error, and canceled by the user, respectively.
int64_t _started = 0;
@@ -173,7 +182,6 @@ private:
applyingOplogEntries(clockSource),
inCriticalSection(clockSource) {}
- using Role = ReporterOptions::Role;
void appendCurrentOpMetrics(BSONObjBuilder*, Role) const;
void appendCumulativeOpMetrics(BSONObjBuilder*) const;
@@ -196,9 +204,9 @@ private:
TimeInterval inCriticalSection;
int64_t writesDuringCriticalSection = 0;
- DonorStateEnum donorState = DonorStateEnum::kUnused;
- RecipientStateEnum recipientState = RecipientStateEnum::kUnused;
- CoordinatorStateEnum coordinatorState = CoordinatorStateEnum::kUnused;
+ boost::optional<DonorStateEnum> donorState;
+ boost::optional<RecipientStateEnum> recipientState;
+ boost::optional<CoordinatorStateEnum> coordinatorState;
};
boost::optional<OperationMetrics> _currentOp;
OperationMetrics _cumulativeOp;