summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/resharding
diff options
context:
space:
mode:
authorBrett Nawrocki <brett.nawrocki@mongodb.com>2023-02-23 21:28:38 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-03-04 01:40:12 +0000
commit83a31ef7599f567a16a98ed355adffd511d3677b (patch)
tree280762c290716f953fa9dfade66c3d59e8fb5519 /src/mongo/db/s/resharding
parent23cb4d914d3f58d5de32ee524f5b6d3614bc2d05 (diff)
downloadmongo-83a31ef7599f567a16a98ed355adffd511d3677b.tar.gz
SERVER-73081 Implement MovePrimaryCumulativeMetrics
This commit also includes a partial refactor of ShardingDataTransformCumulativeMetrics and its children in general, breaking down some elements of monolithic classes into mixins that are more easily composable. Additionally, the ShardingDataTransformMetrics classes have been moved under a metrics subdirectory so that it's clear that they are part of the same subsystem.
Diffstat (limited to 'src/mongo/db/s/resharding')
-rw-r--r--src/mongo/db/s/resharding/resharding_coordinator_service.cpp18
-rw-r--r--src/mongo/db/s/resharding/resharding_cumulative_metrics.cpp236
-rw-r--r--src/mongo/db/s/resharding/resharding_cumulative_metrics.h139
-rw-r--r--src/mongo/db/s/resharding/resharding_cumulative_metrics_field_name_provider.cpp202
-rw-r--r--src/mongo/db/s/resharding/resharding_cumulative_metrics_field_name_provider.h47
-rw-r--r--src/mongo/db/s/resharding/resharding_cumulative_metrics_test.cpp13
-rw-r--r--src/mongo/db/s/resharding/resharding_donor_service.cpp10
-rw-r--r--src/mongo/db/s/resharding/resharding_metrics.cpp133
-rw-r--r--src/mongo/db/s/resharding/resharding_metrics.h37
-rw-r--r--src/mongo/db/s/resharding/resharding_metrics_field_name_provider.h2
-rw-r--r--src/mongo/db/s/resharding/resharding_metrics_helpers.h2
-rw-r--r--src/mongo/db/s/resharding/resharding_metrics_test.cpp13
-rw-r--r--src/mongo/db/s/resharding/resharding_oplog_applier_metrics_test.cpp2
-rw-r--r--src/mongo/db/s/resharding/resharding_oplog_fetcher.cpp2
-rw-r--r--src/mongo/db/s/resharding/resharding_recipient_service.cpp10
15 files changed, 100 insertions, 766 deletions
diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
index 170930aa2ec..8fd3f4c3ed5 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
@@ -42,12 +42,12 @@
#include "mongo/db/s/balancer/balancer_policy.h"
#include "mongo/db/s/config/initial_split_policy.h"
#include "mongo/db/s/config/sharding_catalog_manager.h"
+#include "mongo/db/s/metrics/sharding_data_transform_cumulative_metrics.h"
+#include "mongo/db/s/metrics/sharding_data_transform_metrics.h"
#include "mongo/db/s/resharding/resharding_coordinator_commit_monitor.h"
#include "mongo/db/s/resharding/resharding_future_util.h"
#include "mongo/db/s/resharding/resharding_server_parameters_gen.h"
#include "mongo/db/s/resharding/resharding_util.h"
-#include "mongo/db/s/sharding_data_transform_cumulative_metrics.h"
-#include "mongo/db/s/sharding_data_transform_metrics.h"
#include "mongo/db/s/sharding_ddl_util.h"
#include "mongo/db/s/sharding_logging.h"
#include "mongo/db/session/logical_session_cache.h"
@@ -707,10 +707,6 @@ BSONObj makeFlushRoutingTableCacheUpdatesCmd(const NamespaceString& nss) {
BSON(WriteConcernOptions::kWriteConcernField << kMajorityWriteConcern.toBSON()));
}
-ReshardingMetrics::CoordinatorState toMetricsState(CoordinatorStateEnum state) {
- return ReshardingMetrics::CoordinatorState(state);
-}
-
} // namespace
namespace resharding {
@@ -984,8 +980,7 @@ void removeCoordinatorDocAndReshardingFields(OperationContext* opCtx,
},
ShardingCatalogClient::kLocalWriteConcern);
- metrics->onStateTransition(toMetricsState(coordinatorDoc.getState()),
- toMetricsState(updatedCoordinatorDoc.getState()));
+ metrics->onStateTransition(coordinatorDoc.getState(), updatedCoordinatorDoc.getState());
}
} // namespace resharding
@@ -1245,7 +1240,7 @@ ReshardingCoordinator::ReshardingCoordinator(
_reshardingCoordinatorObserver->onReshardingParticipantTransition(coordinatorDoc);
}
- _metrics->onStateTransition(boost::none, toMetricsState(coordinatorDoc.getState()));
+ _metrics->onStateTransition(boost::none, coordinatorDoc.getState());
}
void ReshardingCoordinator::installCoordinatorDoc(
@@ -1270,8 +1265,7 @@ void ReshardingCoordinator::installCoordinatorDoc(
const auto previousState = _coordinatorDoc.getState();
_coordinatorDoc = doc;
- _metrics->onStateTransition(toMetricsState(previousState),
- toMetricsState(_coordinatorDoc.getState()));
+ _metrics->onStateTransition(previousState, _coordinatorDoc.getState());
ShardingLogging::get(opCtx)->logChange(opCtx,
"resharding.coordinator.transition",
@@ -1636,7 +1630,7 @@ ExecutorFuture<void> ReshardingCoordinator::_runReshardingOp(
.onCompletion([outerStatus](Status) { return outerStatus; });
})
.onCompletion([this, self = shared_from_this()](Status status) {
- _metrics->onStateTransition(toMetricsState(_coordinatorDoc.getState()), boost::none);
+ _metrics->onStateTransition(_coordinatorDoc.getState(), boost::none);
// Destroy metrics early so it's lifetime will not be tied to the lifetime of this
// state machine. This is because we have future callbacks copy shared pointers to this
diff --git a/src/mongo/db/s/resharding/resharding_cumulative_metrics.cpp b/src/mongo/db/s/resharding/resharding_cumulative_metrics.cpp
index c17d555faa0..c53310cbe2b 100644
--- a/src/mongo/db/s/resharding/resharding_cumulative_metrics.cpp
+++ b/src/mongo/db/s/resharding/resharding_cumulative_metrics.cpp
@@ -32,219 +32,65 @@
namespace mongo {
namespace {
+
constexpr auto kResharding = "resharding";
+
+const auto kReportedStateFieldNamesMap = [] {
+ return ReshardingCumulativeMetrics::StateFieldNameMap{
+ {CoordinatorStateEnum::kInitializing, "countInstancesInCoordinatorState1Initializing"},
+ {CoordinatorStateEnum::kPreparingToDonate,
+ "countInstancesInCoordinatorState2PreparingToDonate"},
+ {CoordinatorStateEnum::kCloning, "countInstancesInCoordinatorState3Cloning"},
+ {CoordinatorStateEnum::kApplying, "countInstancesInCoordinatorState4Applying"},
+ {CoordinatorStateEnum::kBlockingWrites, "countInstancesInCoordinatorState5BlockingWrites"},
+ {CoordinatorStateEnum::kAborting, "countInstancesInCoordinatorState6Aborting"},
+ {CoordinatorStateEnum::kCommitting, "countInstancesInCoordinatorState7Committing"},
+ {DonorStateEnum::kPreparingToDonate, "countInstancesInDonorState1PreparingToDonate"},
+ {DonorStateEnum::kDonatingInitialData, "countInstancesInDonorState2DonatingInitialData"},
+ {DonorStateEnum::kDonatingOplogEntries, "countInstancesInDonorState3DonatingOplogEntries"},
+ {DonorStateEnum::kPreparingToBlockWrites,
+ "countInstancesInDonorState4PreparingToBlockWrites"},
+ {DonorStateEnum::kError, "countInstancesInDonorState5Error"},
+ {DonorStateEnum::kBlockingWrites, "countInstancesInDonorState6BlockingWrites"},
+ {DonorStateEnum::kDone, "countInstancesInDonorState7Done"},
+ {RecipientStateEnum::kAwaitingFetchTimestamp,
+ "kCountInstancesInRecipientState1AwaitingFetchTimestamp"},
+ {RecipientStateEnum::kCreatingCollection,
+ "countInstancesInRecipientState2CreatingCollection"},
+ {RecipientStateEnum::kCloning, "countInstancesInRecipientState3Cloning"},
+ {RecipientStateEnum::kApplying, "countInstancesInRecipientState4Applying"},
+ {RecipientStateEnum::kError, "countInstancesInRecipientState5Error"},
+ {RecipientStateEnum::kStrictConsistency,
+ "countInstancesInRecipientState6StrictConsistency"},
+ {RecipientStateEnum::kDone, "countInstancesInRecipientState7Done"},
+ };
+}();
+
+} // namespace
+
+boost::optional<StringData> ReshardingCumulativeMetrics::fieldNameFor(AnyState state) {
+ return getNameFor(state, kReportedStateFieldNamesMap);
}
ReshardingCumulativeMetrics::ReshardingCumulativeMetrics()
- : ShardingDataTransformCumulativeMetrics(
+ : resharding_cumulative_metrics::Base(
kResharding, std::make_unique<ReshardingCumulativeMetricsFieldNameProvider>()),
_fieldNames(
static_cast<const ReshardingCumulativeMetricsFieldNameProvider*>(getFieldNames())) {}
-StringData ReshardingCumulativeMetrics::fieldNameFor(
- CoordinatorStateEnum state, const ReshardingCumulativeMetricsFieldNameProvider* provider) {
- switch (state) {
- case CoordinatorStateEnum::kInitializing:
- return provider->getForCountInstancesInCoordinatorState1Initializing();
-
- case CoordinatorStateEnum::kPreparingToDonate:
- return provider->getForCountInstancesInCoordinatorState2PreparingToDonate();
-
- case CoordinatorStateEnum::kCloning:
- return provider->getForCountInstancesInCoordinatorState3Cloning();
-
- case CoordinatorStateEnum::kApplying:
- return provider->getForCountInstancesInCoordinatorState4Applying();
-
- case CoordinatorStateEnum::kBlockingWrites:
- return provider->getForCountInstancesInCoordinatorState5BlockingWrites();
-
- case CoordinatorStateEnum::kAborting:
- return provider->getForCountInstancesInCoordinatorState6Aborting();
-
- case CoordinatorStateEnum::kCommitting:
- return provider->getForCountInstancesInCoordinatorState7Committing();
-
- default:
- uasserted(6438601,
- str::stream()
- << "no field name for coordinator state " << static_cast<int32_t>(state));
- break;
- }
-
- MONGO_UNREACHABLE;
-}
-
-StringData ReshardingCumulativeMetrics::fieldNameFor(
- DonorStateEnum state, const ReshardingCumulativeMetricsFieldNameProvider* provider) {
- switch (state) {
- case DonorStateEnum::kPreparingToDonate:
- return provider->getForCountInstancesInDonorState1PreparingToDonate();
-
- case DonorStateEnum::kDonatingInitialData:
- return provider->getForCountInstancesInDonorState2DonatingInitialData();
-
- case DonorStateEnum::kDonatingOplogEntries:
- return provider->getForCountInstancesInDonorState3DonatingOplogEntries();
-
- case DonorStateEnum::kPreparingToBlockWrites:
- return provider->getForCountInstancesInDonorState4PreparingToBlockWrites();
-
- case DonorStateEnum::kError:
- return provider->getForCountInstancesInDonorState5Error();
-
- case DonorStateEnum::kBlockingWrites:
- return provider->getForCountInstancesInDonorState6BlockingWrites();
-
- case DonorStateEnum::kDone:
- return provider->getForCountInstancesInDonorState7Done();
-
- default:
- uasserted(6438700,
- str::stream()
- << "no field name for donor state " << static_cast<int32_t>(state));
- break;
- }
-
- MONGO_UNREACHABLE;
-}
-
-StringData ReshardingCumulativeMetrics::fieldNameFor(
- RecipientStateEnum state, const ReshardingCumulativeMetricsFieldNameProvider* provider) {
- switch (state) {
- case RecipientStateEnum::kAwaitingFetchTimestamp:
- return provider->getForCountInstancesInRecipientState1AwaitingFetchTimestamp();
-
- case RecipientStateEnum::kCreatingCollection:
- return provider->getForCountInstancesInRecipientState2CreatingCollection();
-
- case RecipientStateEnum::kCloning:
- return provider->getForCountInstancesInRecipientState3Cloning();
-
- case RecipientStateEnum::kApplying:
- return provider->getForCountInstancesInRecipientState4Applying();
-
- case RecipientStateEnum::kError:
- return provider->getForCountInstancesInRecipientState5Error();
-
- case RecipientStateEnum::kStrictConsistency:
- return provider->getForCountInstancesInRecipientState6StrictConsistency();
-
- case RecipientStateEnum::kDone:
- return provider->getForCountInstancesInRecipientState7Done();
-
- default:
- uasserted(6438900,
- str::stream()
- << "no field name for recipient state " << static_cast<int32_t>(state));
- break;
- }
-
- MONGO_UNREACHABLE;
-}
-
void ReshardingCumulativeMetrics::reportActive(BSONObjBuilder* bob) const {
ShardingDataTransformCumulativeMetrics::reportActive(bob);
-
- bob->append(_fieldNames->getForOplogEntriesFetched(), _oplogEntriesFetched.load());
- bob->append(_fieldNames->getForOplogEntriesApplied(), _oplogEntriesApplied.load());
- bob->append(_fieldNames->getForInsertsApplied(), _insertsApplied.load());
- bob->append(_fieldNames->getForUpdatesApplied(), _updatesApplied.load());
- bob->append(_fieldNames->getForDeletesApplied(), _deletesApplied.load());
+ reportOplogApplicationCountMetrics(_fieldNames, bob);
}
void ReshardingCumulativeMetrics::reportLatencies(BSONObjBuilder* bob) const {
ShardingDataTransformCumulativeMetrics::reportLatencies(bob);
-
- bob->append(_fieldNames->getForOplogFetchingTotalRemoteBatchRetrievalTimeMillis(),
- _oplogFetchingTotalRemoteBatchesRetrievalTimeMillis.load());
- bob->append(_fieldNames->getForOplogFetchingTotalRemoteBatchesRetrieved(),
- _oplogFetchingTotalRemoteBatchesRetrieved.load());
- bob->append(_fieldNames->getForOplogFetchingTotalLocalInsertTimeMillis(),
- _oplogFetchingTotalLocalInsertTimeMillis.load());
- bob->append(_fieldNames->getForOplogFetchingTotalLocalInserts(),
- _oplogFetchingTotalLocalInserts.load());
- bob->append(_fieldNames->getForOplogApplyingTotalLocalBatchRetrievalTimeMillis(),
- _oplogApplyingTotalBatchesRetrievalTimeMillis.load());
- bob->append(_fieldNames->getForOplogApplyingTotalLocalBatchesRetrieved(),
- _oplogApplyingTotalBatchesRetrieved.load());
- bob->append(_fieldNames->getForOplogApplyingTotalLocalBatchApplyTimeMillis(),
- _oplogBatchAppliedMillis.load());
- bob->append(_fieldNames->getForOplogApplyingTotalLocalBatchesApplied(),
- _oplogBatchApplied.load());
+ reportOplogApplicationLatencyMetrics(_fieldNames, bob);
}
void ReshardingCumulativeMetrics::reportCurrentInSteps(BSONObjBuilder* bob) const {
ShardingDataTransformCumulativeMetrics::reportCurrentInSteps(bob);
-
- auto reportState = [this, bob](auto state) {
- bob->append(fieldNameFor(state, _fieldNames), getStateCounter(state)->load());
- };
-
- reportState(CoordinatorStateEnum::kInitializing);
- reportState(CoordinatorStateEnum::kPreparingToDonate);
- reportState(CoordinatorStateEnum::kCloning);
- reportState(CoordinatorStateEnum::kApplying);
- reportState(CoordinatorStateEnum::kBlockingWrites);
- reportState(CoordinatorStateEnum::kAborting);
- reportState(CoordinatorStateEnum::kCommitting);
-
- reportState(RecipientStateEnum::kAwaitingFetchTimestamp);
- reportState(RecipientStateEnum::kCreatingCollection);
- reportState(RecipientStateEnum::kCloning);
- reportState(RecipientStateEnum::kApplying);
- reportState(RecipientStateEnum::kError);
- reportState(RecipientStateEnum::kStrictConsistency);
- reportState(RecipientStateEnum::kDone);
-
- reportState(DonorStateEnum::kPreparingToDonate);
- reportState(DonorStateEnum::kDonatingInitialData);
- reportState(DonorStateEnum::kDonatingOplogEntries);
- reportState(DonorStateEnum::kPreparingToBlockWrites);
- reportState(DonorStateEnum::kError);
- reportState(DonorStateEnum::kBlockingWrites);
- reportState(DonorStateEnum::kDone);
-}
-
-void ReshardingCumulativeMetrics::onInsertApplied() {
- _insertsApplied.fetchAndAdd(1);
-}
-
-void ReshardingCumulativeMetrics::onUpdateApplied() {
- _updatesApplied.fetchAndAdd(1);
-}
-
-void ReshardingCumulativeMetrics::onDeleteApplied() {
- _deletesApplied.fetchAndAdd(1);
-}
-
-void ReshardingCumulativeMetrics::onOplogEntriesFetched(int64_t numEntries, Milliseconds elapsed) {
- _oplogEntriesFetched.fetchAndAdd(numEntries);
- _oplogFetchingTotalRemoteBatchesRetrieved.fetchAndAdd(1);
- _oplogFetchingTotalRemoteBatchesRetrievalTimeMillis.fetchAndAdd(
- durationCount<Milliseconds>(elapsed));
-}
-
-void ReshardingCumulativeMetrics::onOplogEntriesApplied(int64_t numEntries) {
- _oplogEntriesApplied.fetchAndAdd(numEntries);
-}
-
-void ReshardingCumulativeMetrics::onOplogLocalBatchApplied(Milliseconds elapsed) {
- _oplogBatchApplied.fetchAndAdd(1);
- _oplogBatchAppliedMillis.fetchAndAdd(durationCount<Milliseconds>(elapsed));
-}
-
-void ReshardingCumulativeMetrics::onLocalInsertDuringOplogFetching(
- const Milliseconds& elapsedTime) {
- _oplogFetchingTotalLocalInserts.fetchAndAdd(1);
- _oplogFetchingTotalLocalInsertTimeMillis.fetchAndAdd(durationCount<Milliseconds>(elapsedTime));
-}
-
-void ReshardingCumulativeMetrics::onBatchRetrievedDuringOplogApplying(
- const Milliseconds& elapsedTime) {
- _oplogApplyingTotalBatchesRetrieved.fetchAndAdd(1);
- _oplogApplyingTotalBatchesRetrievalTimeMillis.fetchAndAdd(
- durationCount<Milliseconds>(elapsedTime));
+ reportCountsForAllStates(kReportedStateFieldNamesMap, bob);
}
} // namespace mongo
diff --git a/src/mongo/db/s/resharding/resharding_cumulative_metrics.h b/src/mongo/db/s/resharding/resharding_cumulative_metrics.h
index 337750faead..96d69be9c74 100644
--- a/src/mongo/db/s/resharding/resharding_cumulative_metrics.h
+++ b/src/mongo/db/s/resharding/resharding_cumulative_metrics.h
@@ -30,138 +30,41 @@
#pragma once
#include "mongo/db/s/cumulative_metrics_state_holder.h"
+#include "mongo/db/s/metrics/sharding_data_transform_cumulative_metrics.h"
+#include "mongo/db/s/metrics/sharding_data_transform_metrics_macros.h"
+#include "mongo/db/s/metrics/with_oplog_application_count_metrics.h"
+#include "mongo/db/s/metrics/with_oplog_application_latency_metrics.h"
+#include "mongo/db/s/metrics/with_state_management_for_cumulative_metrics.h"
#include "mongo/db/s/resharding/resharding_cumulative_metrics_field_name_provider.h"
-#include "mongo/db/s/sharding_data_transform_cumulative_metrics.h"
+#include "mongo/s/resharding/common_types_gen.h"
namespace mongo {
-class ReshardingCumulativeMetrics : public ShardingDataTransformCumulativeMetrics {
+namespace resharding_cumulative_metrics {
+DEFINE_IDL_ENUM_SIZE_TEMPLATE_HELPER(ReshardingMetrics,
+ CoordinatorStateEnum,
+ DonorStateEnum,
+ RecipientStateEnum)
+using Base = WithOplogApplicationLatencyMetrics<WithOplogApplicationCountMetrics<
+ WithStateManagementForCumulativeMetrics<ShardingDataTransformCumulativeMetrics,
+ ReshardingMetricsEnumSizeTemplateHelper,
+ CoordinatorStateEnum,
+ DonorStateEnum,
+ RecipientStateEnum>>>;
+} // namespace resharding_cumulative_metrics
+
+class ReshardingCumulativeMetrics : public resharding_cumulative_metrics::Base {
public:
- enum class CoordinatorStateEnum : int32_t {
- kUnused = -1,
- kInitializing,
- kPreparingToDonate,
- kCloning,
- kApplying,
- kBlockingWrites,
- kAborting,
- kCommitting,
- kDone,
- kNumStates
- };
-
- enum class DonorStateEnum : int32_t {
- kUnused = -1,
- kPreparingToDonate,
- kDonatingInitialData,
- kDonatingOplogEntries,
- kPreparingToBlockWrites,
- kError,
- kBlockingWrites,
- kDone,
- kNumStates
- };
-
- enum class RecipientStateEnum : int32_t {
- kUnused = -1,
- kAwaitingFetchTimestamp,
- kCreatingCollection,
- kCloning,
- kApplying,
- kError,
- kStrictConsistency,
- kDone,
- kNumStates
- };
-
ReshardingCumulativeMetrics();
- static StringData fieldNameFor(CoordinatorStateEnum state,
- const ReshardingCumulativeMetricsFieldNameProvider* provider);
- static StringData fieldNameFor(DonorStateEnum state,
- const ReshardingCumulativeMetricsFieldNameProvider* provider);
- static StringData fieldNameFor(RecipientStateEnum state,
- const ReshardingCumulativeMetricsFieldNameProvider* provider);
- template <typename T>
- void onStateTransition(boost::optional<T> before, boost::optional<T> after);
- void onInsertApplied();
- void onUpdateApplied();
- void onDeleteApplied();
- void onOplogEntriesFetched(int64_t numEntries, Milliseconds elapsed);
- void onOplogEntriesApplied(int64_t numEntries);
- void onLocalInsertDuringOplogFetching(const Milliseconds& elapsedTime);
- void onBatchRetrievedDuringOplogApplying(const Milliseconds& elapsedTime);
- void onOplogLocalBatchApplied(Milliseconds elapsed);
+ static boost::optional<StringData> fieldNameFor(AnyState state);
private:
- template <typename T>
- const AtomicWord<int64_t>* getStateCounter(T state) const;
virtual void reportActive(BSONObjBuilder* bob) const;
virtual void reportLatencies(BSONObjBuilder* bob) const;
virtual void reportCurrentInSteps(BSONObjBuilder* bob) const;
const ReshardingCumulativeMetricsFieldNameProvider* _fieldNames;
-
- AtomicWord<int64_t> _insertsApplied{0};
- AtomicWord<int64_t> _updatesApplied{0};
- AtomicWord<int64_t> _deletesApplied{0};
- AtomicWord<int64_t> _oplogEntriesApplied{0};
- AtomicWord<int64_t> _oplogEntriesFetched{0};
-
- AtomicWord<int64_t> _oplogFetchingTotalRemoteBatchesRetrieved{0};
- AtomicWord<int64_t> _oplogFetchingTotalRemoteBatchesRetrievalTimeMillis{0};
- AtomicWord<int64_t> _oplogFetchingTotalLocalInserts{0};
- AtomicWord<int64_t> _oplogFetchingTotalLocalInsertTimeMillis{0};
- AtomicWord<int64_t> _oplogApplyingTotalBatchesRetrieved{0};
- AtomicWord<int64_t> _oplogApplyingTotalBatchesRetrievalTimeMillis{0};
- AtomicWord<int64_t> _oplogBatchApplied{0};
- AtomicWord<int64_t> _oplogBatchAppliedMillis{0};
-
- CumulativeMetricsStateHolder<CoordinatorStateEnum,
- static_cast<size_t>(CoordinatorStateEnum::kNumStates)>
- _coordinatorStateList;
- CumulativeMetricsStateHolder<DonorStateEnum, static_cast<size_t>(DonorStateEnum::kNumStates)>
- _donorStateList;
- CumulativeMetricsStateHolder<RecipientStateEnum,
- static_cast<size_t>(RecipientStateEnum::kNumStates)>
- _recipientStateList;
-
- template <typename T>
- auto getStateListForRole() const {
- if constexpr (std::is_same<T, CoordinatorStateEnum>::value) {
- return &_coordinatorStateList;
- } else if constexpr (std::is_same<T, DonorStateEnum>::value) {
- return &_donorStateList;
- } else if constexpr (std::is_same<T, RecipientStateEnum>::value) {
- return &_recipientStateList;
- } else {
- MONGO_UNREACHABLE;
- }
- }
-
- template <typename T>
- auto getMutableStateListForRole() {
- if constexpr (std::is_same<T, CoordinatorStateEnum>::value) {
- return &_coordinatorStateList;
- } else if constexpr (std::is_same<T, DonorStateEnum>::value) {
- return &_donorStateList;
- } else if constexpr (std::is_same<T, RecipientStateEnum>::value) {
- return &_recipientStateList;
- } else {
- MONGO_UNREACHABLE;
- }
- }
};
-template <typename T>
-void ReshardingCumulativeMetrics::onStateTransition(boost::optional<T> before,
- boost::optional<T> after) {
- getMutableStateListForRole<T>()->onStateTransition(before, after);
-}
-
-
-template <typename T>
-const AtomicWord<int64_t>* ReshardingCumulativeMetrics::getStateCounter(T state) const {
- return getStateListForRole<T>()->getStateCounter(state);
-}
} // namespace mongo
diff --git a/src/mongo/db/s/resharding/resharding_cumulative_metrics_field_name_provider.cpp b/src/mongo/db/s/resharding/resharding_cumulative_metrics_field_name_provider.cpp
deleted file mode 100644
index e7fa7e65a03..00000000000
--- a/src/mongo/db/s/resharding/resharding_cumulative_metrics_field_name_provider.cpp
+++ /dev/null
@@ -1,202 +0,0 @@
-/**
- * Copyright (C) 2022-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#include "mongo/db/s/resharding/resharding_cumulative_metrics_field_name_provider.h"
-
-namespace mongo {
-
-namespace {
-using Provider = ReshardingCumulativeMetricsFieldNameProvider;
-constexpr auto kDocumentsCopied = "documentsCopied";
-constexpr auto kBytesCopied = "bytesCopied";
-constexpr auto kOplogEntriesFetched = "oplogEntriesFetched";
-constexpr auto kOplogEntriesApplied = "oplogEntriesApplied";
-constexpr auto kInsertsApplied = "insertsApplied";
-constexpr auto kUpdatesApplied = "updatesApplied";
-constexpr auto kDeletesApplied = "deletesApplied";
-constexpr auto kOplogFetchingTotalRemoteBatchRetrievalTimeMillis =
- "oplogFetchingTotalRemoteBatchRetrievalTimeMillis";
-constexpr auto kOplogFetchingTotalRemoteBatchesRetrieved =
- "oplogFetchingTotalRemoteBatchesRetrieved";
-constexpr auto kOplogFetchingTotalLocalInsertTimeMillis = "oplogFetchingTotalLocalInsertTimeMillis";
-constexpr auto kOplogFetchingTotalLocalInserts = "oplogFetchingTotalLocalInserts";
-constexpr auto kOplogApplyingTotalLocalBatchRetrievalTimeMillis =
- "oplogApplyingTotalLocalBatchRetrievalTimeMillis";
-constexpr auto kOplogApplyingTotalLocalBatchesRetrieved = "oplogApplyingTotalLocalBatchesRetrieved";
-constexpr auto kOplogApplyingTotalLocalBatchApplyTimeMillis =
- "oplogApplyingTotalLocalBatchApplyTimeMillis";
-constexpr auto kOplogApplyingTotalLocalBatchesApplied = "oplogApplyingTotalLocalBatchesApplied";
-constexpr auto kCountInstancesInCoordinatorState1Initializing =
- "countInstancesInCoordinatorState1Initializing";
-constexpr auto kCountInstancesInCoordinatorState2PreparingToDonate =
- "countInstancesInCoordinatorState2PreparingToDonate";
-constexpr auto kCountInstancesInCoordinatorState3Cloning =
- "countInstancesInCoordinatorState3Cloning";
-constexpr auto kCountInstancesInCoordinatorState4Applying =
- "countInstancesInCoordinatorState4Applying";
-constexpr auto kCountInstancesInCoordinatorState5BlockingWrites =
- "countInstancesInCoordinatorState5BlockingWrites";
-constexpr auto kCountInstancesInCoordinatorState6Aborting =
- "countInstancesInCoordinatorState6Aborting";
-constexpr auto kCountInstancesInCoordinatorState7Committing =
- "countInstancesInCoordinatorState7Committing";
-constexpr auto kCountInstancesInRecipientState1AwaitingFetchTimestamp =
- "countInstancesInRecipientState1AwaitingFetchTimestamp";
-constexpr auto kCountInstancesInRecipientState2CreatingCollection =
- "countInstancesInRecipientState2CreatingCollection";
-constexpr auto kCountInstancesInRecipientState3Cloning = "countInstancesInRecipientState3Cloning";
-constexpr auto kCountInstancesInRecipientState4Applying = "countInstancesInRecipientState4Applying";
-constexpr auto kCountInstancesInRecipientState5Error = "countInstancesInRecipientState5Error";
-constexpr auto kCountInstancesInRecipientState6StrictConsistency =
- "countInstancesInRecipientState6StrictConsistency";
-constexpr auto kCountInstancesInRecipientState7Done = "countInstancesInRecipientState7Done";
-constexpr auto kCountInstancesInDonorState1PreparingToDonate =
- "countInstancesInDonorState1PreparingToDonate";
-constexpr auto kCountInstancesInDonorState2DonatingInitialData =
- "countInstancesInDonorState2DonatingInitialData";
-constexpr auto kCountInstancesInDonorState3DonatingOplogEntries =
- "countInstancesInDonorState3DonatingOplogEntries";
-constexpr auto kCountInstancesInDonorState4PreparingToBlockWrites =
- "countInstancesInDonorState4PreparingToBlockWrites";
-constexpr auto kCountInstancesInDonorState5Error = "countInstancesInDonorState5Error";
-constexpr auto kCountInstancesInDonorState6BlockingWrites =
- "countInstancesInDonorState6BlockingWrites";
-constexpr auto kCountInstancesInDonorState7Done = "countInstancesInDonorState7Done";
-} // namespace
-
-StringData Provider::getForDocumentsProcessed() const {
- return kDocumentsCopied;
-}
-StringData Provider::getForBytesWritten() const {
- return kBytesCopied;
-}
-StringData Provider::getForOplogEntriesFetched() const {
- return kOplogEntriesFetched;
-}
-StringData Provider::getForOplogEntriesApplied() const {
- return kOplogEntriesApplied;
-}
-StringData Provider::getForInsertsApplied() const {
- return kInsertsApplied;
-}
-StringData Provider::getForUpdatesApplied() const {
- return kUpdatesApplied;
-}
-StringData Provider::getForDeletesApplied() const {
- return kDeletesApplied;
-}
-StringData Provider::getForOplogFetchingTotalRemoteBatchRetrievalTimeMillis() const {
- return kOplogFetchingTotalRemoteBatchRetrievalTimeMillis;
-}
-StringData Provider::getForOplogFetchingTotalRemoteBatchesRetrieved() const {
- return kOplogFetchingTotalRemoteBatchesRetrieved;
-}
-StringData Provider::getForOplogFetchingTotalLocalInsertTimeMillis() const {
- return kOplogFetchingTotalLocalInsertTimeMillis;
-}
-StringData Provider::getForOplogFetchingTotalLocalInserts() const {
- return kOplogFetchingTotalLocalInserts;
-}
-StringData Provider::getForOplogApplyingTotalLocalBatchRetrievalTimeMillis() const {
- return kOplogApplyingTotalLocalBatchRetrievalTimeMillis;
-}
-StringData Provider::getForOplogApplyingTotalLocalBatchesRetrieved() const {
- return kOplogApplyingTotalLocalBatchesRetrieved;
-}
-StringData Provider::getForOplogApplyingTotalLocalBatchApplyTimeMillis() const {
- return kOplogApplyingTotalLocalBatchApplyTimeMillis;
-}
-StringData Provider::getForOplogApplyingTotalLocalBatchesApplied() const {
- return kOplogApplyingTotalLocalBatchesApplied;
-}
-StringData Provider::getForCountInstancesInCoordinatorState1Initializing() const {
- return kCountInstancesInCoordinatorState1Initializing;
-}
-StringData Provider::getForCountInstancesInCoordinatorState2PreparingToDonate() const {
- return kCountInstancesInCoordinatorState2PreparingToDonate;
-}
-StringData Provider::getForCountInstancesInCoordinatorState3Cloning() const {
- return kCountInstancesInCoordinatorState3Cloning;
-}
-StringData Provider::getForCountInstancesInCoordinatorState4Applying() const {
- return kCountInstancesInCoordinatorState4Applying;
-}
-StringData Provider::getForCountInstancesInCoordinatorState5BlockingWrites() const {
- return kCountInstancesInCoordinatorState5BlockingWrites;
-}
-StringData Provider::getForCountInstancesInCoordinatorState6Aborting() const {
- return kCountInstancesInCoordinatorState6Aborting;
-}
-StringData Provider::getForCountInstancesInCoordinatorState7Committing() const {
- return kCountInstancesInCoordinatorState7Committing;
-}
-StringData Provider::getForCountInstancesInRecipientState1AwaitingFetchTimestamp() const {
- return kCountInstancesInRecipientState1AwaitingFetchTimestamp;
-}
-StringData Provider::getForCountInstancesInRecipientState2CreatingCollection() const {
- return kCountInstancesInRecipientState2CreatingCollection;
-}
-StringData Provider::getForCountInstancesInRecipientState3Cloning() const {
- return kCountInstancesInRecipientState3Cloning;
-}
-StringData Provider::getForCountInstancesInRecipientState4Applying() const {
- return kCountInstancesInRecipientState4Applying;
-}
-StringData Provider::getForCountInstancesInRecipientState5Error() const {
- return kCountInstancesInRecipientState5Error;
-}
-StringData Provider::getForCountInstancesInRecipientState6StrictConsistency() const {
- return kCountInstancesInRecipientState6StrictConsistency;
-}
-StringData Provider::getForCountInstancesInRecipientState7Done() const {
- return kCountInstancesInRecipientState7Done;
-}
-StringData Provider::getForCountInstancesInDonorState1PreparingToDonate() const {
- return kCountInstancesInDonorState1PreparingToDonate;
-}
-StringData Provider::getForCountInstancesInDonorState2DonatingInitialData() const {
- return kCountInstancesInDonorState2DonatingInitialData;
-}
-StringData Provider::getForCountInstancesInDonorState3DonatingOplogEntries() const {
- return kCountInstancesInDonorState3DonatingOplogEntries;
-}
-StringData Provider::getForCountInstancesInDonorState4PreparingToBlockWrites() const {
- return kCountInstancesInDonorState4PreparingToBlockWrites;
-}
-StringData Provider::getForCountInstancesInDonorState5Error() const {
- return kCountInstancesInDonorState5Error;
-}
-StringData Provider::getForCountInstancesInDonorState6BlockingWrites() const {
- return kCountInstancesInDonorState6BlockingWrites;
-}
-StringData Provider::getForCountInstancesInDonorState7Done() const {
- return kCountInstancesInDonorState7Done;
-}
-
-} // namespace mongo
diff --git a/src/mongo/db/s/resharding/resharding_cumulative_metrics_field_name_provider.h b/src/mongo/db/s/resharding/resharding_cumulative_metrics_field_name_provider.h
index 981c04573ef..d4bce30c1fd 100644
--- a/src/mongo/db/s/resharding/resharding_cumulative_metrics_field_name_provider.h
+++ b/src/mongo/db/s/resharding/resharding_cumulative_metrics_field_name_provider.h
@@ -29,49 +29,16 @@
#pragma once
-#include "mongo/db/s/sharding_data_transform_cumulative_metrics_field_name_provider.h"
+#include "mongo/db/s/metrics/field_names/sharding_data_transform_cumulative_metrics_field_name_provider.h"
+#include "mongo/db/s/metrics/field_names/with_document_copy_field_name_overrides.h"
+#include "mongo/db/s/metrics/field_names/with_oplog_application_count_metrics_field_names.h"
+#include "mongo/db/s/metrics/field_names/with_oplog_application_latency_metrics_field_names.h"
namespace mongo {
class ReshardingCumulativeMetricsFieldNameProvider
- : public ShardingDataTransformCumulativeMetricsFieldNameProvider {
-public:
- virtual StringData getForDocumentsProcessed() const override;
- virtual StringData getForBytesWritten() const override;
- StringData getForOplogEntriesFetched() const;
- StringData getForOplogEntriesApplied() const;
- StringData getForInsertsApplied() const;
- StringData getForUpdatesApplied() const;
- StringData getForDeletesApplied() const;
- StringData getForOplogFetchingTotalRemoteBatchRetrievalTimeMillis() const;
- StringData getForOplogFetchingTotalRemoteBatchesRetrieved() const;
- StringData getForOplogFetchingTotalLocalInsertTimeMillis() const;
- StringData getForOplogFetchingTotalLocalInserts() const;
- StringData getForOplogApplyingTotalLocalBatchRetrievalTimeMillis() const;
- StringData getForOplogApplyingTotalLocalBatchesRetrieved() const;
- StringData getForOplogApplyingTotalLocalBatchApplyTimeMillis() const;
- StringData getForOplogApplyingTotalLocalBatchesApplied() const;
- StringData getForCountInstancesInCoordinatorState1Initializing() const;
- StringData getForCountInstancesInCoordinatorState2PreparingToDonate() const;
- StringData getForCountInstancesInCoordinatorState3Cloning() const;
- StringData getForCountInstancesInCoordinatorState4Applying() const;
- StringData getForCountInstancesInCoordinatorState5BlockingWrites() const;
- StringData getForCountInstancesInCoordinatorState6Aborting() const;
- StringData getForCountInstancesInCoordinatorState7Committing() const;
- StringData getForCountInstancesInRecipientState1AwaitingFetchTimestamp() const;
- StringData getForCountInstancesInRecipientState2CreatingCollection() const;
- StringData getForCountInstancesInRecipientState3Cloning() const;
- StringData getForCountInstancesInRecipientState4Applying() const;
- StringData getForCountInstancesInRecipientState5Error() const;
- StringData getForCountInstancesInRecipientState6StrictConsistency() const;
- StringData getForCountInstancesInRecipientState7Done() const;
- StringData getForCountInstancesInDonorState1PreparingToDonate() const;
- StringData getForCountInstancesInDonorState2DonatingInitialData() const;
- StringData getForCountInstancesInDonorState3DonatingOplogEntries() const;
- StringData getForCountInstancesInDonorState4PreparingToBlockWrites() const;
- StringData getForCountInstancesInDonorState5Error() const;
- StringData getForCountInstancesInDonorState6BlockingWrites() const;
- StringData getForCountInstancesInDonorState7Done() const;
-};
+ : public WithOplogApplicationLatencyMetricsFieldNames<
+ WithOplogApplicationCountFieldNames<WithDocumentCopyFieldNameOverrides<
+ ShardingDataTransformCumulativeMetricsFieldNameProvider>>> {};
} // namespace mongo
diff --git a/src/mongo/db/s/resharding/resharding_cumulative_metrics_test.cpp b/src/mongo/db/s/resharding/resharding_cumulative_metrics_test.cpp
index f47a96022ec..245b244509a 100644
--- a/src/mongo/db/s/resharding/resharding_cumulative_metrics_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_cumulative_metrics_test.cpp
@@ -28,8 +28,8 @@
*/
+#include "mongo/db/s/metrics/sharding_data_transform_metrics_test_fixture.h"
#include "mongo/db/s/resharding/resharding_cumulative_metrics.h"
-#include "mongo/db/s/sharding_data_transform_metrics_test_fixture.h"
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
@@ -56,13 +56,11 @@ protected:
return kResharding;
}
- using CoordinatorStateEnum = ReshardingCumulativeMetrics::CoordinatorStateEnum;
- using DonorStateEnum = ReshardingCumulativeMetrics::DonorStateEnum;
- using RecipientStateEnum = ReshardingCumulativeMetrics::RecipientStateEnum;
-
template <typename T>
StringData fieldNameFor(T state) {
- return ReshardingCumulativeMetrics::fieldNameFor(state, _fieldNames.get());
+ auto maybeFieldName = ReshardingCumulativeMetrics::fieldNameFor(state);
+ invariant(maybeFieldName.has_value());
+ return *maybeFieldName;
}
BSONObj getStateSubObj(const ReshardingCumulativeMetrics* metrics) {
@@ -283,7 +281,8 @@ TEST_F(ReshardingCumulativeMetricsTest, ReportContainsOplogEntriesFetched) {
ASSERT_EQ(latencies.getIntField("oplogFetchingTotalRemoteBatchesRetrieved"), 0);
ASSERT_EQ(latencies.getIntField("oplogFetchingTotalRemoteBatchRetrievalTimeMillis"), 0);
- _reshardingCumulativeMetrics->onOplogEntriesFetched(123, Milliseconds(43));
+ _reshardingCumulativeMetrics->onOplogEntriesFetched(123);
+ _reshardingCumulativeMetrics->onBatchRetrievedDuringOplogFetching(Milliseconds(43));
active = getCumulativeMetricsReportForSection(kActive);
ASSERT_EQ(active.getIntField("oplogEntriesFetched"), 123);
diff --git a/src/mongo/db/s/resharding/resharding_donor_service.cpp b/src/mongo/db/s/resharding/resharding_donor_service.cpp
index a0886e63a35..82bd29be52d 100644
--- a/src/mongo/db/s/resharding/resharding_donor_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_donor_service.cpp
@@ -192,10 +192,6 @@ public:
}
};
-ReshardingMetrics::DonorState toMetricsState(DonorStateEnum state) {
- return ReshardingMetrics::DonorState(state);
-}
-
} // namespace
ThreadPool::Limits ReshardingDonorService::getThreadPoolLimits() const {
@@ -245,7 +241,7 @@ ReshardingDonorService::DonorStateMachine::DonorStateMachine(
}()) {
invariant(_externalState);
- _metrics->onStateTransition(boost::none, toMetricsState(_donorCtx.getState()));
+ _metrics->onStateTransition(boost::none, _donorCtx.getState());
}
ExecutorFuture<void> ReshardingDonorService::DonorStateMachine::_runUntilBlockingWritesOrErrored(
@@ -422,7 +418,7 @@ ExecutorFuture<void> ReshardingDonorService::DonorStateMachine::_finishReshardin
Status ReshardingDonorService::DonorStateMachine::_runMandatoryCleanup(
Status status, const CancellationToken& stepdownToken) {
- _metrics->onStateTransition(toMetricsState(_donorCtx.getState()), boost::none);
+ _metrics->onStateTransition(_donorCtx.getState(), boost::none);
// Destroy metrics early so it's lifetime will not be tied to the lifetime of this state
// machine. This is because we have future callbacks copy shared pointers to this state machine
@@ -854,7 +850,7 @@ void ReshardingDonorService::DonorStateMachine::_transitionState(DonorShardConte
_updateDonorDocument(std::move(newDonorCtx));
- _metrics->onStateTransition(toMetricsState(oldState), toMetricsState(newState));
+ _metrics->onStateTransition(oldState, newState);
LOGV2_INFO(5279505,
"Transitioned resharding donor state",
diff --git a/src/mongo/db/s/resharding/resharding_metrics.cpp b/src/mongo/db/s/resharding/resharding_metrics.cpp
index 0bc74f96092..529199181b0 100644
--- a/src/mongo/db/s/resharding/resharding_metrics.cpp
+++ b/src/mongo/db/s/resharding/resharding_metrics.cpp
@@ -263,136 +263,6 @@ void ReshardingMetrics::restoreCoordinatorSpecificFields(
restorePhaseDurationFields(document);
}
-ReshardingMetrics::DonorState::DonorState(DonorStateEnum enumVal) : _enumVal(enumVal) {}
-
-ReshardingCumulativeMetrics::DonorStateEnum ReshardingMetrics::DonorState::toMetrics() const {
- using MetricsEnum = ReshardingCumulativeMetrics::DonorStateEnum;
-
- switch (_enumVal) {
- case DonorStateEnum::kUnused:
- return MetricsEnum::kUnused;
-
- case DonorStateEnum::kPreparingToDonate:
- return MetricsEnum::kPreparingToDonate;
-
- case DonorStateEnum::kDonatingInitialData:
- return MetricsEnum::kDonatingInitialData;
-
- case DonorStateEnum::kDonatingOplogEntries:
- return MetricsEnum::kDonatingOplogEntries;
-
- case DonorStateEnum::kPreparingToBlockWrites:
- return MetricsEnum::kPreparingToBlockWrites;
-
- case DonorStateEnum::kError:
- return MetricsEnum::kError;
-
- case DonorStateEnum::kBlockingWrites:
- return MetricsEnum::kBlockingWrites;
-
- case DonorStateEnum::kDone:
- return MetricsEnum::kDone;
- default:
- invariant(false,
- str::stream() << "Unexpected resharding coordinator state: "
- << DonorState_serializer(_enumVal));
- MONGO_UNREACHABLE;
- }
-}
-
-DonorStateEnum ReshardingMetrics::DonorState::getState() const {
- return _enumVal;
-}
-
-ReshardingMetrics::RecipientState::RecipientState(RecipientStateEnum enumVal) : _enumVal(enumVal) {}
-
-ReshardingCumulativeMetrics::RecipientStateEnum ReshardingMetrics::RecipientState::toMetrics()
- const {
- using MetricsEnum = ReshardingCumulativeMetrics::RecipientStateEnum;
-
- switch (_enumVal) {
- case RecipientStateEnum::kUnused:
- return MetricsEnum::kUnused;
-
- case RecipientStateEnum::kAwaitingFetchTimestamp:
- return MetricsEnum::kAwaitingFetchTimestamp;
-
- case RecipientStateEnum::kCreatingCollection:
- return MetricsEnum::kCreatingCollection;
-
- case RecipientStateEnum::kCloning:
- return MetricsEnum::kCloning;
-
- case RecipientStateEnum::kApplying:
- return MetricsEnum::kApplying;
-
- case RecipientStateEnum::kError:
- return MetricsEnum::kError;
-
- case RecipientStateEnum::kStrictConsistency:
- return MetricsEnum::kStrictConsistency;
-
- case RecipientStateEnum::kDone:
- return MetricsEnum::kDone;
-
- default:
- invariant(false,
- str::stream() << "Unexpected resharding coordinator state: "
- << RecipientState_serializer(_enumVal));
- MONGO_UNREACHABLE;
- }
-}
-
-RecipientStateEnum ReshardingMetrics::RecipientState::getState() const {
- return _enumVal;
-}
-
-ReshardingMetrics::CoordinatorState::CoordinatorState(CoordinatorStateEnum enumVal)
- : _enumVal(enumVal) {}
-
-ReshardingCumulativeMetrics::CoordinatorStateEnum ReshardingMetrics::CoordinatorState::toMetrics()
- const {
- using MetricsEnum = ReshardingCumulativeMetrics::CoordinatorStateEnum;
-
- switch (_enumVal) {
- case CoordinatorStateEnum::kUnused:
- return MetricsEnum::kUnused;
-
- case CoordinatorStateEnum::kInitializing:
- return MetricsEnum::kInitializing;
-
- case CoordinatorStateEnum::kPreparingToDonate:
- return MetricsEnum::kPreparingToDonate;
-
- case CoordinatorStateEnum::kCloning:
- return MetricsEnum::kCloning;
-
- case CoordinatorStateEnum::kApplying:
- return MetricsEnum::kApplying;
-
- case CoordinatorStateEnum::kBlockingWrites:
- return MetricsEnum::kBlockingWrites;
-
- case CoordinatorStateEnum::kAborting:
- return MetricsEnum::kAborting;
-
- case CoordinatorStateEnum::kCommitting:
- return MetricsEnum::kCommitting;
-
- case CoordinatorStateEnum::kDone:
- return MetricsEnum::kDone;
- default:
- invariant(false,
- str::stream() << "Unexpected resharding coordinator state: "
- << CoordinatorState_serializer(_enumVal));
- MONGO_UNREACHABLE;
- }
-}
-
-CoordinatorStateEnum ReshardingMetrics::CoordinatorState::getState() const {
- return _enumVal;
-}
-
void ReshardingMetrics::onDeleteApplied() {
_deletesApplied.addAndFetch(1);
getReshardingCumulativeMetrics()->onDeleteApplied();
@@ -410,7 +280,8 @@ void ReshardingMetrics::onUpdateApplied() {
void ReshardingMetrics::onOplogEntriesFetched(int64_t numEntries, Milliseconds elapsed) {
_oplogEntriesFetched.addAndFetch(numEntries);
- getReshardingCumulativeMetrics()->onOplogEntriesFetched(numEntries, elapsed);
+ getReshardingCumulativeMetrics()->onOplogEntriesFetched(numEntries);
+ getReshardingCumulativeMetrics()->onBatchRetrievedDuringOplogFetching(elapsed);
}
void ReshardingMetrics::restoreOplogEntriesFetched(int64_t numEntries) {
diff --git a/src/mongo/db/s/resharding/resharding_metrics.h b/src/mongo/db/s/resharding/resharding_metrics.h
index 3ff7194e314..dc9af8211da 100644
--- a/src/mongo/db/s/resharding/resharding_metrics.h
+++ b/src/mongo/db/s/resharding/resharding_metrics.h
@@ -31,12 +31,12 @@
#include "mongo/bson/bsonobj.h"
#include "mongo/db/namespace_string.h"
+#include "mongo/db/s/metrics/sharding_data_transform_instance_metrics.h"
#include "mongo/db/s/metrics_state_holder.h"
#include "mongo/db/s/resharding/resharding_cumulative_metrics.h"
#include "mongo/db/s/resharding/resharding_metrics_field_name_provider.h"
#include "mongo/db/s/resharding/resharding_metrics_helpers.h"
#include "mongo/db/s/resharding/resharding_oplog_applier_progress_gen.h"
-#include "mongo/db/s/sharding_data_transform_instance_metrics.h"
#include "mongo/util/uuid.h"
namespace mongo {
@@ -44,41 +44,6 @@ namespace mongo {
class ReshardingMetrics : public ShardingDataTransformInstanceMetrics {
public:
using State = stdx::variant<CoordinatorStateEnum, RecipientStateEnum, DonorStateEnum>;
- class DonorState {
- public:
- using MetricsType = ReshardingCumulativeMetrics::DonorStateEnum;
-
- explicit DonorState(DonorStateEnum enumVal);
- MetricsType toMetrics() const;
- DonorStateEnum getState() const;
-
- private:
- const DonorStateEnum _enumVal;
- };
-
- class RecipientState {
- public:
- using MetricsType = ReshardingCumulativeMetrics::RecipientStateEnum;
-
- explicit RecipientState(RecipientStateEnum enumVal);
- MetricsType toMetrics() const;
- RecipientStateEnum getState() const;
-
- private:
- RecipientStateEnum _enumVal;
- };
-
- class CoordinatorState {
- public:
- using MetricsType = ReshardingCumulativeMetrics::CoordinatorStateEnum;
-
- explicit CoordinatorState(CoordinatorStateEnum enumVal);
- MetricsType toMetrics() const;
- CoordinatorStateEnum getState() const;
-
- private:
- CoordinatorStateEnum _enumVal;
- };
struct ExternallyTrackedRecipientFields {
public:
diff --git a/src/mongo/db/s/resharding/resharding_metrics_field_name_provider.h b/src/mongo/db/s/resharding/resharding_metrics_field_name_provider.h
index 8203b78845f..8dbe528797b 100644
--- a/src/mongo/db/s/resharding/resharding_metrics_field_name_provider.h
+++ b/src/mongo/db/s/resharding/resharding_metrics_field_name_provider.h
@@ -30,7 +30,7 @@
#pragma once
#include "mongo/db/namespace_string.h"
-#include "mongo/db/s/sharding_data_transform_instance_metrics_field_name_provider.h"
+#include "mongo/db/s/metrics/field_names/sharding_data_transform_instance_metrics_field_name_provider.h"
#include "mongo/util/duration.h"
namespace mongo {
diff --git a/src/mongo/db/s/resharding/resharding_metrics_helpers.h b/src/mongo/db/s/resharding/resharding_metrics_helpers.h
index 42d8fc01fd0..9ce618f13ae 100644
--- a/src/mongo/db/s/resharding/resharding_metrics_helpers.h
+++ b/src/mongo/db/s/resharding/resharding_metrics_helpers.h
@@ -29,10 +29,10 @@
#pragma once
+#include "mongo/db/s/metrics/sharding_data_transform_instance_metrics.h"
#include "mongo/db/s/resharding/coordinator_document_gen.h"
#include "mongo/db/s/resharding/donor_document_gen.h"
#include "mongo/db/s/resharding/recipient_document_gen.h"
-#include "mongo/db/s/sharding_data_transform_instance_metrics.h"
#include <type_traits>
namespace mongo {
diff --git a/src/mongo/db/s/resharding/resharding_metrics_test.cpp b/src/mongo/db/s/resharding/resharding_metrics_test.cpp
index b36d4a4d3aa..495e88974bc 100644
--- a/src/mongo/db/s/resharding/resharding_metrics_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_metrics_test.cpp
@@ -30,11 +30,11 @@
#include "mongo/platform/basic.h"
+#include "mongo/db/s/metrics/sharding_data_transform_cumulative_metrics.h"
+#include "mongo/db/s/metrics/sharding_data_transform_metrics_test_fixture.h"
#include "mongo/db/s/resharding/resharding_metrics.h"
#include "mongo/db/s/resharding/resharding_service_test_helpers.h"
#include "mongo/db/s/resharding/resharding_util.h"
-#include "mongo/db/s/sharding_data_transform_cumulative_metrics.h"
-#include "mongo/db/s/sharding_data_transform_metrics_test_fixture.h"
#include "mongo/unittest/unittest.h"
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
@@ -639,8 +639,7 @@ TEST_F(ReshardingMetricsTest, OnApplyingBatchAppliedIncrementsCumulativeMetricsB
TEST_F(ReshardingMetricsTest, OnStateTransitionFromNoneInformsCumulativeMetrics) {
createMetricsAndAssertIncrementsCumulativeMetricsField(
[](auto metrics) {
- metrics->onStateTransition(
- boost::none, ReshardingMetrics::CoordinatorState{CoordinatorStateEnum::kApplying});
+ metrics->onStateTransition(boost::none, CoordinatorStateEnum::kApplying);
},
Section::kCurrentInSteps,
"countInstancesInCoordinatorState4Applying");
@@ -648,7 +647,7 @@ TEST_F(ReshardingMetricsTest, OnStateTransitionFromNoneInformsCumulativeMetrics)
TEST_F(ReshardingMetricsTest, OnStateTransitionToNoneInformsCumulativeMetrics) {
auto metrics = createInstanceMetrics(getClockSource(), UUID::gen(), Role::kCoordinator);
- auto state = ReshardingMetrics::CoordinatorState{CoordinatorStateEnum::kApplying};
+ auto state = CoordinatorStateEnum::kApplying;
metrics->onStateTransition(boost::none, state);
assertDecrementsCumulativeMetricsField(
metrics.get(),
@@ -662,8 +661,8 @@ TEST_F(ReshardingMetricsTest, OnStateTransitionToNoneInformsCumulativeMetrics) {
TEST_F(ReshardingMetricsTest, OnStateTransitionInformsCumulativeMetrics) {
auto metrics = createInstanceMetrics(getClockSource(), UUID::gen(), Role::kCoordinator);
- auto initialState = ReshardingMetrics::CoordinatorState{CoordinatorStateEnum::kApplying};
- auto nextState = ReshardingMetrics::CoordinatorState{CoordinatorStateEnum::kBlockingWrites};
+ auto initialState = CoordinatorStateEnum::kApplying;
+ auto nextState = CoordinatorStateEnum::kBlockingWrites;
metrics->onStateTransition(boost::none, initialState);
assertAltersCumulativeMetrics(
metrics.get(),
diff --git a/src/mongo/db/s/resharding/resharding_oplog_applier_metrics_test.cpp b/src/mongo/db/s/resharding/resharding_oplog_applier_metrics_test.cpp
index 4e5e29943bf..0d09b53d3e9 100644
--- a/src/mongo/db/s/resharding/resharding_oplog_applier_metrics_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_oplog_applier_metrics_test.cpp
@@ -30,8 +30,8 @@
#include "mongo/platform/basic.h"
+#include "mongo/db/s/metrics/sharding_data_transform_metrics_test_fixture.h"
#include "mongo/db/s/resharding/resharding_oplog_applier_metrics.h"
-#include "mongo/db/s/sharding_data_transform_metrics_test_fixture.h"
#include "mongo/unittest/unittest.h"
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
diff --git a/src/mongo/db/s/resharding/resharding_oplog_fetcher.cpp b/src/mongo/db/s/resharding/resharding_oplog_fetcher.cpp
index 8b3621a409f..f4a88845610 100644
--- a/src/mongo/db/s/resharding/resharding_oplog_fetcher.cpp
+++ b/src/mongo/db/s/resharding/resharding_oplog_fetcher.cpp
@@ -42,9 +42,9 @@
#include "mongo/db/pipeline/aggregate_command_gen.h"
#include "mongo/db/repl/read_concern_args.h"
#include "mongo/db/repl/read_concern_level.h"
+#include "mongo/db/s/metrics/sharding_data_transform_cumulative_metrics.h"
#include "mongo/db/s/resharding/resharding_metrics.h"
#include "mongo/db/s/resharding/resharding_util.h"
-#include "mongo/db/s/sharding_data_transform_cumulative_metrics.h"
#include "mongo/db/storage/write_unit_of_work.h"
#include "mongo/executor/task_executor.h"
#include "mongo/logv2/log.h"
diff --git a/src/mongo/db/s/resharding/resharding_recipient_service.cpp b/src/mongo/db/s/resharding/resharding_recipient_service.cpp
index 17f2b800a0d..5bd200f09fa 100644
--- a/src/mongo/db/s/resharding/resharding_recipient_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_recipient_service.cpp
@@ -184,10 +184,6 @@ void setMeticsAfterWrite(ReshardingMetrics* metrics,
}
}
-ReshardingMetrics::RecipientState toMetricsState(RecipientStateEnum state) {
- return ReshardingMetrics::RecipientState(state);
-}
-
} // namespace
ThreadPool::Limits ReshardingRecipientService::getThreadPoolLimits() const {
@@ -244,7 +240,7 @@ ReshardingRecipientService::RecipientStateMachine::RecipientStateMachine(
}()) {
invariant(_externalState);
- _metrics->onStateTransition(boost::none, toMetricsState(_recipientCtx.getState()));
+ _metrics->onStateTransition(boost::none, _recipientCtx.getState());
}
ExecutorFuture<void>
@@ -444,7 +440,7 @@ ExecutorFuture<void> ReshardingRecipientService::RecipientStateMachine::_runMand
self = shared_from_this(),
outerStatus = status,
isCanceled = stepdownToken.isCanceled()](Status dataReplicationHaltStatus) {
- _metrics->onStateTransition(toMetricsState(_recipientCtx.getState()), boost::none);
+ _metrics->onStateTransition(_recipientCtx.getState(), boost::none);
// Destroy metrics early so it's lifetime will not be tied to the lifetime of this
// state machine. This is because we have future callbacks copy shared pointers to this
@@ -888,7 +884,7 @@ void ReshardingRecipientService::RecipientStateMachine::_transitionState(
_updateRecipientDocument(
std::move(newRecipientCtx), std::move(cloneDetails), std::move(configStartTime), factory);
- _metrics->onStateTransition(toMetricsState(oldState), toMetricsState(newState));
+ _metrics->onStateTransition(oldState, newState);
LOGV2_INFO(5279506,
"Transitioned resharding recipient state",