diff options
author | Spencer T Brody <spencer@mongodb.com> | 2015-09-10 15:20:03 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2015-09-17 11:55:12 -0400 |
commit | e44bf3dc351624ff26968a8006dfa385ffc83516 (patch) | |
tree | 7b28dbab277e83f6e8b58925baf71ddaae4efe81 /src/mongo/s/write_ops | |
parent | 9c9356b7887b3fb633203a229007a2b4e225d12f (diff) | |
download | mongo-e44bf3dc351624ff26968a8006dfa385ffc83516.tar.gz |
SERVER-19855 SERVER-20285 Make write commands send shard version information at the top level
Diffstat (limited to 'src/mongo/s/write_ops')
17 files changed, 164 insertions, 458 deletions
diff --git a/src/mongo/s/write_ops/SConscript b/src/mongo/s/write_ops/SConscript index f8301f09e2c..402c73f85bc 100644 --- a/src/mongo/s/write_ops/SConscript +++ b/src/mongo/s/write_ops/SConscript @@ -10,7 +10,6 @@ env.Library( 'batched_delete_request.cpp',
'batched_delete_document.cpp',
'batched_insert_request.cpp',
- 'batched_request_metadata.cpp',
'batched_update_request.cpp',
'batched_update_document.cpp',
'batched_upsert_detail.cpp',
@@ -57,7 +56,6 @@ env.CppUnitTest( 'batched_command_response_test.cpp',
'batched_delete_request_test.cpp',
'batched_insert_request_test.cpp',
- 'batched_request_metadata_test.cpp',
'batched_update_request_test.cpp',
],
LIBDEPS=[
diff --git a/src/mongo/s/write_ops/batch_write_op.cpp b/src/mongo/s/write_ops/batch_write_op.cpp index 2e949321c30..d67537714b0 100644 --- a/src/mongo/s/write_ops/batch_write_op.cpp +++ b/src/mongo/s/write_ops/batch_write_op.cpp @@ -456,12 +456,7 @@ void BatchWriteOp::buildBatchRequest(const TargetedWriteBatch& targetedBatch, request->setOrdered(_clientRequest->getOrdered()); } - unique_ptr<BatchedRequestMetadata> requestMetadata(new BatchedRequestMetadata()); - requestMetadata->setShardVersion( - ChunkVersionAndOpTime(targetedBatch.getEndpoint().shardVersion)); - requestMetadata->setSession(0); - - request->setMetadata(requestMetadata.release()); + request->setShardVersion(targetedBatch.getEndpoint().shardVersion); } // diff --git a/src/mongo/s/write_ops/batched_command_request.cpp b/src/mongo/s/write_ops/batched_command_request.cpp index 936762a0189..914d01b444f 100644 --- a/src/mongo/s/write_ops/batched_command_request.cpp +++ b/src/mongo/s/write_ops/batched_command_request.cpp @@ -31,6 +31,7 @@ #include "mongo/s/write_ops/batched_command_request.h" #include "mongo/bson/bsonobj.h" +#include "mongo/bson/util/bson_extract.h" #include "mongo/db/namespace_string.h" namespace mongo { @@ -191,13 +192,80 @@ bool BatchedCommandRequest::isValid(std::string* errMsg) const { } BSONObj BatchedCommandRequest::toBSON() const { - INVOKE(toBSON); + BSONObjBuilder builder; + + switch (getBatchType()) { + case BatchedCommandRequest::BatchType_Insert: + builder.appendElements(_insertReq->toBSON()); + break; + case BatchedCommandRequest::BatchType_Update: + builder.appendElements(_updateReq->toBSON()); + break; + case BatchedCommandRequest::BatchType_Delete: + builder.appendElements(_deleteReq->toBSON()); + break; + default: + MONGO_UNREACHABLE; + } + + // Append the shard version + if (_shardVersion) { + _shardVersion.get().appendForCommands(&builder); + } + + return builder.obj(); } bool BatchedCommandRequest::parseBSON(StringData dbName, const BSONObj& source, std::string* errMsg) { - INVOKE(parseBSON, dbName, source, errMsg); + bool succeeded; + + switch (getBatchType()) { + case BatchedCommandRequest::BatchType_Insert: + succeeded = _insertReq->parseBSON(dbName, source, errMsg); + break; + case BatchedCommandRequest::BatchType_Update: + succeeded = _updateReq->parseBSON(dbName, source, errMsg); + break; + case BatchedCommandRequest::BatchType_Delete: + succeeded = _deleteReq->parseBSON(dbName, source, errMsg); + break; + default: + MONGO_UNREACHABLE; + } + + if (!succeeded) + return false; + + // Now parse out the chunk version and optime. + BSONObj metadataObj; + bool required = false; + + BSONElement metadataElem; + Status metadataStatus = bsonExtractTypedField(source, "metadata", Object, &metadataElem); + if (metadataStatus.isOK()) { + // Old format, where the shard version is buried under a "metadata" field + metadataObj = metadataElem.Obj(); + required = true; + } else if (metadataStatus == ErrorCodes::NoSuchKey) { + // New format, where the shard version could be on the first level + metadataObj = source; + } else { + *errMsg = causedBy(metadataStatus); + return false; + } + + auto verAndOpT = ChunkVersionAndOpTime::parseFromBSONForCommands(metadataObj); + if (verAndOpT.isOK()) { + _shardVersion = verAndOpT.getValue(); + return true; + } else if ((verAndOpT == ErrorCodes::NoSuchKey) && !required) { + return true; + } + + *errMsg = causedBy(verAndOpT.getStatus()); + return false; } void BatchedCommandRequest::clear() { @@ -259,18 +327,6 @@ bool BatchedCommandRequest::getOrdered() const { INVOKE(getOrdered); } -void BatchedCommandRequest::setMetadata(BatchedRequestMetadata* metadata) { - INVOKE(setMetadata, metadata); -} - -bool BatchedCommandRequest::isMetadataSet() const { - INVOKE(isMetadataSet); -} - -BatchedRequestMetadata* BatchedCommandRequest::getMetadata() const { - INVOKE(getMetadata); -} - void BatchedCommandRequest::setShouldBypassValidation(bool newVal) { INVOKE(setShouldBypassValidation, newVal); } diff --git a/src/mongo/s/write_ops/batched_command_request.h b/src/mongo/s/write_ops/batched_command_request.h index 0325baa7ec4..1fc3cc6d273 100644 --- a/src/mongo/s/write_ops/batched_command_request.h +++ b/src/mongo/s/write_ops/batched_command_request.h @@ -28,7 +28,10 @@ #pragma once +#include <boost/optional.hpp> + #include "mongo/base/disallow_copying.h" +#include "mongo/s/chunk_version.h" #include "mongo/s/write_ops/batched_insert_request.h" #include "mongo/s/write_ops/batched_update_request.h" #include "mongo/s/write_ops/batched_delete_request.h" @@ -128,9 +131,17 @@ public: bool isOrderedSet() const; bool getOrdered() const; - void setMetadata(BatchedRequestMetadata* metadata); - bool isMetadataSet() const; - BatchedRequestMetadata* getMetadata() const; + void setShardVersion(ChunkVersionAndOpTime shardVersion) { + _shardVersion = std::move(shardVersion); + } + + bool hasShardVersion() const { + return _shardVersion.is_initialized(); + } + + const ChunkVersionAndOpTime& getShardVersion() const { + return _shardVersion.get(); + } void setShouldBypassValidation(bool newVal); bool shouldBypassValidation() const; @@ -172,6 +183,9 @@ public: private: BatchType _batchType; + + boost::optional<ChunkVersionAndOpTime> _shardVersion; + std::unique_ptr<BatchedInsertRequest> _insertReq; std::unique_ptr<BatchedUpdateRequest> _updateReq; std::unique_ptr<BatchedDeleteRequest> _deleteReq; diff --git a/src/mongo/s/write_ops/batched_command_request_test.cpp b/src/mongo/s/write_ops/batched_command_request_test.cpp index ea499957033..f12d476051d 100644 --- a/src/mongo/s/write_ops/batched_command_request_test.cpp +++ b/src/mongo/s/write_ops/batched_command_request_test.cpp @@ -36,6 +36,70 @@ namespace mongo { namespace { +TEST(BatchedCommandRequest, BasicInsert) { + BSONArray insertArray = BSON_ARRAY(BSON("a" << 1) << BSON("b" << 1)); + + BSONObj origInsertRequestObj = BSON("insert" + << "test" + << "documents" << insertArray << "writeConcern" + << BSON("w" << 1) << "ordered" << true); + + std::string errMsg; + BatchedCommandRequest insertRequest(BatchedCommandRequest::BatchType_Insert); + ASSERT_TRUE(insertRequest.parseBSON("TestDB", origInsertRequestObj, &errMsg)); + + ASSERT_EQ("TestDB.test", insertRequest.getInsertRequest()->getNS().toString()); + ASSERT(!insertRequest.hasShardVersion()); +} + +TEST(BatchedCommandRequest, InsertWithShardVersion) { + BSONArray insertArray = BSON_ARRAY(BSON("a" << 1) << BSON("b" << 1)); + + const OID epoch = OID::gen(); + + BSONObj origInsertRequestObj = BSON("insert" + << "test" + << "documents" << insertArray << "writeConcern" + << BSON("w" << 1) << "ordered" << true << "shardVersion" + << BSON_ARRAY(Timestamp(1, 2) << epoch) << "ts" + << Timestamp(3, 4) << "t" << 5); + + std::string errMsg; + BatchedCommandRequest insertRequest(BatchedCommandRequest::BatchType_Insert); + ASSERT_TRUE(insertRequest.parseBSON("TestDB", origInsertRequestObj, &errMsg)); + + ASSERT_EQ("TestDB.test", insertRequest.getInsertRequest()->getNS().toString()); + ASSERT(insertRequest.hasShardVersion()); + ASSERT_EQ(ChunkVersion(1, 2, epoch).toString(), + insertRequest.getShardVersion().getVersion().toString()); + ASSERT_EQ(repl::OpTime(Timestamp(3, 4), 5), insertRequest.getShardVersion().getOpTime()); +} + +TEST(BatchedCommandRequest, InsertWithShardVersionInLegacyMetadata) { + BSONArray insertArray = BSON_ARRAY(BSON("a" << 1) << BSON("b" << 1)); + + const OID epoch = OID::gen(); + + BSONObj origInsertRequestObj = BSON("insert" + << "test" + << "documents" << insertArray << "writeConcern" + << BSON("w" << 1) << "ordered" << true << "metadata" + << BSON("shardVersion" + << BSON_ARRAY(Timestamp(1, 2) << epoch) << "ts" + << Timestamp(3, 4) << "t" << 5 << "session" + << 0LL)); + + std::string errMsg; + BatchedCommandRequest insertRequest(BatchedCommandRequest::BatchType_Insert); + ASSERT_TRUE(insertRequest.parseBSON("TestDB", origInsertRequestObj, &errMsg)); + + ASSERT_EQ("TestDB.test", insertRequest.getInsertRequest()->getNS().toString()); + ASSERT(insertRequest.hasShardVersion()); + ASSERT_EQ(ChunkVersion(1, 2, epoch).toString(), + insertRequest.getShardVersion().getVersion().toString()); + ASSERT_EQ(repl::OpTime(Timestamp(3, 4), 5), insertRequest.getShardVersion().getOpTime()); +} + TEST(BatchedCommandRequest, InsertClone) { auto insertRequest = stdx::make_unique<BatchedInsertRequest>(); BatchedCommandRequest batchedRequest(insertRequest.release()); diff --git a/src/mongo/s/write_ops/batched_delete_request.cpp b/src/mongo/s/write_ops/batched_delete_request.cpp index fa5c07f6fba..a01b74568a9 100644 --- a/src/mongo/s/write_ops/batched_delete_request.cpp +++ b/src/mongo/s/write_ops/batched_delete_request.cpp @@ -43,7 +43,6 @@ const BSONField<std::string> BatchedDeleteRequest::collName("delete"); const BSONField<std::vector<BatchedDeleteDocument*>> BatchedDeleteRequest::deletes("deletes"); const BSONField<BSONObj> BatchedDeleteRequest::writeConcern("writeConcern"); const BSONField<bool> BatchedDeleteRequest::ordered("ordered", true); -const BSONField<BSONObj> BatchedDeleteRequest::metadata("metadata"); BatchedDeleteRequest::BatchedDeleteRequest() { clear(); @@ -96,9 +95,6 @@ BSONObj BatchedDeleteRequest::toBSON() const { if (_isOrderedSet) builder.append(ordered(), _ordered); - if (_metadata) - builder.append(metadata(), _metadata->toBSON()); - return builder.obj(); } @@ -132,18 +128,6 @@ bool BatchedDeleteRequest::parseBSON(StringData dbName, const BSONObj& source, s return false; _isOrderedSet = fieldState == FieldParser::FIELD_SET; - BSONObj metadataObj; - fieldState = FieldParser::extract(source, metadata, &metadataObj, errMsg); - if (fieldState == FieldParser::FIELD_INVALID) - return false; - - if (!metadataObj.isEmpty()) { - _metadata.reset(new BatchedRequestMetadata()); - if (!_metadata->parseBSON(metadataObj, errMsg)) { - return false; - } - } - return true; } @@ -158,8 +142,6 @@ void BatchedDeleteRequest::clear() { _ordered = false; _isOrderedSet = false; - - _metadata.reset(); } void BatchedDeleteRequest::cloneTo(BatchedDeleteRequest* other) const { @@ -182,11 +164,6 @@ void BatchedDeleteRequest::cloneTo(BatchedDeleteRequest* other) const { other->_ordered = _ordered; other->_isOrderedSet = _isOrderedSet; - - if (_metadata) { - other->_metadata.reset(new BatchedRequestMetadata()); - _metadata->cloneTo(other->_metadata.get()); - } } std::string BatchedDeleteRequest::toString() const { @@ -286,16 +263,4 @@ bool BatchedDeleteRequest::getOrdered() const { } } -void BatchedDeleteRequest::setMetadata(BatchedRequestMetadata* metadata) { - _metadata.reset(metadata); -} - -bool BatchedDeleteRequest::isMetadataSet() const { - return _metadata.get(); -} - -BatchedRequestMetadata* BatchedDeleteRequest::getMetadata() const { - return _metadata.get(); -} - } // namespace mongo diff --git a/src/mongo/s/write_ops/batched_delete_request.h b/src/mongo/s/write_ops/batched_delete_request.h index 44c6dbb152d..62a9e0034bc 100644 --- a/src/mongo/s/write_ops/batched_delete_request.h +++ b/src/mongo/s/write_ops/batched_delete_request.h @@ -35,7 +35,6 @@ #include "mongo/db/jsobj.h" #include "mongo/db/namespace_string.h" #include "mongo/s/write_ops/batched_delete_document.h" -#include "mongo/s/write_ops/batched_request_metadata.h" namespace mongo { @@ -59,7 +58,6 @@ public: static const BSONField<std::vector<BatchedDeleteDocument*>> deletes; static const BSONField<BSONObj> writeConcern; static const BSONField<bool> ordered; - static const BSONField<BSONObj> metadata; // // construction / destruction @@ -106,13 +104,6 @@ public: bool isOrderedSet() const; bool getOrdered() const; - /* - * metadata ownership will be transferred to this. - */ - void setMetadata(BatchedRequestMetadata* metadata); - bool isMetadataSet() const; - BatchedRequestMetadata* getMetadata() const; - /** * These are no-ops since delete never validates documents. They only exist to fulfill the * unified API. @@ -140,9 +131,6 @@ private: // (O) whether batch is issued in parallel or not bool _ordered; bool _isOrderedSet; - - // (O) metadata associated with this request for internal use. - std::unique_ptr<BatchedRequestMetadata> _metadata; }; } // namespace mongo diff --git a/src/mongo/s/write_ops/batched_delete_request_test.cpp b/src/mongo/s/write_ops/batched_delete_request_test.cpp index 99d845a1e3b..a9fe5ca0c5f 100644 --- a/src/mongo/s/write_ops/batched_delete_request_test.cpp +++ b/src/mongo/s/write_ops/batched_delete_request_test.cpp @@ -46,13 +46,10 @@ TEST(BatchedDeleteRequest, Basic) { BSON(BatchedDeleteDocument::query(BSON("a" << 1)) << BatchedDeleteDocument::limit(1)) << BSON(BatchedDeleteDocument::query(BSON("b" << 1)) << BatchedDeleteDocument::limit(1))); - BSONObj origDeleteRequestObj = - BSON(BatchedDeleteRequest::collName("test") - << BatchedDeleteRequest::deletes() << deleteArray - << BatchedDeleteRequest::writeConcern(BSON("w" << 1)) - << BatchedDeleteRequest::ordered(true) << BatchedDeleteRequest::metadata() - << BSON("shardVersion" << BSON_ARRAY(Timestamp(1, 2) << OID::gen()) << "ts" - << Timestamp(3, 4) << "t" << 5 << "session" << 0LL)); + BSONObj origDeleteRequestObj = BSON(BatchedDeleteRequest::collName("test") + << BatchedDeleteRequest::deletes() << deleteArray + << BatchedDeleteRequest::writeConcern(BSON("w" << 1)) + << BatchedDeleteRequest::ordered(true)); string errMsg; BatchedDeleteRequest request; diff --git a/src/mongo/s/write_ops/batched_insert_request.cpp b/src/mongo/s/write_ops/batched_insert_request.cpp index e224020eaa4..7bc2e0eddf0 100644 --- a/src/mongo/s/write_ops/batched_insert_request.cpp +++ b/src/mongo/s/write_ops/batched_insert_request.cpp @@ -43,7 +43,6 @@ const BSONField<std::string> BatchedInsertRequest::collName("insert"); const BSONField<std::vector<BSONObj>> BatchedInsertRequest::documents("documents"); const BSONField<BSONObj> BatchedInsertRequest::writeConcern("writeConcern"); const BSONField<bool> BatchedInsertRequest::ordered("ordered", true); -const BSONField<BSONObj> BatchedInsertRequest::metadata("metadata"); BatchedInsertRequest::BatchedInsertRequest() { clear(); @@ -92,9 +91,6 @@ BSONObj BatchedInsertRequest::toBSON() const { if (_isOrderedSet) builder.append(ordered(), _ordered); - if (_metadata) - builder.append(metadata(), _metadata->toBSON()); - if (_shouldBypassValidation) builder.append(bypassDocumentValidationCommandOption(), true); @@ -145,19 +141,6 @@ bool BatchedInsertRequest::parseBSON(StringData dbName, const BSONObj& source, s if (fieldState == FieldParser::FIELD_INVALID) return false; _isOrderedSet = fieldState == FieldParser::FIELD_SET; - } else if (metadata() == sourceEl.fieldName()) { - BSONObj metadataObj; - FieldParser::FieldState fieldState = - FieldParser::extract(sourceEl, metadata, &metadataObj, errMsg); - if (fieldState == FieldParser::FIELD_INVALID) - return false; - - if (!metadataObj.isEmpty()) { - _metadata.reset(new BatchedRequestMetadata()); - if (!_metadata->parseBSON(metadataObj, errMsg)) { - return false; - } - } } else if (bypassDocumentValidationCommandOption() == sourceEl.fieldNameStringData()) { _shouldBypassValidation = sourceEl.trueValue(); } @@ -181,8 +164,6 @@ void BatchedInsertRequest::clear() { _isOrderedSet = false; _shouldBypassValidation = false; - - _metadata.reset(); } void BatchedInsertRequest::cloneTo(BatchedInsertRequest* other) const { @@ -203,11 +184,6 @@ void BatchedInsertRequest::cloneTo(BatchedInsertRequest* other) const { other->_ordered = _ordered; other->_isOrderedSet = _isOrderedSet; - - if (_metadata) { - other->_metadata.reset(new BatchedRequestMetadata()); - _metadata->cloneTo(other->_metadata.get()); - } } std::string BatchedInsertRequest::toString() const { @@ -299,17 +275,4 @@ bool BatchedInsertRequest::getOrdered() const { return ordered.getDefault(); } } - -void BatchedInsertRequest::setMetadata(BatchedRequestMetadata* metadata) { - _metadata.reset(metadata); -} - -bool BatchedInsertRequest::isMetadataSet() const { - return _metadata.get(); -} - -BatchedRequestMetadata* BatchedInsertRequest::getMetadata() const { - return _metadata.get(); -} - } // namespace mongo diff --git a/src/mongo/s/write_ops/batched_insert_request.h b/src/mongo/s/write_ops/batched_insert_request.h index 3a43aa861da..221d41d81db 100644 --- a/src/mongo/s/write_ops/batched_insert_request.h +++ b/src/mongo/s/write_ops/batched_insert_request.h @@ -34,7 +34,6 @@ #include "mongo/base/string_data.h" #include "mongo/db/jsobj.h" #include "mongo/db/namespace_string.h" -#include "mongo/s/write_ops/batched_request_metadata.h" namespace mongo { @@ -58,7 +57,6 @@ public: static const BSONField<std::vector<BSONObj>> documents; static const BSONField<BSONObj> writeConcern; static const BSONField<bool> ordered; - static const BSONField<BSONObj> metadata; // // construction / destruction @@ -113,13 +111,6 @@ public: return _shouldBypassValidation; } - /* - * metadata ownership will be transferred to this. - */ - void setMetadata(BatchedRequestMetadata* metadata); - bool isMetadataSet() const; - BatchedRequestMetadata* getMetadata() const; - private: // Convention: (M)andatory, (O)ptional @@ -139,9 +130,6 @@ private: bool _ordered; bool _isOrderedSet; - // (O) metadata associated with this request for internal use. - std::unique_ptr<BatchedRequestMetadata> _metadata; - // (O) cached copied of target ns NamespaceString _targetNSS; diff --git a/src/mongo/s/write_ops/batched_insert_request_test.cpp b/src/mongo/s/write_ops/batched_insert_request_test.cpp index 3c0f6197ff4..8ec4f7621c1 100644 --- a/src/mongo/s/write_ops/batched_insert_request_test.cpp +++ b/src/mongo/s/write_ops/batched_insert_request_test.cpp @@ -45,13 +45,10 @@ namespace { TEST(BatchedInsertRequest, Basic) { BSONArray insertArray = BSON_ARRAY(BSON("a" << 1) << BSON("b" << 1)); - BSONObj origInsertRequestObj = - BSON(BatchedInsertRequest::collName("test") - << BatchedInsertRequest::documents() << insertArray - << BatchedInsertRequest::writeConcern(BSON("w" << 1)) - << BatchedInsertRequest::ordered(true) << BatchedInsertRequest::metadata() - << BSON("shardVersion" << BSON_ARRAY(Timestamp(1, 2) << OID::gen()) << "ts" - << Timestamp(3, 4) << "t" << 5 << "session" << 0LL)); + BSONObj origInsertRequestObj = BSON(BatchedInsertRequest::collName("test") + << BatchedInsertRequest::documents() << insertArray + << BatchedInsertRequest::writeConcern(BSON("w" << 1)) + << BatchedInsertRequest::ordered(true)); string errMsg; BatchedInsertRequest request; diff --git a/src/mongo/s/write_ops/batched_request_metadata.cpp b/src/mongo/s/write_ops/batched_request_metadata.cpp deleted file mode 100644 index 6b3782785a8..00000000000 --- a/src/mongo/s/write_ops/batched_request_metadata.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/** - * Copyright (C) 2013 MongoDB Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the GNU Affero General Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include "mongo/s/write_ops/batched_request_metadata.h" - -#include "mongo/db/field_parser.h" - -namespace mongo { - -using std::unique_ptr; -using std::string; - -const BSONField<ChunkVersion> BatchedRequestMetadata::shardVersion("shardVersion"); -const BSONField<long long> BatchedRequestMetadata::session("session"); - -BatchedRequestMetadata::BatchedRequestMetadata() : _session(0), _isSessionSet(false) {} - -BatchedRequestMetadata::~BatchedRequestMetadata() {} - -bool BatchedRequestMetadata::isValid(string* errMsg) const { - // all fields are mandatory. - return true; -} - -BSONObj BatchedRequestMetadata::toBSON() const { - BSONObjBuilder metadataBuilder; - - if (_shardVersion) { - _shardVersion.get().appendForCommands(&metadataBuilder); - } - - if (_isSessionSet) - metadataBuilder << session(_session); - - return metadataBuilder.obj(); -} - -bool BatchedRequestMetadata::parseBSON(const BSONObj& source, string* errMsg) { - clear(); - - string dummy; - if (!errMsg) - errMsg = &dummy; - - { - auto verAndOpTStatus = ChunkVersionAndOpTime::parseFromBSONForCommands(source); - if (!verAndOpTStatus.isOK()) { - return false; - } - - _shardVersion = verAndOpTStatus.getValue(); - } - - FieldParser::FieldState fieldState = FieldParser::extract(source, session, &_session, errMsg); - if (fieldState == FieldParser::FIELD_INVALID) - return false; - _isSessionSet = fieldState == FieldParser::FIELD_SET; - - return true; -} - -void BatchedRequestMetadata::clear() { - _shardVersion.reset(); - - _session = 0; - _isSessionSet = false; -} - -string BatchedRequestMetadata::toString() const { - return toBSON().toString(); -} - -void BatchedRequestMetadata::cloneTo(BatchedRequestMetadata* other) const { - other->_shardVersion = _shardVersion; - other->_session = _session; - other->_isSessionSet = _isSessionSet; -} - -void BatchedRequestMetadata::setShardVersion(const ChunkVersionAndOpTime& shardVersion) { - _shardVersion = shardVersion; -} - -bool BatchedRequestMetadata::isShardVersionSet() const { - return _shardVersion.is_initialized(); -} - -const ChunkVersion& BatchedRequestMetadata::getShardVersion() const { - return _shardVersion.get().getVersion(); -} - -void BatchedRequestMetadata::setSession(long long session) { - _session = session; - _isSessionSet = true; -} - -void BatchedRequestMetadata::unsetSession() { - _isSessionSet = false; -} - -bool BatchedRequestMetadata::isSessionSet() const { - return _isSessionSet; -} - -long long BatchedRequestMetadata::getSession() const { - dassert(_isSessionSet); - return _session; -} -} diff --git a/src/mongo/s/write_ops/batched_request_metadata.h b/src/mongo/s/write_ops/batched_request_metadata.h deleted file mode 100644 index f1b74cf3ecf..00000000000 --- a/src/mongo/s/write_ops/batched_request_metadata.h +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Copyright (C) 2013 MongoDB Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the GNU Affero General Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#include <boost/optional.hpp> -#include <string> - -#include "mongo/db/jsobj.h" -#include "mongo/s/bson_serializable.h" -#include "mongo/s/chunk_version.h" - -namespace mongo { - -class BatchedRequestMetadata { -public: - static const BSONField<ChunkVersion> shardVersion; - static const BSONField<long long> session; - - BatchedRequestMetadata(); - ~BatchedRequestMetadata(); - - // - // bson serializable interface implementation - // - - bool isValid(std::string* errMsg) const; - BSONObj toBSON() const; - bool parseBSON(const BSONObj& source, std::string* errMsg); - void clear(); - std::string toString() const; - - void cloneTo(BatchedRequestMetadata* other) const; - - void setShardVersion(const ChunkVersionAndOpTime& shardVersion); - bool isShardVersionSet() const; - const ChunkVersion& getShardVersion() const; - const repl::OpTime& getOpTime() const; - - void setSession(long long session); - void unsetSession(); - bool isSessionSet() const; - long long getSession() const; - -private: - // (O) version for this collection on a given shard - boost::optional<ChunkVersionAndOpTime> _shardVersion; - - // (O) session number the inserts belong to - long long _session; - bool _isSessionSet; -}; - -} // namespace mongo diff --git a/src/mongo/s/write_ops/batched_request_metadata_test.cpp b/src/mongo/s/write_ops/batched_request_metadata_test.cpp deleted file mode 100644 index 40b5a7626a1..00000000000 --- a/src/mongo/s/write_ops/batched_request_metadata_test.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (C) 2015 MongoDB Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the GNU Affero General Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include <string> - -#include "mongo/s/write_ops/batched_request_metadata.h" -#include "mongo/unittest/unittest.h" - -namespace mongo { - -using std::string; - -namespace { - -TEST(BatchedRequestMetadata, Basic) { - BSONObj metadataObj(BSON("shardVersion" << BSON_ARRAY(Timestamp(1, 2) << OID::gen()) << "ts" - << Timestamp(3, 4) << "t" << 5 << "session" << 0LL)); - - string errMsg; - BatchedRequestMetadata metadata; - ASSERT_TRUE(metadata.parseBSON(metadataObj, &errMsg)); - - ASSERT_EQUALS(metadataObj, metadata.toBSON()); -} - -} // namespace -} // namespace mongo diff --git a/src/mongo/s/write_ops/batched_update_request.cpp b/src/mongo/s/write_ops/batched_update_request.cpp index 3baeaad2829..a337e2eb0c5 100644 --- a/src/mongo/s/write_ops/batched_update_request.cpp +++ b/src/mongo/s/write_ops/batched_update_request.cpp @@ -44,7 +44,6 @@ const BSONField<std::string> BatchedUpdateRequest::collName("update"); const BSONField<std::vector<BatchedUpdateDocument*>> BatchedUpdateRequest::updates("updates"); const BSONField<BSONObj> BatchedUpdateRequest::writeConcern("writeConcern"); const BSONField<bool> BatchedUpdateRequest::ordered("ordered", true); -const BSONField<BSONObj> BatchedUpdateRequest::metadata("metadata"); BatchedUpdateRequest::BatchedUpdateRequest() { clear(); @@ -97,9 +96,6 @@ BSONObj BatchedUpdateRequest::toBSON() const { if (_isOrderedSet) builder.append(ordered(), _ordered); - if (_metadata) - builder.append(metadata(), _metadata->toBSON()); - if (_shouldBypassValidation) builder.append(bypassDocumentValidationCommandOption(), true); @@ -142,18 +138,6 @@ bool BatchedUpdateRequest::parseBSON(StringData dbName, const BSONObj& source, s if (fieldState == FieldParser::FIELD_INVALID) return false; _isOrderedSet = fieldState == FieldParser::FIELD_SET; - } else if (fieldName == metadata.name()) { - BSONObj metadataObj; - fieldState = FieldParser::extract(elem, metadata, &metadataObj, errMsg); - if (fieldState == FieldParser::FIELD_INVALID) - return false; - - if (!metadataObj.isEmpty()) { - _metadata.reset(new BatchedRequestMetadata()); - if (!_metadata->parseBSON(metadataObj, errMsg)) { - return false; - } - } } else if (fieldName == bypassDocumentValidationCommandOption()) { _shouldBypassValidation = elem.trueValue(); } @@ -174,8 +158,6 @@ void BatchedUpdateRequest::clear() { _isOrderedSet = false; _shouldBypassValidation = false; - - _metadata.reset(); } void BatchedUpdateRequest::cloneTo(BatchedUpdateRequest* other) const { @@ -198,11 +180,6 @@ void BatchedUpdateRequest::cloneTo(BatchedUpdateRequest* other) const { other->_ordered = _ordered; other->_isOrderedSet = _isOrderedSet; - - if (_metadata) { - other->_metadata.reset(new BatchedRequestMetadata()); - _metadata->cloneTo(other->_metadata.get()); - } } std::string BatchedUpdateRequest::toString() const { @@ -302,17 +279,4 @@ bool BatchedUpdateRequest::getOrdered() const { return ordered.getDefault(); } } - -void BatchedUpdateRequest::setMetadata(BatchedRequestMetadata* metadata) { - _metadata.reset(metadata); -} - -bool BatchedUpdateRequest::isMetadataSet() const { - return _metadata.get(); -} - -BatchedRequestMetadata* BatchedUpdateRequest::getMetadata() const { - return _metadata.get(); -} - } // namespace mongo diff --git a/src/mongo/s/write_ops/batched_update_request.h b/src/mongo/s/write_ops/batched_update_request.h index abb2dae533f..791775c2784 100644 --- a/src/mongo/s/write_ops/batched_update_request.h +++ b/src/mongo/s/write_ops/batched_update_request.h @@ -34,7 +34,6 @@ #include "mongo/base/string_data.h" #include "mongo/db/jsobj.h" #include "mongo/db/namespace_string.h" -#include "mongo/s/write_ops/batched_request_metadata.h" #include "mongo/s/write_ops/batched_update_document.h" namespace mongo { @@ -59,7 +58,6 @@ public: static const BSONField<std::vector<BatchedUpdateDocument*>> updates; static const BSONField<BSONObj> writeConcern; static const BSONField<bool> ordered; - static const BSONField<BSONObj> metadata; // // construction / destruction @@ -113,13 +111,6 @@ public: return _shouldBypassValidation; } - /* - * metadata ownership will be transferred to this. - */ - void setMetadata(BatchedRequestMetadata* metadata); - bool isMetadataSet() const; - BatchedRequestMetadata* getMetadata() const; - private: // Convention: (M)andatory, (O)ptional @@ -141,9 +132,6 @@ private: // (O) should document validation be bypassed (default false) bool _shouldBypassValidation; - - // (O) metadata associated with this request for internal use. - std::unique_ptr<BatchedRequestMetadata> _metadata; }; } // namespace mongo diff --git a/src/mongo/s/write_ops/batched_update_request_test.cpp b/src/mongo/s/write_ops/batched_update_request_test.cpp index 4f09044c0fc..a4ce7067e82 100644 --- a/src/mongo/s/write_ops/batched_update_request_test.cpp +++ b/src/mongo/s/write_ops/batched_update_request_test.cpp @@ -50,13 +50,10 @@ TEST(BatchedUpdateRequest, Basic) { << BatchedUpdateDocument::updateExpr(BSON("$set" << BSON("b" << 2))) << BatchedUpdateDocument::multi(false) << BatchedUpdateDocument::upsert(false))); - BSONObj origUpdateRequestObj = - BSON(BatchedUpdateRequest::collName("test") - << BatchedUpdateRequest::updates() << updateArray - << BatchedUpdateRequest::writeConcern(BSON("w" << 1)) - << BatchedUpdateRequest::ordered(true) << BatchedUpdateRequest::metadata() - << BSON("shardVersion" << BSON_ARRAY(Timestamp(1, 2) << OID::gen()) << "ts" - << Timestamp(3, 4) << "t" << 5 << "session" << 0LL)); + BSONObj origUpdateRequestObj = BSON(BatchedUpdateRequest::collName("test") + << BatchedUpdateRequest::updates() << updateArray + << BatchedUpdateRequest::writeConcern(BSON("w" << 1)) + << BatchedUpdateRequest::ordered(true)); string errMsg; BatchedUpdateRequest request; |