diff options
author | Esha Maharishi <esha.maharishi@mongodb.com> | 2016-06-16 01:04:29 -0400 |
---|---|---|
committer | Esha Maharishi <esha.maharishi@mongodb.com> | 2016-07-14 16:32:10 -0400 |
commit | 2ea2c7700d9ccca1150e49c181c97b948889df5e (patch) | |
tree | 1e8d89f6506ea1a7fee2a172d7138e866dd1c111 /src/mongo/s/catalog/type_shard.cpp | |
parent | af5daa51506541d9526ce576f2432809003d2432 (diff) | |
download | mongo-2ea2c7700d9ccca1150e49c181c97b948889df5e.tar.gz |
SERVER-22660 OpObserver on config server for inserts to config.shards from old mongos
Diffstat (limited to 'src/mongo/s/catalog/type_shard.cpp')
-rw-r--r-- | src/mongo/s/catalog/type_shard.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/mongo/s/catalog/type_shard.cpp b/src/mongo/s/catalog/type_shard.cpp index ca01ec8ec2f..0b97a3d3cd6 100644 --- a/src/mongo/s/catalog/type_shard.cpp +++ b/src/mongo/s/catalog/type_shard.cpp @@ -34,6 +34,7 @@ #include "mongo/bson/bsonobj.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/bson/util/bson_extract.h" +#include "mongo/s/grid.h" #include "mongo/util/assert_util.h" #include "mongo/util/mongoutils/str.h" @@ -46,7 +47,7 @@ const BSONField<std::string> ShardType::host("host"); const BSONField<bool> ShardType::draining("draining"); const BSONField<long long> ShardType::maxSizeMB("maxSize"); const BSONField<BSONArray> ShardType::tags("tags"); - +const BSONField<ShardType::ShardState> ShardType::state("state"); StatusWith<ShardType> ShardType::fromBSON(const BSONObj& source) { ShardType shard; @@ -112,6 +113,27 @@ StatusWith<ShardType> ShardType::fromBSON(const BSONObj& source) { } } + { + long long shardState; + Status status = bsonExtractIntegerField(source, state.name(), &shardState); + if (status.isOK()) { + // Make sure the state field falls within the valid range of ShardState values. + if (!(shardState >= static_cast<std::underlying_type<ShardState>::type>( + ShardState::kNotShardAware) && + shardState <= static_cast<std::underlying_type<ShardState>::type>( + ShardState::kShardAware))) { + return Status(ErrorCodes::BadValue, + str::stream() << "Invalid shard state value: " << shardState); + } else { + shard._state = static_cast<ShardState>(shardState); + } + } else if (status == ErrorCodes::NoSuchKey) { + // state field can be mssing in which case it is presumed kNotShardAware + } else { + return status; + } + } + return shard; } @@ -146,6 +168,8 @@ BSONObj ShardType::toBSON() const { builder.append(maxSizeMB(), getMaxSizeMB()); if (_tags) builder.append(tags(), getTags()); + if (_state) + builder.append(state(), static_cast<std::underlying_type<ShardState>::type>(getState())); return builder.obj(); } @@ -176,5 +200,9 @@ void ShardType::setTags(const std::vector<std::string>& tags) { invariant(tags.size() > 0); _tags = tags; } +void ShardType::setState(const ShardState state) { + invariant(!_state.is_initialized()); + _state = state; +} } // namespace mongo |