diff options
author | Benety Goh <benety@mongodb.com> | 2021-10-07 18:23:21 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-11 12:55:37 +0000 |
commit | 3ac74aad2a2b70ad5b1ccb97b07a92c52a51f2f3 (patch) | |
tree | 110217cc97e1de0b5f4562065ab39b4bbfe9183e /src/mongo/db | |
parent | 1fd7913b67d45874f1fde8f6297f4adf618e3d34 (diff) | |
download | mongo-3ac74aad2a2b70ad5b1ccb97b07a92c52a51f2f3.tar.gz |
SERVER-52976 SERVER-42312 disallow validate cmd during rollback and recovering states
(cherry picked from commit 1a3936b3ee365de5dde80e440c01fa6e868a1a54)
(cherry picked from commit 82e34b0d86c6625b5a67d1909e1dcc434f78be82)
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/catalog/collection_impl.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp index d8b774ceabd..ef8b40d4467 100644 --- a/src/mongo/db/catalog/collection_impl.cpp +++ b/src/mongo/db/catalog/collection_impl.cpp @@ -1452,6 +1452,13 @@ Status CollectionImpl::validate(OperationContext* opCtx, BSONObjBuilder* output) { dassert(opCtx->lockState()->isCollectionLockedForMode(ns(), MODE_IS)); + const auto nss = NamespaceString(ns()); + const auto replCoord = repl::ReplicationCoordinator::get(opCtx); + // Check whether we are allowed to read from this node after acquiring our locks. If we are + // in a state where we cannot read, we should not run validate. + uassertStatusOK(replCoord->checkCanServeReadsFor( + opCtx, nss, ReadPreferenceSetting::get(opCtx).canRunOnSecondary())); + try { ValidateResultsMap indexNsResultsMap; BSONObjBuilder keysPerIndex; // not using subObjStart to be exception safe |