diff options
author | Nathan Myers <nathan.myers@10gen.com> | 2017-04-18 17:46:55 -0400 |
---|---|---|
committer | Nathan Myers <nathan.myers@10gen.com> | 2017-04-20 01:31:00 -0400 |
commit | c192a1b9b1e223f8075ab5ce72dde372467f9650 (patch) | |
tree | df2fad3682c5fce44a7f91d9a216cd912017e38b /src/mongo/s/catalog/type_chunk.cpp | |
parent | 53907c0094e26e39b813ae369be52a4e51fc3a08 (diff) | |
download | mongo-c192a1b9b1e223f8075ab5ce72dde372467f9650.tar.gz |
SERVER-27921 New Range Deleter
Diffstat (limited to 'src/mongo/s/catalog/type_chunk.cpp')
-rw-r--r-- | src/mongo/s/catalog/type_chunk.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/mongo/s/catalog/type_chunk.cpp b/src/mongo/s/catalog/type_chunk.cpp index a114f86a681..eb286b7a631 100644 --- a/src/mongo/s/catalog/type_chunk.cpp +++ b/src/mongo/s/catalog/type_chunk.cpp @@ -133,6 +133,28 @@ bool ChunkRange::operator!=(const ChunkRange& other) const { return !(*this == other); } +bool ChunkRange::covers(ChunkRange const& other) const { + auto le = [](auto const& a, auto const& b) { return a.woCompare(b) <= 0; }; + return le(_minKey, other._minKey) && le(other._maxKey, _maxKey); +} + +boost::optional<ChunkRange> ChunkRange::overlapWith(ChunkRange const& other) const { + auto le = [](auto const& a, auto const& b) { return a.woCompare(b) <= 0; }; + if (le(other._maxKey, _minKey) || le(_maxKey, other._minKey)) { + return boost::none; + } + return ChunkRange(le(_minKey, other._minKey) ? other._minKey : _minKey, + le(_maxKey, other._maxKey) ? _maxKey : other._maxKey); +} + +ChunkRange ChunkRange::unionWith(ChunkRange const& other) const { + auto le = [](auto const& a, auto const& b) { return a.woCompare(b) <= 0; }; + return ChunkRange(le(_minKey, other._minKey) ? _minKey : other._minKey, + le(_maxKey, other._maxKey) ? other._maxKey : _maxKey); +} + +// ChunkType + ChunkType::ChunkType() = default; ChunkType::ChunkType(NamespaceString nss, ChunkRange range, ChunkVersion version, ShardId shardId) |