summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2024-09-17 16:24:10 -0400
committerMongoDB Bot <mongo-bot@mongodb.com>2024-09-17 21:05:55 +0000
commit52ace13e97475841ce2d2c0f4f4648111b7be1ec (patch)
tree86573cff1f9dc125a4630b19215b905c6a807945
parent5c02ebfa2b250436807794cd21c5cc60d8e1caf6 (diff)
SERVER-94743 Get replication coordinator out of WT KV engine (#27016)
GitOrigin-RevId: c3784e32978a0436b815ddbb5fd5db448b60bc84
-rw-r--r--src/mongo/db/repl/rollback_impl.cpp12
-rw-r--r--src/mongo/db/server_recovery.cpp15
-rw-r--r--src/mongo/db/server_recovery.h13
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp17
4 files changed, 40 insertions, 17 deletions
diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp
index da9dfc7e95a..a32cf18ef20 100644
--- a/src/mongo/db/repl/rollback_impl.cpp
+++ b/src/mongo/db/repl/rollback_impl.cpp
@@ -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.
diff --git a/src/mongo/db/server_recovery.cpp b/src/mongo/db/server_recovery.cpp
index bf41f0e913f..124cd7c5692 100644
--- a/src/mongo/db/server_recovery.cpp
+++ b/src/mongo/db/server_recovery.cpp
@@ -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) {
diff --git a/src/mongo/db/server_recovery.h b/src/mongo/db/server_recovery.h
index 667f5e6c3aa..82790f8e8af 100644
--- a/src/mongo/db/server_recovery.h
+++ b/src/mongo/db/server_recovery.h
@@ -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;
};
/**
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
index f7ac3d645d9..607132efa0f 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
@@ -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);
}