diff options
Diffstat (limited to 'src/mongo/db/s/collection_metadata.h')
| -rw-r--r-- | src/mongo/db/s/collection_metadata.h | 110 |
1 files changed, 53 insertions, 57 deletions
diff --git a/src/mongo/db/s/collection_metadata.h b/src/mongo/db/s/collection_metadata.h index f123af36e26..ae72682ca49 100644 --- a/src/mongo/db/s/collection_metadata.h +++ b/src/mongo/db/s/collection_metadata.h @@ -64,7 +64,8 @@ public: CollectionMetadata(std::shared_ptr<ChunkManager> cm, const ShardId& thisShardId); /** - * Returns whether this metadata object represents a sharded or unsharded collection. + * Returns whether this metadata object represents a sharded collection which requires + * filtering. */ bool isSharded() const { return bool(_cm); @@ -85,47 +86,6 @@ public: } /** - * Obtains the shard id with which this collection metadata is configured. - */ - const ShardId& shardId() const { - invariant(isSharded()); - return _thisShardId; - } - - /** - * Returns true if 'key' contains exactly the same fields as the shard key pattern. - */ - bool isValidKey(const BSONObj& key) const { - invariant(isSharded()); - return _cm->getShardKeyPattern().isShardKey(key); - } - - const BSONObj& getKeyPattern() const { - invariant(isSharded()); - return _cm->getShardKeyPattern().toBSON(); - } - - const std::vector<std::unique_ptr<FieldRef>>& getKeyPatternFields() const { - invariant(isSharded()); - return _cm->getShardKeyPattern().getKeyPatternFields(); - } - - BSONObj getMinKey() const { - invariant(isSharded()); - return _cm->getShardKeyPattern().getKeyPattern().globalMin(); - } - - BSONObj getMaxKey() const { - invariant(isSharded()); - return _cm->getShardKeyPattern().getKeyPattern().globalMax(); - } - - bool uuidMatches(UUID uuid) const { - invariant(isSharded()); - return _cm->uuidMatches(uuid); - } - - /** * Returns just the shard key fields, if the collection is sharded, and the _id field, from * `doc`. Does not alter any field values (e.g. by hashing); values are copied verbatim. */ @@ -137,17 +97,29 @@ public: void toBSONBasic(BSONObjBuilder& bb) const; /** + * BSON output of the chunks metadata into a BSONArray + */ + void toBSONChunks(BSONArrayBuilder& bb) const; + + /** * String output of the collection and shard versions. */ std::string toStringBasic() const; - // - // Methods used for orphan filtering and general introspection of the chunks owned by the shard - // + /** + * Obtains the shard id with which this collection metadata is configured. + */ + const ShardId& shardId() const { + invariant(isSharded()); + return _thisShardId; + } - ChunkManager* getChunkManager() const { + /** + * Returns true if 'key' contains exactly the same fields as the shard key pattern. + */ + bool isValidKey(const BSONObj& key) const { invariant(isSharded()); - return _cm.get(); + return _cm->getShardKeyPattern().isShardKey(key); } /** @@ -180,7 +152,7 @@ public: /** * Returns true if the argument range overlaps any chunk. */ - bool rangeOverlapsChunk(const ChunkRange& range) const { + bool rangeOverlapsChunk(ChunkRange const& range) const { invariant(isSharded()); return _cm->rangeOverlapsShard(range, _thisShardId); } @@ -203,25 +175,49 @@ public: * * @return orphanRange the output range. Note that the NS is not set. */ - boost::optional<ChunkRange> getNextOrphanRange(const RangeMap& receiveMap, - const BSONObj& lookupKey) const; + boost::optional<ChunkRange> getNextOrphanRange(RangeMap const& receiveMap, + BSONObj const& lookupKey) const; /** * Returns all the chunks which are contained on this shard. */ RangeMap getChunks() const; - /** - * BSON output of the chunks metadata into a BSONArray - */ - void toBSONChunks(BSONArrayBuilder* builder) const; + const BSONObj& getKeyPattern() const { + invariant(isSharded()); + return _cm->getShardKeyPattern().toBSON(); + } + + const std::vector<std::unique_ptr<FieldRef>>& getKeyPatternFields() const { + invariant(isSharded()); + return _cm->getShardKeyPattern().getKeyPatternFields(); + } + + BSONObj getMinKey() const { + invariant(isSharded()); + return _cm->getShardKeyPattern().getKeyPattern().globalMin(); + } + + BSONObj getMaxKey() const { + invariant(isSharded()); + return _cm->getShardKeyPattern().getKeyPattern().globalMax(); + } + + std::shared_ptr<ChunkManager> getChunkManager() const { + invariant(isSharded()); + return _cm; + } + + bool uuidMatches(UUID uuid) const { + invariant(isSharded()); + return _cm->uuidMatches(uuid); + } private: - // The full routing table for the collection or nullptr if the collection is not sharded + // The full routing table for the collection. std::shared_ptr<ChunkManager> _cm; - // The identity of this shard, for the purpose of answering "key belongs to me" queries. If the - // collection is not sharded (_cm is nullptr), then this value will be empty. + // The identity of this shard, for the purpose of answering "key belongs to me" queries. ShardId _thisShardId; }; |
