diff options
Diffstat (limited to 'src/mongo/db/s')
19 files changed, 383 insertions, 17 deletions
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index a20f1c682f8..60b195acda9 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -85,6 +85,7 @@ env.Library( 'resharding/resharding_future_util.cpp', 'resharding/resharding_manual_cleanup.cpp', 'resharding/resharding_metrics.cpp', + 'resharding/resharding_metrics_new.cpp', 'resharding/resharding_op_observer.cpp', 'resharding/resharding_oplog_applier.cpp', 'resharding/resharding_oplog_applier_progress.idl', @@ -500,6 +501,7 @@ env.CppUnitTest( 'resharding/resharding_donor_oplog_iterator_test.cpp', 'resharding/resharding_donor_recipient_common_test.cpp', 'resharding/resharding_metrics_test.cpp', + 'resharding/resharding_metrics_new_test.cpp', 'resharding/resharding_oplog_applier_test.cpp', 'resharding/resharding_oplog_batch_applier_test.cpp', 'resharding/resharding_oplog_batch_preparer_test.cpp', diff --git a/src/mongo/db/s/global_index_metrics.h b/src/mongo/db/s/global_index_metrics.h index 351ed6fb24f..e34a1f24a83 100644 --- a/src/mongo/db/s/global_index_metrics.h +++ b/src/mongo/db/s/global_index_metrics.h @@ -46,9 +46,15 @@ public: bool unique, ShardingDataTransformCumulativeMetrics* cumulativeMetrics); + static std::unique_ptr<GlobalIndexMetrics> makeInstance(UUID uuid, + NamespaceString nss, + Role role, + BSONObj keyPattern, + bool unique, + ServiceContext* serviceContext); + private: std::string createOperationDescription() const noexcept override; - BSONObj _shardKey; }; } // namespace mongo diff --git a/src/mongo/db/s/resharding/resharding_data_replication.cpp b/src/mongo/db/s/resharding/resharding_data_replication.cpp index dc393e5c9b2..647b41f643c 100644 --- a/src/mongo/db/s/resharding/resharding_data_replication.cpp +++ b/src/mongo/db/s/resharding/resharding_data_replication.cpp @@ -164,6 +164,7 @@ std::shared_ptr<executor::TaskExecutor> ReshardingDataReplication::_makeOplogFet std::vector<std::unique_ptr<ReshardingOplogApplier>> ReshardingDataReplication::_makeOplogAppliers( OperationContext* opCtx, ReshardingMetrics* metrics, + ReshardingMetricsNew* metricsNew, const CommonReshardingMetadata& metadata, const std::vector<DonorShardFetchTimestamp>& donorShards, Timestamp cloneTimestamp, @@ -184,7 +185,8 @@ std::vector<std::unique_ptr<ReshardingOplogApplier>> ReshardingDataReplication:: getLocalOplogBufferNamespace(metadata.getSourceUUID(), donorShards[i].getShardId()); oplogAppliers.emplace_back(std::make_unique<ReshardingOplogApplier>( - std::make_unique<ReshardingOplogApplier::Env>(opCtx->getServiceContext(), metrics), + std::make_unique<ReshardingOplogApplier::Env>( + opCtx->getServiceContext(), metrics, metricsNew), std::move(sourceId), metadata.getTempReshardingNss(), stashCollections, @@ -203,6 +205,7 @@ std::vector<std::unique_ptr<ReshardingOplogApplier>> ReshardingDataReplication:: std::unique_ptr<ReshardingDataReplicationInterface> ReshardingDataReplication::make( OperationContext* opCtx, ReshardingMetrics* metrics, + ReshardingMetricsNew* metricsNew, CommonReshardingMetadata metadata, const std::vector<DonorShardFetchTimestamp>& donorShards, Timestamp cloneTimestamp, @@ -224,6 +227,7 @@ std::unique_ptr<ReshardingDataReplicationInterface> ReshardingDataReplication::m auto stashCollections = ensureStashCollectionsExist(opCtx, sourceChunkMgr, donorShards); auto oplogAppliers = _makeOplogAppliers(opCtx, metrics, + metricsNew, metadata, donorShards, cloneTimestamp, diff --git a/src/mongo/db/s/resharding/resharding_data_replication.h b/src/mongo/db/s/resharding/resharding_data_replication.h index 14c31604b0b..a2705abd6f6 100644 --- a/src/mongo/db/s/resharding/resharding_data_replication.h +++ b/src/mongo/db/s/resharding/resharding_data_replication.h @@ -36,6 +36,7 @@ #include "mongo/bson/timestamp.h" #include "mongo/db/cancelable_operation_context.h" #include "mongo/db/s/resharding/donor_oplog_id_gen.h" +#include "mongo/db/s/resharding/resharding_metrics_new.h" #include "mongo/s/chunk_manager.h" #include "mongo/s/resharding/common_types_gen.h" #include "mongo/s/shard_id.h" @@ -138,6 +139,7 @@ public: static std::unique_ptr<ReshardingDataReplicationInterface> make( OperationContext* opCtx, ReshardingMetrics* metrics, + ReshardingMetricsNew* metricsNew, CommonReshardingMetadata metadata, const std::vector<DonorShardFetchTimestamp>& donorShards, Timestamp cloneTimestamp, @@ -213,6 +215,7 @@ private: static std::vector<std::unique_ptr<ReshardingOplogApplier>> _makeOplogAppliers( OperationContext* opCtx, ReshardingMetrics* metrics, + ReshardingMetricsNew* metricsNew, const CommonReshardingMetadata& metadata, const std::vector<DonorShardFetchTimestamp>& donorShards, Timestamp cloneTimestamp, diff --git a/src/mongo/db/s/resharding/resharding_metrics_new.cpp b/src/mongo/db/s/resharding/resharding_metrics_new.cpp new file mode 100644 index 00000000000..e81704c0b3b --- /dev/null +++ b/src/mongo/db/s/resharding/resharding_metrics_new.cpp @@ -0,0 +1,81 @@ +/** + * 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_metrics_new.h" +#include "mongo/db/exec/document_value/document.h" + + +namespace mongo { +namespace { +// Returns the originalCommand with the createIndexes, key and unique fields added. +BSONObj createOriginalCommand(const NamespaceString& nss, BSONObj keyPattern, bool unique) { + + using Doc = Document; + using Arr = std::vector<Value>; + using V = Value; + + return Doc{{"originatingCommand", + V{Doc{{"reshardCollection", V{StringData{nss.toString()}}}, + {"key", std::move(keyPattern)}, + {"unique", V{unique}}, + {"collation", V{Doc{{"locale", V{StringData{"simple"}}}}}}}}}} + .toBson(); +} +} // namespace + +ReshardingMetricsNew::ReshardingMetricsNew( + UUID uuid, + NamespaceString nss, + Role role, + BSONObj shardKey, + bool unique, + ShardingDataTransformCumulativeMetrics* cumulativeMetrics) + : ShardingDataTransformInstanceMetrics(std::move(uuid), + createOriginalCommand(nss, std::move(shardKey), unique), + std::move(nss), + role, + cumulativeMetrics) {} + +std::string ReshardingMetricsNew::createOperationDescription() const noexcept { + return fmt::format("ReshardingMetrics{}Service {}", getRoleName(_role), _instanceId.toString()); +} + +std::unique_ptr<ReshardingMetricsNew> ReshardingMetricsNew::makeInstance( + UUID instanceId, + NamespaceString nss, + Role role, + BSONObj shardKey, + bool unique, + ServiceContext* serviceContext) { + auto cumulativeMetrics = + ShardingDataTransformCumulativeMetrics::getForResharding(serviceContext); + + return std::make_unique<ReshardingMetricsNew>( + instanceId, nss, role, std::move(shardKey), unique, cumulativeMetrics); +} +} // namespace mongo diff --git a/src/mongo/db/s/resharding/resharding_metrics_new.h b/src/mongo/db/s/resharding/resharding_metrics_new.h new file mode 100644 index 00000000000..8bb86fb18c8 --- /dev/null +++ b/src/mongo/db/s/resharding/resharding_metrics_new.h @@ -0,0 +1,60 @@ +/** + * 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. + */ + +#pragma once + +#include "mongo/bson/bsonobj.h" +#include "mongo/db/namespace_string.h" +#include "mongo/db/s/sharding_data_transform_instance_metrics.h" +#include "mongo/util/uuid.h" + +namespace mongo { + + +class ReshardingMetricsNew : public ShardingDataTransformInstanceMetrics { +public: + ReshardingMetricsNew(UUID uuid, + NamespaceString nss, + Role role, + BSONObj shardKey, + bool unique, + ShardingDataTransformCumulativeMetrics* cumulativeMetrics); + + static std::unique_ptr<ReshardingMetricsNew> makeInstance(UUID instanceId, + NamespaceString nss, + Role role, + BSONObj shardKey, + bool unique, + ServiceContext* serviceContext); + +private: + std::string createOperationDescription() const noexcept override; +}; + +} // namespace mongo diff --git a/src/mongo/db/s/resharding/resharding_metrics_new_test.cpp b/src/mongo/db/s/resharding/resharding_metrics_new_test.cpp new file mode 100644 index 00000000000..0eaaf781594 --- /dev/null +++ b/src/mongo/db/s/resharding/resharding_metrics_new_test.cpp @@ -0,0 +1,70 @@ +/** + * 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. + */ + +#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest + +#include "mongo/platform/basic.h" + +#include "mongo/db/s/resharding/resharding_metrics_new.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" + +namespace mongo { +namespace { + + +class ReshardingMetricsTest : public ShardingDataTransformMetricsTestFixture { + +public: + std::unique_ptr<ReshardingMetricsNew> createInstanceMetrics(UUID instanceId = UUID::gen(), + Role role = Role::kDonor) { + return std::make_unique<ReshardingMetricsNew>( + instanceId, kTestNamespace, role, BSON("y" << 1), false, &_cumulativeMetrics); + } +}; + + +TEST_F(ReshardingMetricsTest, ReportForCurrentOpShouldHaveGlobalIndexDescription) { + std::vector<Role> roles{Role::kCoordinator, Role::kDonor, Role::kRecipient}; + + std::for_each(roles.begin(), roles.end(), [&](Role role) { + auto instanceId = UUID::gen(); + auto metrics = createInstanceMetrics(instanceId, role); + auto report = metrics->reportForCurrentOp(); + + ASSERT_EQ(report.getStringField("desc").toString(), + fmt::format("ReshardingMetrics{}Service {}", + ReshardingMetricsNew::getRoleName(role), + instanceId.toString())); + }); +} + +} // namespace +} // namespace mongo diff --git a/src/mongo/db/s/resharding/resharding_oplog_application.cpp b/src/mongo/db/s/resharding/resharding_oplog_application.cpp index eadf96b76bc..7e2aacc030e 100644 --- a/src/mongo/db/s/resharding/resharding_oplog_application.cpp +++ b/src/mongo/db/s/resharding/resharding_oplog_application.cpp @@ -52,6 +52,7 @@ #include "mongo/db/stats/counters.h" #include "mongo/db/transaction_participant.h" #include "mongo/logv2/log.h" +#include "mongo/s/sharding_feature_flags_gen.h" namespace mongo { namespace { @@ -122,14 +123,16 @@ ReshardingOplogApplicationRules::ReshardingOplogApplicationRules( size_t myStashIdx, ShardId donorShardId, ChunkManager sourceChunkMgr, - ReshardingMetrics* metrics) + ReshardingMetrics* metrics, + ReshardingMetricsNew* metricsNew) : _outputNss(std::move(outputNss)), _allStashNss(std::move(allStashNss)), _myStashIdx(myStashIdx), _myStashNss(_allStashNss.at(_myStashIdx)), _donorShardId(std::move(donorShardId)), _sourceChunkMgr(std::move(sourceChunkMgr)), - _metrics(metrics) {} + _metrics(metrics), + _metricsNew(metricsNew) {} Status ReshardingOplogApplicationRules::applyOperation(OperationContext* opCtx, const repl::OplogEntry& op) const { @@ -169,14 +172,26 @@ Status ReshardingOplogApplicationRules::applyOperation(OperationContext* opCtx, case repl::OpTypeEnum::kInsert: _applyInsert_inlock( opCtx, autoCollOutput.getDb(), *autoCollOutput, *autoCollStash, op); + if (feature_flags::gFeatureFlagShardingDataTransformMetrics + .isEnabledAndIgnoreFCV()) { + _metricsNew->onInsertApplied(); + } break; case repl::OpTypeEnum::kUpdate: _applyUpdate_inlock( opCtx, autoCollOutput.getDb(), *autoCollOutput, *autoCollStash, op); + if (feature_flags::gFeatureFlagShardingDataTransformMetrics + .isEnabledAndIgnoreFCV()) { + _metricsNew->onUpdateApplied(); + } break; case repl::OpTypeEnum::kDelete: _applyDelete_inlock( opCtx, autoCollOutput.getDb(), *autoCollOutput, *autoCollStash, op); + if (feature_flags::gFeatureFlagShardingDataTransformMetrics + .isEnabledAndIgnoreFCV()) { + _metricsNew->onDeleteApplied(); + } break; default: MONGO_UNREACHABLE; diff --git a/src/mongo/db/s/resharding/resharding_oplog_application.h b/src/mongo/db/s/resharding/resharding_oplog_application.h index 662f3c1ec28..2f5c03a8592 100644 --- a/src/mongo/db/s/resharding/resharding_oplog_application.h +++ b/src/mongo/db/s/resharding/resharding_oplog_application.h @@ -41,6 +41,7 @@ #include "mongo/db/repl/oplog_entry.h" #include "mongo/db/repl/optime.h" #include "mongo/db/repl/replication_coordinator.h" +#include "mongo/db/s/resharding/resharding_metrics_new.h" #include "mongo/s/chunk_manager.h" namespace mongo { @@ -60,7 +61,8 @@ public: size_t myStashIdx, ShardId donorShardId, ChunkManager sourceChunkMgr, - ReshardingMetrics* metrics); + ReshardingMetrics* metrics, + ReshardingMetricsNew* metricsNew); const NamespaceString& getOutputNss() const { return _outputNss; @@ -120,6 +122,7 @@ private: const ChunkManager _sourceChunkMgr; ReshardingMetrics* _metrics; + ReshardingMetricsNew* _metricsNew; }; } // namespace mongo diff --git a/src/mongo/db/s/resharding/resharding_oplog_applier.cpp b/src/mongo/db/s/resharding/resharding_oplog_applier.cpp index acea14c911f..b65d5376689 100644 --- a/src/mongo/db/s/resharding/resharding_oplog_applier.cpp +++ b/src/mongo/db/s/resharding/resharding_oplog_applier.cpp @@ -40,6 +40,7 @@ #include "mongo/db/s/resharding/resharding_metrics.h" #include "mongo/db/s/resharding/resharding_util.h" #include "mongo/logv2/log.h" +#include "mongo/s/sharding_feature_flags_gen.h" #include "mongo/util/assert_util.h" #include "mongo/util/fail_point.h" #include "mongo/util/uuid.h" @@ -66,7 +67,8 @@ ReshardingOplogApplier::ReshardingOplogApplier( myStashIdx, _sourceId.getShardId(), std::move(sourceChunkMgr), - _env->metrics()}, + _env->metrics(), + _env->metricsNew()}, _sessionApplication{}, _batchApplier{_crudApplication, _sessionApplication}, _oplogIter(std::move(oplogIterator)) {} @@ -233,6 +235,9 @@ void ReshardingOplogApplier::_clearAppliedOpsAndStoreProgress(OperationContext* BSON(ReshardingOplogApplierProgress::kOplogSourceIdFieldName << _sourceId.toBSON()), builder.obj()); _env->metrics()->onOplogEntriesApplied(_currentBatchToApply.size()); + if (feature_flags::gFeatureFlagShardingDataTransformMetrics.isEnabledAndIgnoreFCV()) { + _env->metricsNew()->onOplogEntriesApplied(_currentBatchToApply.size()); + } _currentBatchToApply.clear(); _currentDerivedOps.clear(); diff --git a/src/mongo/db/s/resharding/resharding_oplog_applier.h b/src/mongo/db/s/resharding/resharding_oplog_applier.h index a61de92f6f9..0c3a8bc8306 100644 --- a/src/mongo/db/s/resharding/resharding_oplog_applier.h +++ b/src/mongo/db/s/resharding/resharding_oplog_applier.h @@ -36,6 +36,7 @@ #include "mongo/db/repl/oplog_entry.h" #include "mongo/db/s/resharding/donor_oplog_id_gen.h" #include "mongo/db/s/resharding/resharding_donor_oplog_iterator.h" +#include "mongo/db/s/resharding/resharding_metrics_new.h" #include "mongo/db/s/resharding/resharding_oplog_application.h" #include "mongo/db/s/resharding/resharding_oplog_applier_progress_gen.h" #include "mongo/db/s/resharding/resharding_oplog_batch_applier.h" @@ -66,8 +67,9 @@ class ReshardingOplogApplier { public: class Env { public: - Env(ServiceContext* service, ReshardingMetrics* metrics) - : _service(service), _metrics(metrics) {} + Env(ServiceContext* service, ReshardingMetrics* metrics, ReshardingMetricsNew* metricsNew) + : _service(service), _metrics(metrics), _metricsNew(metricsNew) {} + ServiceContext* service() const { return _service; } @@ -75,9 +77,14 @@ public: return _metrics; } + ReshardingMetricsNew* metricsNew() const { + return _metricsNew; + } + private: ServiceContext* _service; ReshardingMetrics* _metrics; + ReshardingMetricsNew* _metricsNew; }; ReshardingOplogApplier(std::unique_ptr<Env> env, diff --git a/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp b/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp index 638d1ca77cc..5256cd8f3da 100644 --- a/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp +++ b/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp @@ -155,6 +155,12 @@ public: _cm = createChunkManagerForOriginalColl(); _metrics = std::make_unique<ReshardingMetrics>(getServiceContext()); + _metricsNew = ReshardingMetricsNew::makeInstance(kCrudUUID, + kCrudNs, + ReshardingMetricsNew::Role::kRecipient, + BSON("y" << 1), + false, + getServiceContext()); _metrics->onStart(ReshardingMetrics::Role::kRecipient, getServiceContext()->getFastClockSource()->now()); _metrics->setRecipientState(RecipientStateEnum::kApplying); @@ -297,7 +303,8 @@ public: protected: auto makeApplierEnv() { - return std::make_unique<ReshardingOplogApplier::Env>(getServiceContext(), &*_metrics); + return std::make_unique<ReshardingOplogApplier::Env>( + getServiceContext(), _metrics.get(), _metricsNew.get()); } std::shared_ptr<executor::ThreadPoolTaskExecutor> makeTaskExecutorForApplier() { @@ -354,6 +361,7 @@ protected: const ReshardingSourceId _sourceId{UUID::gen(), kMyShardId}; std::unique_ptr<ReshardingMetrics> _metrics; + std::unique_ptr<ReshardingMetricsNew> _metricsNew; std::shared_ptr<executor::ThreadPoolTaskExecutor> _executor; std::shared_ptr<ThreadPool> _cancelableOpCtxExecutor; diff --git a/src/mongo/db/s/resharding/resharding_oplog_batch_applier_test.cpp b/src/mongo/db/s/resharding/resharding_oplog_batch_applier_test.cpp index 91479dcdbd5..27d1c2ef4f3 100644 --- a/src/mongo/db/s/resharding/resharding_oplog_batch_applier_test.cpp +++ b/src/mongo/db/s/resharding/resharding_oplog_batch_applier_test.cpp @@ -109,14 +109,20 @@ public: } _metrics = std::make_unique<ReshardingMetrics>(serviceContext); - + _metricsNew = ReshardingMetricsNew::makeInstance(UUID::gen(), + _outputNss, + ReshardingMetricsNew::kRecipient, + BSON("y" << 1), + false, + serviceContext); _crudApplication = std::make_unique<ReshardingOplogApplicationRules>( _outputNss, std::vector<NamespaceString>{_myStashNss, _otherStashNss}, 0U, _myDonorId, makeChunkManagerForSourceCollection(), - _metrics.get()); + _metrics.get(), + _metricsNew.get()); _sessionApplication = std::make_unique<ReshardingOplogSessionApplication>(); @@ -337,6 +343,7 @@ private: getLocalConflictStashNamespace(_sourceUUID, _otherDonorId); std::unique_ptr<ReshardingMetrics> _metrics; + std::unique_ptr<ReshardingMetricsNew> _metricsNew; std::unique_ptr<ReshardingOplogApplicationRules> _crudApplication; std::unique_ptr<ReshardingOplogSessionApplication> _sessionApplication; diff --git a/src/mongo/db/s/resharding/resharding_oplog_crud_application_test.cpp b/src/mongo/db/s/resharding/resharding_oplog_crud_application_test.cpp index b64f60a7e04..154baba79c8 100644 --- a/src/mongo/db/s/resharding/resharding_oplog_crud_application_test.cpp +++ b/src/mongo/db/s/resharding/resharding_oplog_crud_application_test.cpp @@ -111,13 +111,20 @@ public: } _metrics = std::make_unique<ReshardingMetrics>(getServiceContext()); + _metricsNew = ReshardingMetricsNew::makeInstance(_sourceUUID, + _outputNss, + ReshardingMetricsNew::kRecipient, + BSON(_newShardKey << 1), + false, + serviceContext); _applier = std::make_unique<ReshardingOplogApplicationRules>( _outputNss, std::vector<NamespaceString>{_myStashNss, _otherStashNss}, 0U, _myDonorId, makeChunkManagerForSourceCollection(), - _metrics.get()); + _metrics.get(), + _metricsNew.get()); } } @@ -332,6 +339,7 @@ private: std::unique_ptr<ReshardingOplogApplicationRules> _applier; std::unique_ptr<ReshardingMetrics> _metrics; + std::unique_ptr<ReshardingMetricsNew> _metricsNew; }; TEST_F(ReshardingOplogCrudApplicationTest, InsertOpInsertsIntoOuputCollection) { diff --git a/src/mongo/db/s/resharding/resharding_recipient_service.cpp b/src/mongo/db/s/resharding/resharding_recipient_service.cpp index ece74b78f45..d6d22888511 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service.cpp +++ b/src/mongo/db/s/resharding/resharding_recipient_service.cpp @@ -135,6 +135,13 @@ ReshardingRecipientService::RecipientStateMachine::RecipientStateMachine( ReshardingDataReplicationFactory dataReplicationFactory) : repl::PrimaryOnlyService::TypedInstance<RecipientStateMachine>(), _recipientService{recipientService}, + _metricsNew{ReshardingMetricsNew::makeInstance( + recipientDoc.getReshardingUUID(), + recipientDoc.getSourceNss(), + ReshardingMetricsNew::Role::kRecipient, + recipientDoc.getCommonReshardingMetadata().getReshardingKey().toBSON(), + false, + getGlobalServiceContext())}, _metadata{recipientDoc.getCommonReshardingMetadata()}, _minimumOperationDuration{Milliseconds{recipientDoc.getMinimumOperationDurationMillis()}}, _recipientCtx{recipientDoc.getMutableState()}, @@ -539,6 +546,7 @@ ReshardingRecipientService::RecipientStateMachine::_makeDataReplication(Operatio return _dataReplicationFactory(opCtx, _metrics(), + _metricsNew.get(), _metadata, _donorShards, *_cloneTimestamp, diff --git a/src/mongo/db/s/resharding/resharding_recipient_service.h b/src/mongo/db/s/resharding/resharding_recipient_service.h index e0ed18c124f..e1fe504a970 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service.h +++ b/src/mongo/db/s/resharding/resharding_recipient_service.h @@ -33,6 +33,7 @@ #include "mongo/db/s/resharding/recipient_document_gen.h" #include "mongo/db/s/resharding/resharding_data_replication.h" #include "mongo/db/s/resharding/resharding_future_util.h" +#include "mongo/db/s/resharding/resharding_metrics_new.h" #include "mongo/db/s/resharding/resharding_util.h" #include "mongo/s/resharding/type_collection_fields_gen.h" #include "mongo/util/concurrency/thread_pool.h" @@ -275,6 +276,8 @@ private: // The primary-only service instance corresponding to the recipient instance. Not owned. const ReshardingRecipientService* const _recipientService; + std::unique_ptr<ReshardingMetricsNew> _metricsNew; + // The in-memory representation of the immutable portion of the document in // config.localReshardingOperations.recipient. const CommonReshardingMetadata _metadata; diff --git a/src/mongo/db/s/sharding_data_transform_instance_metrics.cpp b/src/mongo/db/s/sharding_data_transform_instance_metrics.cpp index 1ae1be54a4a..f678b446d4c 100644 --- a/src/mongo/db/s/sharding_data_transform_instance_metrics.cpp +++ b/src/mongo/db/s/sharding_data_transform_instance_metrics.cpp @@ -81,7 +81,11 @@ ShardingDataTransformInstanceMetrics::ShardingDataTransformInstanceMetrics( _observer{std::move(observer)}, _cumulativeMetrics{cumulativeMetrics}, _deregister{_cumulativeMetrics->registerInstanceMetrics(_observer.get())}, - _placeholderUuidForTesting(UUID::gen()) {} + _placeholderUuidForTesting(UUID::gen()), + _insertsApplied{0}, + _updatesApplied{0}, + _deletesApplied{0}, + _oplogEntriesApplied{0} {} ShardingDataTransformInstanceMetrics::~ShardingDataTransformInstanceMetrics() { if (_deregister) { @@ -141,10 +145,10 @@ BSONObj ShardingDataTransformInstanceMetrics::reportForCurrentOp() const noexcep builder.append(kApproxBytesToCopy, TEMP_VALUE); builder.append(kBytesCopied, TEMP_VALUE); builder.append(kCountWritesToStashCollections, TEMP_VALUE); - builder.append(kInsertsApplied, TEMP_VALUE); - builder.append(kUpdatesApplied, TEMP_VALUE); - builder.append(kDeletesApplied, TEMP_VALUE); - builder.append(kOplogEntriesApplied, TEMP_VALUE); + builder.append(kInsertsApplied, _insertsApplied.load()); + builder.append(kUpdatesApplied, _updatesApplied.load()); + builder.append(kDeletesApplied, _deletesApplied.load()); + builder.append(kOplogEntriesApplied, _oplogEntriesApplied.load()); builder.append(kOplogEntriesFetched, TEMP_VALUE); builder.append(kDocumentsCopied, TEMP_VALUE); break; @@ -155,4 +159,20 @@ BSONObj ShardingDataTransformInstanceMetrics::reportForCurrentOp() const noexcep return builder.obj(); } +void ShardingDataTransformInstanceMetrics::onInsertApplied() { + _insertsApplied.addAndFetch(1); +} + +void ShardingDataTransformInstanceMetrics::onUpdateApplied() { + _updatesApplied.addAndFetch(1); +} + +void ShardingDataTransformInstanceMetrics::onDeleteApplied() { + _deletesApplied.addAndFetch(1); +} + +void ShardingDataTransformInstanceMetrics::onOplogEntriesApplied(int64_t numEntries) { + _oplogEntriesApplied.addAndFetch(numEntries); +} + } // namespace mongo diff --git a/src/mongo/db/s/sharding_data_transform_instance_metrics.h b/src/mongo/db/s/sharding_data_transform_instance_metrics.h index f4cac5c26c4..a2afce0775e 100644 --- a/src/mongo/db/s/sharding_data_transform_instance_metrics.h +++ b/src/mongo/db/s/sharding_data_transform_instance_metrics.h @@ -59,6 +59,10 @@ public: int64_t getRemainingTimeMillis() const; int64_t getStartTimestamp() const; const UUID& getUuid() const; + void onInsertApplied(); + void onUpdateApplied(); + void onDeleteApplied(); + void onOplogEntriesApplied(int64_t numEntries); protected: virtual std::string createOperationDescription() const noexcept; @@ -102,6 +106,10 @@ private: ShardingDataTransformCumulativeMetrics::DeregistrationFunction _deregister; UUID _placeholderUuidForTesting; + AtomicWord<int64_t> _insertsApplied; + AtomicWord<int64_t> _updatesApplied; + AtomicWord<int64_t> _deletesApplied; + AtomicWord<int64_t> _oplogEntriesApplied; }; } // namespace mongo diff --git a/src/mongo/db/s/sharding_data_transform_instance_metrics_test.cpp b/src/mongo/db/s/sharding_data_transform_instance_metrics_test.cpp index 8e12236d80b..8546ca02931 100644 --- a/src/mongo/db/s/sharding_data_transform_instance_metrics_test.cpp +++ b/src/mongo/db/s/sharding_data_transform_instance_metrics_test.cpp @@ -139,5 +139,53 @@ TEST_F(ShardingDataTransformInstanceMetricsTest, GetRoleNameShouldReturnCorrectN }); } + +TEST_F(ShardingDataTransformInstanceMetricsTest, OnInsertAppliedShouldIncrementInsertsApplied) { + auto metrics = createInstanceMetrics(UUID::gen(), Role::kRecipient); + + auto report = metrics->reportForCurrentOp(); + ASSERT_EQ(report.getIntField("insertsApplied"), 0); + metrics->onInsertApplied(); + + report = metrics->reportForCurrentOp(); + ASSERT_EQ(report.getIntField("insertsApplied"), 1); +} + + +TEST_F(ShardingDataTransformInstanceMetricsTest, OnUpdateAppliedShouldIncrementUpdatesApplied) { + auto metrics = createInstanceMetrics(UUID::gen(), Role::kRecipient); + + auto report = metrics->reportForCurrentOp(); + ASSERT_EQ(report.getIntField("updatesApplied"), 0); + metrics->onUpdateApplied(); + + report = metrics->reportForCurrentOp(); + ASSERT_EQ(report.getIntField("updatesApplied"), 1); +} + +TEST_F(ShardingDataTransformInstanceMetricsTest, OnDeleteAppliedShouldIncrementDeletesApplied) { + auto metrics = createInstanceMetrics(UUID::gen(), Role::kRecipient); + + auto report = metrics->reportForCurrentOp(); + ASSERT_EQ(report.getIntField("deletesApplied"), 0); + metrics->onDeleteApplied(); + + report = metrics->reportForCurrentOp(); + ASSERT_EQ(report.getIntField("deletesApplied"), 1); +} + + +TEST_F(ShardingDataTransformInstanceMetricsTest, + OnOplogsEntriesAppliedShouldIncrementOplogsEntriesApplied) { + auto metrics = createInstanceMetrics(UUID::gen(), Role::kRecipient); + + auto report = metrics->reportForCurrentOp(); + ASSERT_EQ(report.getIntField("oplogEntriesApplied"), 0); + metrics->onOplogEntriesApplied(100); + + report = metrics->reportForCurrentOp(); + ASSERT_EQ(report.getIntField("oplogEntriesApplied"), 100); +} + } // namespace } // namespace mongo |