summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r--src/mongo/db/repl/migrating_tenant_donor_util.cpp25
-rw-r--r--src/mongo/db/repl/migrating_tenant_donor_util.h3
2 files changed, 28 insertions, 0 deletions
diff --git a/src/mongo/db/repl/migrating_tenant_donor_util.cpp b/src/mongo/db/repl/migrating_tenant_donor_util.cpp
index 826551972a6..84c93afacfd 100644
--- a/src/mongo/db/repl/migrating_tenant_donor_util.cpp
+++ b/src/mongo/db/repl/migrating_tenant_donor_util.cpp
@@ -27,7 +27,10 @@
* it in the license file.
*/
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kReplication;
+
#include "mongo/platform/basic.h"
+#include "mongo/util/str.h"
#include "mongo/db/repl/migrating_tenant_donor_util.h"
@@ -36,10 +39,13 @@
#include "mongo/db/dbhelpers.h"
#include "mongo/db/repl/migrate_tenant_state_machine_gen.h"
#include "mongo/db/repl/migrating_tenant_access_blocker_by_prefix.h"
+#include "mongo/db/s/persistent_task_store.h"
#include "mongo/executor/network_interface_factory.h"
#include "mongo/executor/thread_pool_task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/concurrency/thread_pool.h"
+
namespace mongo {
namespace migrating_tenant_donor_util {
@@ -137,13 +143,16 @@ void dataSync(OperationContext* opCtx, const TenantMigrationDonorDocument& origi
// Reserve an opTime for the write and use it as the blockTimestamp for the migration.
auto oplogSlot = repl::LocalOplogInfo::get(opCtx)->getNextOpTimes(opCtx, 1U)[0];
+
TenantMigrationDonorDocument updatedDoc;
updatedDoc.setId(originalDoc.getId());
updatedDoc.setDatabasePrefix(originalDoc.getDatabasePrefix());
updatedDoc.setState(TenantMigrationDonorStateEnum::kBlocking);
updatedDoc.setBlockTimestamp(oplogSlot.getTimestamp());
+
CollectionUpdateArgs args;
+ // ! Since the updatedDoc isn't properly created, this will throw an error
args.update = updatedDoc.toBSON();
args.criteria = BSON("_id" << originalDoc.getId());
args.oplogSlot = oplogSlot;
@@ -196,6 +205,22 @@ void onTenantMigrationDonorStateTransition(OperationContext* opCtx, const BSONOb
}
}
+void persistDonorStateMachine(OperationContext* opCtx,
+ const TenantMigrationDonorDocument& donorDoc) {
+ PersistentTaskStore<TenantMigrationDonorDocument> store(
+ NamespaceString::kMigrationDonorsNamespace);
+ try {
+ store.add(opCtx, donorDoc);
+ } catch (const ExceptionFor<ErrorCodes::DuplicateKey>&) {
+ uasserted(
+ 4917300,
+ str::stream()
+ << "While attempting to persist the donor state machine for tenant migration"
+ << ", found another document with the same migration id. Attempted migration: "
+ << donorDoc.toBSON());
+ }
+}
+
} // namespace migrating_tenant_donor_util
} // namespace mongo
diff --git a/src/mongo/db/repl/migrating_tenant_donor_util.h b/src/mongo/db/repl/migrating_tenant_donor_util.h
index 64bfe1474ec..fd48b203057 100644
--- a/src/mongo/db/repl/migrating_tenant_donor_util.h
+++ b/src/mongo/db/repl/migrating_tenant_donor_util.h
@@ -53,6 +53,9 @@ std::shared_ptr<executor::TaskExecutor> getTenantMigrationExecutor(ServiceContex
* config.migrationDonors document.
*/
void onTenantMigrationDonorStateTransition(OperationContext* opCtx, const BSONObj& doc);
+
+void persistDonorStateMachine(OperationContext* opCtx,
+ const TenantMigrationDonorDocument& donorDoc);
} // namespace migrating_tenant_donor_util
} // namespace mongo