SERVER-94743 Get replication coordinator out of WT KV engine (#27016)

GitOrigin-RevId: c3784e32978a0436b815ddbb5fd5db448b60bc84
This commit is contained in:
Gregory Noma 2024-09-17 16:24:10 -04:00 committed by MongoDB Bot
parent 5c02ebfa2b
commit 52ace13e97
4 changed files with 40 additions and 17 deletions

View File

@ -267,10 +267,20 @@ Status RollbackImpl::runRollback(OperationContext* opCtx) {
rollbackHangAfterTransitionToRollback.pauseWhileSet(opCtx);
}
auto& sizeRecovery = sizeRecoveryState(opCtx->getServiceContext());
// We clear the SizeRecoveryState before we recover to a stable timestamp. This ensures that we
// only use size adjustment markings from the storage and replication recovery processes in this
// rollback.
sizeRecoveryState(opCtx->getServiceContext()).clearStateBeforeRecovery();
sizeRecovery.clearStateBeforeRecovery();
// Sizes should always be checked when creating a collection during rollback. This is in case
// the size storer information is no longer accurate. This may be necessary if capped deletes
// are rolled-back or if rollback occurs across a collection rename.
sizeRecovery.setRecordStoresShouldAlwaysCheckSize(true);
ScopeGuard sizeRecoveryStateGuard{[&sizeRecovery] {
sizeRecovery.setRecordStoresShouldAlwaysCheckSize(false);
}};
// After successfully transitioning to the ROLLBACK state, we must always transition back to
// SECONDARY, even if we fail at any point during the rollback process.

View File

@ -63,6 +63,21 @@ void SizeRecoveryState::clearStateBeforeRecovery() {
stdx::lock_guard<Latch> lock(_mutex);
_collectionsAlwaysNeedingSizeAdjustment.clear();
}
void SizeRecoveryState::setRecordStoresShouldAlwaysCheckSize(bool shouldAlwayCheckSize) {
stdx::lock_guard<Latch> lock(_mutex);
_recordStoresShouldAlwayCheckSize = shouldAlwayCheckSize;
}
bool SizeRecoveryState::shouldRecordStoresAlwaysCheckSize() const {
stdx::lock_guard<Latch> lock(_mutex);
// Regardless of whether the _recordStoresShouldAlwayCheckSize flag is set, if we are in
// replication recovery then sizes should always be checked. This is in case the size storer
// information is no longer accurate. This may be necessary if a collection creation was not
// part of a stable checkpoint.
return _recordStoresShouldAlwayCheckSize ||
inReplicationRecovery(getGlobalServiceContext()).load();
}
} // namespace mongo
mongo::AtomicWord<bool>& mongo::inReplicationRecovery(ServiceContext* serviceCtx) {

View File

@ -80,9 +80,22 @@ public:
*/
void clearStateBeforeRecovery();
/**
* Informs the SizeRecoveryState that record stores should always check their size information.
*/
void setRecordStoresShouldAlwaysCheckSize(bool);
/**
* Returns whether record stores should always check their size information. This can either be
* due to setRecordStoresShouldAlwaysCheckSize being called or due to being in replication
* recovery.
*/
bool shouldRecordStoresAlwaysCheckSize() const;
private:
mutable Mutex _mutex = MONGO_MAKE_LATCH("SizeRecoveryState::_mutex");
StringSet _collectionsAlwaysNeedingSizeAdjustment;
bool _recordStoresShouldAlwayCheckSize = false;
};
/**

View File

@ -79,7 +79,6 @@
#include "mongo/db/query/bson/dotted_path_support.h"
#include "mongo/db/repl/member_state.h"
#include "mongo/db/repl/repl_settings.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/server_feature_flags_gen.h"
#include "mongo/db/server_options.h"
#include "mongo/db/server_parameter.h"
@ -182,14 +181,6 @@ std::string extractIdentFromPath(const boost::filesystem::path& dbpath,
}
bool WiredTigerFileVersion::shouldDowngrade(bool hasRecoveryTimestamp) {
const auto replCoord = repl::ReplicationCoordinator::get(getGlobalServiceContext());
if (replCoord && replCoord->getMemberState().arbiter()) {
// SERVER-35361: Arbiters will no longer downgrade their data files. To downgrade
// binaries, the user must delete the dbpath. It's not particularly expensive for a
// replica set to re-initialize an arbiter that comes online.
return false;
}
const auto fcvSnapshot = serverGlobalParams.featureCompatibility.acquireFCVSnapshot();
if (!fcvSnapshot.isVersionInitialized()) {
// If the FCV document hasn't been read, trust the WT compatibility. MongoD will
@ -1620,13 +1611,7 @@ std::unique_ptr<RecordStore> WiredTigerKVEngine::getRecordStore(OperationContext
ret = std::make_unique<WiredTigerRecordStore>(this, opCtx, params);
ret->postConstructorInit(opCtx, nss);
// Sizes should always be checked when creating a collection during rollback or replication
// recovery. This is in case the size storer information is no longer accurate. This may be
// necessary if capped deletes are rolled-back, if rollback occurs across a collection rename,
// or when collection creation is not part of a stable checkpoint.
const auto replCoord = repl::ReplicationCoordinator::get(getGlobalServiceContext());
const bool inRollback = replCoord && replCoord->getMemberState().rollback();
if (inRollback || inReplicationRecovery(getGlobalServiceContext()).load()) {
if (sizeRecoveryState(opCtx->getServiceContext()).shouldRecordStoresAlwaysCheckSize()) {
ret->checkSize(opCtx);
}