summaryrefslogtreecommitdiff
path: root/src/mongo/s/chunk_diff.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/chunk_diff.h')
-rw-r--r--src/mongo/s/chunk_diff.h164
1 files changed, 84 insertions, 80 deletions
diff --git a/src/mongo/s/chunk_diff.h b/src/mongo/s/chunk_diff.h
index 9a67583a53b..00d713addd5 100644
--- a/src/mongo/s/chunk_diff.h
+++ b/src/mongo/s/chunk_diff.h
@@ -35,104 +35,108 @@
namespace mongo {
- class ChunkType;
- struct ChunkVersion;
- class CatalogManager;
- class Query;
+class ChunkType;
+struct ChunkVersion;
+class CatalogManager;
+class Query;
- /**
- * This class manages and applies diffs from partial config server data reloads. Because the
- * config data can be large, we want to update it in small parts, not all-at-once. Once a
- * ConfigDiffTracker is created, the current config data is *attached* to it, and it is then
- * able to modify the data.
- *
- * The current form is templated b/c the overall algorithm is identical between mongos and
- * mongod, but the actual chunk maps used differ in implementation. We don't want to copy the
- * implementation, because the logic is identical, or the chunk data, because that would be
- * slow for big clusters, so this is the alternative for now.
- *
- * TODO: Standardize between mongos and mongod and convert template parameters to types.
- */
- template <class ValType, class ShardType>
- class ConfigDiffTracker {
- public:
- // Stores ranges indexed by max or min key
- typedef typename std::map<BSONObj, ValType, BSONObjCmp> RangeMap;
+/**
+ * This class manages and applies diffs from partial config server data reloads. Because the
+ * config data can be large, we want to update it in small parts, not all-at-once. Once a
+ * ConfigDiffTracker is created, the current config data is *attached* to it, and it is then
+ * able to modify the data.
+ *
+ * The current form is templated b/c the overall algorithm is identical between mongos and
+ * mongod, but the actual chunk maps used differ in implementation. We don't want to copy the
+ * implementation, because the logic is identical, or the chunk data, because that would be
+ * slow for big clusters, so this is the alternative for now.
+ *
+ * TODO: Standardize between mongos and mongod and convert template parameters to types.
+ */
+template <class ValType, class ShardType>
+class ConfigDiffTracker {
+public:
+ // Stores ranges indexed by max or min key
+ typedef typename std::map<BSONObj, ValType, BSONObjCmp> RangeMap;
- // Pair of iterators defining a subset of ranges
- typedef typename std::pair<typename RangeMap::iterator,
- typename RangeMap::iterator> RangeOverlap;
+ // Pair of iterators defining a subset of ranges
+ typedef
+ typename std::pair<typename RangeMap::iterator, typename RangeMap::iterator> RangeOverlap;
- // Map of shard identifiers to the maximum chunk version on that shard
- typedef typename std::map<ShardType, ChunkVersion> MaxChunkVersionMap;
+ // Map of shard identifiers to the maximum chunk version on that shard
+ typedef typename std::map<ShardType, ChunkVersion> MaxChunkVersionMap;
- ConfigDiffTracker();
- virtual ~ConfigDiffTracker();
+ ConfigDiffTracker();
+ virtual ~ConfigDiffTracker();
- /**
- * The tracker attaches to a set of ranges with versions, and uses a config server
- * connection to update these. Because the set of ranges and versions may be large, they
- * aren't owned by the tracker, they're just passed in and updated. Therefore they must all
- * stay in scope while the tracker is working.
- *
- * TODO: Make a standard VersionedRange to encapsulate this info in both mongod and mongos?
- */
- void attach(const std::string& ns,
- RangeMap& currMap,
- ChunkVersion& maxVersion,
- MaxChunkVersionMap& maxShardVersions);
+ /**
+ * The tracker attaches to a set of ranges with versions, and uses a config server
+ * connection to update these. Because the set of ranges and versions may be large, they
+ * aren't owned by the tracker, they're just passed in and updated. Therefore they must all
+ * stay in scope while the tracker is working.
+ *
+ * TODO: Make a standard VersionedRange to encapsulate this info in both mongod and mongos?
+ */
+ void attach(const std::string& ns,
+ RangeMap& currMap,
+ ChunkVersion& maxVersion,
+ MaxChunkVersionMap& maxShardVersions);
- // Call after load for more information
- int numValidDiffs() const { return _validDiffs; }
+ // Call after load for more information
+ int numValidDiffs() const {
+ return _validDiffs;
+ }
- // Whether or not a range exists in the min/max region
- bool isOverlapping(const BSONObj& min, const BSONObj& max);
+ // Whether or not a range exists in the min/max region
+ bool isOverlapping(const BSONObj& min, const BSONObj& max);
- // Removes all ranges in the region from min/max
- void removeOverlapping(const BSONObj& min, const BSONObj& max);
+ // Removes all ranges in the region from min/max
+ void removeOverlapping(const BSONObj& min, const BSONObj& max);
- // Returns a subset of ranges overlapping the region min/max
- RangeOverlap overlappingRange(const BSONObj& min, const BSONObj& max);
+ // Returns a subset of ranges overlapping the region min/max
+ RangeOverlap overlappingRange(const BSONObj& min, const BSONObj& max);
- // Finds and applies the changes to a collection from the config servers via
- // the catalog manager.
- // Also includes minor version changes for particular major-version chunks if explicitly
- // specified.
- // Returns the number of diffs processed, or -1 if the diffs were inconsistent
- // Throws a DBException on connection errors
- int calculateConfigDiff(CatalogManager* catalogManager);
+ // Finds and applies the changes to a collection from the config servers via
+ // the catalog manager.
+ // Also includes minor version changes for particular major-version chunks if explicitly
+ // specified.
+ // Returns the number of diffs processed, or -1 if the diffs were inconsistent
+ // Throws a DBException on connection errors
+ int calculateConfigDiff(CatalogManager* catalogManager);
- // Applies changes to the config data from a vector of chunks passed in
- // Returns the number of diffs processed, or -1 if the diffs were inconsistent
- // Throws a DBException on connection errors
- int calculateConfigDiff(const std::vector<ChunkType>& chunks);
+ // Applies changes to the config data from a vector of chunks passed in
+ // Returns the number of diffs processed, or -1 if the diffs were inconsistent
+ // Throws a DBException on connection errors
+ int calculateConfigDiff(const std::vector<ChunkType>& chunks);
- // Returns the query needed to find new changes to a collection from the config server
- // Needed only if a custom connection is required to the config server
- Query configDiffQuery() const;
+ // Returns the query needed to find new changes to a collection from the config server
+ // Needed only if a custom connection is required to the config server
+ Query configDiffQuery() const;
- protected:
- // Determines which chunks are actually being remembered by our RangeMap
- virtual bool isTracked(const ChunkType& chunk) const = 0;
+protected:
+ // Determines which chunks are actually being remembered by our RangeMap
+ virtual bool isTracked(const ChunkType& chunk) const = 0;
- // Whether or not our RangeMap uses min or max keys
- virtual bool isMinKeyIndexed() const { return true; }
+ // Whether or not our RangeMap uses min or max keys
+ virtual bool isMinKeyIndexed() const {
+ return true;
+ }
- virtual std::pair<BSONObj, ValType> rangeFor(const ChunkType& chunk) const = 0;
+ virtual std::pair<BSONObj, ValType> rangeFor(const ChunkType& chunk) const = 0;
- virtual ShardType shardFor(const std::string& name) const = 0;
+ virtual ShardType shardFor(const std::string& name) const = 0;
- private:
- void _assertAttached() const;
+private:
+ void _assertAttached() const;
- std::string _ns;
- RangeMap* _currMap;
- ChunkVersion* _maxVersion;
- MaxChunkVersionMap* _maxShardVersions;
+ std::string _ns;
+ RangeMap* _currMap;
+ ChunkVersion* _maxVersion;
+ MaxChunkVersionMap* _maxShardVersions;
- // Store for later use
- int _validDiffs;
- };
+ // Store for later use
+ int _validDiffs;
+};
-} // namespace mongo
+} // namespace mongo