summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaley Connelly <haley.connelly@mongodb.com>2021-05-06 21:27:36 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-10 20:05:50 +0000
commitf3dbbebb303be094a563989f086cbf35e61e1b69 (patch)
treec6b504c7d67c41e003719bdffbf04bfbbd7be765 /src
parentf33b05d75b83798b0a5e301876666d9b75e27633 (diff)
downloadmongo-f3dbbebb303be094a563989f086cbf35e61e1b69.tar.gz
SERVER-55677 Remove resharding's DonorStateEnum::kPreparingToBlockWrites state
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/s/resharding/resharding_donor_service.cpp24
-rw-r--r--src/mongo/db/s/resharding/resharding_donor_service.h2
-rw-r--r--src/mongo/db/s/resharding/resharding_donor_service_test.cpp2
-rw-r--r--src/mongo/db/s/resharding/resharding_metrics.cpp19
-rw-r--r--src/mongo/db/s/resharding/resharding_metrics.h6
-rw-r--r--src/mongo/db/s/resharding/resharding_metrics_test.cpp6
-rw-r--r--src/mongo/db/s/resharding/resharding_util_test.cpp2
-rw-r--r--src/mongo/s/resharding/common_types.idl1
8 files changed, 32 insertions, 30 deletions
diff --git a/src/mongo/db/s/resharding/resharding_donor_service.cpp b/src/mongo/db/s/resharding/resharding_donor_service.cpp
index e88e38c88c1..5b27a1132b4 100644
--- a/src/mongo/db/s/resharding/resharding_donor_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_donor_service.cpp
@@ -59,7 +59,7 @@
namespace mongo {
-MONGO_FAIL_POINT_DEFINE(reshardingDonorFailsBeforePreparingToMirror);
+MONGO_FAIL_POINT_DEFINE(reshardingDonorFailsAfterTransitionToDonatingOplogEntries);
MONGO_FAIL_POINT_DEFINE(removeDonorDocFailpoint);
using namespace fmt::literals;
@@ -247,8 +247,7 @@ ExecutorFuture<void> ReshardingDonorService::DonorStateMachine::_runUntilBlockin
executor, abortToken);
})
.then([this, executor, abortToken] {
- return _awaitAllRecipientsDoneApplyingThenTransitionToPreparingToBlockWrites(
- executor, abortToken);
+ return _awaitAllRecipientsDoneApplying(executor, abortToken);
})
.then(
[this] { _writeTransactionOplogEntryThenTransitionToBlockingWrites(); });
@@ -265,8 +264,8 @@ ExecutorFuture<void> ReshardingDonorService::DonorStateMachine::_runUntilBlockin
"error"_attr = status);
return withAutomaticRetry(**executor, abortToken, [this, status] {
- // It is illegal to transition into kError if state has already surpassed
- // kPreparingToBlockWrites.
+ // It is illegal to transition into kError if the state is in or has already
+ // surpassed kBlockingWrites.
invariant(_donorCtx.getState() < DonorStateEnum::kBlockingWrites);
_transitionToError(status);
@@ -528,28 +527,27 @@ ExecutorFuture<void> ReshardingDonorService::DonorStateMachine::
.thenRunOn(**executor)
.then([this]() { _transitionState(DonorStateEnum::kDonatingOplogEntries); })
.onCompletion([=](Status s) {
- if (MONGO_unlikely(reshardingDonorFailsBeforePreparingToMirror.shouldFail())) {
+ if (MONGO_unlikely(
+ reshardingDonorFailsAfterTransitionToDonatingOplogEntries.shouldFail())) {
uasserted(ErrorCodes::InternalError, "Failing for test");
}
});
}
-ExecutorFuture<void> ReshardingDonorService::DonorStateMachine::
- _awaitAllRecipientsDoneApplyingThenTransitionToPreparingToBlockWrites(
- const std::shared_ptr<executor::ScopedTaskExecutor>& executor,
- const CancellationToken& abortToken) {
+ExecutorFuture<void> ReshardingDonorService::DonorStateMachine::_awaitAllRecipientsDoneApplying(
+ const std::shared_ptr<executor::ScopedTaskExecutor>& executor,
+ const CancellationToken& abortToken) {
if (_donorCtx.getState() > DonorStateEnum::kDonatingOplogEntries) {
return ExecutorFuture<void>(**executor, Status::OK());
}
return future_util::withCancellation(_allRecipientsDoneApplying.getFuture(), abortToken)
- .thenRunOn(**executor)
- .then([this]() { _transitionState(DonorStateEnum::kPreparingToBlockWrites); });
+ .thenRunOn(**executor);
}
void ReshardingDonorService::DonorStateMachine::
_writeTransactionOplogEntryThenTransitionToBlockingWrites() {
- if (_donorCtx.getState() > DonorStateEnum::kPreparingToBlockWrites) {
+ if (_donorCtx.getState() > DonorStateEnum::kDonatingOplogEntries) {
return;
}
diff --git a/src/mongo/db/s/resharding/resharding_donor_service.h b/src/mongo/db/s/resharding/resharding_donor_service.h
index 1c855160881..782b9ac287f 100644
--- a/src/mongo/db/s/resharding/resharding_donor_service.h
+++ b/src/mongo/db/s/resharding/resharding_donor_service.h
@@ -141,7 +141,7 @@ private:
const std::shared_ptr<executor::ScopedTaskExecutor>& executor,
const CancellationToken& abortToken);
- ExecutorFuture<void> _awaitAllRecipientsDoneApplyingThenTransitionToPreparingToBlockWrites(
+ ExecutorFuture<void> _awaitAllRecipientsDoneApplying(
const std::shared_ptr<executor::ScopedTaskExecutor>& executor,
const CancellationToken& abortToken);
diff --git a/src/mongo/db/s/resharding/resharding_donor_service_test.cpp b/src/mongo/db/s/resharding/resharding_donor_service_test.cpp
index 79de3f0fecb..312024e0223 100644
--- a/src/mongo/db/s/resharding/resharding_donor_service_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_donor_service_test.cpp
@@ -298,7 +298,6 @@ TEST_F(ReshardingDonorServiceTest, WritesFinalReshardOpOplogEntriesWhileWritesBl
TEST_F(ReshardingDonorServiceTest, StepDownStepUpEachTransition) {
const std::vector<DonorStateEnum> donorStates{DonorStateEnum::kDonatingInitialData,
DonorStateEnum::kDonatingOplogEntries,
- DonorStateEnum::kPreparingToBlockWrites,
DonorStateEnum::kBlockingWrites,
DonorStateEnum::kDone};
PauseDuringStateTransitions stateTransitionsGuard{controller(), donorStates};
@@ -327,7 +326,6 @@ TEST_F(ReshardingDonorServiceTest, StepDownStepUpEachTransition) {
notifyRecipientsDoneCloning(opCtx.get(), *donor, doc);
break;
}
- case DonorStateEnum::kPreparingToBlockWrites:
case DonorStateEnum::kBlockingWrites: {
notifyToStartBlockingWrites(opCtx.get(), *donor, doc);
break;
diff --git a/src/mongo/db/s/resharding/resharding_metrics.cpp b/src/mongo/db/s/resharding/resharding_metrics.cpp
index cdfbeb8b6a9..92b33687e9c 100644
--- a/src/mongo/db/s/resharding/resharding_metrics.cpp
+++ b/src/mongo/db/s/resharding/resharding_metrics.cpp
@@ -126,14 +126,6 @@ void ReshardingMetrics::setDonorState(DonorStateEnum state) noexcept {
const auto oldState = std::exchange(_currentOp->donorState, state);
invariant(oldState != state);
-
- if (state == DonorStateEnum::kPreparingToBlockWrites) {
- _currentOp->inCriticalSection.start();
- }
-
- if (oldState == DonorStateEnum::kBlockingWrites) {
- _currentOp->inCriticalSection.end();
- }
}
void ReshardingMetrics::setRecipientState(RecipientStateEnum state) noexcept {
@@ -213,6 +205,16 @@ void ReshardingMetrics::onDocumentsCopied(int64_t documents, int64_t bytes) noex
_cumulativeOp.bytesCopied += bytes;
}
+void ReshardingMetrics::startInCriticalSection() {
+ stdx::lock_guard<Latch> lk(_mutex);
+ _currentOp->inCriticalSection.start();
+}
+
+void ReshardingMetrics::endInCritcialSection() {
+ stdx::lock_guard<Latch> lk(_mutex);
+ _currentOp->inCriticalSection.end();
+}
+
void ReshardingMetrics::onOplogEntriesFetched(int64_t entries) noexcept {
stdx::lock_guard<Latch> lk(_mutex);
if (!_currentOp)
@@ -249,7 +251,6 @@ void ReshardingMetrics::onWriteDuringCriticalSection(int64_t writes) noexcept {
invariant(checkState(_currentOp->donorState,
{DonorStateEnum::kDonatingOplogEntries,
- DonorStateEnum::kPreparingToBlockWrites,
DonorStateEnum::kBlockingWrites,
DonorStateEnum::kError}));
diff --git a/src/mongo/db/s/resharding/resharding_metrics.h b/src/mongo/db/s/resharding/resharding_metrics.h
index eed36a39786..81a7a7af8fd 100644
--- a/src/mongo/db/s/resharding/resharding_metrics.h
+++ b/src/mongo/db/s/resharding/resharding_metrics.h
@@ -72,12 +72,16 @@ public:
// Allows updating metrics on "documents to copy" so long as the recipient is in cloning state.
void onDocumentsCopied(int64_t documents, int64_t bytes) noexcept;
+ // Starts/ends the timer recording the time spent in the critical section.
+ void startInCriticalSection();
+ void endInCritcialSection();
+
// Allows updating "oplog entries to apply" metrics when the recipient is in applying state.
void onOplogEntriesFetched(int64_t entries) noexcept;
void onOplogEntriesApplied(int64_t entries) noexcept;
// Allows tracking writes during a critical section when the donor's state is either of
- // "preparing-to-block-writes" or "blocking-writes".
+ // "donating-oplog-entries" or "blocking-writes".
void onWriteDuringCriticalSection(int64_t writes) noexcept;
// Marks the completion of the current (active) resharding operation. Aborts the process if no
diff --git a/src/mongo/db/s/resharding/resharding_metrics_test.cpp b/src/mongo/db/s/resharding/resharding_metrics_test.cpp
index 1e7322aef1b..1e2177ec201 100644
--- a/src/mongo/db/s/resharding/resharding_metrics_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_metrics_test.cpp
@@ -173,7 +173,8 @@ TEST_F(ReshardingMetricsTest, TestDonorAndRecipientMetrics) {
// Update metrics for donor
const auto kWritesDuringCriticalSection = 7;
- getMetrics()->setDonorState(DonorStateEnum::kPreparingToBlockWrites);
+ getMetrics()->setDonorState(DonorStateEnum::kDonatingOplogEntries);
+ getMetrics()->startInCriticalSection();
getMetrics()->onWriteDuringCriticalSection(kWritesDuringCriticalSection);
advanceTime(Seconds(elapsedTime));
@@ -326,10 +327,11 @@ TEST_F(ReshardingMetricsTest, EstimatedRemainingOperationTime) {
}
TEST_F(ReshardingMetricsTest, CurrentOpReportForDonor) {
- const auto kDonorState = DonorStateEnum::kPreparingToBlockWrites;
+ const auto kDonorState = DonorStateEnum::kDonatingOplogEntries;
getMetrics()->onStart();
advanceTime(Seconds(2));
getMetrics()->setDonorState(kDonorState);
+ getMetrics()->startInCriticalSection();
advanceTime(Seconds(3));
const ReshardingMetrics::ReporterOptions options(
diff --git a/src/mongo/db/s/resharding/resharding_util_test.cpp b/src/mongo/db/s/resharding/resharding_util_test.cpp
index 70e24932c2b..1fc70d03434 100644
--- a/src/mongo/db/s/resharding/resharding_util_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_util_test.cpp
@@ -134,7 +134,7 @@ TEST(ReshardingUtilTest, HighestMinFetchTimestampThrowsWhenDonorMissingTimestamp
TEST(ReshardingUtilTest, HighestMinFetchTimestampSucceedsWithDonorStateGTkDonatingOplogEntries) {
std::vector<DonorShardEntry> donorShards{
- makeDonorShard(ShardId("s0"), DonorStateEnum::kPreparingToBlockWrites, Timestamp(10, 2)),
+ makeDonorShard(ShardId("s0"), DonorStateEnum::kBlockingWrites, Timestamp(10, 2)),
makeDonorShard(ShardId("s1"), DonorStateEnum::kDonatingOplogEntries, Timestamp(10, 3)),
makeDonorShard(ShardId("s2"), DonorStateEnum::kDonatingOplogEntries, Timestamp(10, 1))};
auto highestMinFetchTimestamp = getHighestMinFetchTimestamp(donorShards);
diff --git a/src/mongo/s/resharding/common_types.idl b/src/mongo/s/resharding/common_types.idl
index cc34746dd93..e868c2f8d44 100644
--- a/src/mongo/s/resharding/common_types.idl
+++ b/src/mongo/s/resharding/common_types.idl
@@ -59,7 +59,6 @@ enums:
kPreparingToDonate: "preparing-to-donate"
kDonatingInitialData: "donating-initial-data"
kDonatingOplogEntries: "donating-oplog-entries"
- kPreparingToBlockWrites: "preparing-to-block-writes"
kError: "error"
kBlockingWrites: "blocking-writes"
kDone: "done"