summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2021-01-12 04:49:01 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-01-12 05:58:51 +0000
commita585658b923b716a977b2df2bdeb1b7663fe3824 (patch)
tree369d303ddb3da08101f1d94b392556a4cb11574b /src
parentb6df39916f37f6029dc561f73ab157346982340b (diff)
downloadmongo-a585658b923b716a977b2df2bdeb1b7663fe3824.tar.gz
SERVER-53224 Fix collection drop on donor shards for resharding.
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/s/resharding/resharding_data_copy_util.cpp22
-rw-r--r--src/mongo/db/s/resharding/resharding_data_copy_util.h15
-rw-r--r--src/mongo/db/s/resharding/resharding_donor_service.cpp29
3 files changed, 42 insertions, 24 deletions
diff --git a/src/mongo/db/s/resharding/resharding_data_copy_util.cpp b/src/mongo/db/s/resharding/resharding_data_copy_util.cpp
index bf59a4af30c..ad85a69d241 100644
--- a/src/mongo/db/s/resharding/resharding_data_copy_util.cpp
+++ b/src/mongo/db/s/resharding/resharding_data_copy_util.cpp
@@ -40,6 +40,7 @@
namespace mongo::resharding::data_copy {
void ensureCollectionExists(OperationContext* opCtx, const NamespaceString& nss) {
+ invariant(!opCtx->lockState()->isLocked());
invariant(!opCtx->lockState()->inAWriteUnitOfWork());
writeConflictRetry(opCtx, "resharding::data_copy::ensureCollectionExists", nss.toString(), [&] {
@@ -54,4 +55,25 @@ void ensureCollectionExists(OperationContext* opCtx, const NamespaceString& nss)
});
}
+void ensureCollectionDropped(OperationContext* opCtx,
+ const NamespaceString& nss,
+ const boost::optional<CollectionUUID>& uuid) {
+ invariant(!opCtx->lockState()->isLocked());
+ invariant(!opCtx->lockState()->inAWriteUnitOfWork());
+
+ writeConflictRetry(
+ opCtx, "resharding::data_copy::ensureCollectionDropped", nss.toString(), [&] {
+ AutoGetCollection coll(opCtx, nss, MODE_X);
+ if (!coll || (uuid && coll->uuid() != uuid)) {
+ // If the collection doesn't exist or exists with a different UUID, then the
+ // requested collection has been dropped already.
+ return;
+ }
+
+ WriteUnitOfWork wuow(opCtx);
+ uassertStatusOK(coll.getDb()->dropCollectionEvenIfSystem(opCtx, nss));
+ wuow.commit();
+ });
+}
+
} // namespace mongo::resharding::data_copy
diff --git a/src/mongo/db/s/resharding/resharding_data_copy_util.h b/src/mongo/db/s/resharding/resharding_data_copy_util.h
index 72ccd0cd8b1..22b96a1b26a 100644
--- a/src/mongo/db/s/resharding/resharding_data_copy_util.h
+++ b/src/mongo/db/s/resharding/resharding_data_copy_util.h
@@ -29,6 +29,10 @@
#pragma once
+#include <boost/optional.hpp>
+
+#include "mongo/db/catalog/collection_catalog.h"
+
namespace mongo {
class NamespaceString;
@@ -38,5 +42,16 @@ namespace resharding::data_copy {
void ensureCollectionExists(OperationContext* opCtx, const NamespaceString& nss);
+/**
+ * Drops the specified collection or returns without error if the collection has already been
+ * dropped. A particular incarnation of the collection can be dropped by specifying its UUID.
+ *
+ * This functions assumes the collection being dropped doesn't have any two-phase index builds
+ * active on it.
+ */
+void ensureCollectionDropped(OperationContext* opCtx,
+ const NamespaceString& nss,
+ const boost::optional<CollectionUUID>& uuid = boost::none);
+
} // namespace resharding::data_copy
} // namespace mongo
diff --git a/src/mongo/db/s/resharding/resharding_donor_service.cpp b/src/mongo/db/s/resharding/resharding_donor_service.cpp
index 8bece262499..18869850144 100644
--- a/src/mongo/db/s/resharding/resharding_donor_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_donor_service.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/op_observer.h"
#include "mongo/db/persistent_task_store.h"
#include "mongo/db/repl/repl_client_info.h"
+#include "mongo/db/s/resharding/resharding_data_copy_util.h"
#include "mongo/db/s/resharding/resharding_server_parameters_gen.h"
#include "mongo/db/s/resharding_util.h"
#include "mongo/db/s/sharding_state.h"
@@ -408,30 +409,10 @@ void ReshardingDonorService::DonorStateMachine::_dropOriginalCollection() {
return;
}
- auto origNssRoutingInfo =
- getShardedCollectionRoutingInfoWithRefreshAndFlush(_donorDoc.getNss());
- auto currentCollectionUUID =
- getCollectionUUIDFromChunkManger(_donorDoc.getNss(), origNssRoutingInfo);
-
- if (currentCollectionUUID == _donorDoc.getExistingUUID()) {
- DBDirectClient client(cc().makeOperationContext().get());
- BSONObj dropResult;
- if (!client.dropCollection(
- _donorDoc.getNss().toString(), WriteConcerns::kMajorityWriteConcern, &dropResult)) {
- auto dropStatus = getStatusFromCommandResult(dropResult);
- if (dropStatus != ErrorCodes::NamespaceNotFound) {
- uassertStatusOK(dropStatus);
- }
- }
- } else {
- uassert(ErrorCodes::InvalidUUID,
- "Expected collection {} to have either the original UUID {} or the resharding UUID"
- " {}, but the collection instead has UUID {}"_format(
- _donorDoc.getNss().toString(),
- _donorDoc.getExistingUUID().toString(),
- _donorDoc.get_id().toString(),
- currentCollectionUUID.toString()),
- currentCollectionUUID == _donorDoc.get_id());
+ {
+ auto opCtx = cc().makeOperationContext();
+ resharding::data_copy::ensureCollectionDropped(
+ opCtx.get(), _donorDoc.getNss(), _donorDoc.getExistingUUID());
}
_transitionStateAndUpdateCoordinator(DonorStateEnum::kDone);