summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergi Mateo Bellido <sergi.mateo-bellido@mongodb.com>2022-09-13 11:40:49 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-10-13 12:50:49 +0000
commit86e4ce0ac68e9b408aefdd531e46bdfda437b6f2 (patch)
treee541897080ea3aa8d3f5f7dfea4aea75fa3eb80e
parent316a5717fe08153421d708863514b776b625e498 (diff)
downloadmongo-86e4ce0ac68e9b408aefdd531e46bdfda437b6f2.tar.gz
SERVER-69134 Adding a way to clear the metadata manager
(cherry picked from commit fa94f5fb6216a1cc1e23f5ad4df05295b380070e)
-rw-r--r--src/mongo/db/s/collection_sharding_runtime.cpp17
-rw-r--r--src/mongo/db/s/collection_sharding_runtime.h10
-rw-r--r--src/mongo/db/s/drop_collection_coordinator.cpp2
-rw-r--r--src/mongo/db/s/rename_collection_participant_service.cpp21
-rw-r--r--src/mongo/db/s/shard_server_op_observer.cpp21
5 files changed, 57 insertions, 14 deletions
diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp
index a66fd675743..a21ace9791b 100644
--- a/src/mongo/db/s/collection_sharding_runtime.cpp
+++ b/src/mongo/db/s/collection_sharding_runtime.cpp
@@ -222,7 +222,8 @@ void CollectionShardingRuntime::setFilteringMetadata_withLock(OperationContext*
}
}
-void CollectionShardingRuntime::clearFilteringMetadata(OperationContext* opCtx) {
+void CollectionShardingRuntime::_clearFilteringMetadata(OperationContext* opCtx,
+ bool clearMetadataManager) {
const auto csrLock = CSRLock::lockExclusive(opCtx, this);
if (_shardVersionInRecoverOrRefresh) {
_shardVersionInRecoverOrRefresh->cancellationSource.cancel();
@@ -234,11 +235,23 @@ void CollectionShardingRuntime::clearFilteringMetadata(OperationContext* opCtx)
1,
"Clearing metadata for collection {namespace}",
"Clearing collection metadata",
- "namespace"_attr = _nss);
+ "namespace"_attr = _nss,
+ "clearMetadataManager"_attr = clearMetadataManager);
_metadataType = MetadataType::kUnknown;
+ if (clearMetadataManager)
+ _metadataManager.reset();
}
}
+void CollectionShardingRuntime::clearFilteringMetadata(OperationContext* opCtx) {
+ _clearFilteringMetadata(opCtx, /* clearMetadataManager */ false);
+}
+
+void CollectionShardingRuntime::clearFilteringMetadataForDroppedCollection(
+ OperationContext* opCtx) {
+ _clearFilteringMetadata(opCtx, /* clearMetadataManager */ true);
+}
+
SharedSemiFuture<void> CollectionShardingRuntime::cleanUpRange(ChunkRange const& range,
boost::optional<UUID> migrationId,
CleanWhen when) {
diff --git a/src/mongo/db/s/collection_sharding_runtime.h b/src/mongo/db/s/collection_sharding_runtime.h
index bbc343d5bcb..46920f82061 100644
--- a/src/mongo/db/s/collection_sharding_runtime.h
+++ b/src/mongo/db/s/collection_sharding_runtime.h
@@ -127,6 +127,11 @@ public:
void clearFilteringMetadata(OperationContext* opCtx);
/**
+ * Calls to clearFilteringMetadata + clears the _metadataManager object.
+ */
+ void clearFilteringMetadataForDroppedCollection(OperationContext* opCtx);
+
+ /**
* 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.
*
@@ -254,6 +259,11 @@ private:
std::shared_ptr<ScopedCollectionDescription::Impl> _getMetadataWithVersionCheckAt(
OperationContext* opCtx, const boost::optional<mongo::LogicalTime>& atClusterTime);
+ /**
+ * Auxiliary function used to implement the different flavours of clearFilteringMetadata.
+ */
+ void _clearFilteringMetadata(OperationContext* opCtx, bool clearFilteringMetadata);
+
// The service context under which this instance runs
ServiceContext* const _serviceContext;
diff --git a/src/mongo/db/s/drop_collection_coordinator.cpp b/src/mongo/db/s/drop_collection_coordinator.cpp
index 9d80b041a8b..ca3079e4073 100644
--- a/src/mongo/db/s/drop_collection_coordinator.cpp
+++ b/src/mongo/db/s/drop_collection_coordinator.cpp
@@ -81,7 +81,7 @@ DropReply DropCollectionCoordinator::dropCollectionLocally(OperationContext* opC
Lock::DBLock dbLock(opCtx, nss.db(), MODE_IX);
Lock::CollectionLock collLock(opCtx, nss, MODE_IX);
auto* csr = CollectionShardingRuntime::get(opCtx, nss);
- csr->clearFilteringMetadata(opCtx);
+ csr->clearFilteringMetadataForDroppedCollection(opCtx);
}
DropReply result;
diff --git a/src/mongo/db/s/rename_collection_participant_service.cpp b/src/mongo/db/s/rename_collection_participant_service.cpp
index 15d7d11bd3c..4c2fca846bb 100644
--- a/src/mongo/db/s/rename_collection_participant_service.cpp
+++ b/src/mongo/db/s/rename_collection_participant_service.cpp
@@ -319,10 +319,23 @@ SemiFuture<void> RenameParticipantInstance::_runImpl(
service->promoteRecoverableCriticalSectionToBlockAlsoReads(
opCtx, toNss(), reason, ShardingCatalogClient::kLocalWriteConcern);
- // Clear the filtering metadata to safely create new range deletion tasks: the
- // submission will serialize on the renamed collection's metadata refresh.
- clearFilteringMetadata(opCtx, fromNss());
- clearFilteringMetadata(opCtx, toNss());
+ // Clear the filtering metadata before releasing the critical section (it will be
+ // recovered the next time is accessed) and to safely create new range deletion
+ // tasks (the submission will serialize on the renamed collection's metadata
+ // refresh).
+ {
+ Lock::DBLock dbLock(opCtx, fromNss().db(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, fromNss(), MODE_IX);
+ auto* csr = CollectionShardingRuntime::get(opCtx, fromNss());
+ csr->clearFilteringMetadataForDroppedCollection(opCtx);
+ }
+
+ {
+ Lock::DBLock dbLock(opCtx, toNss().db(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, toNss(), MODE_IX);
+ auto* csr = CollectionShardingRuntime::get(opCtx, toNss());
+ csr->clearFilteringMetadata(opCtx);
+ }
snapshotRangeDeletionsForRename(opCtx, fromNss(), toNss());
}))
diff --git a/src/mongo/db/s/shard_server_op_observer.cpp b/src/mongo/db/s/shard_server_op_observer.cpp
index b77c11dc810..53ea0cea74c 100644
--- a/src/mongo/db/s/shard_server_op_observer.cpp
+++ b/src/mongo/db/s/shard_server_op_observer.cpp
@@ -78,8 +78,10 @@ bool isStandaloneOrPrimary(OperationContext* opCtx) {
*/
class CollectionVersionLogOpHandler final : public RecoveryUnit::Change {
public:
- CollectionVersionLogOpHandler(OperationContext* opCtx, const NamespaceString& nss)
- : _opCtx(opCtx), _nss(nss) {}
+ CollectionVersionLogOpHandler(OperationContext* opCtx,
+ const NamespaceString& nss,
+ bool droppingCollection)
+ : _opCtx(opCtx), _nss(nss), _droppingCollection(droppingCollection) {}
void commit(boost::optional<Timestamp>) override {
invariant(_opCtx->lockState()->isCollectionLockedForMode(_nss, MODE_IX));
@@ -89,7 +91,11 @@ public:
// Force subsequent uses of the namespace to refresh the filtering metadata so they can
// synchronize with any work happening on the primary (e.g., migration critical section).
UninterruptibleLockGuard noInterrupt(_opCtx->lockState());
- CollectionShardingRuntime::get(_opCtx, _nss)->clearFilteringMetadata(_opCtx);
+ if (_droppingCollection)
+ CollectionShardingRuntime::get(_opCtx, _nss)
+ ->clearFilteringMetadataForDroppedCollection(_opCtx);
+ else
+ CollectionShardingRuntime::get(_opCtx, _nss)->clearFilteringMetadata(_opCtx);
}
void rollback() override {}
@@ -97,6 +103,7 @@ public:
private:
OperationContext* _opCtx;
const NamespaceString _nss;
+ const bool _droppingCollection;
};
/**
@@ -170,8 +177,8 @@ void onConfigDeleteInvalidateCachedCollectionMetadataAndNotify(OperationContext*
// Need the WUOW to retain the lock for CollectionVersionLogOpHandler::commit().
AutoGetCollection autoColl(opCtx, deletedNss, MODE_IX);
- opCtx->recoveryUnit()->registerChange(
- std::make_unique<CollectionVersionLogOpHandler>(opCtx, deletedNss));
+ opCtx->recoveryUnit()->registerChange(std::make_unique<CollectionVersionLogOpHandler>(
+ opCtx, deletedNss, /* droppingCollection */ true));
}
/**
@@ -347,8 +354,8 @@ void ShardServerOpObserver::onUpdate(OperationContext* opCtx, const OplogUpdateE
// Need the WUOW to retain the lock for CollectionVersionLogOpHandler::commit().
AutoGetCollection autoColl(opCtx, updatedNss, MODE_IX);
if (refreshingFieldNewVal.isBoolean() && !refreshingFieldNewVal.boolean()) {
- opCtx->recoveryUnit()->registerChange(
- std::make_unique<CollectionVersionLogOpHandler>(opCtx, updatedNss));
+ opCtx->recoveryUnit()->registerChange(std::make_unique<CollectionVersionLogOpHandler>(
+ opCtx, updatedNss, /* droppingCollection */ false));
}
if (enterCriticalSectionFieldNewVal.ok()) {