void ReplicationCoordinatorExternalStateImpl::shutdown(OperationContext* txn) {
    UniqueLock lk(_threadMutex);
    if (_startedThreads) {
        _stopDataReplication_inlock(txn, &lk);

        if (_snapshotThread) {
            log() << "Stopping replication snapshot thread";
            _snapshotThread->shutdown();
        }

        if (_storageInterface->getOplogDeleteFromPoint(txn).isNull() &&
            loadLastOpTime(txn) == _storageInterface->getAppliedThrough(txn)) {
            // Clear the appliedThrough marker to indicate we are consistent with the top of the
            // oplog.
            _storageInterface->setAppliedThrough(txn, {});
        }

        if (_noopWriter) {
            LOG(1) << "Stopping noop writer";
            _noopWriter->stopWritingPeriodicNoops();
        }

        log() << "Stopping replication storage threads";
        _taskExecutor->shutdown();
        _taskExecutor->join();
        _storageInterface->shutdown();
    }
}
void ReplicationCoordinatorExternalStateImpl::shutdown(OperationContext* opCtx) {
    UniqueLock lk(_threadMutex);
    if (!_startedThreads) {
        return;
    }

    _inShutdown = true;
    _stopDataReplication_inlock(opCtx, &lk);

    if (_noopWriter) {
        LOG(1) << "Stopping noop writer";
        _noopWriter->stopWritingPeriodicNoops();
    }

    log() << "Stopping replication storage threads";
    _taskExecutor->shutdown();
    _taskExecutor->join();
    lk.unlock();

    // Perform additional shutdown steps below that must be done outside _threadMutex.

    if (_replicationProcess->getConsistencyMarkers()->getOplogTruncateAfterPoint(opCtx).isNull() &&
        loadLastOpTime(opCtx) ==
            _replicationProcess->getConsistencyMarkers()->getAppliedThrough(opCtx)) {
        // Clear the appliedThrough marker to indicate we are consistent with the top of the
        // oplog. We record this update at the 'lastAppliedOpTime'. If there are any outstanding
        // checkpoints being taken, they should only reflect this write if they see all writes up
        // to our 'lastAppliedOpTime'.
        auto lastAppliedOpTime = repl::ReplicationCoordinator::get(opCtx)->getMyLastAppliedOpTime();
        _replicationProcess->getConsistencyMarkers()->clearAppliedThrough(
            opCtx, lastAppliedOpTime.getTimestamp());
    }
}
void ReplicationCoordinatorExternalStateImpl::stopDataReplication(OperationContext* txn) {
    UniqueLock lk(_threadMutex);
    _stopDataReplication_inlock(txn, &lk);
}