summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlake Oler <blake.oler@mongodb.com>2021-04-03 16:03:16 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-09 15:19:17 +0000
commit52f52fbfce24cdaa806b31e4f32c9a96248eb807 (patch)
treef4ece6128c78cf044cd139c748bb7f36bfdf79f4
parentef755943b1d52975a828b5c634c19ecabe236610 (diff)
downloadmongo-52f52fbfce24cdaa806b31e4f32c9a96248eb807.tar.gz
SERVER-54035 Commit resharding manual cleanup base classes
-rw-r--r--src/mongo/db/s/SConscript1
-rw-r--r--src/mongo/db/s/config/configsvr_cleanup_reshard_collection_command.cpp21
-rw-r--r--src/mongo/db/s/resharding/resharding_manual_cleanup.cpp131
-rw-r--r--src/mongo/db/s/resharding/resharding_manual_cleanup.h108
-rw-r--r--src/mongo/db/s/shardsvr_cleanup_reshard_collection_command.cpp11
5 files changed, 269 insertions, 3 deletions
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index 12e0fa2ef94..2f8fd92ab26 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -80,6 +80,7 @@ env.Library(
'resharding/resharding_donor_recipient_common.cpp',
'resharding/resharding_donor_service.cpp',
'resharding/resharding_future_util.cpp',
+ 'resharding/resharding_manual_cleanup.cpp',
'resharding/resharding_metrics.cpp',
'resharding/resharding_op_observer.cpp',
'resharding/resharding_oplog_applier.cpp',
diff --git a/src/mongo/db/s/config/configsvr_cleanup_reshard_collection_command.cpp b/src/mongo/db/s/config/configsvr_cleanup_reshard_collection_command.cpp
index d3e5940a52a..049087402ea 100644
--- a/src/mongo/db/s/config/configsvr_cleanup_reshard_collection_command.cpp
+++ b/src/mongo/db/s/config/configsvr_cleanup_reshard_collection_command.cpp
@@ -33,8 +33,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
-#include "mongo/db/s/config/sharding_catalog_manager.h"
-#include "mongo/logv2/log.h"
+#include "mongo/db/s/resharding/resharding_manual_cleanup.h"
#include "mongo/s/grid.h"
#include "mongo/s/request_types/cleanup_reshard_collection_gen.h"
#include "mongo/s/resharding/resharding_feature_flag_gen.h"
@@ -63,6 +62,24 @@ public:
uassert(ErrorCodes::InvalidOptions,
"_configsvrCleanupReshardCollection must be called with majority writeConcern",
opCtx->getWriteConcern().wMode == WriteConcernOptions::kMajority);
+
+ repl::ReadConcernArgs::get(opCtx) =
+ repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern);
+
+ const auto catalogClient = Grid::get(opCtx)->catalogClient();
+ const auto collEntry = catalogClient->getCollection(opCtx, ns());
+ if (!collEntry.getReshardingFields()) {
+ // If the collection entry doesn't have resharding fields, we assume that the
+ // resharding operation has already been cleaned up.
+ return;
+ }
+
+ ReshardingCoordinatorCleaner cleaner(
+ ns(), collEntry.getReshardingFields()->getReshardingUUID());
+ cleaner.clean(opCtx);
+
+ // TODO SERVER-54035 Implement post-cleanup removal of reshardingFields to indicate
+ // complete cleanup.
}
private:
diff --git a/src/mongo/db/s/resharding/resharding_manual_cleanup.cpp b/src/mongo/db/s/resharding/resharding_manual_cleanup.cpp
new file mode 100644
index 00000000000..af48adf8699
--- /dev/null
+++ b/src/mongo/db/s/resharding/resharding_manual_cleanup.cpp
@@ -0,0 +1,131 @@
+/**
+ * Copyright (C) 2021-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kResharding
+
+#include "mongo/db/s/resharding/resharding_manual_cleanup.h"
+
+#include "mongo/logv2/log.h"
+
+namespace mongo {
+
+template <class Service, class StateMachine, class ReshardingDocument>
+ReshardingCleaner<Service, StateMachine, ReshardingDocument>::ReshardingCleaner(
+ NamespaceString reshardingDocumentNss,
+ NamespaceString originalCollectionNss,
+ UUID reshardingUUID)
+ : _originalCollectionNss(originalCollectionNss),
+ _reshardingDocumentNss(reshardingDocumentNss),
+ _reshardingUUID(reshardingUUID),
+ _store(reshardingDocumentNss) {}
+
+template <class Service, class StateMachine, class ReshardingDocument>
+void ReshardingCleaner<Service, StateMachine, ReshardingDocument>::clean(OperationContext* opCtx) {
+
+ LOGV2(5403503,
+ "Cleaning up resharding operation",
+ "namespace"_attr = _originalCollectionNss,
+ "reshardingUUID"_attr = _reshardingUUID,
+ "serviceType"_attr = Service::kServiceName);
+
+ auto reshardingDocument = _fetchReshardingDocumentFromDisk(opCtx);
+ if (!reshardingDocument) {
+ return;
+ }
+
+ opCtx->setAlwaysInterruptAtStepDownOrUp();
+
+ _waitOnMachineCompletionIfExists(opCtx);
+
+ _doClean(opCtx, *reshardingDocument);
+
+ // TODO SERVER-54035 Remove resharding document on local disk.
+}
+
+template <class Service, class StateMachine, class ReshardingDocument>
+boost::optional<ReshardingDocument>
+ReshardingCleaner<Service, StateMachine, ReshardingDocument>::_fetchReshardingDocumentFromDisk(
+ OperationContext* opCtx) {
+ return boost::none;
+}
+
+template <class Service, class StateMachine, class ReshardingDocument>
+void ReshardingCleaner<Service, StateMachine, ReshardingDocument>::_waitOnMachineCompletionIfExists(
+ OperationContext* opCtx) {}
+
+template class ReshardingCleaner<ReshardingCoordinatorService,
+ ReshardingCoordinatorService::ReshardingCoordinator,
+ ReshardingCoordinatorDocument>;
+
+template class ReshardingCleaner<ReshardingDonorService,
+ ReshardingDonorService::DonorStateMachine,
+ ReshardingDonorDocument>;
+
+template class ReshardingCleaner<ReshardingRecipientService,
+ ReshardingRecipientService::RecipientStateMachine,
+ ReshardingRecipientDocument>;
+
+ReshardingCoordinatorCleaner::ReshardingCoordinatorCleaner(NamespaceString nss, UUID reshardingUUID)
+ : ReshardingCleaner(NamespaceString::kConfigReshardingOperationsNamespace,
+ std::move(nss),
+ std::move(reshardingUUID)) {
+ invariant(serverGlobalParams.clusterRole == ClusterRole::ConfigServer);
+}
+
+void ReshardingCoordinatorCleaner::_doClean(OperationContext* opCtx,
+ const ReshardingCoordinatorDocument& doc) {
+ _cleanOnParticipantShards(opCtx, doc);
+ _dropTemporaryReshardingCollection(opCtx);
+}
+
+void ReshardingCoordinatorCleaner::_cleanOnParticipantShards(
+ OperationContext* opCtx, const ReshardingCoordinatorDocument& doc) {}
+
+void ReshardingCoordinatorCleaner::_dropTemporaryReshardingCollection(OperationContext* opCtx) {}
+
+ReshardingDonorCleaner::ReshardingDonorCleaner(NamespaceString nss, UUID reshardingUUID)
+ : ReshardingCleaner(NamespaceString::kDonorReshardingOperationsNamespace,
+ std::move(nss),
+ std::move(reshardingUUID)) {
+ invariant(serverGlobalParams.clusterRole == ClusterRole::ShardServer);
+}
+
+ReshardingRecipientCleaner::ReshardingRecipientCleaner(NamespaceString nss, UUID reshardingUUID)
+ : ReshardingCleaner(NamespaceString::kRecipientReshardingOperationsNamespace,
+ std::move(nss),
+ std::move(reshardingUUID)) {
+ invariant(serverGlobalParams.clusterRole == ClusterRole::ShardServer);
+}
+
+void ReshardingRecipientCleaner::_doClean(OperationContext* opCtx,
+ const ReshardingRecipientDocument& doc) {
+ // TODO SERVER-54035 Call into shared recipient metadata cleanup function.
+}
+
+} // namespace mongo
diff --git a/src/mongo/db/s/resharding/resharding_manual_cleanup.h b/src/mongo/db/s/resharding/resharding_manual_cleanup.h
new file mode 100644
index 00000000000..1fe3e433705
--- /dev/null
+++ b/src/mongo/db/s/resharding/resharding_manual_cleanup.h
@@ -0,0 +1,108 @@
+/**
+ * Copyright (C) 2021-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#pragma once
+
+#include "mongo/db/namespace_string.h"
+#include "mongo/db/persistent_task_store.h"
+#include "mongo/db/s/resharding/resharding_coordinator_service.h"
+#include "mongo/db/s/resharding/resharding_donor_service.h"
+#include "mongo/db/s/resharding/resharding_recipient_service.h"
+#include "mongo/util/uuid.h"
+
+namespace mongo {
+
+class OperationContext;
+
+template <class Service, class StateMachine, class ReshardingDocument>
+class ReshardingCleaner {
+public:
+ ReshardingCleaner(NamespaceString reshardingDocumentNss,
+ NamespaceString originalCollectionNss,
+ UUID reshardingUUID);
+
+ virtual ~ReshardingCleaner() = default;
+
+ void clean(OperationContext* opCtx);
+
+protected:
+ virtual void _doClean(OperationContext* opCtx, const ReshardingDocument& doc) = 0;
+
+ boost::optional<ReshardingDocument> _fetchReshardingDocumentFromDisk(OperationContext* opCtx);
+
+ void _waitOnMachineCompletionIfExists(OperationContext* opCtx);
+
+ const NamespaceString _originalCollectionNss;
+
+ const NamespaceString _reshardingDocumentNss;
+
+ const UUID _reshardingUUID;
+
+private:
+ PersistentTaskStore<ReshardingDocument> _store;
+};
+
+class ReshardingCoordinatorCleaner
+ : public ReshardingCleaner<ReshardingCoordinatorService,
+ ReshardingCoordinatorService::ReshardingCoordinator,
+ ReshardingCoordinatorDocument> {
+public:
+ ReshardingCoordinatorCleaner(NamespaceString nss, UUID reshardingUUID);
+
+private:
+ void _doClean(OperationContext* opCtx, const ReshardingCoordinatorDocument& doc) override;
+
+ void _cleanOnParticipantShards(OperationContext* opCtx,
+ const ReshardingCoordinatorDocument& doc);
+
+ void _dropTemporaryReshardingCollection(OperationContext* opCtx);
+};
+
+class ReshardingDonorCleaner : public ReshardingCleaner<ReshardingDonorService,
+ ReshardingDonorService::DonorStateMachine,
+ ReshardingDonorDocument> {
+public:
+ ReshardingDonorCleaner(NamespaceString nss, UUID reshardingUUID);
+
+private:
+ void _doClean(OperationContext* opCtx, const ReshardingDonorDocument& doc) override{};
+};
+
+class ReshardingRecipientCleaner
+ : public ReshardingCleaner<ReshardingRecipientService,
+ ReshardingRecipientService::RecipientStateMachine,
+ ReshardingRecipientDocument> {
+public:
+ ReshardingRecipientCleaner(NamespaceString nss, UUID reshardingUUID);
+
+private:
+ void _doClean(OperationContext* opCtx, const ReshardingRecipientDocument& doc) override;
+};
+
+} // namespace mongo
diff --git a/src/mongo/db/s/shardsvr_cleanup_reshard_collection_command.cpp b/src/mongo/db/s/shardsvr_cleanup_reshard_collection_command.cpp
index 2f3ebf4aeaf..f233ab28a5c 100644
--- a/src/mongo/db/s/shardsvr_cleanup_reshard_collection_command.cpp
+++ b/src/mongo/db/s/shardsvr_cleanup_reshard_collection_command.cpp
@@ -33,7 +33,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
-#include "mongo/logv2/log.h"
+#include "mongo/db/s/resharding/resharding_manual_cleanup.h"
#include "mongo/s/request_types/cleanup_reshard_collection_gen.h"
#include "mongo/s/resharding/resharding_feature_flag_gen.h"
@@ -61,6 +61,15 @@ public:
uassert(ErrorCodes::InvalidOptions,
"_shardsvrCleanupReshardCollection must be called with majority writeConcern",
opCtx->getWriteConcern().wMode == WriteConcernOptions::kMajority);
+
+ repl::ReadConcernArgs::get(opCtx) =
+ repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern);
+
+ ReshardingDonorCleaner donorCleaner(ns(), request().getReshardingUUID());
+ donorCleaner.clean(opCtx);
+
+ ReshardingRecipientCleaner recipientCleaner(ns(), request().getReshardingUUID());
+ recipientCleaner.clean(opCtx);
}
private: