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, 57 insertions, 53 deletions
diff --git a/src/mongo/db/s/collection_metadata.h b/src/mongo/db/s/collection_metadata.h index ae72682ca49..f123af36e26 100644 --- a/src/mongo/db/s/collection_metadata.h +++ b/src/mongo/db/s/collection_metadata.h @@ -64,8 +64,7 @@ public: CollectionMetadata(std::shared_ptr<ChunkManager> cm, const ShardId& thisShardId); /** - * Returns whether this metadata object represents a sharded collection which requires - * filtering. + * Returns whether this metadata object represents a sharded or unsharded collection. */ bool isSharded() const { return bool(_cm); @@ -86,6 +85,47 @@ 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. */ @@ -97,29 +137,17 @@ 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; - /** - * Obtains the shard id with which this collection metadata is configured. - */ - const ShardId& shardId() const { - invariant(isSharded()); - return _thisShardId; - } + // + // Methods used for orphan filtering and general introspection of the chunks owned by the shard + // - /** - * Returns true if 'key' contains exactly the same fields as the shard key pattern. - */ - bool isValidKey(const BSONObj& key) const { + ChunkManager* getChunkManager() const { invariant(isSharded()); - return _cm->getShardKeyPattern().isShardKey(key); + return _cm.get(); } /** @@ -152,7 +180,7 @@ public: /** * Returns true if the argument range overlaps any chunk. */ - bool rangeOverlapsChunk(ChunkRange const& range) const { + bool rangeOverlapsChunk(const ChunkRange& range) const { invariant(isSharded()); return _cm->rangeOverlapsShard(range, _thisShardId); } @@ -175,49 +203,25 @@ public: * * @return orphanRange the output range. Note that the NS is not set. */ - boost::optional<ChunkRange> getNextOrphanRange(RangeMap const& receiveMap, - BSONObj const& lookupKey) const; + boost::optional<ChunkRange> getNextOrphanRange(const RangeMap& receiveMap, + const BSONObj& lookupKey) const; /** * Returns all the chunks which are contained on this shard. */ RangeMap getChunks() 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); - } + /** + * BSON output of the chunks metadata into a BSONArray + */ + void toBSONChunks(BSONArrayBuilder* builder) const; private: - // The full routing table for the collection. + // The full routing table for the collection or nullptr if the collection is not sharded std::shared_ptr<ChunkManager> _cm; - // The identity of this shard, for the purpose of answering "key belongs to me" queries. + // 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. ShardId _thisShardId; }; |
