summaryrefslogtreecommitdiff
path: root/src/mongo/db/s
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-03-12 17:27:34 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-03-12 17:27:34 -0400
commit8125c55a251805899552d0af4776930216223703 (patch)
tree3e1a43aa762a2136422b4fa66f70ee89222d29a1 /src/mongo/db/s
parentae2518adace4ba7ed6a16eba6943bff6ea4ade10 (diff)
downloadmongo-8125c55a251805899552d0af4776930216223703.tar.gz
Revert "SERVER-22611 Sharding catalog cache refactor"
This reverts commit ae2518adace4ba7ed6a16eba6943bff6ea4ade10.
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r--src/mongo/db/s/balancer/balancer.cpp20
-rw-r--r--src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp51
-rw-r--r--src/mongo/db/s/balancer/migration_manager.cpp26
-rw-r--r--src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp1
-rw-r--r--src/mongo/db/s/split_vector_command.cpp1
5 files changed, 49 insertions, 50 deletions
diff --git a/src/mongo/db/s/balancer/balancer.cpp b/src/mongo/db/s/balancer/balancer.cpp
index b85f08b7189..60a765cf5d6 100644
--- a/src/mongo/db/s/balancer/balancer.cpp
+++ b/src/mongo/db/s/balancer/balancer.cpp
@@ -46,11 +46,12 @@
#include "mongo/s/balancer_configuration.h"
#include "mongo/s/catalog/sharding_catalog_client.h"
#include "mongo/s/catalog/type_chunk.h"
-#include "mongo/s/catalog_cache.h"
+#include "mongo/s/client/shard.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/cluster_identity_loader.h"
#include "mongo/s/grid.h"
#include "mongo/s/shard_util.h"
+#include "mongo/s/sharding_raii.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
@@ -533,20 +534,18 @@ Status Balancer::_enforceTagRanges(OperationContext* opCtx) {
}
for (const auto& splitInfo : chunksToSplitStatus.getValue()) {
- auto routingInfoStatus =
- Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(
- opCtx, splitInfo.nss);
- if (!routingInfoStatus.isOK()) {
- return routingInfoStatus.getStatus();
+ auto scopedCMStatus = ScopedChunkManager::refreshAndGet(opCtx, splitInfo.nss);
+ if (!scopedCMStatus.isOK()) {
+ return scopedCMStatus.getStatus();
}
- auto cm = routingInfoStatus.getValue().cm();
+ const auto& scopedCM = scopedCMStatus.getValue();
auto splitStatus =
shardutil::splitChunkAtMultiplePoints(opCtx,
splitInfo.shardId,
splitInfo.nss,
- cm->getShardKeyPattern(),
+ scopedCM.cm()->getShardKeyPattern(),
splitInfo.collectionVersion,
ChunkRange(splitInfo.minKey, splitInfo.maxKey),
splitInfo.splitKeys);
@@ -614,9 +613,8 @@ int Balancer::_moveChunks(OperationContext* opCtx,
void Balancer::_splitOrMarkJumbo(OperationContext* opCtx,
const NamespaceString& nss,
const BSONObj& minKey) {
- auto routingInfo = uassertStatusOK(
- Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(opCtx, nss));
- const auto cm = routingInfo.cm().get();
+ auto scopedCM = uassertStatusOK(ScopedChunkManager::refreshAndGet(opCtx, nss));
+ const auto cm = scopedCM.cm().get();
auto chunk = cm->findIntersectingChunkWithSimpleCollation(minKey);
diff --git a/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp b/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp
index 2fe6ce10746..a4574dfc676 100644
--- a/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp
+++ b/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp
@@ -43,6 +43,7 @@
#include "mongo/s/catalog/type_tags.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/grid.h"
+#include "mongo/s/sharding_raii.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
@@ -71,7 +72,7 @@ StatusWith<DistributionStatus> createCollectionDistributionStatus(
shardToChunksMap[stat.shardId];
}
- for (const auto& entry : chunkMgr->chunkMap()) {
+ for (const auto& entry : chunkMgr->getChunkMap()) {
const auto& chunkEntry = entry.second;
ChunkType chunk;
@@ -298,16 +299,17 @@ BalancerChunkSelectionPolicyImpl::selectSpecificChunkToMove(OperationContext* op
return shardStatsStatus.getStatus();
}
- auto& shardStats = std::move(shardStatsStatus.getValue());
+ const auto shardStats = std::move(shardStatsStatus.getValue());
+
+ const NamespaceString nss(chunk.getNS());
- auto routingInfoStatus =
- Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(opCtx,
- chunk.getNS());
- if (!routingInfoStatus.isOK()) {
- return routingInfoStatus.getStatus();
+ auto scopedCMStatus = ScopedChunkManager::refreshAndGet(opCtx, nss);
+ if (!scopedCMStatus.isOK()) {
+ return scopedCMStatus.getStatus();
}
- const auto cm = routingInfoStatus.getValue().cm().get();
+ const auto& scopedCM = scopedCMStatus.getValue();
+ const auto cm = scopedCM.cm().get();
const auto collInfoStatus = createCollectionDistributionStatus(opCtx, shardStats, cm);
if (!collInfoStatus.isOK()) {
@@ -329,14 +331,15 @@ Status BalancerChunkSelectionPolicyImpl::checkMoveAllowed(OperationContext* opCt
auto shardStats = std::move(shardStatsStatus.getValue());
- auto routingInfoStatus =
- Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(opCtx,
- chunk.getNS());
- if (!routingInfoStatus.isOK()) {
- return routingInfoStatus.getStatus();
+ const NamespaceString nss(chunk.getNS());
+
+ auto scopedCMStatus = ScopedChunkManager::refreshAndGet(opCtx, nss);
+ if (!scopedCMStatus.isOK()) {
+ return scopedCMStatus.getStatus();
}
- const auto cm = routingInfoStatus.getValue().cm().get();
+ const auto& scopedCM = scopedCMStatus.getValue();
+ const auto cm = scopedCM.cm().get();
const auto collInfoStatus = createCollectionDistributionStatus(opCtx, shardStats, cm);
if (!collInfoStatus.isOK()) {
@@ -363,13 +366,13 @@ Status BalancerChunkSelectionPolicyImpl::checkMoveAllowed(OperationContext* opCt
StatusWith<SplitInfoVector> BalancerChunkSelectionPolicyImpl::_getSplitCandidatesForCollection(
OperationContext* opCtx, const NamespaceString& nss, const ShardStatisticsVector& shardStats) {
- auto routingInfoStatus =
- Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(opCtx, nss);
- if (!routingInfoStatus.isOK()) {
- return routingInfoStatus.getStatus();
+ auto scopedCMStatus = ScopedChunkManager::refreshAndGet(opCtx, nss);
+ if (!scopedCMStatus.isOK()) {
+ return scopedCMStatus.getStatus();
}
- const auto cm = routingInfoStatus.getValue().cm().get();
+ const auto& scopedCM = scopedCMStatus.getValue();
+ const auto cm = scopedCM.cm().get();
const auto& shardKeyPattern = cm->getShardKeyPattern().getKeyPattern();
@@ -417,13 +420,13 @@ StatusWith<MigrateInfoVector> BalancerChunkSelectionPolicyImpl::_getMigrateCandi
const NamespaceString& nss,
const ShardStatisticsVector& shardStats,
bool aggressiveBalanceHint) {
- auto routingInfoStatus =
- Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(opCtx, nss);
- if (!routingInfoStatus.isOK()) {
- return routingInfoStatus.getStatus();
+ auto scopedCMStatus = ScopedChunkManager::refreshAndGet(opCtx, nss);
+ if (!scopedCMStatus.isOK()) {
+ return scopedCMStatus.getStatus();
}
- const auto cm = routingInfoStatus.getValue().cm().get();
+ const auto& scopedCM = scopedCMStatus.getValue();
+ const auto cm = scopedCM.cm().get();
const auto& shardKeyPattern = cm->getShardKeyPattern().getKeyPattern();
diff --git a/src/mongo/db/s/balancer/migration_manager.cpp b/src/mongo/db/s/balancer/migration_manager.cpp
index 9c70e8458ba..7f267b97e67 100644
--- a/src/mongo/db/s/balancer/migration_manager.cpp
+++ b/src/mongo/db/s/balancer/migration_manager.cpp
@@ -45,10 +45,10 @@
#include "mongo/executor/task_executor_pool.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/catalog/sharding_catalog_client.h"
-#include "mongo/s/catalog_cache.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
#include "mongo/s/move_chunk_request.h"
+#include "mongo/s/sharding_raii.h"
#include "mongo/util/log.h"
#include "mongo/util/net/hostandport.h"
#include "mongo/util/scopeguard.h"
@@ -180,16 +180,14 @@ Status MigrationManager::executeManualMigration(
RemoteCommandResponse remoteCommandResponse =
_schedule(opCtx, migrateInfo, maxChunkSizeBytes, secondaryThrottle, waitForDelete)->get();
- auto routingInfoStatus =
- Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(
- opCtx, migrateInfo.ns);
- if (!routingInfoStatus.isOK()) {
- return routingInfoStatus.getStatus();
+ auto scopedCMStatus = ScopedChunkManager::refreshAndGet(opCtx, NamespaceString(migrateInfo.ns));
+ if (!scopedCMStatus.isOK()) {
+ return scopedCMStatus.getStatus();
}
- auto& routingInfo = routingInfoStatus.getValue();
+ const auto& scopedCM = scopedCMStatus.getValue();
- auto chunk = routingInfo.cm()->findIntersectingChunkWithSimpleCollation(migrateInfo.minKey);
+ auto chunk = scopedCM.cm()->findIntersectingChunkWithSimpleCollation(migrateInfo.minKey);
invariant(chunk);
Status commandStatus = _processRemoteCommandResponse(
@@ -312,20 +310,18 @@ void MigrationManager::finishRecovery(OperationContext* opCtx,
auto& migrateInfos = nssAndMigrateInfos.second;
invariant(!migrateInfos.empty());
- auto routingInfoStatus =
- Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(opCtx,
- nss);
- if (!routingInfoStatus.isOK()) {
+ auto scopedCMStatus = ScopedChunkManager::refreshAndGet(opCtx, nss);
+ if (!scopedCMStatus.isOK()) {
// This shouldn't happen because the collection was intact and sharded when the previous
// config primary was active and the dist locks have been held by the balancer
// throughout. Abort migration recovery.
log() << "Unable to reload chunk metadata for collection '" << nss
<< "' during balancer recovery. Abandoning recovery."
- << causedBy(redact(routingInfoStatus.getStatus()));
+ << causedBy(redact(scopedCMStatus.getStatus()));
return;
}
- auto& routingInfo = routingInfoStatus.getValue();
+ const auto& scopedCM = scopedCMStatus.getValue();
int scheduledMigrations = 0;
@@ -336,7 +332,7 @@ void MigrationManager::finishRecovery(OperationContext* opCtx,
migrateInfos.pop_front();
auto chunk =
- routingInfo.cm()->findIntersectingChunkWithSimpleCollation(migrationInfo.minKey);
+ scopedCM.cm()->findIntersectingChunkWithSimpleCollation(migrationInfo.minKey);
invariant(chunk);
if (chunk->getShardId() != migrationInfo.from) {
diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
index fda5fffdcfb..9354f60b8e1 100644
--- a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
+++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
@@ -48,6 +48,7 @@
#include "mongo/executor/task_executor.h"
#include "mongo/executor/task_executor_pool.h"
#include "mongo/rpc/get_status_from_command_result.h"
+#include "mongo/s/chunk.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
#include "mongo/util/elapsed_tracker.h"
diff --git a/src/mongo/db/s/split_vector_command.cpp b/src/mongo/db/s/split_vector_command.cpp
index b2dc34a6396..73a424e5d27 100644
--- a/src/mongo/db/s/split_vector_command.cpp
+++ b/src/mongo/db/s/split_vector_command.cpp
@@ -50,6 +50,7 @@
#include "mongo/db/keypattern.h"
#include "mongo/db/query/internal_plans.h"
#include "mongo/s/catalog/type_chunk.h"
+#include "mongo/s/chunk.h"
#include "mongo/util/log.h"
#include "mongo/util/timer.h"