summaryrefslogtreecommitdiff
path: root/src/mongo/s/chunk.h
diff options
context:
space:
mode:
authorMartin Neupauer <martin.neupauer@10gen.com>2018-04-19 14:04:00 -0400
committerMartin Neupauer <martin.neupauer@mongodb.com>2018-04-23 15:42:36 -0400
commit559910472384b3625fca4d9eca47dd9d165c6958 (patch)
treea11bf817e36e727966449b90688e945921be99cf /src/mongo/s/chunk.h
parent2ca9e55b076d5bd117c44780ed7646b8b772d2d3 (diff)
downloadmongo-559910472384b3625fca4d9eca47dd9d165c6958.tar.gz
SERVER-34100 - Make the Chunk object not expose implementation details of the ChunkManager
Diffstat (limited to 'src/mongo/s/chunk.h')
-rw-r--r--src/mongo/s/chunk.h90
1 files changed, 79 insertions, 11 deletions
diff --git a/src/mongo/s/chunk.h b/src/mongo/s/chunk.h
index c6a6bbec550..34a2e02b57d 100644
--- a/src/mongo/s/chunk.h
+++ b/src/mongo/s/chunk.h
@@ -37,14 +37,11 @@ namespace mongo {
class BSONObj;
/**
- * Represents a cache entry for a single Chunk. Owned by a ChunkManager.
+ * Represents a cache entry for a single Chunk. Owned by a RoutingTableHistory.
*/
-class Chunk {
+class ChunkInfo {
public:
- // Test whether we should split once data * kSplitTestFactor > chunkSize (approximately)
- static const uint64_t kSplitTestFactor = 5;
-
- explicit Chunk(const ChunkType& from);
+ explicit ChunkInfo(const ChunkType& from);
const BSONObj& getMin() const {
return _range.getMin();
@@ -54,11 +51,6 @@ public:
return _range.getMax();
}
- const ShardId& getShardId() const {
- // TODO: SERVER-34100 - consolidate a usage of getShardAt and getShardIdAt
- return getShardIdAt(boost::none);
- }
-
const ShardId& getShardIdAt(const boost::optional<Timestamp>& ts) const;
ChunkVersion getLastmod() const {
@@ -115,4 +107,80 @@ private:
mutable uint64_t _dataWritten;
};
+class Chunk {
+public:
+ // Test whether we should split once data * kSplitTestFactor > chunkSize (approximately)
+ static const uint64_t kSplitTestFactor = 5;
+
+ Chunk(ChunkInfo& chunkInfo, const boost::optional<Timestamp>& atClusterTime)
+ : _chunkInfo(chunkInfo), _atClusterTime(atClusterTime) {}
+
+ const BSONObj& getMin() const {
+ return _chunkInfo.getMin();
+ }
+
+ const BSONObj& getMax() const {
+ return _chunkInfo.getMax();
+ }
+
+ const ShardId& getShardId() const {
+ return _chunkInfo.getShardIdAt(_atClusterTime);
+ }
+
+ ChunkVersion getLastmod() const {
+ return _chunkInfo.getLastmod();
+ }
+
+ const auto& getHistory() const {
+ return _chunkInfo.getHistory();
+ }
+
+ bool isJumbo() const {
+ return _chunkInfo.isJumbo();
+ }
+
+ /**
+ * Returns a string represenation of the chunk for logging.
+ */
+ std::string toString() const {
+ return _chunkInfo.toString();
+ }
+
+ // Returns true if this chunk contains the given shard key, and false otherwise
+ //
+ // Note: this function takes an extracted *key*, not an original document (the point may be
+ // computed by, say, hashing a given field or projecting to a subset of fields).
+ bool containsKey(const BSONObj& shardKey) const {
+ return _chunkInfo.containsKey(shardKey);
+ }
+
+ /**
+ * Get/increment/set the estimation of how much data was written for this chunk.
+ */
+ uint64_t getBytesWritten() const {
+ return _chunkInfo.getBytesWritten();
+ }
+ uint64_t addBytesWritten(uint64_t bytesWrittenIncrement) {
+ return _chunkInfo.addBytesWritten(bytesWrittenIncrement);
+ }
+ void clearBytesWritten() {
+ _chunkInfo.clearBytesWritten();
+ }
+
+ bool shouldSplit(uint64_t desiredChunkSize, bool minIsInf, bool maxIsInf) const {
+ return _chunkInfo.shouldSplit(desiredChunkSize, minIsInf, maxIsInf);
+ }
+
+ /**
+ * Marks this chunk as jumbo. Only moves from false to true once and is used by the balancer.
+ */
+ void markAsJumbo() {
+ _chunkInfo.markAsJumbo();
+ }
+
+private:
+ ChunkInfo& _chunkInfo;
+ const boost::optional<Timestamp> _atClusterTime;
+};
+
} // namespace mongo