diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
| commit | 294bc6ecabf14c09c9bc8644704921dcf97cb44e (patch) | |
| tree | 279b1e0bab53901a1647ac63c1c724f0f789a663 /src/mongo/db/s/resharding/resharding_metrics.cpp | |
| parent | 70be7c27a251621187a1de533462ae2bb1e3bd39 (diff) | |
| parent | 1e917fd798aa25b7066d4b414b51184f13d5a092 (diff) | |
Update upstream source from tag 'upstream/6.0.10'debian/6.0.10-1
Update to upstream version '6.0.10'
with Debian dir 2d176fa254eee97b139f712fec5709641335a8c3
Diffstat (limited to 'src/mongo/db/s/resharding/resharding_metrics.cpp')
| -rw-r--r-- | src/mongo/db/s/resharding/resharding_metrics.cpp | 77 |
1 files changed, 61 insertions, 16 deletions
diff --git a/src/mongo/db/s/resharding/resharding_metrics.cpp b/src/mongo/db/s/resharding/resharding_metrics.cpp index 6e4e4e041e9..b42c9df5c9e 100644 --- a/src/mongo/db/s/resharding/resharding_metrics.cpp +++ b/src/mongo/db/s/resharding/resharding_metrics.cpp @@ -406,6 +406,60 @@ void ReshardingMetrics::onStepUp(Role role) noexcept { // instead of starting from the current time. } +void ReshardingMetrics::onStepUp(RecipientStateEnum state, + const ReshardingRecipientCountsAndMetrics& recipientMetrics) { + stdx::lock_guard<Latch> lk(_mutex); + + _emplaceCurrentOpForRole(Role::kRecipient, boost::none); + _onStepUpCalled = true; + + invariant(_currentOp, kNoOperationInProgress); + invariant(_currentOp->documentsCopied == 0, kMetricsSetBeforeRestore); + invariant(_currentOp->bytesCopied == 0, kMetricsSetBeforeRestore); + invariant(_currentOp->oplogEntriesFetched == 0, kMetricsSetBeforeRestore); + invariant(_currentOp->oplogEntriesApplied == 0, kMetricsSetBeforeRestore); + + _currentOp->recipientState = state; + _currentOp->documentsCopied = recipientMetrics.documentCountCopied; + _currentOp->bytesCopied = recipientMetrics.documentBytesCopied; + _currentOp->oplogEntriesFetched = recipientMetrics.oplogEntriesFetched; + _currentOp->oplogEntriesApplied = recipientMetrics.oplogEntriesApplied; + + if (recipientMetrics.approxBytesToCopy) + _currentOp->bytesToCopy = recipientMetrics.approxBytesToCopy.get(); + + + const auto& timeIntervals = recipientMetrics.metrics; + + // Restore in memory state of document copy metrics. + // Not calling startCopyingDocuments or endCopyingDocuments because they acquire a mutex that we + // already have. + // + // Also, note that it is possible for documentCopyInterval->getStart() to be none and for + // documentCopyInterval->getStop() to be not none. That can happen if the cluster is upgraded + // to include code for persisting time intervals during a resharding operation. + // In that case, restore neither the start nor stop time. The resharding coordinator will still + // treat this scenario as the recipient shard being completely caught up after a primary + // failover and engage the critical section too early. + const auto& documentCopyInterval = timeIntervals.getDocumentCopy(); + if (documentCopyInterval && documentCopyInterval->getStart()) { + _currentOp->copyingDocuments.start(documentCopyInterval->getStart().get()); + if (documentCopyInterval->getStop()) { + _currentOp->copyingDocuments.end(documentCopyInterval->getStop().get()); + } + } + // Restore in memory state of oplog application metrics. + // Not calling startApplyingOplogEntries or endApplyingOplogEntries because they acquire a mutex + // that we already have. + const auto& oplogApplicationInterval = timeIntervals.getOplogApplication(); + if (oplogApplicationInterval && oplogApplicationInterval->getStart()) { + _currentOp->applyingOplogEntries.start(oplogApplicationInterval->getStart().get()); + if (oplogApplicationInterval->getStop()) { + _currentOp->applyingOplogEntries.end(oplogApplicationInterval->getStop().get()); + } + } +} + void ReshardingMetrics::onStepUp(DonorStateEnum state, ReshardingDonorMetrics donorMetrics) { stdx::lock_guard<Latch> lk(_mutex); auto operationRuntime = donorMetrics.getOperationRuntime(); @@ -484,6 +538,9 @@ void ReshardingMetrics::setDonorState(DonorStateEnum state) noexcept { void ReshardingMetrics::setRecipientState(RecipientStateEnum state) noexcept { stdx::lock_guard<Latch> lk(_mutex); + if (!_currentOp && state == RecipientStateEnum::kDone) { + return; + } invariant(_currentOp, kNoOperationInProgress); const auto oldState = std::exchange(_currentOp->recipientState, state); @@ -634,6 +691,10 @@ void ReshardingMetrics::enterCriticalSection(Date_t start) { void ReshardingMetrics::leaveCriticalSection(Date_t end) { stdx::lock_guard<Latch> lk(_mutex); + if (!_currentOp) { + return; + } + _currentOp->inCriticalSection.forceEnd(end); } @@ -662,22 +723,6 @@ void ReshardingMetrics::onOplogEntriesApplied(int64_t entries) noexcept { _cumulativeOp->oplogEntriesApplied += entries; } -void ReshardingMetrics::restoreForCurrentOp(int64_t documentCountCopied, - int64_t documentBytesCopied, - int64_t oplogEntriesFetched, - int64_t oplogEntriesApplied) noexcept { - invariant(_currentOp, kNoOperationInProgress); - invariant(_currentOp->documentsCopied == 0, kMetricsSetBeforeRestore); - invariant(_currentOp->bytesCopied == 0, kMetricsSetBeforeRestore); - invariant(_currentOp->oplogEntriesFetched == 0, kMetricsSetBeforeRestore); - invariant(_currentOp->oplogEntriesApplied == 0, kMetricsSetBeforeRestore); - - _currentOp->documentsCopied = documentCountCopied; - _currentOp->bytesCopied = documentBytesCopied; - _currentOp->oplogEntriesFetched = oplogEntriesFetched; - _currentOp->oplogEntriesApplied = oplogEntriesApplied; -} - void ReshardingMetrics::onWriteDuringCriticalSection(int64_t writes) noexcept { stdx::lock_guard<Latch> lk(_mutex); if (!_currentOp) |
