diff --git a/src/mongo/s/write_ops/bulk_write_exec.cpp b/src/mongo/s/write_ops/bulk_write_exec.cpp index 947956cf5d6..1a62f8a2403 100644 --- a/src/mongo/s/write_ops/bulk_write_exec.cpp +++ b/src/mongo/s/write_ops/bulk_write_exec.cpp @@ -1423,7 +1423,7 @@ void BulkWriteOp::noteChildBatchResponse( int firstTargetedWriteOpIdx = targetedBatch.getWrites().front()->writeOpRef.first; bool isWithoutShardKeyWithIdWrite = (_writeOps[firstTargetedWriteOpIdx].getWriteType() == WriteType::WithoutShardKeyWithId); - bool shouldDeferWriteWithoutShardKeyReponse = + bool shouldDeferWriteWithoutShardKeyResponse = isWithoutShardKeyWithIdWrite && targetedBatch.getNumOps() > 1; const auto& replyItems = exhaustCursorForReplyItems(_opCtx, targetedBatch, commandReply); @@ -1445,12 +1445,12 @@ void BulkWriteOp::noteChildBatchResponse( // replies: [1, 3] -> [1, 3] -> [1, 3] -> [1, 3] // ^ ^ ^ ^ // Only moving forward in replies when we see a matching write op. - int replyIndex = -1; + size_t replyIndex = static_cast(-1); // A batch will fail on an error if the request was sent with ordered:true or we are executing // the request within a transaction. bool batchWillContinue = !_clientRequest.getOrdered() && !_inTransaction; boost::optional lastError; - for (int writeOpIdx = 0; writeOpIdx < (int)targetedBatch.getWrites().size(); ++writeOpIdx) { + for (size_t writeOpIdx = 0; writeOpIdx < targetedBatch.getWrites().size(); ++writeOpIdx) { const auto& write = targetedBatch.getWrites()[writeOpIdx]; WriteOp& writeOp = _writeOps[write->writeOpRef.first]; @@ -1459,7 +1459,7 @@ void BulkWriteOp::noteChildBatchResponse( tassert(8266001, "bulkWrite should always get replies when not in errorsOnly", _clientRequest.getErrorsOnly()); - if (shouldDeferWriteWithoutShardKeyReponse) { + if (shouldDeferWriteWithoutShardKeyResponse) { if (!_deferredResponses) { _deferredResponses.emplace(); } @@ -1480,7 +1480,7 @@ void BulkWriteOp::noteChildBatchResponse( if (!batchWillContinue && lastError) { tassert(8266002, "bulkWrite should not see replies after an error when ordered:true", - replyIndex >= (int)replyItems.size()); + replyIndex >= replyItems.size()); writeOp.resetWriteToReady(_opCtx); continue; } @@ -1501,7 +1501,7 @@ void BulkWriteOp::noteChildBatchResponse( lastError->getStatus().code() == ErrorCodes::ShardCannotRefreshDueToLocksHeld || lastError->getStatus() == ErrorCodes::CannotImplicitlyCreateCollection); - if (batchWillContinue && isStaleError && (replyIndex == (int)replyItems.size())) { + if (batchWillContinue && isStaleError && (replyIndex == replyItems.size())) { // Decrement the replyIndex so it keeps pointing to the same error (i.e. the // last error, which is a staleness error). LOGV2_DEBUG(7695304, @@ -1514,7 +1514,7 @@ void BulkWriteOp::noteChildBatchResponse( // If we are out of replyItems but have more write ops then we must be in an ordered:false // errorsOnly:true bulkWrite where we have successful results after the last error. - if (replyIndex >= (int)replyItems.size()) { + if (replyIndex >= replyItems.size()) { tassert(8516601, "bulkWrite received more replies than writes", _clientRequest.getErrorsOnly()); @@ -1523,6 +1523,7 @@ void BulkWriteOp::noteChildBatchResponse( continue; } + tassert(11491901, "replyIndex out of range of replyItems", replyIndex < replyItems.size()); auto& reply = replyItems[replyIndex]; // This can only happen when running an errorsOnly:true bulkWrite. We will only receive a @@ -1532,7 +1533,8 @@ void BulkWriteOp::noteChildBatchResponse( // a safe assumption. // writeOpIdx can be > than reply.getIdx when we are duplicating the last error // as described in the block above. - if (writeOpIdx < reply.getIdx()) { + tassert(11491902, "reply.getIdx() must not be negative", reply.getIdx() >= 0); + if (writeOpIdx < static_cast(reply.getIdx())) { tassert(8266003, "bulkWrite should get a reply for every write op when not in errorsOnly mode", _clientRequest.getErrorsOnly()); @@ -1550,7 +1552,7 @@ void BulkWriteOp::noteChildBatchResponse( _approximateSize += reply.getApproximateSize(); } - if (shouldDeferWriteWithoutShardKeyReponse) { + if (shouldDeferWriteWithoutShardKeyResponse) { if (!_deferredResponses) { _deferredResponses.emplace(); }