summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/s/collection_metadata_test.cpp1
-rw-r--r--src/mongo/db/s/merge_chunks_command.cpp2
-rw-r--r--src/mongo/db/s/metadata_loader_test.cpp2
-rw-r--r--src/mongo/s/catalog/replset/catalog_manager_replica_set_shard_collection_test.cpp11
-rw-r--r--src/mongo/s/catalog/replset/catalog_manager_replica_set_test.cpp8
-rw-r--r--src/mongo/s/catalog/type_chunk.cpp25
-rw-r--r--src/mongo/s/catalog/type_chunk.h7
-rw-r--r--src/mongo/s/catalog/type_chunk_test.cpp10
-rw-r--r--src/mongo/s/chunk.cpp39
-rw-r--r--src/mongo/s/chunk_manager.cpp1
-rw-r--r--src/mongo/s/commands/cluster_move_chunk_cmd.cpp1
-rw-r--r--src/mongo/s/commands/cluster_shard_collection_cmd.cpp1
12 files changed, 34 insertions, 74 deletions
diff --git a/src/mongo/db/s/collection_metadata_test.cpp b/src/mongo/db/s/collection_metadata_test.cpp
index d2570607712..c831bc42581 100644
--- a/src/mongo/db/s/collection_metadata_test.cpp
+++ b/src/mongo/db/s/collection_metadata_test.cpp
@@ -71,7 +71,6 @@ protected:
chunkType.setMin(BSON("a" << MINKEY));
chunkType.setMax(BSON("a" << MAXKEY));
chunkType.setVersion(ChunkVersion(1, 0, epoch));
- chunkType.setName(OID::gen().toString());
ASSERT_OK(chunkType.validate());
std::vector<BSONObj> chunksToSend{chunkType.toBSON()};
diff --git a/src/mongo/db/s/merge_chunks_command.cpp b/src/mongo/db/s/merge_chunks_command.cpp
index b65d0931149..612bf92616c 100644
--- a/src/mongo/db/s/merge_chunks_command.cpp
+++ b/src/mongo/db/s/merge_chunks_command.cpp
@@ -131,7 +131,6 @@ Status runApplyOpsCmd(OperationContext* txn,
// Fill in details not tracked by metadata
ChunkType mergedChunk(firstChunk);
- mergedChunk.setName(ChunkType::genID(firstChunk.getNS(), firstChunk.getMin()));
mergedChunk.setMax(chunksToMerge.back().getMax());
mergedChunk.setVersion(newMergedVersion);
@@ -140,7 +139,6 @@ 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(ChunkType::genID(chunkToMerge.getNS(), chunkToMerge.getMin()));
updatesB.append(buildOpRemoveChunk(chunkToMerge));
}
diff --git a/src/mongo/db/s/metadata_loader_test.cpp b/src/mongo/db/s/metadata_loader_test.cpp
index df53618da4c..c0756a8f29b 100644
--- a/src/mongo/db/s/metadata_loader_test.cpp
+++ b/src/mongo/db/s/metadata_loader_test.cpp
@@ -103,7 +103,6 @@ protected:
for (const auto chunkVal : chunks.vector()) {
ChunkType chunk(*chunkVal);
- chunk.setName(OID::gen().toString());
if (!chunk.isVersionSet()) {
chunk.setVersion(version);
version.incMajor();
@@ -280,7 +279,6 @@ TEST_F(MetadataLoaderFixture, CheckNumChunk) {
chunkType.setMin(BSON("a" << MINKEY));
chunkType.setMax(BSON("a" << MAXKEY));
chunkType.setVersion(ChunkVersion(1, 0, epoch));
- chunkType.setName(OID::gen().toString());
ASSERT(chunkType.validate().isOK());
auto future = launchAsync([this] {
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 46a8d19ece5..db161d6b36e 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
@@ -306,7 +306,6 @@ TEST_F(ShardCollectionTest, noInitialChunksOrData) {
ShardKeyPattern keyPattern(BSON("_id" << 1));
ChunkType expectedChunk;
- expectedChunk.setName(ChunkType::genID(ns, keyPattern.getKeyPattern().globalMin()));
expectedChunk.setNS(ns);
expectedChunk.setMin(keyPattern.getKeyPattern().globalMin());
expectedChunk.setMax(keyPattern.getKeyPattern().globalMax());
@@ -441,7 +440,6 @@ TEST_F(ShardCollectionTest, withInitialChunks) {
expectedChunk0.setShard(shard0.getName());
expectedChunk0.setMin(keyPattern.getKeyPattern().globalMin());
expectedChunk0.setMax(splitPoint0);
- expectedChunk0.setName(ChunkType::genID(ns, expectedChunk0.getMin()));
expectedChunk0.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -450,7 +448,6 @@ TEST_F(ShardCollectionTest, withInitialChunks) {
expectedChunk1.setShard(shard1.getName());
expectedChunk1.setMin(splitPoint0);
expectedChunk1.setMax(splitPoint1);
- expectedChunk1.setName(ChunkType::genID(ns, expectedChunk1.getMin()));
expectedChunk1.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -459,7 +456,6 @@ TEST_F(ShardCollectionTest, withInitialChunks) {
expectedChunk2.setShard(shard2.getName());
expectedChunk2.setMin(splitPoint1);
expectedChunk2.setMax(splitPoint2);
- expectedChunk2.setName(ChunkType::genID(ns, expectedChunk2.getMin()));
expectedChunk2.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -468,7 +464,6 @@ TEST_F(ShardCollectionTest, withInitialChunks) {
expectedChunk3.setShard(shard0.getName());
expectedChunk3.setMin(splitPoint2);
expectedChunk3.setMax(splitPoint3);
- expectedChunk3.setName(ChunkType::genID(ns, expectedChunk3.getMin()));
expectedChunk3.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -477,7 +472,6 @@ TEST_F(ShardCollectionTest, withInitialChunks) {
expectedChunk4.setShard(shard1.getName());
expectedChunk4.setMin(splitPoint3);
expectedChunk4.setMax(keyPattern.getKeyPattern().globalMax());
- expectedChunk4.setName(ChunkType::genID(ns, expectedChunk4.getMin()));
expectedChunk4.setVersion(expectedVersion);
vector<ChunkType> expectedChunks{
@@ -596,7 +590,6 @@ TEST_F(ShardCollectionTest, withInitialData) {
expectedChunk0.setShard(shard.getName());
expectedChunk0.setMin(keyPattern.getKeyPattern().globalMin());
expectedChunk0.setMax(splitPoint0);
- expectedChunk0.setName(ChunkType::genID(ns, expectedChunk0.getMin()));
expectedChunk0.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -605,7 +598,6 @@ TEST_F(ShardCollectionTest, withInitialData) {
expectedChunk1.setShard(shard.getName());
expectedChunk1.setMin(splitPoint0);
expectedChunk1.setMax(splitPoint1);
- expectedChunk1.setName(ChunkType::genID(ns, expectedChunk1.getMin()));
expectedChunk1.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -614,7 +606,6 @@ TEST_F(ShardCollectionTest, withInitialData) {
expectedChunk2.setShard(shard.getName());
expectedChunk2.setMin(splitPoint1);
expectedChunk2.setMax(splitPoint2);
- expectedChunk2.setName(ChunkType::genID(ns, expectedChunk2.getMin()));
expectedChunk2.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -623,7 +614,6 @@ TEST_F(ShardCollectionTest, withInitialData) {
expectedChunk3.setShard(shard.getName());
expectedChunk3.setMin(splitPoint2);
expectedChunk3.setMax(splitPoint3);
- expectedChunk3.setName(ChunkType::genID(ns, expectedChunk3.getMin()));
expectedChunk3.setVersion(expectedVersion);
expectedVersion.incMinor();
@@ -632,7 +622,6 @@ TEST_F(ShardCollectionTest, withInitialData) {
expectedChunk4.setShard(shard.getName());
expectedChunk4.setMin(splitPoint3);
expectedChunk4.setMax(keyPattern.getKeyPattern().globalMax());
- 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_test.cpp b/src/mongo/s/catalog/replset/catalog_manager_replica_set_test.cpp
index 8ed21d44952..c539ee6ad5d 100644
--- a/src/mongo/s/catalog/replset/catalog_manager_replica_set_test.cpp
+++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set_test.cpp
@@ -449,7 +449,6 @@ TEST_F(CatalogManagerReplSetTest, GetChunksForNSWithSortAndLimit) {
OID oid = OID::gen();
ChunkType chunkA;
- chunkA.setName("chunk0000");
chunkA.setNS("TestDB.TestColl");
chunkA.setMin(BSON("a" << 1));
chunkA.setMax(BSON("a" << 100));
@@ -457,7 +456,6 @@ TEST_F(CatalogManagerReplSetTest, GetChunksForNSWithSortAndLimit) {
chunkA.setShard("shard0000");
ChunkType chunkB;
- chunkB.setName("chunk0001");
chunkB.setNS("TestDB.TestColl");
chunkB.setMin(BSON("a" << 100));
chunkB.setMax(BSON("a" << 200));
@@ -579,7 +577,6 @@ TEST_F(CatalogManagerReplSetTest, GetChunksForNSInvalidChunk) {
onFindCommand([&chunksQuery](const RemoteCommandRequest& request) {
ChunkType chunkA;
- chunkA.setName("chunk0000");
chunkA.setNS("TestDB.TestColl");
chunkA.setMin(BSON("a" << 1));
chunkA.setMax(BSON("a" << 100));
@@ -587,7 +584,6 @@ TEST_F(CatalogManagerReplSetTest, GetChunksForNSInvalidChunk) {
chunkA.setShard("shard0000");
ChunkType chunkB;
- chunkB.setName("chunk0001");
chunkB.setNS("TestDB.TestColl");
chunkB.setMin(BSON("a" << 100));
chunkB.setMax(BSON("a" << 200));
@@ -1176,7 +1172,6 @@ TEST_F(CatalogManagerReplSetTest, GetTagForChunkOneTagFound) {
configTargeter()->setFindHostReturnValue(HostAndPort("TestHost1"));
ChunkType chunk;
- chunk.setName("chunk0000");
chunk.setNS("test.coll");
chunk.setMin(BSON("a" << 1));
chunk.setMax(BSON("a" << 100));
@@ -1221,7 +1216,6 @@ TEST_F(CatalogManagerReplSetTest, GetTagForChunkNoTagFound) {
configTargeter()->setFindHostReturnValue(HostAndPort("TestHost1"));
ChunkType chunk;
- chunk.setName("chunk0000");
chunk.setNS("test.coll");
chunk.setMin(BSON("a" << 1));
chunk.setMax(BSON("a" << 100));
@@ -1260,7 +1254,6 @@ TEST_F(CatalogManagerReplSetTest, GetTagForChunkInvalidTagDoc) {
configTargeter()->setFindHostReturnValue(HostAndPort("TestHost1"));
ChunkType chunk;
- chunk.setName("chunk0000");
chunk.setNS("test.coll");
chunk.setMin(BSON("a" << 1));
chunk.setMax(BSON("a" << 100));
@@ -1438,7 +1431,6 @@ TEST_F(CatalogManagerReplSetTest, ApplyChunkOpsDeprecatedSuccessfulWithCheck) {
onFindCommand([this](const RemoteCommandRequest& request) {
OID oid = OID::gen();
ChunkType chunk;
- chunk.setName("chunk0000");
chunk.setNS("TestDB.TestColl");
chunk.setMin(BSON("a" << 1));
chunk.setMax(BSON("a" << 100));
diff --git a/src/mongo/s/catalog/type_chunk.cpp b/src/mongo/s/catalog/type_chunk.cpp
index b9dba9b53cb..55e7020fa01 100644
--- a/src/mongo/s/catalog/type_chunk.cpp
+++ b/src/mongo/s/catalog/type_chunk.cpp
@@ -109,14 +109,6 @@ StatusWith<ChunkType> ChunkType::fromBSON(const BSONObj& source) {
ChunkType chunk;
{
- std::string chunkName;
- Status status = bsonExtractStringField(source, name.name(), &chunkName);
- if (!status.isOK())
- return status;
- chunk._name = chunkName;
- }
-
- {
std::string chunkNS;
Status status = bsonExtractStringField(source, ns.name(), &chunkNS);
if (!status.isOK())
@@ -179,11 +171,6 @@ std::string ChunkType::genID(StringData ns, const BSONObj& o) {
}
Status ChunkType::validate() const {
- if (!_name.is_initialized() || _name->empty()) {
- return Status(ErrorCodes::NoSuchKey,
- str::stream() << "missing " << name.name() << " field");
- }
-
if (!_ns.is_initialized() || _ns->empty()) {
return Status(ErrorCodes::NoSuchKey, str::stream() << "missing " << ns.name() << " field");
}
@@ -233,7 +220,7 @@ Status ChunkType::validate() const {
BSONObj ChunkType::toBSON() const {
BSONObjBuilder builder;
- if (_name)
+ if (_ns && _min)
builder.append(name.name(), getName());
if (_ns)
builder.append(ns.name(), getNS());
@@ -243,9 +230,8 @@ BSONObj ChunkType::toBSON() const {
builder.append(max.name(), getMax());
if (_shard)
builder.append(shard.name(), getShard());
- if (_version) {
+ if (_version)
_version->appendForChunk(&builder);
- }
if (_jumbo)
builder.append(jumbo.name(), getJumbo());
@@ -256,9 +242,10 @@ std::string ChunkType::toString() const {
return toBSON().toString();
}
-void ChunkType::setName(const std::string& name) {
- invariant(!name.empty());
- _name = name;
+std::string ChunkType::getName() const {
+ invariant(_ns);
+ invariant(_min);
+ return genID(*_ns, *_min);
}
void ChunkType::setNS(const std::string& ns) {
diff --git a/src/mongo/s/catalog/type_chunk.h b/src/mongo/s/catalog/type_chunk.h
index fbf8e31e654..e731ed0ab43 100644
--- a/src/mongo/s/catalog/type_chunk.h
+++ b/src/mongo/s/catalog/type_chunk.h
@@ -126,10 +126,7 @@ public:
*/
std::string toString() const;
- const std::string& getName() const {
- return _name.get();
- }
- void setName(const std::string& name);
+ std::string getName() const;
const std::string& getNS() const {
return _ns.get();
@@ -167,8 +164,6 @@ public:
private:
// Convention: (M)andatory, (O)ptional, (S)pecial rule.
- // (M) chunk's id
- boost::optional<std::string> _name;
// (M) collection this chunk is in
boost::optional<std::string> _ns;
// (M) first key of the range, inclusive
diff --git a/src/mongo/s/catalog/type_chunk_test.cpp b/src/mongo/s/catalog/type_chunk_test.cpp
index ffd357c1adc..cd4bbb4b1d4 100644
--- a/src/mongo/s/catalog/type_chunk_test.cpp
+++ b/src/mongo/s/catalog/type_chunk_test.cpp
@@ -53,14 +53,6 @@ TEST(ChunkType, MissingRequiredFields) {
StatusWith<ChunkType> chunkRes = ChunkType::fromBSON(objModNS);
ASSERT_FALSE(chunkRes.isOK());
- BSONObj objModName =
- BSON(ChunkType::ns("test.mycol") << ChunkType::min(BSON("a" << 10 << "b" << 10))
- << ChunkType::max(BSON("a" << 20)) << "lastmod"
- << Timestamp(chunkVersion.toLong()) << "lastmodEpoch"
- << chunkVersion.epoch() << ChunkType::shard("shard0001"));
- chunkRes = ChunkType::fromBSON(objModName);
- ASSERT_FALSE(chunkRes.isOK());
-
BSONObj objModKeys =
BSON(ChunkType::name("test.mycol-a_MinKey")
<< ChunkType::ns("test.mycol") << "lastmod" << Timestamp(chunkVersion.toLong())
@@ -124,7 +116,6 @@ TEST(ChunkType, CorrectContents) {
ASSERT_OK(chunkRes.getStatus());
ChunkType chunk = chunkRes.getValue();
- ASSERT_EQUALS(chunk.getName(), "test.mycol-a_MinKey");
ASSERT_EQUALS(chunk.getNS(), "test.mycol");
ASSERT_EQUALS(chunk.getMin(), BSON("a" << 10));
ASSERT_EQUALS(chunk.getMax(), BSON("a" << 20));
@@ -144,7 +135,6 @@ TEST(ChunkType, Pre22Format) {
<< "shard0001")));
ASSERT_OK(chunk.validate());
- ASSERT_EQUALS(chunk.getName(), "test.mycol-a_MinKey");
ASSERT_EQUALS(chunk.getNS(), "test.mycol");
ASSERT_EQUALS(chunk.getMin(), BSON("a" << 10));
ASSERT_EQUALS(chunk.getMax(), BSON("a" << 20));
diff --git a/src/mongo/s/chunk.cpp b/src/mongo/s/chunk.cpp
index f3d53346825..5e81999afe7 100644
--- a/src/mongo/s/chunk.cpp
+++ b/src/mongo/s/chunk.cpp
@@ -44,6 +44,7 @@
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
#include "mongo/s/shard_util.h"
+#include "mongo/s/sharding_raii.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -299,7 +300,7 @@ bool Chunk::splitIfShould(OperationContext* txn, long dataWritten) {
try {
_dataWritten += dataWritten;
- uint64_t splitThreshold = getManager()->getCurrentDesiredChunkSize();
+ uint64_t splitThreshold = _manager->getCurrentDesiredChunkSize();
if (_minIsInf() || _maxIsInf()) {
splitThreshold = static_cast<uint64_t>((double)splitThreshold * 0.9);
}
@@ -308,12 +309,12 @@ bool Chunk::splitIfShould(OperationContext* txn, long dataWritten) {
return false;
}
- if (!getManager()->_splitHeuristics._splitTickets.tryAcquire()) {
- LOG(1) << "won't auto split because not enough tickets: " << getManager()->getns();
+ if (!_manager->_splitHeuristics._splitTickets.tryAcquire()) {
+ LOG(1) << "won't auto split because not enough tickets: " << _manager->getns();
return false;
}
- TicketHolderReleaser releaser(&(getManager()->_splitHeuristics._splitTickets));
+ TicketHolderReleaser releaser(&(_manager->_splitHeuristics._splitTickets));
LOG(1) << "about to initiate autosplit: " << *this << " dataWritten: " << _dataWritten
<< " splitThreshold: " << splitThreshold;
@@ -335,13 +336,15 @@ bool Chunk::splitIfShould(OperationContext* txn, long dataWritten) {
_dataWritten = 0;
}
- Status refreshStatus = Grid::get(txn)->getBalancerConfiguration()->refreshAndCheck(txn);
+ const auto balancerConfig = Grid::get(txn)->getBalancerConfiguration();
+
+ Status refreshStatus = balancerConfig->refreshAndCheck(txn);
if (!refreshStatus.isOK()) {
warning() << "Unable to refresh balancer settings" << causedBy(refreshStatus);
return false;
}
- bool shouldBalance = Grid::get(txn)->getBalancerConfiguration()->isBalancerActive();
+ bool shouldBalance = balancerConfig->isBalancerActive();
if (shouldBalance) {
auto collStatus = grid.catalogManager(txn)->getCollection(txn, _manager->getns());
if (!collStatus.isOK()) {
@@ -365,14 +368,26 @@ bool Chunk::splitIfShould(OperationContext* txn, long dataWritten) {
// spot from staying on a single shard. This is based on the assumption that succeeding
// inserts will fall on the top chunk.
if (suggestedMigrateChunk && shouldBalance) {
+ const NamespaceString nss(_manager->getns());
+
+ // We need to use the latest chunk manager (after the split) in order to have the most
+ // up-to-date view of the chunk we are about to move
+ auto scopedCM = uassertStatusOK(ScopedChunkManager::getExisting(txn, nss));
+ auto suggestedChunk =
+ scopedCM.cm()->findIntersectingChunk(txn, suggestedMigrateChunk->getMin());
+
ChunkType chunkToMove;
- chunkToMove.setNS(_manager->getns());
- chunkToMove.setShard(getShardId());
- chunkToMove.setMin(suggestedMigrateChunk->getMin());
- chunkToMove.setMax(suggestedMigrateChunk->getMax());
+ chunkToMove.setNS(nss.ns());
+ chunkToMove.setShard(suggestedChunk->getShardId());
+ chunkToMove.setMin(suggestedChunk->getMin());
+ chunkToMove.setMax(suggestedChunk->getMax());
+ chunkToMove.setVersion(suggestedChunk->getLastmod());
+
+ Status rebalanceStatus = Balancer::get(txn)->rebalanceSingleChunk(txn, chunkToMove);
+ if (!rebalanceStatus.isOK()) {
+ msgassertedNoTraceWithStatus(10412, rebalanceStatus);
+ }
- msgassertedNoTraceWithStatus(
- 10412, Balancer::get(txn)->rebalanceSingleChunk(txn, chunkToMove));
_manager->reload(txn);
}
diff --git a/src/mongo/s/chunk_manager.cpp b/src/mongo/s/chunk_manager.cpp
index 862d5cd1ade..8c6cba6033c 100644
--- a/src/mongo/s/chunk_manager.cpp
+++ b/src/mongo/s/chunk_manager.cpp
@@ -421,7 +421,6 @@ Status ChunkManager::createFirstChunks(OperationContext* txn,
i < splitPoints.size() ? splitPoints[i] : _keyPattern.getKeyPattern().globalMax();
ChunkType chunk;
- chunk.setName(ChunkType::genID(_ns, min));
chunk.setNS(_ns);
chunk.setMin(min);
chunk.setMax(max);
diff --git a/src/mongo/s/commands/cluster_move_chunk_cmd.cpp b/src/mongo/s/commands/cluster_move_chunk_cmd.cpp
index d853f68a244..ca08547f300 100644
--- a/src/mongo/s/commands/cluster_move_chunk_cmd.cpp
+++ b/src/mongo/s/commands/cluster_move_chunk_cmd.cpp
@@ -222,7 +222,6 @@ public:
{
ChunkType chunkType;
chunkType.setNS(nss.ns());
- chunkType.setName(ChunkType::genID(nss.ns(), chunk->getMin()));
chunkType.setMin(chunk->getMin());
chunkType.setMax(chunk->getMax());
chunkType.setShard(chunk->getShardId());
diff --git a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp
index 6eddee0f17c..faf63593d58 100644
--- a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp
+++ b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp
@@ -441,7 +441,6 @@ public:
ChunkType chunkType;
chunkType.setNS(nss.ns());
- chunkType.setName(ChunkType::genID(nss.ns(), chunk->getMin()));
chunkType.setMin(chunk->getMin());
chunkType.setMax(chunk->getMax());
chunkType.setShard(chunk->getShardId());