summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp')
-rw-r--r--src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp103
1 files changed, 77 insertions, 26 deletions
diff --git a/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp b/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp
index 3dfb002c54d..469ce5821aa 100644
--- a/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp
+++ b/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp
@@ -37,7 +37,6 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/collection_catalog.h"
-#include "mongo/db/catalog/collection_uuid_mismatch.h"
#include "mongo/db/catalog/create_collection.h"
#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/catalog/document_validation.h"
@@ -46,7 +45,7 @@
#include "mongo/db/catalog/list_indexes.h"
#include "mongo/db/catalog/rename_collection.h"
#include "mongo/db/concurrency/d_concurrency.h"
-#include "mongo/db/concurrency/exception_util.h"
+#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/curop.h"
#include "mongo/db/cursor_manager.h"
#include "mongo/db/db_raii.h"
@@ -201,8 +200,7 @@ std::vector<Document> CommonMongodProcessInterface::getIndexStats(OperationConte
auto idxCatalog = collection->getIndexCatalog();
auto idx = idxCatalog->findIndexByName(opCtx,
indexName,
- IndexCatalog::InclusionPolicy::kReady |
- IndexCatalog::InclusionPolicy::kUnfinished);
+ /* includeUnfinishedIndexes */ true);
uassert(ErrorCodes::IndexNotFound,
"Could not find entry in IndexCatalog for index " + indexName,
idx);
@@ -310,33 +308,34 @@ std::deque<BSONObj> CommonMongodProcessInterface::listCatalog(OperationContext*
}
boost::optional<BSONObj> CommonMongodProcessInterface::getCatalogEntry(
- OperationContext* opCtx,
- const NamespaceString& ns,
- const boost::optional<UUID>& collUUID) const {
-
- // Perform an AutoGetCollection. This will verify that the collection still exists at the given
- // read concern. If it doesn't and the aggregation has specified a UUID then this acquisition
- // will fail.
- AutoGetCollectionForRead coll{opCtx, ns};
- const auto& collPtr = coll.getCollection();
- checkCollectionUUIDMismatch(opCtx, ns, collPtr, collUUID);
+ OperationContext* opCtx, const NamespaceString& ns) const {
+ Lock::GlobalLock globalLock{opCtx, MODE_IS};
- if (!collPtr) {
+ auto rs = DurableCatalog::get(opCtx)->getRecordStore();
+ if (!rs) {
return boost::none;
}
- auto obj = DurableCatalog::get(opCtx)->getCatalogEntry(opCtx, collPtr->getCatalogId());
+ auto cursor = rs->getCursor(opCtx);
+ while (auto record = cursor->next()) {
+ auto obj = record->data.toBson();
+ if (NamespaceString{obj.getStringField("ns")} != ns) {
+ continue;
+ }
- BSONObjBuilder builder;
- builder.append("db", ns.db());
- builder.append("name", ns.coll());
- builder.append("type", "collection");
- if (auto shardName = getShardName(opCtx); !shardName.empty()) {
- builder.append("shard", shardName);
+ BSONObjBuilder builder;
+ builder.append("db", ns.db());
+ builder.append("name", ns.coll());
+ builder.append("type", "collection");
+ if (auto shardName = getShardName(opCtx); !shardName.empty()) {
+ builder.append("shard", shardName);
+ }
+ builder.appendElements(obj);
+
+ return builder.obj();
}
- builder.appendElements(obj);
- return builder.obj();
+ return boost::none;
}
void CommonMongodProcessInterface::appendLatencyStats(OperationContext* opCtx,
@@ -605,8 +604,7 @@ bool CommonMongodProcessInterface::fieldsHaveSupportingUniqueIndex(
return fieldPaths == std::set<FieldPath>{"_id"};
}
- auto indexIterator = collection->getIndexCatalog()->getIndexIterator(
- opCtx, IndexCatalog::InclusionPolicy::kReady);
+ auto indexIterator = collection->getIndexCatalog()->getIndexIterator(opCtx, false);
while (indexIterator->more()) {
const IndexCatalogEntry* entry = indexIterator->next();
if (supportsUniqueKey(expCtx, entry, fieldPaths)) {
@@ -747,6 +745,59 @@ CommonMongodProcessInterface::ensureFieldsUniqueOrResolveDocumentKey(
return {*fieldPaths, targetCollectionVersion};
}
+write_ops::InsertCommandRequest CommonMongodProcessInterface::buildInsertOp(
+ const NamespaceString& nss, std::vector<BSONObj>&& objs, bool bypassDocValidation) {
+ write_ops::InsertCommandRequest insertOp(nss);
+ insertOp.setDocuments(std::move(objs));
+ insertOp.setWriteCommandRequestBase([&] {
+ write_ops::WriteCommandRequestBase wcb;
+ wcb.setOrdered(false);
+ wcb.setBypassDocumentValidation(bypassDocValidation);
+ return wcb;
+ }());
+ return insertOp;
+}
+
+write_ops::UpdateCommandRequest CommonMongodProcessInterface::buildUpdateOp(
+ const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ const NamespaceString& nss,
+ BatchedObjects&& batch,
+ UpsertType upsert,
+ bool multi) {
+ write_ops::UpdateCommandRequest updateOp(nss);
+ updateOp.setUpdates([&] {
+ std::vector<write_ops::UpdateOpEntry> updateEntries;
+ for (auto&& obj : batch) {
+ updateEntries.push_back([&] {
+ write_ops::UpdateOpEntry entry;
+ auto&& [q, u, c] = obj;
+ entry.setQ(std::move(q));
+ entry.setU(std::move(u));
+ entry.setC(std::move(c));
+ entry.setUpsert(upsert != UpsertType::kNone);
+ entry.setUpsertSupplied(
+ {{entry.getUpsert(), upsert == UpsertType::kInsertSuppliedDoc}});
+ entry.setMulti(multi);
+ return entry;
+ }());
+ }
+ return updateEntries;
+ }());
+ updateOp.setWriteCommandRequestBase([&] {
+ write_ops::WriteCommandRequestBase wcb;
+ wcb.setOrdered(false);
+ wcb.setBypassDocumentValidation(expCtx->bypassDocumentValidation);
+ return wcb;
+ }());
+ auto [constants, letParams] =
+ expCtx->variablesParseState.transitionalCompatibilitySerialize(expCtx->variables);
+ updateOp.setLegacyRuntimeConstants(std::move(constants));
+ if (!letParams.isEmpty()) {
+ updateOp.setLet(std::move(letParams));
+ }
+ return updateOp;
+}
+
BSONObj CommonMongodProcessInterface::_convertRenameToInternalRename(
OperationContext* opCtx,
const BSONObj& renameCommandObj,