summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2021-06-03 06:32:28 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-03 06:54:54 +0000
commitdcd9f60e591acffeedabb5fa368f407a035473b2 (patch)
tree1b17c6b157ac8d951c987acc73548dedff096a37
parent4fac50c0a0c2b8f108cd32c90534aeedf2aa1e2e (diff)
downloadmongo-dcd9f60e591acffeedabb5fa368f407a035473b2.tar.gz
Revert "SERVER-56779 Allow multiple concurrent merges for the same collection across the cluster"
This reverts commit 13e28eb1e3a70211038e10afec3b6713fd63f4b8.
-rw-r--r--src/mongo/db/s/active_migrations_registry.cpp70
-rw-r--r--src/mongo/db/s/active_migrations_registry.h73
2 files changed, 13 insertions, 130 deletions
diff --git a/src/mongo/db/s/active_migrations_registry.cpp b/src/mongo/db/s/active_migrations_registry.cpp
index 18f2b3dbf47..1fec861ffe2 100644
--- a/src/mongo/db/s/active_migrations_registry.cpp
+++ b/src/mongo/db/s/active_migrations_registry.cpp
@@ -121,11 +121,6 @@ StatusWith<ScopedDonateChunk> ActiveMigrationsRegistry::registerDonateChunk(
return _activeMoveChunkState->constructErrorStatus();
}
- if (auto it = _activeSplitMergeChunkStates.find(args.getNss());
- it != _activeSplitMergeChunkStates.end()) {
- return it->second.constructErrorStatus();
- }
-
_activeMoveChunkState.emplace(args);
return {ScopedDonateChunk(this, true, _activeMoveChunkState->notification)};
@@ -163,27 +158,6 @@ StatusWith<ScopedReceiveChunk> ActiveMigrationsRegistry::registerReceiveChunk(
return {ScopedReceiveChunk(this)};
}
-StatusWith<ScopedSplitMergeChunk> ActiveMigrationsRegistry::registerSplitOrMergeChunk(
- const NamespaceString& nss, const ChunkRange& chunkRange) {
- stdx::unique_lock<Latch> lk(_mutex);
-
- if (_activeReceiveChunkState) {
- return _activeReceiveChunkState->constructErrorStatus();
- }
-
- if (_activeMoveChunkState) {
- return _activeMoveChunkState->constructErrorStatus();
- }
-
- auto [it, inserted] =
- _activeSplitMergeChunkStates.emplace(nss, ActiveSplitMergeChunkState(nss, chunkRange));
- if (!inserted) {
- return it->second.constructErrorStatus();
- }
-
- return {ScopedSplitMergeChunk(this, nss)};
-}
-
boost::optional<NamespaceString> ActiveMigrationsRegistry::getActiveDonateChunkNss() {
stdx::lock_guard<Latch> lk(_mutex);
if (_activeMoveChunkState) {
@@ -241,15 +215,10 @@ void ActiveMigrationsRegistry::_clearReceiveChunk() {
_lockCond.notify_all();
}
-void ActiveMigrationsRegistry::_clearSplitMergeChunk(const NamespaceString& nss) {
- stdx::lock_guard<Latch> lk(_mutex);
- invariant(_activeSplitMergeChunkStates.erase(nss));
-}
-
Status ActiveMigrationsRegistry::ActiveMoveChunkState::constructErrorStatus() const {
return {ErrorCodes::ConflictingOperationInProgress,
- str::stream() << "Unable to start new balancer operation because this shard is "
- "currently donating chunk "
+ str::stream() << "Unable to start new migration because this shard is currently "
+ "donating chunk "
<< ChunkRange(args.getMinKey(), args.getMaxKey()).toString()
<< " for namespace " << args.getNss().ns() << " to "
<< args.getToShardId()};
@@ -257,19 +226,12 @@ Status ActiveMigrationsRegistry::ActiveMoveChunkState::constructErrorStatus() co
Status ActiveMigrationsRegistry::ActiveReceiveChunkState::constructErrorStatus() const {
return {ErrorCodes::ConflictingOperationInProgress,
- str::stream() << "Unable to start new balancer operation because this shard is "
- "currently receiving chunk "
+ str::stream() << "Unable to start new migration because this shard is currently "
+ "receiving chunk "
<< range.toString() << " for namespace " << nss.ns() << " from "
<< fromShardId};
}
-Status ActiveMigrationsRegistry::ActiveSplitMergeChunkState::constructErrorStatus() const {
- return {ErrorCodes::ConflictingOperationInProgress,
- str::stream() << "Unable to start new balancer operation because this shard is "
- "currently splitting or merging chunk "
- << range.toString() << " for namespace " << nss.ns()};
-}
-
ScopedDonateChunk::ScopedDonateChunk(ActiveMigrationsRegistry* registry,
bool shouldExecute,
std::shared_ptr<Notification<Status>> completionNotification)
@@ -332,28 +294,4 @@ ScopedReceiveChunk& ScopedReceiveChunk::operator=(ScopedReceiveChunk&& other) {
return *this;
}
-ScopedSplitMergeChunk::ScopedSplitMergeChunk(ActiveMigrationsRegistry* registry,
- const NamespaceString& nss)
- : _registry(registry), _nss(nss) {}
-
-ScopedSplitMergeChunk::~ScopedSplitMergeChunk() {
- if (_registry) {
- _registry->_clearSplitMergeChunk(_nss);
- }
-}
-
-ScopedSplitMergeChunk::ScopedSplitMergeChunk(ScopedSplitMergeChunk&& other) {
- *this = std::move(other);
-}
-
-ScopedSplitMergeChunk& ScopedSplitMergeChunk::operator=(ScopedSplitMergeChunk&& other) {
- if (&other != this) {
- _registry = other._registry;
- other._registry = nullptr;
- _nss = std::move(other._nss);
- }
-
- return *this;
-}
-
} // namespace mongo
diff --git a/src/mongo/db/s/active_migrations_registry.h b/src/mongo/db/s/active_migrations_registry.h
index d3c4db28775..29b326cf4ef 100644
--- a/src/mongo/db/s/active_migrations_registry.h
+++ b/src/mongo/db/s/active_migrations_registry.h
@@ -30,6 +30,7 @@
#pragma once
#include <boost/optional.hpp>
+#include <memory>
#include "mongo/db/s/migration_session_id.h"
#include "mongo/platform/mutex.h"
@@ -41,7 +42,8 @@ namespace mongo {
class OperationContext;
class ScopedDonateChunk;
class ScopedReceiveChunk;
-class ScopedSplitMergeChunk;
+template <typename T>
+class StatusWith;
/**
* Thread-safe object that keeps track of the active migrations running on a node and limits them
@@ -68,9 +70,9 @@ public:
void unlock(StringData reason);
/**
- * If there are no migrations or split/merges running on this shard, registers an active
- * migration with the specified arguments. Returns a ScopedDonateChunk, which must be signaled
- * by the caller before it goes out of scope.
+ * If there are no migrations running on this shard, registers an active migration with the
+ * specified arguments. Returns a ScopedDonateChunk, which must be signaled by the
+ * caller before it goes out of scope.
*
* If there is an active migration already running on this shard and it has the exact same
* arguments, returns a ScopedDonateChunk. The ScopedDonateChunk can be used to join the
@@ -82,10 +84,9 @@ public:
const MoveChunkRequest& args);
/**
- * If there are no migrations or split/merges running on this shard, registers an active receive
- * operation with the specified session id and returns a ScopedReceiveChunk. The
- * ScopedReceiveChunk will unregister the migration when the ScopedReceiveChunk goes out of
- * scope.
+ * If there are no migrations running on this shard, registers an active receive operation with
+ * the specified session id and returns a ScopedReceiveChunk. The ScopedReceiveChunk will
+ * unregister the migration when the ScopedReceiveChunk goes out of scope.
*
* Otherwise returns a ConflictingOperationInProgress error.
*/
@@ -95,14 +96,6 @@ public:
const ShardId& fromShardId);
/**
- * If there are no migrations running on this shard, registers an active split or merge
- * operation for the specified namespace and returns a scoped object which will in turn disallow
- * other migrations or splits/merges for the same namespace (but not for other namespaces).
- */
- StatusWith<ScopedSplitMergeChunk> registerSplitOrMergeChunk(const NamespaceString& nss,
- const ChunkRange& chunkRange);
-
- /**
* If a migration has been previously registered through a call to registerDonateChunk, returns
* that namespace. Otherwise returns boost::none.
*/
@@ -119,7 +112,6 @@ public:
private:
friend class ScopedDonateChunk;
friend class ScopedReceiveChunk;
- friend class ScopedSplitMergeChunk;
// Describes the state of a currently active moveChunk operation
struct ActiveMoveChunkState {
@@ -158,24 +150,6 @@ private:
ShardId fromShardId;
};
- // Describes the state of a currently active split or merge operation
- struct ActiveSplitMergeChunkState {
- ActiveSplitMergeChunkState(NamespaceString inNss, ChunkRange inRange)
- : nss(std::move(inNss)), range(std::move(inRange)) {}
-
- /**
- * Constructs an error status to return in the case of conflicting operations.
- */
- Status constructErrorStatus() const;
-
- // Namespace for which a chunk is being split or merged
- NamespaceString nss;
-
- // If split, bounds of the chunk being split; if merge, the end bounds of the range being
- // merged
- ChunkRange range;
- };
-
/**
* Unregisters a previously registered namespace with an ongoing migration. Must only be called
* if a previous call to registerDonateChunk has succeeded.
@@ -188,12 +162,6 @@ private:
*/
void _clearReceiveChunk();
- /**
- * Unregisters a previously registered split/merge chunk operation. Must only be called if a
- * previous call to registerSplitOrMergeChunk has succeeded.
- */
- void _clearSplitMergeChunk(const NamespaceString& nss);
-
// Protects the state below
Mutex _mutex = MONGO_MAKE_LATCH("ActiveMigrationsRegistry::_mutex");
stdx::condition_variable _lockCond;
@@ -205,10 +173,6 @@ private:
// If there is an active chunk receive operation, this field contains the original session id
boost::optional<ActiveReceiveChunkState> _activeReceiveChunkState;
-
- // If there is an active split or merge chunk operation for a particular namespace, this map
- // will contain an entry
- stdx::unordered_map<NamespaceString, ActiveSplitMergeChunkState> _activeSplitMergeChunkStates;
};
class MigrationBlockingGuard {
@@ -305,23 +269,4 @@ private:
ActiveMigrationsRegistry* _registry;
};
-/**
- * Object of this class is returned from the registerSplitOrMergeChunk call of the active migrations
- * registry.
- */
-class ScopedSplitMergeChunk {
-public:
- ScopedSplitMergeChunk(ActiveMigrationsRegistry* registry, const NamespaceString& nss);
- ~ScopedSplitMergeChunk();
-
- ScopedSplitMergeChunk(ScopedSplitMergeChunk&&);
- ScopedSplitMergeChunk& operator=(ScopedSplitMergeChunk&&);
-
-private:
- // Registry from which to unregister the split/merge. Not owned.
- ActiveMigrationsRegistry* _registry;
-
- NamespaceString _nss;
-};
-
} // namespace mongo