summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/s/chunk_manager_refresh_bm.cpp12
-rw-r--r--src/mongo/s/chunk_version.h8
-rw-r--r--src/mongo/s/chunk_version_test.cpp23
3 files changed, 29 insertions, 14 deletions
diff --git a/src/mongo/s/chunk_manager_refresh_bm.cpp b/src/mongo/s/chunk_manager_refresh_bm.cpp
index e6e8dde099f..b7a5c7a71da 100644
--- a/src/mongo/s/chunk_manager_refresh_bm.cpp
+++ b/src/mongo/s/chunk_manager_refresh_bm.cpp
@@ -55,14 +55,14 @@ ChunkRange getRangeForChunk(int i, int nChunks) {
}
template <typename ShardSelectorFn>
-auto makeChunkManagerWithShardSelector(int nShards, int nChunks, ShardSelectorFn selectShard) {
+auto makeChunkManagerWithShardSelector(int nShards, uint32_t nChunks, ShardSelectorFn selectShard) {
const auto collEpoch = OID::gen();
const auto collName = NamespaceString("test.foo");
const auto shardKeyPattern = KeyPattern(BSON("_id" << 1));
std::vector<ChunkType> chunks;
chunks.reserve(nChunks);
- for (int i = 0; i < nChunks; ++i) {
+ for (uint32_t i = 0; i < nChunks; ++i) {
chunks.emplace_back(collName,
getRangeForChunk(i, nChunks),
ChunkVersion{i + 1, 0, collEpoch},
@@ -84,11 +84,11 @@ ShardId optimalShardSelector(int i, int nShards, int nChunks) {
return ShardId(str::stream() << "shard" << shardNum);
}
-NOINLINE_DECL auto makeChunkManagerWithPessimalBalancedDistribution(int nShards, int nChunks) {
+NOINLINE_DECL auto makeChunkManagerWithPessimalBalancedDistribution(int nShards, uint32_t nChunks) {
return makeChunkManagerWithShardSelector(nShards, nChunks, pessimalShardSelector);
}
-NOINLINE_DECL auto makeChunkManagerWithOptimalBalancedDistribution(int nShards, int nChunks) {
+NOINLINE_DECL auto makeChunkManagerWithOptimalBalancedDistribution(int nShards, uint32_t nChunks) {
return makeChunkManagerWithShardSelector(nShards, nChunks, optimalShardSelector);
}
@@ -123,7 +123,7 @@ BENCHMARK(BM_IncrementalRefreshOfPessimalBalancedDistribution)->Args({2, 50000})
template <typename ShardSelectorFn>
auto BM_FullBuildOfChunkManager(benchmark::State& state, ShardSelectorFn selectShard) {
const int nShards = state.range(0);
- const int nChunks = state.range(1);
+ const uint32_t nChunks = state.range(1);
const auto collEpoch = OID::gen();
const auto collName = NamespaceString("test.foo");
@@ -131,7 +131,7 @@ auto BM_FullBuildOfChunkManager(benchmark::State& state, ShardSelectorFn selectS
std::vector<ChunkType> chunks;
chunks.reserve(nChunks);
- for (int i = 0; i < nChunks; ++i) {
+ for (uint32_t i = 0; i < nChunks; ++i) {
chunks.emplace_back(collName,
getRangeForChunk(i, nChunks),
ChunkVersion{i + 1, 0, collEpoch},
diff --git a/src/mongo/s/chunk_version.h b/src/mongo/s/chunk_version.h
index 1c5a811b04d..600b5937d02 100644
--- a/src/mongo/s/chunk_version.h
+++ b/src/mongo/s/chunk_version.h
@@ -59,7 +59,7 @@ public:
ChunkVersion() : _combined(0), _epoch(OID()) {}
- ChunkVersion(int major, int minor, const OID& epoch)
+ ChunkVersion(uint32_t major, uint32_t minor, const OID& epoch)
: _combined(static_cast<uint64_t>(minor) | (static_cast<uint64_t>(major) << 32)),
_epoch(epoch) {}
@@ -157,12 +157,12 @@ public:
return _combined > 0;
}
- int majorVersion() const {
+ uint32_t majorVersion() const {
return _combined >> 32;
}
- int minorVersion() const {
- return _combined & 0xFFFF;
+ uint32_t minorVersion() const {
+ return _combined & 0xFFFFFFFF;
}
OID epoch() const {
diff --git a/src/mongo/s/chunk_version_test.cpp b/src/mongo/s/chunk_version_test.cpp
index 4bea7f466bd..e9a17ea3b7b 100644
--- a/src/mongo/s/chunk_version_test.cpp
+++ b/src/mongo/s/chunk_version_test.cpp
@@ -28,6 +28,8 @@
#include "mongo/platform/basic.h"
+#include <limits>
+
#include "mongo/db/jsobj.h"
#include "mongo/s/chunk_version.h"
#include "mongo/unittest/unittest.h"
@@ -35,6 +37,7 @@
namespace mongo {
namespace {
+
TEST(Parsing, EpochIsOptional) {
const OID oid = OID::gen();
bool canParse = false;
@@ -44,16 +47,16 @@ TEST(Parsing, EpochIsOptional) {
ASSERT(canParse);
ASSERT(chunkVersionComplete.epoch().isSet());
ASSERT(chunkVersionComplete.epoch() == oid);
- ASSERT_EQ(2, chunkVersionComplete.majorVersion());
- ASSERT_EQ(3, chunkVersionComplete.minorVersion());
+ ASSERT_EQ(2u, chunkVersionComplete.majorVersion());
+ ASSERT_EQ(3u, chunkVersionComplete.minorVersion());
canParse = false;
ChunkVersion chunkVersionNoEpoch =
ChunkVersion::fromBSON(BSON("lastmod" << Timestamp(Seconds(3), 4)), "lastmod", &canParse);
ASSERT(canParse);
ASSERT(!chunkVersionNoEpoch.epoch().isSet());
- ASSERT_EQ(3, chunkVersionNoEpoch.majorVersion());
- ASSERT_EQ(4, chunkVersionNoEpoch.minorVersion());
+ ASSERT_EQ(3u, chunkVersionNoEpoch.majorVersion());
+ ASSERT_EQ(4u, chunkVersionNoEpoch.minorVersion());
}
TEST(Comparison, StrictEqual) {
@@ -83,5 +86,17 @@ TEST(Comparison, OlderThan) {
ASSERT(!ChunkVersion(3, 1, epoch).isOlderThan(ChunkVersion(3, 1, epoch)));
}
+TEST(ChunkVersionConstruction, CreateWithLargeValues) {
+ const auto minorVersion = std::numeric_limits<uint32_t>::max();
+ const uint32_t majorVersion = 1 << 24;
+ const auto epoch = OID::gen();
+
+ ChunkVersion version(majorVersion, minorVersion, epoch);
+ ASSERT_EQ(majorVersion, version.majorVersion());
+ ASSERT_EQ(minorVersion, version.minorVersion());
+ ASSERT_EQ(epoch, version.epoch());
+}
+
} // unnamed namespace
+
} // namespace mongo