summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/collection_metadata.cpp
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@mongodb.com>2017-06-28 16:52:56 -0400
committerAndy Schwerin <schwerin@mongodb.com>2017-07-12 15:25:22 -0400
commit4b9d69eb00361083ce835d42c4107a4caa52f6fc (patch)
tree4cbdb8f69dbe7b8333f6c5ddf05afe662dcae413 /src/mongo/db/s/collection_metadata.cpp
parent4c15828d7bd7222fbcb5dc5b3c2060ea2c136dc7 (diff)
downloadmongo-4b9d69eb00361083ce835d42c4107a4caa52f6fc.tar.gz
SERVER-29817 Move construction of CollectionMetadata data structures out of ShardingState.
Diffstat (limited to 'src/mongo/db/s/collection_metadata.cpp')
-rw-r--r--src/mongo/db/s/collection_metadata.cpp43
1 files changed, 22 insertions, 21 deletions
diff --git a/src/mongo/db/s/collection_metadata.cpp b/src/mongo/db/s/collection_metadata.cpp
index 9813a45275b..6c05e401661 100644
--- a/src/mongo/db/s/collection_metadata.cpp
+++ b/src/mongo/db/s/collection_metadata.cpp
@@ -41,20 +41,22 @@
namespace mongo {
-CollectionMetadata::CollectionMetadata(const BSONObj& keyPattern,
- ChunkVersion collectionVersion,
- ChunkVersion shardVersion,
- RangeMap shardChunksMap)
- : _shardKeyPattern(keyPattern),
- _collVersion(collectionVersion),
- _shardVersion(shardVersion),
- _chunksMap(std::move(shardChunksMap)),
+CollectionMetadata::CollectionMetadata(std::shared_ptr<ChunkManager> cm, const ShardId& thisShardId)
+ : _cm(cm),
+ _thisShardId(thisShardId),
+ _shardVersion(_cm->getVersion(thisShardId)),
+ _chunksMap(SimpleBSONObjComparator::kInstance.makeBSONObjIndexedMap<CachedChunkInfo>()),
_rangesMap(SimpleBSONObjComparator::kInstance.makeBSONObjIndexedMap<CachedChunkInfo>()) {
- invariant(_shardKeyPattern.isValid());
- invariant(_collVersion.epoch() == _shardVersion.epoch());
- invariant(_collVersion.isSet());
- invariant(_collVersion >= _shardVersion);
+ invariant(_cm->getVersion().isSet());
+ invariant(_cm->getVersion() >= _shardVersion);
+
+ for (const auto& chunk : _cm->chunks()) {
+ if (chunk->getShardId() != _thisShardId)
+ continue;
+
+ _chunksMap.emplace(chunk->getMin(), CachedChunkInfo(chunk->getMax(), chunk->getLastmod()));
+ }
if (_chunksMap.empty()) {
invariant(!_shardVersion.isSet());
@@ -104,8 +106,7 @@ void CollectionMetadata::_buildRangesMap() {
}
std::unique_ptr<CollectionMetadata> CollectionMetadata::clone() const {
- return stdx::make_unique<CollectionMetadata>(
- _shardKeyPattern.toBSON(), getCollVersion(), getShardVersion(), getChunks());
+ return stdx::make_unique<CollectionMetadata>(_cm, _thisShardId);
}
bool CollectionMetadata::keyBelongsToMe(const BSONObj& key) const {
@@ -193,9 +194,9 @@ bool CollectionMetadata::rangeOverlapsChunk(ChunkRange const& range) {
}
void CollectionMetadata::toBSONBasic(BSONObjBuilder& bb) const {
- _collVersion.addToBSON(bb, "collVersion");
+ _cm->getVersion().addToBSON(bb, "collVersion");
_shardVersion.addToBSON(bb, "shardVersion");
- bb.append("keyPattern", _shardKeyPattern.toBSON());
+ bb.append("keyPattern", _cm->getShardKeyPattern().toBSON());
}
void CollectionMetadata::toBSONChunks(BSONArrayBuilder& bb) const {
@@ -211,7 +212,7 @@ void CollectionMetadata::toBSONChunks(BSONArrayBuilder& bb) const {
}
std::string CollectionMetadata::toStringBasic() const {
- return str::stream() << "collection version: " << _collVersion.toString()
+ return str::stream() << "collection version: " << _cm->getVersion().toString()
<< ", shard version: " << _shardVersion.toString();
}
@@ -253,7 +254,7 @@ boost::optional<KeyRange> CollectionMetadata::getNextOrphanRange(
}
boost::optional<KeyRange> range =
- KeyRange("", getMinKey(), maxKey, _shardKeyPattern.toBSON());
+ KeyRange("", getMinKey(), maxKey, _cm->getShardKeyPattern().toBSON());
auto patchArgRange = [&range](RangeMap const& map, Its its) {
// We know that the lookup key is not covered by a chunk or pending range, and where the
@@ -278,15 +279,15 @@ boost::optional<KeyRange> CollectionMetadata::getNextOrphanRange(
}
BSONObj CollectionMetadata::getMinKey() const {
- return _shardKeyPattern.getKeyPattern().globalMin();
+ return _cm->getShardKeyPattern().getKeyPattern().globalMin();
}
BSONObj CollectionMetadata::getMaxKey() const {
- return _shardKeyPattern.getKeyPattern().globalMax();
+ return _cm->getShardKeyPattern().getKeyPattern().globalMax();
}
bool CollectionMetadata::isValidKey(const BSONObj& key) const {
- return _shardKeyPattern.isShardKey(key);
+ return _cm->getShardKeyPattern().isShardKey(key);
}
} // namespace mongo