Skip to content

Commit 1b6505d

Browse files
silviasuhuEvergreen Agent
authored andcommitted
SERVER-81534 DDL locks musn't be acquired during step down or shutdown
1 parent 96841a6 commit 1b6505d

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

src/mongo/db/repl/primary_only_service.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,14 +514,13 @@ void PrimaryOnlyService::onStepDown() {
514514
"numInstances"_attr = _activeInstances.size(),
515515
"numOperationContexts"_attr = _opCtxs.size());
516516

517+
_onServiceTermination();
517518
_interruptInstances(lk,
518519
{ErrorCodes::InterruptedDueToReplStateChange,
519520
"PrimaryOnlyService interrupted due to stepdown"});
520521

521522
_setState(State::kPaused, lk);
522523
_rebuildStatus = Status::OK();
523-
524-
_afterStepDown();
525524
}
526525

527526
void PrimaryOnlyService::shutdown() {
@@ -540,6 +539,7 @@ void PrimaryOnlyService::shutdown() {
540539

541540
// If the _state is already kPaused, the instances have already been interrupted.
542541
if (_state != State::kPaused) {
542+
_onServiceTermination();
543543
_interruptInstances(lk,
544544
{ErrorCodes::InterruptedAtShutdown,
545545
"PrimaryOnlyService interrupted due to shutdown"});

src/mongo/db/repl/primary_only_service.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,9 @@ class PrimaryOnlyService {
459459
};
460460

461461
/**
462-
* Called at the end of the service stepdown procedure.
463-
* In order to not block the stepdown procedure, no blocking work must be done in this
464-
* function.
462+
* Called as part of the POS onStepDown/onShutdown hooks before interrupting instances.
465463
*/
466-
virtual void _afterStepDown() {}
464+
virtual void _onServiceTermination() {}
467465

468466
/**
469467
* Called as part of onStepUp. Queries the state document collection for this

src/mongo/db/s/sharding_ddl_coordinator_service.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void ShardingDDLCoordinatorService::waitForOngoingCoordinatorsToFinish(
234234
}
235235
}
236236

237-
void ShardingDDLCoordinatorService::_afterStepDown() {
237+
void ShardingDDLCoordinatorService::_onServiceTermination() {
238238
stdx::lock_guard lg(_mutex);
239239
_state = State::kPaused;
240240
_numCoordinatorsToWait = 0;

src/mongo/db/s/sharding_ddl_coordinator_service.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class ShardingDDLCoordinatorService final : public repl::PrimaryOnlyService {
121121
ExecutorFuture<void> _rebuildService(std::shared_ptr<executor::ScopedTaskExecutor> executor,
122122
const CancellationToken& token) override;
123123

124-
void _afterStepDown() override;
124+
void _onServiceTermination() override;
125125
size_t _countCoordinatorDocs(OperationContext* opCtx);
126126

127127
void _transitionToRecovered(WithLock lk, OperationContext* opCtx);

0 commit comments

Comments
 (0)