diff options
-rw-r--r-- | src/mongo/s/write_ops/batch_write_op.cpp | 22 | ||||
-rw-r--r-- | src/mongo/s/write_ops/batch_write_op.h | 8 |
2 files changed, 10 insertions, 20 deletions
diff --git a/src/mongo/s/write_ops/batch_write_op.cpp b/src/mongo/s/write_ops/batch_write_op.cpp index 4ac63ff2b1b..85138b92db0 100644 --- a/src/mongo/s/write_ops/batch_write_op.cpp +++ b/src/mongo/s/write_ops/batch_write_op.cpp @@ -392,7 +392,7 @@ Status BatchWriteOp::targetBatch(const NSTargeter& targeter, // StaleShardVersion and has to return number of errors equivalent to the number of writes // in the batch, the response size will not exceed the max BSON size. // - // The constant of 272 is chosen as an approximation of the size of the BSON representataion + // The constant of 272 is chosen as an approximation of the size of the BSON representation // of the StaleConfigInfo (which contains the shard id) and the adjacent error message. const int errorResponsePotentialSizeBytes = ordered ? 0 : write_ops::kWriteCommandBSONArrayPerElementOverheadBytes + 272; @@ -474,7 +474,7 @@ BatchedCommandRequest BatchWriteOp::buildBatchRequest(const TargetedWriteBatch& boost::optional<std::vector<write_ops::UpdateOpEntry>> updates; boost::optional<std::vector<write_ops::DeleteOpEntry>> deletes; - for (const auto& targetedWrite : targetedBatch.getWrites()) { + for (auto&& targetedWrite : targetedBatch.getWrites()) { const WriteOpRef& writeOpRef = targetedWrite->writeOpRef; switch (batchType) { @@ -625,7 +625,7 @@ void BatchWriteOp::noteBatchResponse(const TargetedWriteBatch& targetedBatch, } // - // Go through all pending responses of the op and sorted remote reponses, populate errors + // Go through all pending responses of the op and sorted remote responses, populate errors // This will either set all errors to the batch error or apply per-item errors as-needed // // If the batch is ordered, cancel all writes after the first error for retargeting. @@ -757,7 +757,7 @@ bool BatchWriteOp::isFinished() { } void BatchWriteOp::buildClientResponse(BatchedCommandResponse* batchResp) { - // Note: we aggresively abandon the batch when encountering errors during transactions, so + // Note: we aggressively abandon the batch when encountering errors during transactions, so // it can be in a state that is not "finished" even for unordered batches. dassert(_inTransaction || isFinished()); @@ -892,13 +892,8 @@ void BatchWriteOp::_cancelBatches(const WriteErrorDetail& why, // Collect all the writeOps that are currently targeted for (TargetedBatchMap::iterator it = batchMap.begin(); it != batchMap.end();) { TargetedWriteBatch* batch = it->second; - const std::vector<TargetedWrite*>& writes = batch->getWrites(); - - for (std::vector<TargetedWrite*>::const_iterator writeIt = writes.begin(); - writeIt != writes.end(); - ++writeIt) { - TargetedWrite* write = *writeIt; + for (auto&& write : batch->getWrites()) { // NOTE: We may repeatedly cancel a write op here, but that's fast and we want to cancel // before erasing the TargetedWrite* (which owns the cancelled targeting info) for // reporting reasons. @@ -973,13 +968,6 @@ const std::vector<ShardError>& TrackedErrors::getErrors(int errCode) const { return _errorMap.find(errCode)->second; } -std::vector<TargetedWrite*> TargetedWriteBatch::getWrites() const { - std::vector<TargetedWrite*> rv; - std::transform( - _writes.begin(), _writes.end(), std::back_inserter(rv), [](auto&& w) { return w.get(); }); - return rv; -} - void TargetedWriteBatch::addWrite(std::unique_ptr<TargetedWrite> targetedWrite, int estWriteSize) { _writes.push_back(std::move(targetedWrite)); _estimatedSizeBytes += estWriteSize; diff --git a/src/mongo/s/write_ops/batch_write_op.h b/src/mongo/s/write_ops/batch_write_op.h index 70c3a3ba7b1..83156122a3b 100644 --- a/src/mongo/s/write_ops/batch_write_op.h +++ b/src/mongo/s/write_ops/batch_write_op.h @@ -267,7 +267,9 @@ public: return _endpoint; } - std::vector<TargetedWrite*> getWrites() const; + const std::vector<std::unique_ptr<TargetedWrite>>& getWrites() const { + return _writes; + }; size_t getNumOps() const { return _writes.size(); @@ -290,8 +292,8 @@ private: // TargetedWrite*s are owned by the TargetedWriteBatch std::vector<std::unique_ptr<TargetedWrite>> _writes; - // Conservatvely estimated size of the batch, for ensuring it doesn't grow past the maximum BSON - // size + // Conservatively estimated size of the batch, for ensuring it doesn't grow past the maximum + // BSON size int _estimatedSizeBytes{0}; }; |