diff options
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r-- | src/mongo/db/commands/bulk_write.cpp | 29 | ||||
-rw-r--r-- | src/mongo/db/commands/bulk_write_common.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/commands/bulk_write_common.h | 6 |
3 files changed, 26 insertions, 21 deletions
diff --git a/src/mongo/db/commands/bulk_write.cpp b/src/mongo/db/commands/bulk_write.cpp index c2d989ef9a7..2f283ec5ed0 100644 --- a/src/mongo/db/commands/bulk_write.cpp +++ b/src/mongo/db/commands/bulk_write.cpp @@ -375,24 +375,6 @@ void finishCurOp(OperationContext* opCtx, CurOp* curOp) { } } -int32_t getStatementId(OperationContext* opCtx, - const BulkWriteCommandRequest& req, - const size_t currentOpIdx) { - if (opCtx->isRetryableWrite()) { - auto stmtId = req.getStmtId(); - auto stmtIds = req.getStmtIds(); - - if (stmtIds) { - return stmtIds->at(currentOpIdx); - } - - const int32_t firstStmtId = stmtId ? *stmtId : 0; - return firstStmtId + currentOpIdx; - } - - return kUninitializedStmtId; -} - std::tuple<long long, boost::optional<BSONObj>> getRetryResultForDelete( OperationContext* opCtx, const NamespaceString& nsString, @@ -501,7 +483,8 @@ bool handleInsertOp(OperationContext* opCtx, const auto& nsInfo = req.getNsInfo(); auto idx = op->getInsert(); - auto stmtId = getStatementId(opCtx, req, currentOpIdx); + auto stmtId = opCtx->isRetryableWrite() ? bulk_write_common::getStatementId(req, currentOpIdx) + : kUninitializedStmtId; auto txnParticipant = TransactionParticipant::get(opCtx); @@ -582,7 +565,9 @@ bool handleUpdateOp(OperationContext* opCtx, doTransactionValidationForWrites(opCtx, nsString); - auto stmtId = getStatementId(opCtx, req, currentOpIdx); + auto stmtId = opCtx->isRetryableWrite() + ? bulk_write_common::getStatementId(req, currentOpIdx) + : kUninitializedStmtId; if (opCtx->isRetryableWrite()) { const auto txnParticipant = TransactionParticipant::get(opCtx); if (auto entry = txnParticipant.checkStatementExecuted(opCtx, stmtId)) { @@ -728,7 +713,9 @@ bool handleDeleteOp(OperationContext* opCtx, doTransactionValidationForWrites(opCtx, nsString); - auto stmtId = getStatementId(opCtx, req, currentOpIdx); + auto stmtId = opCtx->isRetryableWrite() + ? bulk_write_common::getStatementId(req, currentOpIdx) + : kUninitializedStmtId; if (opCtx->isRetryableWrite()) { const auto txnParticipant = TransactionParticipant::get(opCtx); // If 'return' is not specified then we do not need to parse the statement. Since diff --git a/src/mongo/db/commands/bulk_write_common.cpp b/src/mongo/db/commands/bulk_write_common.cpp index 691932dfc17..2b39688dc1b 100644 --- a/src/mongo/db/commands/bulk_write_common.cpp +++ b/src/mongo/db/commands/bulk_write_common.cpp @@ -129,5 +129,17 @@ std::vector<Privilege> getPrivileges(const BulkWriteCommandRequest& req) { return privileges; } +int32_t getStatementId(const BulkWriteCommandRequest& req, size_t currentOpIdx) { + auto stmtId = req.getStmtId(); + auto stmtIds = req.getStmtIds(); + + if (stmtIds) { + return stmtIds->at(currentOpIdx); + } + + int32_t firstStmtId = stmtId ? *stmtId : 0; + return firstStmtId + currentOpIdx; +} + } // namespace bulk_write_common } // namespace mongo diff --git a/src/mongo/db/commands/bulk_write_common.h b/src/mongo/db/commands/bulk_write_common.h index 754a644083f..ec79ea13464 100644 --- a/src/mongo/db/commands/bulk_write_common.h +++ b/src/mongo/db/commands/bulk_write_common.h @@ -49,5 +49,11 @@ void validateRequest(const BulkWriteCommandRequest& req, bool isRetryableWrite); */ std::vector<Privilege> getPrivileges(const BulkWriteCommandRequest& req); +/** + * Get the statement ID for an operation within a bulkWrite command, taking into consideration + * whether the stmtId / stmtIds fields are present on the request. + */ +int32_t getStatementId(const BulkWriteCommandRequest& req, size_t currentOpIdx); + } // namespace bulk_write_common } // namespace mongo |