summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/bulk_write_common.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/commands/bulk_write_common.cpp')
-rw-r--r--src/mongo/db/commands/bulk_write_common.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/mongo/db/commands/bulk_write_common.cpp b/src/mongo/db/commands/bulk_write_common.cpp
index e3d649ea309..691932dfc17 100644
--- a/src/mongo/db/commands/bulk_write_common.cpp
+++ b/src/mongo/db/commands/bulk_write_common.cpp
@@ -34,7 +34,7 @@
namespace mongo {
namespace bulk_write_common {
-void validateRequest(const BulkWriteCommandRequest& req) {
+void validateRequest(const BulkWriteCommandRequest& req, bool isRetryableWrite) {
const auto& ops = req.getOps();
const auto& nsInfo = req.getNsInfo();
@@ -55,6 +55,8 @@ void validateRequest(const BulkWriteCommandRequest& req) {
}
// Validate that every ops entry has a valid nsInfo index.
+ // Also validate that we only have one findAndModify for retryable writes.
+ bool seenFindAndModify = false;
for (const auto& op : ops) {
const auto& bulkWriteOp = BulkWriteCRUDOp(op);
unsigned int nsInfoIdx = bulkWriteOp.getNsInfoIdx();
@@ -62,6 +64,35 @@ void validateRequest(const BulkWriteCommandRequest& req) {
str::stream() << "BulkWrite ops entry " << bulkWriteOp.toBSON()
<< " has an invalid nsInfo index.",
nsInfoIdx < nsInfo.size());
+
+ if (isRetryableWrite) {
+ switch (bulkWriteOp.getType()) {
+ case BulkWriteCRUDOp::kInsert:
+ break;
+ case BulkWriteCRUDOp::kUpdate: {
+ auto update = bulkWriteOp.getUpdate();
+ if (update->getReturn()) {
+ uassert(
+ ErrorCodes::BadValue,
+ "BulkWrite can only support 1 op with a return for a retryable write",
+ !seenFindAndModify);
+ seenFindAndModify = true;
+ }
+ break;
+ }
+ case BulkWriteCRUDOp::kDelete: {
+ auto deleteOp = bulkWriteOp.getDelete();
+ if (deleteOp->getReturn()) {
+ uassert(
+ ErrorCodes::BadValue,
+ "BulkWrite can only support 1 op with a return for a retryable write",
+ !seenFindAndModify);
+ seenFindAndModify = true;
+ }
+ break;
+ }
+ }
+ }
}
}