summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-04-03 17:39:49 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-04-04 15:44:22 -0400
commit071d0637977ebc815218daa6c3fe32ddd2830435 (patch)
tree53b33c1a674062262aec0dd6e5e12974d56bee44 /src
parent7be0eae950a33d49aaae967db250c265ccdfe463 (diff)
downloadmongo-071d0637977ebc815218daa6c3fe32ddd2830435.tar.gz
SERVER-23484 Move Chunk::genID to ChunkType
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/s/migration_source_manager.cpp9
-rw-r--r--src/mongo/s/catalog/replset/catalog_manager_replica_set_drop_coll_test.cpp2
-rw-r--r--src/mongo/s/catalog/replset/catalog_manager_replica_set_shard_collection_test.cpp24
-rw-r--r--src/mongo/s/catalog/replset/catalog_manager_replica_set_write_retry_test.cpp1
-rw-r--r--src/mongo/s/catalog/type_chunk.cpp13
-rw-r--r--src/mongo/s/catalog/type_chunk.h5
-rw-r--r--src/mongo/s/chunk.cpp15
-rw-r--r--src/mongo/s/chunk.h2
-rw-r--r--src/mongo/s/chunk_manager.cpp7
-rw-r--r--src/mongo/s/chunk_manager.h3
-rw-r--r--src/mongo/s/commands/cluster_move_chunk_cmd.cpp4
-rw-r--r--src/mongo/s/d_merge.cpp5
-rw-r--r--src/mongo/s/d_split.cpp4
13 files changed, 48 insertions, 46 deletions
diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp
index 71d407fc182..1619efa9af8 100644
--- a/src/mongo/db/s/migration_source_manager.cpp
+++ b/src/mongo/db/s/migration_source_manager.cpp
@@ -42,7 +42,6 @@
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/s/sharding_state_recovery.h"
#include "mongo/s/catalog/type_chunk.h"
-#include "mongo/s/chunk.h"
#include "mongo/s/grid.h"
#include "mongo/s/shard_key_pattern.h"
#include "mongo/s/stale_exception.h"
@@ -307,7 +306,7 @@ Status MigrationSourceManager::commitDonateChunk(OperationContext* txn) {
op.append("ns", ChunkType::ConfigNS);
BSONObjBuilder n(op.subobjStart("o"));
- n.append(ChunkType::name(), Chunk::genID(_args.getNss().ns(), _args.getMinKey()));
+ n.append(ChunkType::name(), ChunkType::genID(_args.getNss().ns(), _args.getMinKey()));
_uncommittedMetadata->getCollVersion().addToBSON(n, ChunkType::DEPRECATED_lastmod());
n.append(ChunkType::ns(), _args.getNss().ns());
n.append(ChunkType::min(), _args.getMinKey());
@@ -316,7 +315,7 @@ Status MigrationSourceManager::commitDonateChunk(OperationContext* txn) {
n.done();
BSONObjBuilder q(op.subobjStart("o2"));
- q.append(ChunkType::name(), Chunk::genID(_args.getNss().ns(), _args.getMinKey()));
+ q.append(ChunkType::name(), ChunkType::genID(_args.getNss().ns(), _args.getMinKey()));
q.done();
updates.append(op.obj());
@@ -348,7 +347,7 @@ Status MigrationSourceManager::commitDonateChunk(OperationContext* txn) {
op.append("ns", ChunkType::ConfigNS);
BSONObjBuilder n(op.subobjStart("o"));
- n.append(ChunkType::name(), Chunk::genID(_args.getNss().ns(), bumpMin));
+ n.append(ChunkType::name(), ChunkType::genID(_args.getNss().ns(), bumpMin));
nextVersion.addToBSON(n, ChunkType::DEPRECATED_lastmod());
n.append(ChunkType::ns(), _args.getNss().ns());
n.append(ChunkType::min(), bumpMin);
@@ -357,7 +356,7 @@ Status MigrationSourceManager::commitDonateChunk(OperationContext* txn) {
n.done();
BSONObjBuilder q(op.subobjStart("o2"));
- q.append(ChunkType::name(), Chunk::genID(_args.getNss().ns(), bumpMin));
+ q.append(ChunkType::name(), ChunkType::genID(_args.getNss().ns(), bumpMin));
q.done();
updates.append(op.obj());
diff --git a/src/mongo/s/catalog/replset/catalog_manager_replica_set_drop_coll_test.cpp b/src/mongo/s/catalog/replset/catalog_manager_replica_set_drop_coll_test.cpp
index 8b04214038c..ab49bad9a13 100644
--- a/src/mongo/s/catalog/replset/catalog_manager_replica_set_drop_coll_test.cpp
+++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set_drop_coll_test.cpp
@@ -41,7 +41,7 @@
#include "mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.h"
#include "mongo/s/catalog/type_collection.h"
#include "mongo/s/catalog/type_shard.h"
-#include "mongo/s/chunk.h"
+#include "mongo/s/chunk_version.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/write_ops/batched_update_request.h"
#include "mongo/stdx/chrono.h"
diff --git a/src/mongo/s/catalog/replset/catalog_manager_replica_set_shard_collection_test.cpp b/src/mongo/s/catalog/replset/catalog_manager_replica_set_shard_collection_test.cpp
index c63767ec0c3..2873b1f2a35 100644
--- a/src/mongo/s/catalog/replset/catalog_manager_replica_set_shard_collection_test.cpp
+++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set_shard_collection_test.cpp
@@ -50,8 +50,8 @@
#include "mongo/s/catalog/type_collection.h"
#include "mongo/s/catalog/type_database.h"
#include "mongo/s/catalog/type_shard.h"
-#include "mongo/s/chunk.h"
#include "mongo/s/client/shard_registry.h"
+#include "mongo/s/chunk.h"
#include "mongo/s/grid.h"
#include "mongo/s/shard_key_pattern.h"
#include "mongo/s/write_ops/batched_command_request.h"
@@ -307,7 +307,7 @@ TEST_F(ShardCollectionTest, noInitialChunksOrData) {
ShardKeyPattern keyPattern(BSON("_id" << 1));
ChunkType expectedChunk;
- expectedChunk.setName(Chunk::genID(ns, keyPattern.getKeyPattern().globalMin()));
+ expectedChunk.setName(ChunkType::genID(ns, keyPattern.getKeyPattern().globalMin()));
expectedChunk.setNS(ns);
expectedChunk.setMin(keyPattern.getKeyPattern().globalMin());
expectedChunk.setMax(keyPattern.getKeyPattern().globalMax());
@@ -442,7 +442,7 @@ TEST_F(ShardCollectionTest, withInitialChunks) {
expectedChunk0.setShard(shard0.getName());
expectedChunk0.setMin(keyPattern.getKeyPattern().globalMin());
expectedChunk0.setMax(splitPoint0);
- expectedChunk0.setName(Chunk::genID(ns, expectedChunk0.getMin()));
+ expectedChunk0.setName(ChunkType::genID(ns, expectedChunk0.getMin()));
expectedChunk0.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -451,7 +451,7 @@ TEST_F(ShardCollectionTest, withInitialChunks) {
expectedChunk1.setShard(shard1.getName());
expectedChunk1.setMin(splitPoint0);
expectedChunk1.setMax(splitPoint1);
- expectedChunk1.setName(Chunk::genID(ns, expectedChunk1.getMin()));
+ expectedChunk1.setName(ChunkType::genID(ns, expectedChunk1.getMin()));
expectedChunk1.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -460,7 +460,7 @@ TEST_F(ShardCollectionTest, withInitialChunks) {
expectedChunk2.setShard(shard2.getName());
expectedChunk2.setMin(splitPoint1);
expectedChunk2.setMax(splitPoint2);
- expectedChunk2.setName(Chunk::genID(ns, expectedChunk2.getMin()));
+ expectedChunk2.setName(ChunkType::genID(ns, expectedChunk2.getMin()));
expectedChunk2.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -469,7 +469,7 @@ TEST_F(ShardCollectionTest, withInitialChunks) {
expectedChunk3.setShard(shard0.getName());
expectedChunk3.setMin(splitPoint2);
expectedChunk3.setMax(splitPoint3);
- expectedChunk3.setName(Chunk::genID(ns, expectedChunk3.getMin()));
+ expectedChunk3.setName(ChunkType::genID(ns, expectedChunk3.getMin()));
expectedChunk3.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -478,7 +478,7 @@ TEST_F(ShardCollectionTest, withInitialChunks) {
expectedChunk4.setShard(shard1.getName());
expectedChunk4.setMin(splitPoint3);
expectedChunk4.setMax(keyPattern.getKeyPattern().globalMax());
- expectedChunk4.setName(Chunk::genID(ns, expectedChunk4.getMin()));
+ expectedChunk4.setName(ChunkType::genID(ns, expectedChunk4.getMin()));
expectedChunk4.setVersion(expectedVersion);
vector<ChunkType> expectedChunks{
@@ -597,7 +597,7 @@ TEST_F(ShardCollectionTest, withInitialData) {
expectedChunk0.setShard(shard.getName());
expectedChunk0.setMin(keyPattern.getKeyPattern().globalMin());
expectedChunk0.setMax(splitPoint0);
- expectedChunk0.setName(Chunk::genID(ns, expectedChunk0.getMin()));
+ expectedChunk0.setName(ChunkType::genID(ns, expectedChunk0.getMin()));
expectedChunk0.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -606,7 +606,7 @@ TEST_F(ShardCollectionTest, withInitialData) {
expectedChunk1.setShard(shard.getName());
expectedChunk1.setMin(splitPoint0);
expectedChunk1.setMax(splitPoint1);
- expectedChunk1.setName(Chunk::genID(ns, expectedChunk1.getMin()));
+ expectedChunk1.setName(ChunkType::genID(ns, expectedChunk1.getMin()));
expectedChunk1.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -615,7 +615,7 @@ TEST_F(ShardCollectionTest, withInitialData) {
expectedChunk2.setShard(shard.getName());
expectedChunk2.setMin(splitPoint1);
expectedChunk2.setMax(splitPoint2);
- expectedChunk2.setName(Chunk::genID(ns, expectedChunk2.getMin()));
+ expectedChunk2.setName(ChunkType::genID(ns, expectedChunk2.getMin()));
expectedChunk2.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -624,7 +624,7 @@ TEST_F(ShardCollectionTest, withInitialData) {
expectedChunk3.setShard(shard.getName());
expectedChunk3.setMin(splitPoint2);
expectedChunk3.setMax(splitPoint3);
- expectedChunk3.setName(Chunk::genID(ns, expectedChunk3.getMin()));
+ expectedChunk3.setName(ChunkType::genID(ns, expectedChunk3.getMin()));
expectedChunk3.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -633,7 +633,7 @@ TEST_F(ShardCollectionTest, withInitialData) {
expectedChunk4.setShard(shard.getName());
expectedChunk4.setMin(splitPoint3);
expectedChunk4.setMax(keyPattern.getKeyPattern().globalMax());
- expectedChunk4.setName(Chunk::genID(ns, expectedChunk4.getMin()));
+ expectedChunk4.setName(ChunkType::genID(ns, expectedChunk4.getMin()));
expectedChunk4.setVersion(expectedVersion);
vector<ChunkType> expectedChunks{
diff --git a/src/mongo/s/catalog/replset/catalog_manager_replica_set_write_retry_test.cpp b/src/mongo/s/catalog/replset/catalog_manager_replica_set_write_retry_test.cpp
index 205fe8ca3cd..f41aaf08c68 100644
--- a/src/mongo/s/catalog/replset/catalog_manager_replica_set_write_retry_test.cpp
+++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set_write_retry_test.cpp
@@ -50,7 +50,6 @@
#include "mongo/s/catalog/type_collection.h"
#include "mongo/s/catalog/type_database.h"
#include "mongo/s/catalog/type_shard.h"
-#include "mongo/s/chunk.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
#include "mongo/s/write_ops/batched_command_request.h"
diff --git a/src/mongo/s/catalog/type_chunk.cpp b/src/mongo/s/catalog/type_chunk.cpp
index aea8197acb5..5805642803f 100644
--- a/src/mongo/s/catalog/type_chunk.cpp
+++ b/src/mongo/s/catalog/type_chunk.cpp
@@ -117,6 +117,19 @@ StatusWith<ChunkType> ChunkType::fromBSON(const BSONObj& source) {
return chunk;
}
+std::string ChunkType::genID(StringData ns, const BSONObj& o) {
+ StringBuilder buf;
+ buf << ns << "-";
+
+ BSONObjIterator i(o);
+ while (i.more()) {
+ BSONElement e = i.next();
+ buf << e.fieldName() << "_" << e.toString(false, true);
+ }
+
+ return buf.str();
+}
+
Status ChunkType::validate() const {
if (!_name.is_initialized() || _name->empty()) {
return Status(ErrorCodes::NoSuchKey,
diff --git a/src/mongo/s/catalog/type_chunk.h b/src/mongo/s/catalog/type_chunk.h
index 7690d141917..a13cda9aed9 100644
--- a/src/mongo/s/catalog/type_chunk.h
+++ b/src/mongo/s/catalog/type_chunk.h
@@ -68,6 +68,11 @@ public:
static StatusWith<ChunkType> fromBSON(const BSONObj& source);
/**
+ * Generates chunk id based on the namespace name and the lower bound of the chunk.
+ */
+ static std::string genID(StringData ns, const BSONObj& min);
+
+ /**
* Returns OK if all fields have been set. Otherwise returns NoSuchKey
* and information about the first field that is missing.
*/
diff --git a/src/mongo/s/chunk.cpp b/src/mongo/s/chunk.cpp
index a824ab0b80a..3d62387e3b9 100644
--- a/src/mongo/s/chunk.cpp
+++ b/src/mongo/s/chunk.cpp
@@ -629,19 +629,6 @@ bool Chunk::operator==(const Chunk& s) const {
return _min.woCompare(s._min) == 0 && _max.woCompare(s._max) == 0;
}
-string Chunk::genID(const string& ns, const BSONObj& o) {
- StringBuilder buf;
- buf << ns << "-";
-
- BSONObjIterator i(o);
- while (i.more()) {
- BSONElement e = i.next();
- buf << e.fieldName() << "_" << e.toString(false, true);
- }
-
- return buf.str();
-}
-
string Chunk::toString() const {
stringstream ss;
ss << ChunkType::ns() << ": " << _manager->getns() << ", " << ChunkType::shard() << ": "
@@ -656,7 +643,7 @@ void Chunk::markAsJumbo(OperationContext* txn) const {
// at least this mongos won't try and keep moving
_jumbo = true;
- const string chunkName = genID(_manager->getns(), _min);
+ const string chunkName = ChunkType::genID(_manager->getns(), _min);
auto status =
grid.catalogManager(txn)->updateConfigDocument(txn,
diff --git a/src/mongo/s/chunk.h b/src/mongo/s/chunk.h
index 711de24b44b..83668968604 100644
--- a/src/mongo/s/chunk.h
+++ b/src/mongo/s/chunk.h
@@ -88,8 +88,6 @@ public:
// to a subset of fields).
bool containsKey(const BSONObj& shardKey) const;
- static std::string genID(const std::string& ns, const BSONObj& min);
-
//
// chunk version support
//
diff --git a/src/mongo/s/chunk_manager.cpp b/src/mongo/s/chunk_manager.cpp
index 0d6cd212273..2b1f9eef85d 100644
--- a/src/mongo/s/chunk_manager.cpp
+++ b/src/mongo/s/chunk_manager.cpp
@@ -420,7 +420,7 @@ Status ChunkManager::createFirstChunks(OperationContext* txn,
i < splitPoints.size() ? splitPoints[i] : _keyPattern.getKeyPattern().globalMax();
ChunkType chunk;
- chunk.setName(Chunk::genID(_ns, min));
+ chunk.setName(ChunkType::genID(_ns, min));
chunk.setNS(_ns);
chunk.setMin(min);
chunk.setMax(max);
@@ -444,10 +444,11 @@ Status ChunkManager::createFirstChunks(OperationContext* txn,
return Status::OK();
}
-ChunkPtr ChunkManager::findIntersectingChunk(OperationContext* txn, const BSONObj& shardKey) const {
+shared_ptr<Chunk> ChunkManager::findIntersectingChunk(OperationContext* txn,
+ const BSONObj& shardKey) const {
{
BSONObj chunkMin;
- ChunkPtr chunk;
+ shared_ptr<Chunk> chunk;
{
ChunkMap::const_iterator it = _chunkMap.upper_bound(shardKey);
if (it != _chunkMap.end()) {
diff --git a/src/mongo/s/chunk_manager.h b/src/mongo/s/chunk_manager.h
index a861e386585..28b755aa419 100644
--- a/src/mongo/s/chunk_manager.h
+++ b/src/mongo/s/chunk_manager.h
@@ -194,7 +194,8 @@ public:
* when the shard key is {a : "hashed"}, you can call
* findIntersectingChunk() on {a : hash("foo") }
*/
- ChunkPtr findIntersectingChunk(OperationContext* txn, const BSONObj& shardKey) const;
+ std::shared_ptr<Chunk> findIntersectingChunk(OperationContext* txn,
+ const BSONObj& shardKey) const;
void getShardIdsForQuery(OperationContext* txn,
const BSONObj& query,
diff --git a/src/mongo/s/commands/cluster_move_chunk_cmd.cpp b/src/mongo/s/commands/cluster_move_chunk_cmd.cpp
index 6cca0081281..afd761294f6 100644
--- a/src/mongo/s/commands/cluster_move_chunk_cmd.cpp
+++ b/src/mongo/s/commands/cluster_move_chunk_cmd.cpp
@@ -161,8 +161,8 @@ public:
}
// This refreshes the chunk metadata if stale.
- ChunkManagerPtr info = config->getChunkManager(txn, nss.ns(), true);
- ChunkPtr chunk;
+ shared_ptr<ChunkManager> info = config->getChunkManager(txn, nss.ns(), true);
+ shared_ptr<Chunk> chunk;
if (!find.isEmpty()) {
StatusWith<BSONObj> status = info->getShardKeyPattern().extractShardKeyFromQuery(find);
diff --git a/src/mongo/s/d_merge.cpp b/src/mongo/s/d_merge.cpp
index 6d3e4235cf2..b7d8e73efdf 100644
--- a/src/mongo/s/d_merge.cpp
+++ b/src/mongo/s/d_merge.cpp
@@ -40,7 +40,6 @@
#include "mongo/db/s/sharding_state.h"
#include "mongo/s/catalog/catalog_manager.h"
#include "mongo/s/catalog/type_chunk.h"
-#include "mongo/s/chunk.h"
#include "mongo/s/config.h"
#include "mongo/s/grid.h"
#include "mongo/util/log.h"
@@ -341,7 +340,7 @@ Status runApplyOpsCmd(OperationContext* txn,
// Fill in details not tracked by metadata
ChunkType mergedChunk(firstChunk);
- mergedChunk.setName(Chunk::genID(firstChunk.getNS(), firstChunk.getMin()));
+ mergedChunk.setName(ChunkType::genID(firstChunk.getNS(), firstChunk.getMin()));
mergedChunk.setMax(chunksToMerge.back().getMax());
mergedChunk.setVersion(newMergedVersion);
@@ -350,7 +349,7 @@ Status runApplyOpsCmd(OperationContext* txn,
// Don't remove chunk we're expanding
for (size_t i = 1; i < chunksToMerge.size(); ++i) {
ChunkType chunkToMerge(chunksToMerge[i]);
- chunkToMerge.setName(Chunk::genID(chunkToMerge.getNS(), chunkToMerge.getMin()));
+ chunkToMerge.setName(ChunkType::genID(chunkToMerge.getNS(), chunkToMerge.getMin()));
updatesB.append(buildOpRemoveChunk(chunkToMerge));
}
diff --git a/src/mongo/s/d_split.cpp b/src/mongo/s/d_split.cpp
index ecf12ebb4c7..311057b8269 100644
--- a/src/mongo/s/d_split.cpp
+++ b/src/mongo/s/d_split.cpp
@@ -774,7 +774,7 @@ public:
// add the modified (new) chunk information as the update object
BSONObjBuilder n(op.subobjStart("o"));
- n.append(ChunkType::name(), Chunk::genID(nss.ns(), startKey));
+ n.append(ChunkType::name(), ChunkType::genID(nss.ns(), startKey));
nextChunkVersion.addToBSON(n, ChunkType::DEPRECATED_lastmod());
n.append(ChunkType::ns(), nss.ns());
n.append(ChunkType::min(), startKey);
@@ -784,7 +784,7 @@ public:
// add the chunk's _id as the query part of the update statement
BSONObjBuilder q(op.subobjStart("o2"));
- q.append(ChunkType::name(), Chunk::genID(nss.ns(), startKey));
+ q.append(ChunkType::name(), ChunkType::genID(nss.ns(), startKey));
q.done();
updates.append(op.obj());