summaryrefslogtreecommitdiff
path: root/src/mongo/db/s
diff options
context:
space:
mode:
authorAllison Easton <allison.easton@mongodb.com>2022-04-26 10:30:11 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-26 10:56:58 +0000
commit5e160450d659437dc7455c0138dfa0667ab091b6 (patch)
tree202b9f493f2719384c8e5d9df12d36db68b9ab4f /src/mongo/db/s
parent568226e1d66e88880daa901bea011aa8ed83d501 (diff)
downloadmongo-5e160450d659437dc7455c0138dfa0667ab091b6.tar.gz
SERVER-65015 Granular locks for synchronizing orphans tracking
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r--src/mongo/db/s/migration_util.cpp2
-rw-r--r--src/mongo/db/s/range_deletion_util.cpp18
-rw-r--r--src/mongo/db/s/range_deletion_util.h2
3 files changed, 17 insertions, 5 deletions
diff --git a/src/mongo/db/s/migration_util.cpp b/src/mongo/db/s/migration_util.cpp
index 0aeb5e8bbe3..ec151caec50 100644
--- a/src/mongo/db/s/migration_util.cpp
+++ b/src/mongo/db/s/migration_util.cpp
@@ -701,7 +701,7 @@ void persistUpdatedNumOrphans(OperationContext* opCtx,
<< BSON("$exists" << true));
try {
PersistentTaskStore<RangeDeletionTask> store(NamespaceString::kRangeDeletionNamespace);
- ScopedRangeDeleterLock rangeDeleterLock(opCtx);
+ ScopedRangeDeleterLock rangeDeleterLock(opCtx, collectionUuid);
// TODO (SERVER-54284) Remove writeConflictRetry loop
writeConflictRetry(
opCtx, "updateOrphanCount", NamespaceString::kRangeDeletionNamespace.ns(), [&] {
diff --git a/src/mongo/db/s/range_deletion_util.cpp b/src/mongo/db/s/range_deletion_util.cpp
index 311973d4bee..b04bf94b9a9 100644
--- a/src/mongo/db/s/range_deletion_util.cpp
+++ b/src/mongo/db/s/range_deletion_util.cpp
@@ -645,6 +645,7 @@ void setOrphanCountersOnRangeDeletionTasks(OperationContext* opCtx) {
BSONObj(),
[opCtx, &store, &setNumOrphansOnTask](const RangeDeletionTask& deletionTask) {
AutoGetCollection collection(opCtx, deletionTask.getNss(), MODE_IX);
+ ScopedRangeDeleterLock rangeDeleterLock(opCtx, deletionTask.getCollectionUuid());
if (!collection || collection->uuid() != deletionTask.getCollectionUuid()) {
// The deletion task is referring to a collection that has been dropped
setNumOrphansOnTask(deletionTask, 0);
@@ -704,10 +705,19 @@ void clearOrphanCountersFromRangeDeletionTasks(OperationContext* opCtx) {
}
}
-// TODO (SERVER-65015) Use granular locks for synchronizing orphan tracking
ScopedRangeDeleterLock::ScopedRangeDeleterLock(OperationContext* opCtx)
- : _configLock(Lock::DBLock(opCtx, NamespaceString::kConfigDb, MODE_IX)),
- _rangeDeletionLock(
- Lock::CollectionLock(opCtx, NamespaceString::kRangeDeletionNamespace, MODE_X)) {}
+ : _configLock(opCtx, NamespaceString::kConfigDb, MODE_IX),
+ _rangeDeletionLock(opCtx, NamespaceString::kRangeDeletionNamespace, MODE_X) {}
+
+// Take DB and Collection lock in mode IX as well as collection UUID lock to serialize with
+// operations that take the above version of the ScopedRangeDeleterLock such as FCV downgrade and
+// BalancerStatsRegistry initialization.
+ScopedRangeDeleterLock::ScopedRangeDeleterLock(OperationContext* opCtx, const UUID& collectionUuid)
+ : _configLock(opCtx, NamespaceString::kConfigDb, MODE_IX),
+ _rangeDeletionLock(opCtx, NamespaceString::kRangeDeletionNamespace, MODE_IX),
+ _collectionUuidLock(Lock::ResourceLock(
+ opCtx->lockState(),
+ ResourceId(RESOURCE_MUTEX, "RangeDeleterCollLock::" + collectionUuid.toString()),
+ MODE_X)) {}
} // namespace mongo
diff --git a/src/mongo/db/s/range_deletion_util.h b/src/mongo/db/s/range_deletion_util.h
index 2d537eee8cc..9d30bcc577c 100644
--- a/src/mongo/db/s/range_deletion_util.h
+++ b/src/mongo/db/s/range_deletion_util.h
@@ -59,10 +59,12 @@ extern AtomicWord<int> rangeDeleterBatchDelayMS;
class ScopedRangeDeleterLock {
public:
ScopedRangeDeleterLock(OperationContext* opCtx);
+ ScopedRangeDeleterLock(OperationContext* opCtx, const UUID& collectionUuid);
private:
Lock::DBLock _configLock;
Lock::CollectionLock _rangeDeletionLock;
+ boost::optional<Lock::ResourceLock> _collectionUuidLock;
};
/**