diff options
author | kauboy26 <vishnu.kaushik@mongodb.com> | 2023-05-17 20:55:33 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-05-17 23:17:02 +0000 |
commit | 7ce60b59b24a893bb6494089ea4db8e19901f48d (patch) | |
tree | a528735ad4207c8f409bb361f4b120492d5732ca /src/mongo/db/commands/bulk_write.cpp | |
parent | de55cd2ac227dcc8cae2fd021abc291e86b2abb2 (diff) | |
download | mongo-7ce60b59b24a893bb6494089ea4db8e19901f48d.tar.gz |
SERVER-72989 Attach stmtIds to bulkWrite request sent by mongos
Diffstat (limited to 'src/mongo/db/commands/bulk_write.cpp')
-rw-r--r-- | src/mongo/db/commands/bulk_write.cpp | 29 |
1 files changed, 8 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 |