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-09-13 12:10:41 +0000
commitfa94f5fb6216a1cc1e23f5ad4df05295b380070e (patch)
treeb97c03072a8f051ef07d04ddca6aa0d971d395fd
parentc70bc17083cc73c2b2d32b4fc693fe22c58a863d (diff)
downloadmongo-fa94f5fb6216a1cc1e23f5ad4df05295b380070e.tar.gz
SERVER-69134 Adding a way to clear the metadata manager
-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.cpp15
-rw-r--r--src/mongo/db/s/shard_server_op_observer.cpp21
5 files changed, 53 insertions, 12 deletions
diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp
index 5a447a539cf..a46fe3bdc66 100644
--- a/src/mongo/db/s/collection_sharding_runtime.cpp
+++ b/src/mongo/db/s/collection_sharding_runtime.cpp
@@ -234,7 +234,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();
@@ -246,11 +247,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,
CleanWhen when) {
stdx::lock_guard lk(_metadataManagerLock);
diff --git a/src/mongo/db/s/collection_sharding_runtime.h b/src/mongo/db/s/collection_sharding_runtime.h
index acbf4831b70..47ed17a914e 100644
--- a/src/mongo/db/s/collection_sharding_runtime.h
+++ b/src/mongo/db/s/collection_sharding_runtime.h
@@ -121,6 +121,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.
*
@@ -258,6 +263,11 @@ private:
const boost::optional<mongo::LogicalTime>& atClusterTime,
bool supportNonVersionedOperations = false);
+ /**
+ * 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 49c7a273ffa..332d1bebf17 100644
--- a/src/mongo/db/s/drop_collection_coordinator.cpp
+++ b/src/mongo/db/s/drop_collection_coordinator.cpp
@@ -51,7 +51,7 @@ DropReply DropCollectionCoordinator::dropCollectionLocally(OperationContext* opC
Lock::DBLock dbLock(opCtx, nss.dbName(), 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 0047e265f6a..910505e5cf9 100644
--- a/src/mongo/db/s/rename_collection_participant_service.cpp
+++ b/src/mongo/db/s/rename_collection_participant_service.cpp
@@ -320,8 +320,19 @@ SemiFuture<void> RenameParticipantInstance::_runImpl(
// 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).
- clearFilteringMetadata(opCtx, fromNss());
- clearFilteringMetadata(opCtx, toNss());
+ {
+ Lock::DBLock dbLock(opCtx, fromNss().dbName(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, fromNss(), MODE_IX);
+ auto* csr = CollectionShardingRuntime::get(opCtx, fromNss());
+ csr->clearFilteringMetadataForDroppedCollection(opCtx);
+ }
+
+ {
+ Lock::DBLock dbLock(opCtx, toNss().dbName(), 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 32ad318a1de..0e138e333ec 100644
--- a/src/mongo/db/s/shard_server_op_observer.cpp
+++ b/src/mongo/db/s/shard_server_op_observer.cpp
@@ -83,8 +83,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));
@@ -94,7 +96,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 {}
@@ -102,6 +108,7 @@ public:
private:
OperationContext* _opCtx;
const NamespaceString _nss;
+ const bool _droppingCollection;
};
/**
@@ -155,8 +162,8 @@ void onConfigDeleteInvalidateCachedCollectionMetadataAndNotify(OperationContext*
AllowLockAcquisitionOnTimestampedUnitOfWork allowLockAcquisition(opCtx->lockState());
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));
}
/**
@@ -375,8 +382,8 @@ void ShardServerOpObserver::onUpdate(OperationContext* opCtx, const OplogUpdateE
AllowLockAcquisitionOnTimestampedUnitOfWork allowLockAcquisition(opCtx->lockState());
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()) {