summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/collection_metadata.h
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2019-02-26 08:27:04 -0500
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2019-02-28 07:36:35 -0500
commit851dad7902d6bb8c3ed25f99f565a2e2c8c8bc47 (patch)
tree63db6c7ca09b69e442afda8dc3d86babb5ee19a7 /src/mongo/db/s/collection_metadata.h
parent8b4f0a7893a329b0c0370385180d6a13077a8f22 (diff)
downloadmongo-851dad7902d6bb8c3ed25f99f565a2e2c8c8bc47.tar.gz
SERVER-39495 Only return versioned filtering metadata for cases that actually need to do filtering
Diffstat (limited to 'src/mongo/db/s/collection_metadata.h')
-rw-r--r--src/mongo/db/s/collection_metadata.h110
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 61af4fd8bc5..824787506f4 100644
--- a/src/mongo/db/s/collection_metadata.h
+++ b/src/mongo/db/s/collection_metadata.h
@@ -63,8 +63,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);
@@ -85,6 +84,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.
*/
@@ -96,29 +136,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();
}
/**
@@ -146,7 +174,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);
}
@@ -169,49 +197,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;
};