summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjannaerin <golden.janna@gmail.com>2021-02-10 17:31:57 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-02-17 02:29:12 +0000
commitc4e13438cb94345c347d97dde6d381fadeb458b6 (patch)
tree2686b0d4eddc4a481e0a3368c3724286b0a81368
parent02115791f2ca7769ad9c1fe85b39c82bdc3c2d1e (diff)
downloadmongo-c4e13438cb94345c347d97dde6d381fadeb458b6.tar.gz
SERVER-53374 Clean up oplog related collections created for resharding
-rw-r--r--jstests/sharding/libs/resharding_test_fixture.js36
-rw-r--r--src/mongo/db/namespace_string.cpp8
-rw-r--r--src/mongo/db/namespace_string.h17
-rw-r--r--src/mongo/db/s/resharding/resharding_oplog_applier.cpp4
-rw-r--r--src/mongo/db/s/resharding/resharding_recipient_service.cpp43
-rw-r--r--src/mongo/db/s/resharding/resharding_recipient_service.h5
-rw-r--r--src/mongo/db/s/resharding_util.cpp10
-rw-r--r--src/mongo/db/s/resharding_util.h4
8 files changed, 118 insertions, 9 deletions
diff --git a/jstests/sharding/libs/resharding_test_fixture.js b/jstests/sharding/libs/resharding_test_fixture.js
index 2e219ec2082..e4c0edbd9b0 100644
--- a/jstests/sharding/libs/resharding_test_fixture.js
+++ b/jstests/sharding/libs/resharding_test_fixture.js
@@ -490,6 +490,42 @@ var ReshardingTest = class {
`collection exists on ${recipient.shardName} despite resharding having failed`);
}
+ assert.eq(
+ [],
+ recipient.getCollection(`config.localReshardingOperations.recipient.progress_applier`)
+ .find()
+ .toArray(),
+ `config.localReshardingOperations.recipient.progress_applier wasn't cleaned up on ${
+ recipient.shardName}`);
+
+ assert.eq(
+ [],
+ recipient
+ .getCollection(`config.localReshardingOperations.recipient.progress_txn_cloner`)
+ .find()
+ .toArray(),
+ `config.localReshardingOperations.recipient.progress_txn_cloner wasn't cleaned up on ${
+ recipient.shardName}`);
+
+ const sourceCollectionUUIDString = extractUUIDFromObject(this._sourceCollectionUUID);
+ for (const donor of this._donorShards()) {
+ assert.eq(null,
+ recipient
+ .getCollection(`config.localReshardingOplogBuffer.${
+ sourceCollectionUUIDString}.${donor.shardName}`)
+ .exists(),
+ `expected config.localReshardingOplogBuffer.${sourceCollectionUUIDString}.${
+ donor.shardName} not to exist on ${recipient.shardName}, but it did.`);
+
+ assert.eq(null,
+ recipient
+ .getCollection(`config.localReshardingConflictStash.${
+ sourceCollectionUUIDString}.${donor.shardName}`)
+ .exists(),
+ `expected config.localReshardingConflictStash.${sourceCollectionUUIDString}.${
+ donor.shardName} not to exist on ${recipient.shardName}, but it did.`);
+ }
+
const localRecipientOpsNs = "config.localReshardingOperations.recipient";
let res;
assert.soon(
diff --git a/src/mongo/db/namespace_string.cpp b/src/mongo/db/namespace_string.cpp
index 4d07147c24b..0d59ea139ec 100644
--- a/src/mongo/db/namespace_string.cpp
+++ b/src/mongo/db/namespace_string.cpp
@@ -293,6 +293,14 @@ bool NamespaceString::isConfigDotCacheDotChunks() const {
return db() == "config" && coll().startsWith("cache.chunks.");
}
+bool NamespaceString::isReshardingLocalOplogBufferCollection() const {
+ return db() == "config" && coll().startsWith(kReshardingLocalOplogBufferPrefix);
+}
+
+bool NamespaceString::isReshardingConflictStashCollection() const {
+ return db() == "config" && coll().startsWith(kReshardingConflictStashPrefix);
+}
+
bool NamespaceString::isTemporaryReshardingCollection() const {
return coll().startsWith(kTemporaryReshardingCollectionPrefix);
}
diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h
index 8a5959ba986..6e4c050948c 100644
--- a/src/mongo/db/namespace_string.h
+++ b/src/mongo/db/namespace_string.h
@@ -73,6 +73,13 @@ public:
static constexpr StringData kOrphanCollectionPrefix = "orphan."_sd;
static constexpr StringData kOrphanCollectionDb = "local"_sd;
+ // Prefix for collections that store the local resharding oplog buffer.
+ static constexpr StringData kReshardingLocalOplogBufferPrefix =
+ "localReshardingOplogBuffer."_sd;
+
+ // Prefix for resharding conflict stash collections.
+ static constexpr StringData kReshardingConflictStashPrefix = "localReshardingConflictStash."_sd;
+
// Prefix for temporary resharding collection.
static constexpr StringData kTemporaryReshardingCollectionPrefix = "system.resharding."_sd;
@@ -316,6 +323,16 @@ public:
bool isConfigDotCacheDotChunks() const;
/**
+ * Returns whether the specified namespace is config.localReshardingOplogBuffer.<>.
+ */
+ bool isReshardingLocalOplogBufferCollection() const;
+
+ /**
+ * Returns whether the specified namespace is config.localReshardingConflictStash.<>.
+ */
+ bool isReshardingConflictStashCollection() const;
+
+ /**
* Returns whether the specified namespace is <database>.system.resharding.<>.
*/
bool isTemporaryReshardingCollection() const;
diff --git a/src/mongo/db/s/resharding/resharding_oplog_applier.cpp b/src/mongo/db/s/resharding/resharding_oplog_applier.cpp
index e2b4cc76667..8fcc9f18942 100644
--- a/src/mongo/db/s/resharding/resharding_oplog_applier.cpp
+++ b/src/mongo/db/s/resharding/resharding_oplog_applier.cpp
@@ -501,9 +501,7 @@ NamespaceString ReshardingOplogApplier::ensureStashCollectionExists(
const UUID& existingUUID,
const ShardId& donorShardId,
const CollectionOptions& options) {
- auto nss = NamespaceString{NamespaceString::kConfigDb,
- "localReshardingConflictStash.{}.{}"_format(
- existingUUID.toString(), donorShardId.toString())};
+ auto nss = getLocalConflictStashNamespace(existingUUID, donorShardId);
resharding::data_copy::ensureCollectionExists(opCtx, nss, options);
return nss;
diff --git a/src/mongo/db/s/resharding/resharding_recipient_service.cpp b/src/mongo/db/s/resharding/resharding_recipient_service.cpp
index 7d4cefc3705..d846bf9290c 100644
--- a/src/mongo/db/s/resharding/resharding_recipient_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_recipient_service.cpp
@@ -40,8 +40,10 @@
#include "mongo/db/repl/read_concern_args.h"
#include "mongo/db/s/migration_destination_manager.h"
#include "mongo/db/s/resharding/resharding_collection_cloner.h"
+#include "mongo/db/s/resharding/resharding_data_copy_util.h"
#include "mongo/db/s/resharding/resharding_metrics.h"
#include "mongo/db/s/resharding/resharding_server_parameters_gen.h"
+#include "mongo/db/s/resharding/resharding_txn_cloner_progress_gen.h"
#include "mongo/db/s/resharding_util.h"
#include "mongo/db/s/shard_key_util.h"
#include "mongo/db/s/sharding_state.h"
@@ -382,7 +384,7 @@ ReshardingRecipientService::RecipientStateMachine::_cloneThenTransitionToApplyin
*_recipientDoc.getFetchTimestamp()},
donor.getId(),
recipientId,
- getLocalOplogBufferNamespace(_recipientDoc.get_id(), donor.getId())));
+ getLocalOplogBufferNamespace(_recipientDoc.getExistingUUID(), donor.getId())));
_oplogFetcherFutures.emplace_back(
_oplogFetchers.back()
@@ -454,7 +456,7 @@ ExecutorFuture<void> ReshardingRecipientService::RecipientStateMachine::
}
const auto& oplogBufferNss =
- getLocalOplogBufferNamespace(_recipientDoc.get_id(), donor.getId());
+ getLocalOplogBufferNamespace(_recipientDoc.getExistingUUID(), donor.getId());
_oplogAppliers.emplace_back(std::make_unique<ReshardingOplogApplier>(
serviceContext,
ReshardingSourceId{_recipientDoc.get_id(), donor.getId()},
@@ -505,7 +507,6 @@ ExecutorFuture<void> ReshardingRecipientService::RecipientStateMachine::
}
void ReshardingRecipientService::RecipientStateMachine::_renameTemporaryReshardingCollection() {
-
if (_recipientDoc.getState() > RecipientStateEnum::kRenaming) {
return;
}
@@ -520,6 +521,8 @@ void ReshardingRecipientService::RecipientStateMachine::_renameTemporaryReshardi
options.dropTarget = true;
uassertStatusOK(
renameCollection(opCtx.get(), reshardingNss, _recipientDoc.getNss(), options));
+
+ _dropOplogCollections(opCtx.get());
}
_transitionStateAndUpdateCoordinator(RecipientStateEnum::kDone);
@@ -613,4 +616,38 @@ void ReshardingRecipientService::RecipientStateMachine::_removeRecipientDocument
_recipientDoc = {};
}
+void ReshardingRecipientService::RecipientStateMachine::_dropOplogCollections(
+ OperationContext* opCtx) {
+ for (const auto& donor : _recipientDoc.getDonorShardsMirroring()) {
+ auto reshardingSourceId = ReshardingSourceId{_recipientDoc.get_id(), donor.getId()};
+
+ // Remove the oplog applier progress doc for this donor.
+ PersistentTaskStore<ReshardingOplogApplierProgress> oplogApplierProgressStore(
+ NamespaceString::kReshardingApplierProgressNamespace);
+ oplogApplierProgressStore.remove(
+ opCtx,
+ QUERY(ReshardingOplogApplierProgress::kOplogSourceIdFieldName
+ << reshardingSourceId.toBSON()),
+ WriteConcernOptions());
+
+ // Remove the txn cloner progress doc for this donor.
+ PersistentTaskStore<ReshardingTxnClonerProgress> txnClonerProgressStore(
+ NamespaceString::kReshardingTxnClonerProgressNamespace);
+ txnClonerProgressStore.remove(
+ opCtx,
+ QUERY(ReshardingTxnClonerProgress::kSourceIdFieldName << reshardingSourceId.toBSON()),
+ WriteConcernOptions());
+
+ // Drop the conflict stash collection for this donor.
+ auto stashNss =
+ getLocalConflictStashNamespace(_recipientDoc.getExistingUUID(), donor.getId());
+ resharding::data_copy::ensureCollectionDropped(opCtx, stashNss);
+
+ // Drop the oplog buffer collection for this donor.
+ auto oplogBufferNss =
+ getLocalOplogBufferNamespace(_recipientDoc.getExistingUUID(), donor.getId());
+ resharding::data_copy::ensureCollectionDropped(opCtx, oplogBufferNss);
+ }
+}
+
} // namespace mongo
diff --git a/src/mongo/db/s/resharding/resharding_recipient_service.h b/src/mongo/db/s/resharding/resharding_recipient_service.h
index 71939cdb06c..0e508783b5c 100644
--- a/src/mongo/db/s/resharding/resharding_recipient_service.h
+++ b/src/mongo/db/s/resharding/resharding_recipient_service.h
@@ -158,6 +158,11 @@ private:
// Removes the local recipient document from disk and clears the in-memory state.
void _removeRecipientDocument();
+ // Removes any docs from the oplog applier progress and txn applier progress collections that
+ // are associated with the in-progress operation. Also drops all oplog buffer collections and
+ // all conflict stash collections that are associated with the in-progress operation.
+ void _dropOplogCollections(OperationContext* opCtx);
+
// The in-memory representation of the underlying document in
// config.localReshardingOperations.recipient.
ReshardingRecipientDocument _recipientDoc;
diff --git a/src/mongo/db/s/resharding_util.cpp b/src/mongo/db/s/resharding_util.cpp
index 98216b74805..0f99b1747ef 100644
--- a/src/mongo/db/s/resharding_util.cpp
+++ b/src/mongo/db/s/resharding_util.cpp
@@ -563,9 +563,15 @@ bool isFinalOplog(const repl::OplogEntry& oplog, UUID reshardingUUID) {
}
-NamespaceString getLocalOplogBufferNamespace(UUID reshardingUUID, ShardId donorShardId) {
+NamespaceString getLocalOplogBufferNamespace(UUID existingUUID, ShardId donorShardId) {
return NamespaceString("config.localReshardingOplogBuffer.{}.{}"_format(
- reshardingUUID.toString(), donorShardId.toString()));
+ existingUUID.toString(), donorShardId.toString()));
+}
+
+NamespaceString getLocalConflictStashNamespace(UUID existingUUID, ShardId donorShardId) {
+ return NamespaceString{NamespaceString::kConfigDb,
+ "localReshardingConflictStash.{}.{}"_format(existingUUID.toString(),
+ donorShardId.toString())};
}
} // namespace mongo
diff --git a/src/mongo/db/s/resharding_util.h b/src/mongo/db/s/resharding_util.h
index 4e4dc0b4d2d..70a2d5b65a9 100644
--- a/src/mongo/db/s/resharding_util.h
+++ b/src/mongo/db/s/resharding_util.h
@@ -262,6 +262,8 @@ boost::optional<ShardId> getDestinedRecipient(OperationContext* opCtx,
bool isFinalOplog(const repl::OplogEntry& oplog);
bool isFinalOplog(const repl::OplogEntry& oplog, UUID reshardingUUID);
-NamespaceString getLocalOplogBufferNamespace(UUID reshardingUUID, ShardId donorShardId);
+NamespaceString getLocalOplogBufferNamespace(UUID existingUUID, ShardId donorShardId);
+
+NamespaceString getLocalConflictStashNamespace(UUID existingUUID, ShardId donorShardId);
} // namespace mongo