diff options
Diffstat (limited to 'src/mongo/s/write_ops/batched_request_metadata.cpp')
-rw-r--r-- | src/mongo/s/write_ops/batched_request_metadata.cpp | 45 |
1 files changed, 14 insertions, 31 deletions
diff --git a/src/mongo/s/write_ops/batched_request_metadata.cpp b/src/mongo/s/write_ops/batched_request_metadata.cpp index a2e21f99e4c..78ecefbb9df 100644 --- a/src/mongo/s/write_ops/batched_request_metadata.cpp +++ b/src/mongo/s/write_ops/batched_request_metadata.cpp @@ -26,6 +26,8 @@ * 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" @@ -55,9 +57,8 @@ BSONObj BatchedRequestMetadata::toBSON() const { if (_isShardNameSet) metadataBuilder << shardName(_shardName); - if (_shardVersion.get()) { - // ChunkVersion wants to be an array. - metadataBuilder.append(shardVersion(), static_cast<BSONArray>(_shardVersion->toBSON())); + if (_shardVersion) { + _shardVersion.get().appendForCommands(&metadataBuilder); } if (_isSessionSet) @@ -80,12 +81,12 @@ bool BatchedRequestMetadata::parseBSON(const BSONObj& source, string* errMsg) { _isShardNameSet = fieldState == FieldParser::FIELD_SET; { - std::unique_ptr<ChunkVersion> tempChunkVersion(new ChunkVersion); - fieldState = FieldParser::extract(source, shardVersion, tempChunkVersion.get(), errMsg); - if (fieldState == FieldParser::FIELD_INVALID) + auto verAndOpTStatus = ChunkVersionAndOpTime::parseFromBSONForCommands(source); + if (!verAndOpTStatus.isOK()) { return false; - if (fieldState == FieldParser::FIELD_SET) - _shardVersion.swap(tempChunkVersion); + } + + _shardVersion = verAndOpTStatus.getValue(); } fieldState = FieldParser::extract(source, session, &_session, errMsg); @@ -113,10 +114,7 @@ string BatchedRequestMetadata::toString() const { void BatchedRequestMetadata::cloneTo(BatchedRequestMetadata* other) const { other->_shardName = _shardName; other->_isShardNameSet = _isShardNameSet; - - if (other->_shardVersion.get()) - _shardVersion->cloneTo(other->_shardVersion.get()); - + other->_shardVersion = _shardVersion; other->_session = _session; other->_isSessionSet = _isSessionSet; } @@ -126,36 +124,21 @@ void BatchedRequestMetadata::setShardName(StringData shardName) { _isShardNameSet = true; } -void BatchedRequestMetadata::unsetShardName() { - _isShardNameSet = false; -} - -bool BatchedRequestMetadata::isShardNameSet() const { - return _isShardNameSet; -} - const string& BatchedRequestMetadata::getShardName() const { dassert(_isShardNameSet); return _shardName; } -void BatchedRequestMetadata::setShardVersion(const ChunkVersion& shardVersion) { - unique_ptr<ChunkVersion> temp(new ChunkVersion); - shardVersion.cloneTo(temp.get()); - _shardVersion.reset(temp.release()); -} - -void BatchedRequestMetadata::unsetShardVersion() { - _shardVersion.reset(); +void BatchedRequestMetadata::setShardVersion(const ChunkVersionAndOpTime& shardVersion) { + _shardVersion = shardVersion; } bool BatchedRequestMetadata::isShardVersionSet() const { - return _shardVersion.get() != NULL; + return _shardVersion.is_initialized(); } const ChunkVersion& BatchedRequestMetadata::getShardVersion() const { - dassert(_shardVersion.get()); - return *_shardVersion; + return _shardVersion.get().getVersion(); } void BatchedRequestMetadata::setSession(long long session) { |