diff options
author | Randolph Tan <randolph@10gen.com> | 2022-04-27 20:40:05 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-04-27 21:48:05 +0000 |
commit | d68a849239961b2e59484f5955052a8a80adc00b (patch) | |
tree | abb4fcd733d0c9439c6f2375e820a054a4becfbe | |
parent | dc51c89abfef9f4202f9cb3cbe32674439f7e9f6 (diff) | |
download | mongo-d68a849239961b2e59484f5955052a8a80adc00b.tar.gz |
SERVER-65895 Also create applier metrics for donor shards with no progress document
-rw-r--r-- | src/mongo/db/s/resharding/resharding_recipient_service.cpp | 49 | ||||
-rw-r--r-- | src/mongo/db/s/resharding/resharding_recipient_service_test.cpp | 65 |
2 files changed, 89 insertions, 25 deletions
diff --git a/src/mongo/db/s/resharding/resharding_recipient_service.cpp b/src/mongo/db/s/resharding/resharding_recipient_service.cpp index 01d313c73a5..97fc1e9c6f2 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service.cpp +++ b/src/mongo/db/s/resharding/resharding_recipient_service.cpp @@ -559,7 +559,9 @@ ReshardingRecipientService::RecipientStateMachine::_makeDataReplication(Operatio std::make_unique<ReshardingOplogApplierMetrics>(_metricsNew.get(), boost::none)); } } else { - invariant(_applierMetricsMap.size() == _donorShards.size()); + invariant(_applierMetricsMap.size() == _donorShards.size(), + str::stream() << "applier metrics map size: " << _applierMetricsMap.size() + << " != donor shards count: " << _donorShards.size()); } return _dataReplicationFactory(opCtx, @@ -1135,32 +1137,29 @@ void ReshardingRecipientService::RecipientStateMachine::_restoreMetrics( } } - { - AutoGetCollection progressApplierColl( - opCtx.get(), NamespaceString::kReshardingApplierProgressNamespace, MODE_IS); - if (progressApplierColl) { - BSONObj result; - Helpers::findOne( - opCtx.get(), - progressApplierColl.getCollection(), - BSON(ReshardingOplogApplierProgress::kOplogSourceIdFieldName - << (ReshardingSourceId{_metadata.getReshardingUUID(), donor.getShardId()}) - .toBSON()), - result); - - if (!result.isEmpty()) { - auto progressDoc = ReshardingOplogApplierProgress::parse( - IDLParserErrorContext("resharding-recipient-service-progress-doc"), result); - oplogEntriesApplied += progressDoc.getNumEntriesApplied(); - - if (ShardingDataTransformMetrics::isEnabled()) { - progressDocList.emplace_back(donor.getShardId(), progressDoc); - } - } - } else { - progressDocList.emplace_back(donor.getShardId(), boost::none); + boost::optional<ReshardingOplogApplierProgress> progressDoc; + AutoGetCollection progressApplierColl( + opCtx.get(), NamespaceString::kReshardingApplierProgressNamespace, MODE_IS); + if (progressApplierColl) { + BSONObj result; + Helpers::findOne( + opCtx.get(), + progressApplierColl.getCollection(), + BSON(ReshardingOplogApplierProgress::kOplogSourceIdFieldName + << (ReshardingSourceId{_metadata.getReshardingUUID(), donor.getShardId()}) + .toBSON()), + result); + + if (!result.isEmpty()) { + progressDoc = ReshardingOplogApplierProgress::parse( + IDLParserErrorContext("resharding-recipient-service-progress-doc"), result); + oplogEntriesApplied += progressDoc->getNumEntriesApplied(); } } + + if (ShardingDataTransformMetrics::isEnabled()) { + progressDocList.emplace_back(donor.getShardId(), progressDoc); + } } // Restore stats here where interrupts will never occur, this is to ensure we will only update diff --git a/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp b/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp index 518df23e17b..6bddf3386c2 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp +++ b/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp @@ -31,6 +31,7 @@ #include "mongo/platform/basic.h" +#include "mongo/bson/timestamp.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/op_observer_noop.h" #include "mongo/db/op_observer_registry.h" @@ -48,6 +49,7 @@ #include "mongo/db/s/resharding/resharding_recipient_service.h" #include "mongo/db/s/resharding/resharding_recipient_service_external_state.h" #include "mongo/db/s/resharding/resharding_service_test_helpers.h" +#include "mongo/idl/server_parameter_test_util.h" #include "mongo/logv2/log.h" #include "mongo/unittest/death_test.h" #include "mongo/util/fail_point.h" @@ -267,6 +269,15 @@ public: resharding::data_copy::ensureCollectionExists(opCtx, recipientDoc.getSourceNss(), options); } + void createTempReshardingCollection(OperationContext* opCtx, + const ReshardingRecipientDocument& recipientDoc) { + CollectionOptions options; + options.uuid = recipientDoc.getReshardingUUID(); + resharding::data_copy::ensureCollectionDropped(opCtx, recipientDoc.getTempReshardingNss()); + resharding::data_copy::ensureCollectionExists( + opCtx, recipientDoc.getTempReshardingNss(), options); + } + void notifyToStartCloning(OperationContext* opCtx, RecipientStateMachine& recipient, const ReshardingRecipientDocument& recipientDoc) { @@ -859,5 +870,59 @@ TEST_F(ReshardingRecipientServiceTest, RestoreMetricsAfterStepUp) { } } +TEST_F(ReshardingRecipientServiceTest, RestoreMetricsAfterStepUpWithMissingProgressDoc) { + RAIIServerParameterControllerForTest featureFlagController( + "featureFlagShardingDataTransformMetrics", true); + + auto doc = makeStateDocument(false); + auto instanceId = + BSON(ReshardingRecipientDocument::kReshardingUUIDFieldName << doc.getReshardingUUID()); + auto opCtx = makeOperationContext(); + + auto donorShards = doc.getDonorShards(); + auto insertFn = [&](const NamespaceString nss, const InsertStatement insertStatement) { + resharding::data_copy::ensureCollectionExists(opCtx.get(), nss, CollectionOptions()); + + std::vector<InsertStatement> inserts{insertStatement}; + resharding::data_copy::insertBatch(opCtx.get(), nss, inserts); + }; + + for (unsigned i = 0; i < donorShards.size(); i++) { + if (i == 0) { + continue; + } + + const auto& donor = donorShards[i]; + + // Setup oplogBuffer collection. + ReshardingDonorOplogId donorOplogId{{20, i}, {19, 0}}; + insertFn(getLocalOplogBufferNamespace(doc.getSourceUUID(), donor.getShardId()), + InsertStatement{BSON("_id" << donorOplogId.toBSON())}); + + // Setup reshardingApplierProgress collection. + ReshardingOplogApplierProgress progressDoc( + {doc.getReshardingUUID(), donor.getShardId()}, donorOplogId, 10 /* numOplogApplied */); + insertFn(NamespaceString::kReshardingApplierProgressNamespace, + InsertStatement{progressDoc.toBSON()}); + } + + auto mutableState = doc.getMutableState(); + mutableState.setState(RecipientStateEnum::kApplying); + doc.setMutableState(mutableState); + doc.setCloneTimestamp(Timestamp{10, 0}); + doc.setStartConfigTxnCloneTime(Date_t::now()); + + auto metadata = doc.getCommonReshardingMetadata(); + metadata.setStartTime(Date_t::now()); + doc.setCommonReshardingMetadata(metadata); + + createTempReshardingCollection(opCtx.get(), doc); + + RecipientStateMachine::insertStateDocument(opCtx.get(), doc); + auto recipient = RecipientStateMachine::getOrCreate(opCtx.get(), _service, doc.toBSON()); + notifyReshardingCommitting(opCtx.get(), *recipient, doc); + ASSERT_OK(recipient->getCompletionFuture().getNoThrow()); +} + } // namespace } // namespace mongo |