diff options
author | Lingzhi Deng <lingzhi.deng@mongodb.com> | 2021-02-01 11:35:37 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-01 22:37:56 +0000 |
commit | ca2d817f0a7dc8cad500a7b2e304400c65243217 (patch) | |
tree | 035cf9c5cbf388d4203e3d4b3d03c99ebbc9a2d7 /src/mongo/db/repl/tenant_migration_access_blocker_util.h | |
parent | 120901099ba270b557054bc8ef06ac87418c0834 (diff) | |
download | mongo-ca2d817f0a7dc8cad500a7b2e304400c65243217.tar.gz |
SERVER-53581: Refactor TenantMigrationAccessBlock
Diffstat (limited to 'src/mongo/db/repl/tenant_migration_access_blocker_util.h')
-rw-r--r-- | src/mongo/db/repl/tenant_migration_access_blocker_util.h | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/src/mongo/db/repl/tenant_migration_access_blocker_util.h b/src/mongo/db/repl/tenant_migration_access_blocker_util.h new file mode 100644 index 00000000000..6cd7d7b9102 --- /dev/null +++ b/src/mongo/db/repl/tenant_migration_access_blocker_util.h @@ -0,0 +1,111 @@ +/** + * Copyright (C) 2020-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/catalog/database.h" +#include "mongo/db/commands.h" +#include "mongo/db/commands/tenant_migration_donor_cmds_gen.h" +#include "mongo/db/operation_context.h" +#include "mongo/db/repl/tenant_migration_access_blocker_registry.h" +#include "mongo/db/repl/tenant_migration_conflict_info.h" +#include "mongo/db/repl/tenant_migration_state_machine_gen.h" +#include "mongo/db/request_execution_context.h" +#include "mongo/executor/task_executor.h" +#include "mongo/rpc/get_status_from_command_result.h" +#include "mongo/rpc/reply_builder_interface.h" +#include "mongo/util/functional.h" +#include "mongo/util/future.h" + +namespace mongo { + +namespace tenant_migration_access_blocker { + +std::shared_ptr<TenantMigrationDonorAccessBlocker> getTenantMigrationDonorAccessBlocker( + ServiceContext* const serviceContext, StringData tenantId); + +/** + * Returns a TenantMigrationDonorDocument constructed from the given bson doc and validate the + * resulting doc. + */ +TenantMigrationDonorDocument parseDonorStateDocument(const BSONObj& doc); + +/** + * If the operation has read concern "snapshot" or includes afterClusterTime, and the database is + * in the read blocking state at the given atClusterTime or afterClusterTime or the selected read + * timestamp, blocks until the migration is committed or aborted. + * TODO SERVER-53505: Change this to return + * SharedSemiFuture<TenantMigrationDonorAccessBlocker::State>. + */ +void checkIfCanReadOrBlock(OperationContext* opCtx, StringData dbName); + +/** + * If the operation has read concern "linearizable", throws TenantMigrationCommitted error if the + * database has been migrated to a different replica set. + */ +void checkIfLinearizableReadWasAllowedOrThrow(OperationContext* opCtx, StringData dbName); + +/** + * Throws TenantMigrationConflict if the database is being migrated and the migration is in the + * blocking state. Throws TenantMigrationCommitted if it is in committed. + */ +void onWriteToDatabase(OperationContext* opCtx, StringData dbName); + +/** + * Returns TenantMigrationConflict if the database is being migrated (even if migration is not yet + * in the blocking state). Returns TenantMigrationCommitted if it is in committed. + */ +Status checkIfCanBuildIndex(OperationContext* opCtx, StringData dbName); + +/** + * Scan config.tenantMigrationDonors and creates the necessary TenantMigrationAccessBlockers for + * unfinished migrations. + */ +void recoverTenantMigrationAccessBlockers(OperationContext* opCtx); + +/** + * Blocks until the migration commits or aborts, then returns TenantMigrationCommitted or + * TenantMigrationAborted. + */ +void handleTenantMigrationConflict(OperationContext* opCtx, Status status); + +/** + * Append a no-op to the oplog. + */ +void performNoopWrite(OperationContext* opCtx, StringData msg); + +/** + * Creates a view on the oplog that allows a tenant migration recipient to fetch retryable writes + * from a tenant migration donor. + */ +void createRetryableWritesView(OperationContext* opCtx, Database* db); + +} // namespace tenant_migration_access_blocker + +} // namespace mongo |