summaryrefslogtreecommitdiff
path: root/src/mongo/db/s
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2020-05-30 06:10:11 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-06-04 15:56:46 +0000
commit62ab107ba8f82c5c049a8ec6c987bef0f90f18b5 (patch)
treeb0f571ff690e7982fa617d5447e42f05834c4438 /src/mongo/db/s
parent3b8ba036f2d553c9e15528fa6f7badf533e28e2a (diff)
downloadmongo-62ab107ba8f82c5c049a8ec6c987bef0f90f18b5.tar.gz
SERVER-47978 Make cleanupOrphaned command use onShardVersionMismatch with boost::none
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r--src/mongo/db/s/cleanup_orphaned_cmd.cpp2
-rw-r--r--src/mongo/db/s/collection_sharding_runtime.h95
-rw-r--r--src/mongo/db/s/collection_sharding_state.cpp7
-rw-r--r--src/mongo/db/s/collection_sharding_state.h2
-rw-r--r--src/mongo/db/s/migration_source_manager.cpp9
-rw-r--r--src/mongo/db/s/shard_filtering_metadata_refresh.cpp1
-rw-r--r--src/mongo/db/s/sharding_state_command.cpp2
7 files changed, 56 insertions, 62 deletions
diff --git a/src/mongo/db/s/cleanup_orphaned_cmd.cpp b/src/mongo/db/s/cleanup_orphaned_cmd.cpp
index 4278d442a5f..f994182717e 100644
--- a/src/mongo/db/s/cleanup_orphaned_cmd.cpp
+++ b/src/mongo/db/s/cleanup_orphaned_cmd.cpp
@@ -213,7 +213,7 @@ public:
return false;
}
- forceShardFilteringMetadataRefresh(opCtx, nss, true /* forceRefreshFromThisThread */);
+ onShardVersionMismatch(opCtx, nss, boost::none);
CleanupResult cleanupResult = cleanupOrphanedData(opCtx, nss, startingFromKey, &errmsg);
diff --git a/src/mongo/db/s/collection_sharding_runtime.h b/src/mongo/db/s/collection_sharding_runtime.h
index 3551bf39eb5..5b7dcbf7d0c 100644
--- a/src/mongo/db/s/collection_sharding_runtime.h
+++ b/src/mongo/db/s/collection_sharding_runtime.h
@@ -36,27 +36,24 @@
#include "mongo/db/s/sharding_migration_critical_section.h"
#include "mongo/db/s/sharding_state_lock.h"
#include "mongo/platform/atomic_word.h"
-#include "mongo/stdx/variant.h"
#include "mongo/util/decorable.h"
namespace mongo {
-extern AtomicWord<int> migrationLockAcquisitionMaxWaitMS;
-
/**
* See the comments for CollectionShardingState for more information on how this class fits in the
* sharding architecture.
*/
class CollectionShardingRuntime final : public CollectionShardingState,
public Decorable<CollectionShardingRuntime> {
+ CollectionShardingRuntime(const CollectionShardingRuntime&) = delete;
+ CollectionShardingRuntime& operator=(const CollectionShardingRuntime&) = delete;
+
public:
CollectionShardingRuntime(ServiceContext* service,
NamespaceString nss,
std::shared_ptr<executor::TaskExecutor> rangeDeleterExecutor);
- CollectionShardingRuntime(const CollectionShardingRuntime&) = delete;
- CollectionShardingRuntime& operator=(const CollectionShardingRuntime&) = delete;
-
using CSRLock = ShardingStateLock<CollectionShardingRuntime>;
/**
@@ -75,15 +72,6 @@ public:
static CollectionShardingRuntime* get_UNSAFE(ServiceContext* svcCtx,
const NamespaceString& nss);
- /**
- * Waits for all ranges deletion tasks with UUID 'collectionUuid' overlapping range
- * 'orphanRange' to be processed, even if the collection does not exist in the storage catalog.
- */
- static Status waitForClean(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& collectionUuid,
- ChunkRange orphanRange);
-
ScopedCollectionFilter getOwnershipFilter(OperationContext* opCtx,
OrphanCleanupPolicy orphanCleanupPolicy) override;
@@ -128,6 +116,32 @@ public:
void clearFilteringMetadata();
/**
+ * Methods to control the collection's critical section. Methods listed below must be called
+ * with both the collection lock and CSRLock held in exclusive mode.
+ *
+ * In these methods, the CSRLock ensures concurrent access to the critical section.
+ */
+ void enterCriticalSectionCatchUpPhase(OperationContext* opCtx, const CSRLock&);
+ void enterCriticalSectionCommitPhase(OperationContext* opCtx, const CSRLock&);
+
+ /**
+ * Method to control the collection's critical secion. Method listed below must be called with
+ * the collection lock in IX mode and the CSRLock in exclusive mode.
+ *
+ * In this method, the CSRLock ensures concurrent access to the critical section.
+ */
+ void exitCriticalSection(OperationContext* opCtx);
+
+ /**
+ * If the collection is currently in a critical section, returns the critical section signal to
+ * be waited on. Otherwise, returns nullptr.
+ *
+ * In this method, the CSRLock ensures concurrent access to the critical section.
+ */
+ std::shared_ptr<Notification<void>> getCriticalSectionSignal(
+ OperationContext* opCtx, ShardingMigrationCriticalSection::Operation op);
+
+ /**
* Schedules any documents in `range` for immediate cleanup iff no running queries can depend
* on them, and adds the range to the list of ranges being received.
*
@@ -142,6 +156,17 @@ public:
void forgetReceive(const ChunkRange& range);
/**
+ * Clears the list of chunks that are being received as a part of an incoming migration.
+ */
+ void clearReceivingChunks();
+
+ /**
+ * Returns a range _not_ owned by this shard that starts no lower than the specified
+ * startingFrom key value, if any, or boost::none if there is no such range.
+ */
+ boost::optional<ChunkRange> getNextOrphanRange(BSONObj const& startingFrom);
+
+ /**
* Schedules documents in `range` for cleanup after any running queries that may depend on them
* have terminated. Does not block. Fails if range overlaps any current local shard chunk.
* Passed kDelayed, an additional delay (configured via server parameter orphanCleanupDelaySecs)
@@ -156,36 +181,13 @@ public:
CleanWhen when);
/**
- * Returns a range _not_ owned by this shard that starts no lower than the specified
- * startingFrom key value, if any, or boost::none if there is no such range.
- */
- boost::optional<ChunkRange> getNextOrphanRange(BSONObj const& startingFrom);
-
- /**
- * Methods to control the collection's critical section. Methods listed below must be called
- * with both the collection lock and CSRLock held in exclusive mode.
- *
- * In these methods, the CSRLock ensures concurrent access to the critical section.
- */
- void enterCriticalSectionCatchUpPhase(OperationContext* opCtx, const CSRLock&);
- void enterCriticalSectionCommitPhase(OperationContext* opCtx, const CSRLock&);
-
- /**
- * Method to control the collection's critical secion. Method listed below must be called with
- * the collection lock in IX mode and the CSRLock in exclusive mode.
- *
- * In this method, the CSRLock ensures concurrent access to the critical section.
- */
- void exitCriticalSection(OperationContext* opCtx);
-
- /**
- * If the collection is currently in a critical section, returns the critical section signal to
- * be waited on. Otherwise, returns nullptr.
- *
- * In this method, the CSRLock ensures concurrent access to the critical section.
+ * Waits for all ranges deletion tasks with UUID 'collectionUuid' overlapping range
+ * 'orphanRange' to be processed, even if the collection does not exist in the storage catalog.
*/
- std::shared_ptr<Notification<void>> getCriticalSectionSignal(
- OperationContext* opCtx, ShardingMigrationCriticalSection::Operation op);
+ static Status waitForClean(OperationContext* opCtx,
+ const NamespaceString& nss,
+ const UUID& collectionUuid,
+ ChunkRange orphanRange);
/**
* Appends information about any chunks for which incoming migration has been requested, but the
@@ -194,11 +196,6 @@ public:
*/
void appendPendingReceiveChunks(BSONArrayBuilder* builder);
- /**
- * Clears the list of chunks that are being received as a part of an incoming migration.
- */
- void clearReceivingChunks();
-
std::uint64_t getNumMetadataManagerChanges_forTest() {
return _numMetadataManagerChanges;
}
diff --git a/src/mongo/db/s/collection_sharding_state.cpp b/src/mongo/db/s/collection_sharding_state.cpp
index 8dc5ed55de1..894291ab676 100644
--- a/src/mongo/db/s/collection_sharding_state.cpp
+++ b/src/mongo/db/s/collection_sharding_state.cpp
@@ -72,7 +72,7 @@ public:
return *it->second;
}
- void report(BSONObjBuilder* builder) {
+ void appendInfoForShardingStateCommand(BSONObjBuilder* builder) {
BSONObjBuilder versionB(builder->subobjStart("versions"));
{
@@ -130,9 +130,10 @@ CollectionShardingState* CollectionShardingState::get_UNSAFE(ServiceContext* svc
return &collectionsMap->getOrCreate(nss);
}
-void CollectionShardingState::report(OperationContext* opCtx, BSONObjBuilder* builder) {
+void CollectionShardingState::appendInfoForShardingStateCommand(OperationContext* opCtx,
+ BSONObjBuilder* builder) {
auto& collectionsMap = CollectionShardingStateMap::get(opCtx->getServiceContext());
- collectionsMap->report(builder);
+ collectionsMap->appendInfoForShardingStateCommand(builder);
}
void CollectionShardingState::appendInfoForServerStatus(OperationContext* opCtx,
diff --git a/src/mongo/db/s/collection_sharding_state.h b/src/mongo/db/s/collection_sharding_state.h
index 4e79c7d172e..d2505601729 100644
--- a/src/mongo/db/s/collection_sharding_state.h
+++ b/src/mongo/db/s/collection_sharding_state.h
@@ -76,7 +76,7 @@ public:
/**
* Reports all collections which have filtering information associated.
*/
- static void report(OperationContext* opCtx, BSONObjBuilder* builder);
+ static void appendInfoForShardingStateCommand(OperationContext* opCtx, BSONObjBuilder* builder);
/**
* Attaches info for server status.
diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp
index a9ad196e69f..ce55ada1ca7 100644
--- a/src/mongo/db/s/migration_source_manager.cpp
+++ b/src/mongo/db/s/migration_source_manager.cpp
@@ -33,8 +33,6 @@
#include "mongo/db/s/migration_source_manager.h"
-#include <memory>
-
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/db/catalog_raii.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
@@ -51,6 +49,7 @@
#include "mongo/db/s/shard_filtering_metadata_refresh.h"
#include "mongo/db/s/shard_metadata_util.h"
#include "mongo/db/s/sharding_logging.h"
+#include "mongo/db/s/sharding_runtime_d_params_gen.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/s/sharding_state_recovery.h"
#include "mongo/db/s/sharding_statistics.h"
@@ -66,14 +65,10 @@
#include "mongo/s/shard_key_pattern.h"
#include "mongo/util/duration.h"
#include "mongo/util/elapsed_tracker.h"
-#include "mongo/util/exit.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/scopeguard.h"
namespace mongo {
-
-using namespace shardmetadatautil;
-
namespace {
const auto msmForCsr = CollectionShardingRuntime::declareDecoration<MigrationSourceManager*>();
@@ -345,7 +340,7 @@ Status MigrationSourceManager::enterCriticalSection() {
// time inclusive of the migration config commit update from accessing secondary data.
// Note: this write must occur after the critSec flag is set, to ensure the secondary refresh
// will stall behind the flag.
- Status signalStatus = updateShardCollectionsEntry(
+ Status signalStatus = shardmetadatautil::updateShardCollectionsEntry(
_opCtx,
BSON(ShardCollectionType::kNssFieldName << getNss().ns()),
BSONObj(),
diff --git a/src/mongo/db/s/shard_filtering_metadata_refresh.cpp b/src/mongo/db/s/shard_filtering_metadata_refresh.cpp
index 05142460514..d7b52f92238 100644
--- a/src/mongo/db/s/shard_filtering_metadata_refresh.cpp
+++ b/src/mongo/db/s/shard_filtering_metadata_refresh.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/s/database_sharding_state.h"
#include "mongo/db/s/migration_util.h"
#include "mongo/db/s/operation_sharding_state.h"
+#include "mongo/db/s/sharding_runtime_d_params_gen.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/s/sharding_statistics.h"
#include "mongo/logv2/log.h"
diff --git a/src/mongo/db/s/sharding_state_command.cpp b/src/mongo/db/s/sharding_state_command.cpp
index 072a89eb6e4..948ba614c80 100644
--- a/src/mongo/db/s/sharding_state_command.cpp
+++ b/src/mongo/db/s/sharding_state_command.cpp
@@ -81,7 +81,7 @@ public:
result.append("shardName", shardingState->shardId());
result.append("clusterId", shardingState->clusterId());
- CollectionShardingState::report(opCtx, &result);
+ CollectionShardingState::appendInfoForShardingStateCommand(opCtx, &result);
}
return true;