diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2022-02-07 16:50:03 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-02-07 20:30:56 +0000 |
commit | 522da292b8e89d6288916f744f318cb1f32ac8a8 (patch) | |
tree | ae361da0444a406929da01bfb50786ba8387a1b1 /src/mongo/s/write_ops | |
parent | ccd044ecf761baf8a8cb6487b2ebe676e6611599 (diff) | |
download | mongo-522da292b8e89d6288916f744f318cb1f32ac8a8.tar.gz |
SERVER-63331 Remove useless methods from BatchCommandResponse
Diffstat (limited to 'src/mongo/s/write_ops')
-rw-r--r-- | src/mongo/s/write_ops/batch_write_exec.cpp | 3 | ||||
-rw-r--r-- | src/mongo/s/write_ops/batch_write_op.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/write_ops/batch_write_op_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/write_ops/batched_command_response.cpp | 50 | ||||
-rw-r--r-- | src/mongo/s/write_ops/batched_command_response.h | 29 | ||||
-rw-r--r-- | src/mongo/s/write_ops/batched_upsert_detail.h | 4 |
6 files changed, 9 insertions, 83 deletions
diff --git a/src/mongo/s/write_ops/batch_write_exec.cpp b/src/mongo/s/write_ops/batch_write_exec.cpp index 757c4c29a69..509f242db11 100644 --- a/src/mongo/s/write_ops/batch_write_exec.cpp +++ b/src/mongo/s/write_ops/batch_write_exec.cpp @@ -286,8 +286,7 @@ void BatchWriteExec::executeBatch(OperationContext* opCtx, if (responseStatus.isOK()) { std::string errMsg; if (!batchedCommandResponse.parseBSON(response.swResponse.getValue().data, - &errMsg) || - !batchedCommandResponse.isValid(&errMsg)) { + &errMsg)) { responseStatus = {ErrorCodes::FailedToParse, errMsg}; } } diff --git a/src/mongo/s/write_ops/batch_write_op.cpp b/src/mongo/s/write_ops/batch_write_op.cpp index ecf57cd2e8f..e78924ae529 100644 --- a/src/mongo/s/write_ops/batch_write_op.cpp +++ b/src/mongo/s/write_ops/batch_write_op.cpp @@ -711,7 +711,6 @@ void BatchWriteOp::noteBatchError(const TargetedWriteBatch& targetedBatch, emulatedResponse.addToErrDetails(errorClone.release()); } - dassert(emulatedResponse.isValid(nullptr)); noteBatchResponse(targetedBatch, emulatedResponse, nullptr); } @@ -766,7 +765,6 @@ void BatchWriteOp::buildClientResponse(BatchedCommandResponse* batchResp) { // For non-verbose, it's all we need. if (!_clientRequest.isVerboseWC()) { - dassert(batchResp->isValid(nullptr)); return; } @@ -844,8 +842,6 @@ void BatchWriteOp::buildClientResponse(BatchedCommandResponse* batchResp) { _numModified >= 0) { batchResp->setNModified(_numModified); } - - dassert(batchResp->isValid(nullptr)); } int BatchWriteOp::numWriteOpsIn(WriteOpState opState) const { diff --git a/src/mongo/s/write_ops/batch_write_op_test.cpp b/src/mongo/s/write_ops/batch_write_op_test.cpp index 7632d70a6ed..2d0012cbabb 100644 --- a/src/mongo/s/write_ops/batch_write_op_test.cpp +++ b/src/mongo/s/write_ops/batch_write_op_test.cpp @@ -86,14 +86,12 @@ void buildResponse(int n, BatchedCommandResponse* response) { response->clear(); response->setStatus(Status::OK()); response->setN(n); - ASSERT(response->isValid(nullptr)); } void buildErrResponse(int code, const std::string& message, BatchedCommandResponse* response) { response->clear(); response->setN(0); response->setStatus({ErrorCodes::Error(code), message}); - ASSERT(response->isValid(nullptr)); } void addError(int code, const std::string& message, int index, BatchedCommandResponse* response) { diff --git a/src/mongo/s/write_ops/batched_command_response.cpp b/src/mongo/s/write_ops/batched_command_response.cpp index e50bc74699f..fe010d2a235 100644 --- a/src/mongo/s/write_ops/batched_command_response.cpp +++ b/src/mongo/s/write_ops/batched_command_response.cpp @@ -64,21 +64,6 @@ BatchedCommandResponse::~BatchedCommandResponse() { unsetUpsertDetails(); } -bool BatchedCommandResponse::isValid(std::string* errMsg) const { - std::string dummy; - if (errMsg == nullptr) { - errMsg = &dummy; - } - - // All the mandatory fields must be present. - if (!_isStatusSet) { - *errMsg = stream() << "missing status fields"; - return false; - } - - return true; -} - BSONObj BatchedCommandResponse::toBSON() const { BSONObjBuilder builder; @@ -257,9 +242,6 @@ void BatchedCommandResponse::clear() { _n = 0; _isNSet = false; - _singleUpserted = BSONObj(); - _isSingleUpsertedSet = false; - if (_upsertDetails.get()) { for (std::vector<BatchedUpsertDetail*>::const_iterator it = _upsertDetails->begin(); it != _upsertDetails->end(); @@ -287,10 +269,6 @@ void BatchedCommandResponse::clear() { _wcErrDetails.reset(); } -std::string BatchedCommandResponse::toString() const { - return toBSON().toString(); -} - void BatchedCommandResponse::setStatus(Status status) { _status = std::move(status); _isStatusSet = true; @@ -301,14 +279,6 @@ void BatchedCommandResponse::setNModified(long long n) { _isNModifiedSet = true; } -void BatchedCommandResponse::unsetNModified() { - _isNModifiedSet = false; -} - -bool BatchedCommandResponse::isNModified() const { - return _isNModifiedSet; -} - long long BatchedCommandResponse::getNModified() const { if (_isNModifiedSet) { return _nModified; @@ -322,14 +292,6 @@ void BatchedCommandResponse::setN(long long n) { _isNSet = true; } -void BatchedCommandResponse::unsetN() { - _isNSet = false; -} - -bool BatchedCommandResponse::isNSet() const { - return _isNSet; -} - long long BatchedCommandResponse::getN() const { if (_isNSet) { return _n; @@ -393,10 +355,6 @@ void BatchedCommandResponse::setLastOp(repl::OpTime lastOp) { _isLastOpSet = true; } -void BatchedCommandResponse::unsetLastOp() { - _isLastOpSet = false; -} - bool BatchedCommandResponse::isLastOpSet() const { return _isLastOpSet; } @@ -411,10 +369,6 @@ void BatchedCommandResponse::setElectionId(const OID& electionId) { _isElectionIdSet = true; } -void BatchedCommandResponse::unsetElectionId() { - _isElectionIdSet = false; -} - bool BatchedCommandResponse::isElectionIdSet() const { return _isElectionIdSet; } @@ -466,10 +420,6 @@ void BatchedCommandResponse::setWriteConcernError(WriteConcernErrorDetail* error _wcErrDetails.reset(error); } -void BatchedCommandResponse::unsetWriteConcernError() { - _wcErrDetails.reset(); -} - bool BatchedCommandResponse::isWriteConcernErrorSet() const { return _wcErrDetails.get(); } diff --git a/src/mongo/s/write_ops/batched_command_response.h b/src/mongo/s/write_ops/batched_command_response.h index e81b682f450..e93c2010fb2 100644 --- a/src/mongo/s/write_ops/batched_command_response.h +++ b/src/mongo/s/write_ops/batched_command_response.h @@ -50,10 +50,6 @@ class BatchedCommandResponse { BatchedCommandResponse& operator=(const BatchedCommandResponse&) = delete; public: - // - // schema declarations - // - static const BSONField<long long> n; static const BSONField<long long> nModified; static const BSONField<std::vector<BatchedUpsertDetail*>> upsertDetails; @@ -64,14 +60,13 @@ public: BatchedCommandResponse(); ~BatchedCommandResponse(); + BatchedCommandResponse(BatchedCommandResponse&&) = default; BatchedCommandResponse& operator=(BatchedCommandResponse&&) = default; - bool isValid(std::string* errMsg) const; BSONObj toBSON() const; bool parseBSON(const BSONObj& source, std::string* errMsg); void clear(); - std::string toString() const; // // individual field accessors @@ -92,14 +87,15 @@ public: return _status.isOK(); } + /** + * Converts the specified command response into a status, based on all of its contents. + */ + Status toStatus() const; + void setNModified(long long n); - void unsetNModified(); - bool isNModified() const; long long getNModified() const; void setN(long long n); - void unsetN(); - bool isNSet() const; long long getN() const; void setUpsertDetails(const std::vector<BatchedUpsertDetail*>& upsertDetails); @@ -111,12 +107,10 @@ public: const BatchedUpsertDetail* getUpsertDetailsAt(std::size_t pos) const; void setLastOp(repl::OpTime lastOp); - void unsetLastOp(); bool isLastOpSet() const; repl::OpTime getLastOp() const; void setElectionId(const OID& electionId); - void unsetElectionId(); bool isElectionIdSet() const; OID getElectionId() const; @@ -129,18 +123,12 @@ public: const WriteErrorDetail* getErrDetailsAt(std::size_t pos) const; void setWriteConcernError(WriteConcernErrorDetail* error); - void unsetWriteConcernError(); bool isWriteConcernErrorSet() const; const WriteConcernErrorDetail* getWriteConcernError() const; bool isErrorLabelsSet() const; const std::vector<std::string>& getErrorLabels() const; - /** - * Converts the specified command response into a status, based on all of its contents. - */ - Status toStatus() const; - private: // Convention: (M)andatory, (O)ptional @@ -156,11 +144,6 @@ private: long long _nModified; bool _isNModifiedSet; - // (O) "promoted" _upserted, if the corresponding request contained only one batch item - // Should only be present if _upserted is not. - BSONObj _singleUpserted; - bool _isSingleUpsertedSet; - // (O) Array of upserted items' _id's // Should only be present if _singleUpserted is not. std::unique_ptr<std::vector<BatchedUpsertDetail*>> _upsertDetails; diff --git a/src/mongo/s/write_ops/batched_upsert_detail.h b/src/mongo/s/write_ops/batched_upsert_detail.h index c4eb49868f9..c012f2b906c 100644 --- a/src/mongo/s/write_ops/batched_upsert_detail.h +++ b/src/mongo/s/write_ops/batched_upsert_detail.h @@ -36,8 +36,8 @@ namespace mongo { /** - * This class represents the layout and content of an idem inside the 'upserted' array - * of a write command's response (see batched_command_response.h) + * This class represents the layout and content of an idem inside the 'upserted' array of a write + * command's response (see BatchedCommandResponse). */ class BatchedUpsertDetail { BatchedUpsertDetail(const BatchedUpsertDetail&) = delete; |