Revert "SERVER-105921 Replace usage of AutoGetCollectionForRead under the db/commands path (#37170)" (#39649)
GitOrigin-RevId: 2a02e38ade3bdaab26dea534f46e2a2b8cac5afe
This commit is contained in:
parent
b0f36602de
commit
8f2c658842
@ -45,7 +45,6 @@
|
||||
#include "mongo/db/namespace_string.h"
|
||||
#include "mongo/db/operation_context.h"
|
||||
#include "mongo/db/profile_collection.h"
|
||||
#include "mongo/db/profile_settings.h"
|
||||
#include "mongo/db/query/canonical_query.h"
|
||||
#include "mongo/db/query/find_command.h"
|
||||
#include "mongo/db/query/get_executor.h"
|
||||
@ -175,20 +174,12 @@ public:
|
||||
// Check shard version at startup.
|
||||
// This will throw before we've done any work if shard version is outdated
|
||||
// We drop and re-acquire these locks every document because md5'ing is expensive
|
||||
auto ctx = acquireCollection(opCtx,
|
||||
CollectionAcquisitionRequest::fromOpCtx(
|
||||
opCtx, nss, AcquisitionPrerequisites::kRead),
|
||||
MODE_IS);
|
||||
|
||||
AutoStatsTracker statsTracker(opCtx,
|
||||
nss,
|
||||
Top::LockType::ReadLocked,
|
||||
AutoStatsTracker::LogMode::kUpdateTopAndCurOp,
|
||||
DatabaseProfileSettings::get(opCtx->getServiceContext())
|
||||
.getDatabaseProfileLevel(nss.dbName()));
|
||||
std::unique_ptr<AutoGetCollectionForReadCommand> ctx(
|
||||
new AutoGetCollectionForReadCommand(opCtx, nss));
|
||||
const CollectionPtr& coll = ctx->getCollection();
|
||||
|
||||
auto exec = uassertStatusOK(getExecutorFind(opCtx,
|
||||
MultipleCollectionAccessor{ctx},
|
||||
MultipleCollectionAccessor{coll},
|
||||
std::move(cq),
|
||||
PlanYieldPolicy::YieldPolicy::YIELD_MANUAL,
|
||||
QueryPlannerParams::NO_TABLE_SCAN));
|
||||
@ -224,7 +215,7 @@ public:
|
||||
|
||||
exec->saveState();
|
||||
// UNLOCKED
|
||||
auto yieldResources = yieldTransactionResourcesFromOperationContext(opCtx);
|
||||
ctx.reset();
|
||||
|
||||
int len;
|
||||
const char* data = owned["data"].binDataClean(len);
|
||||
@ -237,8 +228,7 @@ public:
|
||||
|
||||
try {
|
||||
// RELOCKED
|
||||
restoreTransactionResourcesToOperationContext(opCtx,
|
||||
std::move(yieldResources));
|
||||
ctx.reset(new AutoGetCollectionForReadCommand(opCtx, nss));
|
||||
} catch (const ExceptionFor<ErrorCodes::StaleConfig>&) {
|
||||
LOGV2_DEBUG(
|
||||
20453,
|
||||
@ -248,7 +238,7 @@ public:
|
||||
}
|
||||
|
||||
// Now that we have the lock again, we can restore the PlanExecutor.
|
||||
exec->restoreState(nullptr);
|
||||
exec->restoreState(&ctx->getCollection());
|
||||
}
|
||||
} catch (DBException& exception) {
|
||||
exception.addContext("Executor error during filemd5 command");
|
||||
|
||||
@ -47,7 +47,6 @@
|
||||
#include "mongo/db/namespace_string.h"
|
||||
#include "mongo/db/operation_context.h"
|
||||
#include "mongo/db/pipeline/field_path.h"
|
||||
#include "mongo/db/profile_settings.h"
|
||||
#include "mongo/db/query/allowed_contexts.h"
|
||||
#include "mongo/db/query/analyze_command_gen.h"
|
||||
#include "mongo/db/query/compiler/stats/scalar_histogram.h"
|
||||
@ -56,7 +55,6 @@
|
||||
#include "mongo/db/query/query_feature_flags_gen.h"
|
||||
#include "mongo/db/server_options.h"
|
||||
#include "mongo/db/service_context.h"
|
||||
#include "mongo/db/shard_role.h"
|
||||
#include "mongo/rpc/get_status_from_command_result.h"
|
||||
#include "mongo/rpc/op_msg.h"
|
||||
#include "mongo/transport/session.h"
|
||||
@ -72,6 +70,7 @@
|
||||
|
||||
#include <boost/move/utility_core.hpp>
|
||||
#include <boost/optional/optional.hpp>
|
||||
|
||||
namespace mongo {
|
||||
namespace {
|
||||
|
||||
@ -176,44 +175,34 @@ public:
|
||||
|
||||
// Validate collection
|
||||
{
|
||||
auto coll = acquireCollectionMaybeLockFree(
|
||||
opCtx,
|
||||
CollectionAcquisitionRequest::fromOpCtx(
|
||||
opCtx, nss, AcquisitionPrerequisites::kRead));
|
||||
AutoStatsTracker statsTracker(
|
||||
opCtx,
|
||||
nss,
|
||||
Top::LockType::ReadLocked,
|
||||
AutoStatsTracker::LogMode::kUpdateTopAndCurOp,
|
||||
DatabaseProfileSettings::get(opCtx->getServiceContext())
|
||||
.getDatabaseProfileLevel(nss.dbName()));
|
||||
const auto& collectionPtr = coll.getCollectionPtr();
|
||||
AutoGetCollectionForReadMaybeLockFree autoColl(opCtx, nss);
|
||||
const auto& collection = autoColl.getCollection();
|
||||
|
||||
// Namespace exists
|
||||
uassert(6799700,
|
||||
str::stream() << "Couldn't find collection " << nss.toStringForErrorMsg(),
|
||||
coll.exists());
|
||||
collection);
|
||||
|
||||
// Namespace cannot be capped collection
|
||||
const bool isCapped = collectionPtr->isCapped();
|
||||
const bool isCapped = collection->isCapped();
|
||||
uassert(6799701,
|
||||
str::stream() << "Analyze command is not supported on capped collections",
|
||||
!isCapped);
|
||||
|
||||
// Namespace is normal or clustered collection
|
||||
const bool isNormalColl = nss.isNormalCollection();
|
||||
const bool isClusteredColl = collectionPtr->isClustered();
|
||||
const bool isClusteredColl = collection->isClustered();
|
||||
uassert(6799702,
|
||||
str::stream() << nss.toStringForErrorMsg()
|
||||
<< " is not a normal or clustered collection",
|
||||
isNormalColl || isClusteredColl);
|
||||
|
||||
if (sampleSize) {
|
||||
auto numRecords = collectionPtr->numRecords(opCtx);
|
||||
auto numRecords = collection->numRecords(opCtx);
|
||||
if (numRecords == 0 || *sampleSize > numRecords) {
|
||||
sampleRate = 1.0;
|
||||
} else {
|
||||
sampleRate = double(*sampleSize) / collectionPtr->numRecords(opCtx);
|
||||
sampleRate = double(*sampleSize) / collection->numRecords(opCtx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,7 +50,6 @@
|
||||
#include "mongo/db/matcher/extensions_callback_real.h"
|
||||
#include "mongo/db/namespace_string.h"
|
||||
#include "mongo/db/pipeline/expression_context.h"
|
||||
#include "mongo/db/profile_settings.h"
|
||||
#include "mongo/db/query/canonical_query.h"
|
||||
#include "mongo/db/query/canonical_query_encoder.h"
|
||||
#include "mongo/db/query/collection_query_info.h"
|
||||
@ -98,19 +97,8 @@ bool IndexFilterCommand::run(OperationContext* opCtx,
|
||||
"https://www.mongodb.com/docs/manual/reference/command/setQuerySettings");
|
||||
}
|
||||
const NamespaceString nss(CommandHelpers::parseNsCollectionRequired(dbName, cmdObj));
|
||||
|
||||
auto ctx = acquireCollection(
|
||||
opCtx,
|
||||
CollectionAcquisitionRequest::fromOpCtx(opCtx, nss, AcquisitionPrerequisites::kRead),
|
||||
MODE_IS);
|
||||
|
||||
AutoStatsTracker statsTracker(opCtx,
|
||||
nss,
|
||||
Top::LockType::ReadLocked,
|
||||
AutoStatsTracker::LogMode::kUpdateTopAndCurOp,
|
||||
DatabaseProfileSettings::get(opCtx->getServiceContext())
|
||||
.getDatabaseProfileLevel(nss.dbName()));
|
||||
uassertStatusOK(runIndexFilterCommand(opCtx, ctx.getCollectionPtr(), cmdObj, &result));
|
||||
AutoGetCollectionForReadCommand ctx(opCtx, nss);
|
||||
uassertStatusOK(runIndexFilterCommand(opCtx, ctx.getCollection(), cmdObj, &result));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -44,7 +44,6 @@
|
||||
#include "mongo/db/db_raii.h"
|
||||
#include "mongo/db/namespace_string.h"
|
||||
#include "mongo/db/operation_context.h"
|
||||
#include "mongo/db/profile_settings.h"
|
||||
#include "mongo/db/query/canonical_query_encoder.h"
|
||||
#include "mongo/db/query/collection_query_info.h"
|
||||
#include "mongo/db/query/plan_cache/classic_plan_cache.h"
|
||||
@ -190,23 +189,14 @@ bool PlanCacheClearCommand::run(OperationContext* opCtx,
|
||||
const NamespaceString nss(CommandHelpers::parseNsCollectionRequired(dbName, cmdObj));
|
||||
|
||||
// This is a read lock. The query cache is owned by the collection.
|
||||
auto ctx = acquireCollection(
|
||||
opCtx,
|
||||
CollectionAcquisitionRequest::fromOpCtx(opCtx, nss, AcquisitionPrerequisites::kRead),
|
||||
MODE_IS);
|
||||
AutoStatsTracker statsTracker(opCtx,
|
||||
nss,
|
||||
Top::LockType::ReadLocked,
|
||||
AutoStatsTracker::LogMode::kUpdateTopAndCurOp,
|
||||
DatabaseProfileSettings::get(opCtx->getServiceContext())
|
||||
.getDatabaseProfileLevel(nss.dbName()));
|
||||
if (!ctx.exists()) {
|
||||
AutoGetCollectionForReadCommand ctx(opCtx, nss);
|
||||
if (!ctx.getCollection()) {
|
||||
// Clearing a non-existent collection always succeeds.
|
||||
return true;
|
||||
}
|
||||
|
||||
auto planCache = getPlanCache(opCtx, ctx.getCollectionPtr());
|
||||
uassertStatusOK(clear(opCtx, ctx.getCollectionPtr(), planCache, nss, cmdObj));
|
||||
auto planCache = getPlanCache(opCtx, ctx.getCollection());
|
||||
uassertStatusOK(clear(opCtx, ctx.getCollection(), planCache, nss, cmdObj));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -1322,25 +1322,15 @@ private:
|
||||
bool hasUserDocs, hasRoleDocs = false;
|
||||
BSONObj userDoc, roleDoc;
|
||||
{
|
||||
auto userColl = acquireCollectionMaybeLockFree(
|
||||
opCtx,
|
||||
CollectionAcquisitionRequest{
|
||||
NamespaceString::kAdminUsersNamespace,
|
||||
PlacementConcern{boost::none, ShardVersion::UNSHARDED()},
|
||||
repl::ReadConcernArgs::get(opCtx),
|
||||
AcquisitionPrerequisites::kRead});
|
||||
hasUserDocs = Helpers::findOne(opCtx, userColl.getCollectionPtr(), BSONObj(), userDoc);
|
||||
AutoGetCollectionForReadCommandMaybeLockFree usersColl(
|
||||
opCtx, NamespaceString::kAdminUsersNamespace);
|
||||
hasUserDocs = Helpers::findOne(opCtx, usersColl.getCollection(), BSONObj(), userDoc);
|
||||
}
|
||||
|
||||
{
|
||||
auto rolesColl = acquireCollectionMaybeLockFree(
|
||||
opCtx,
|
||||
CollectionAcquisitionRequest{
|
||||
NamespaceString::kAdminRolesNamespace,
|
||||
PlacementConcern{boost::none, ShardVersion::UNSHARDED()},
|
||||
repl::ReadConcernArgs::get(opCtx),
|
||||
AcquisitionPrerequisites::kRead});
|
||||
hasRoleDocs = Helpers::findOne(opCtx, rolesColl.getCollectionPtr(), BSONObj(), roleDoc);
|
||||
AutoGetCollectionForReadCommandMaybeLockFree rolesColl(
|
||||
opCtx, NamespaceString::kAdminRolesNamespace);
|
||||
hasRoleDocs = Helpers::findOne(opCtx, rolesColl.getCollection(), BSONObj(), roleDoc);
|
||||
}
|
||||
|
||||
// If they do, write an authorization schema document to disk set to schemaVersionSCRAM28.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user