diff options
author | Jason Zhang <jason.zhang@mongodb.com> | 2020-10-13 00:28:43 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-10-22 23:47:43 +0000 |
commit | e428dcb7b9bc3d6b39c4a0de4db46c75441c9d64 (patch) | |
tree | cb90ac43f42bdb170af05959bd3f13b42ab669cf /src/mongo/db/commands | |
parent | 22eb29f52ff8349d6cc10ec27b35af80d455f9ab (diff) | |
download | mongo-e428dcb7b9bc3d6b39c4a0de4db46c75441c9d64.tar.gz |
SERVER-51423 Test that a bulk write returns ok for the writes that complete before a migration starts blocking and TenantMigrationCommitted for the ones that don't
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r-- | src/mongo/db/commands/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/commands/write_commands/write_commands.cpp | 40 |
2 files changed, 39 insertions, 2 deletions
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript index 8103d17b935..88797068b62 100644 --- a/src/mongo/db/commands/SConscript +++ b/src/mongo/db/commands/SConscript @@ -320,6 +320,7 @@ env.Library( '$BUILD_DIR/mongo/db/query/command_request_response', '$BUILD_DIR/mongo/db/query_exec', '$BUILD_DIR/mongo/db/repl/replica_set_messages', + '$BUILD_DIR/mongo/db/repl/tenant_migration_donor', '$BUILD_DIR/mongo/db/rw_concern_d', '$BUILD_DIR/mongo/db/stats/counters', '$BUILD_DIR/mongo/db/stats/server_read_concern_write_concern_metrics', diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp index 06ecbf0f175..45b3b2c78ee 100644 --- a/src/mongo/db/commands/write_commands/write_commands.cpp +++ b/src/mongo/db/commands/write_commands/write_commands.cpp @@ -54,6 +54,9 @@ #include "mongo/db/query/get_executor.h" #include "mongo/db/repl/repl_client_info.h" #include "mongo/db/repl/replication_coordinator.h" +#include "mongo/db/repl/tenant_migration_access_blocker_registry.h" +#include "mongo/db/repl/tenant_migration_committed_info.h" +#include "mongo/db/repl/tenant_migration_conflict_info.h" #include "mongo/db/stats/counters.h" #include "mongo/db/storage/duplicate_key_error_info.h" #include "mongo/db/write_concern.h" @@ -100,7 +103,8 @@ void serializeReply(OperationContext* opCtx, const auto& lastResult = result.results.back(); if (lastResult == ErrorCodes::StaleDbVersion || - ErrorCodes::isStaleShardVersionError(lastResult.getStatus())) { + ErrorCodes::isStaleShardVersionError(lastResult.getStatus()) || + ErrorCodes::isTenantMigrationError(lastResult.getStatus())) { // For ordered:false commands we need to duplicate these error results for all ops after // we stopped. See handleError() in write_ops_exec.cpp for more info. // @@ -159,6 +163,34 @@ void serializeReply(OperationContext* opCtx, status.extraInfo<doc_validation_error::DocumentValidationFailureInfo>(); error.append("code", static_cast<int>(ErrorCodes::DocumentValidationFailure)); error.append("errInfo", docValidationError->getDetails()); + } else if (ErrorCodes::isTenantMigrationError(status.code())) { + if (ErrorCodes::TenantMigrationConflict == status.code()) { + auto migrationConflictInfo = status.extraInfo<TenantMigrationConflictInfo>(); + auto& mtabRegistry = + TenantMigrationAccessBlockerRegistry::get(opCtx->getServiceContext()); + auto mtab = mtabRegistry.getTenantMigrationAccessBlockerForTenantId( + migrationConflictInfo->getTenantId()); + + auto migrationStatus = mtab->waitUntilCommittedOrAbortedNoThrow(opCtx); + error.append("code", static_cast<int>(migrationStatus.code())); + + // We want to append an empty errmsg for the errors after the first one, so let the + // code below that appends errmsg do that. + if (status.reason() != "") { + error.append("errmsg", errorMessage(migrationStatus.reason())); + } + if (migrationStatus.extraInfo()) { + error.append( + "errInfo", + migrationStatus.extraInfo<TenantMigrationCommittedInfo>()->toBSON()); + } + } else { + error.append("code", int(status.code())); + if (status.extraInfo()) { + error.append("errInfo", + status.extraInfo<TenantMigrationCommittedInfo>()->toBSON()); + } + } } else { error.append("code", int(status.code())); if (auto const extraInfo = status.extraInfo()) { @@ -166,7 +198,11 @@ void serializeReply(OperationContext* opCtx, } } - error.append("errmsg", errorMessage(status.reason())); + // Skip appending errmsg if it has already been appended like in the case of + // TenantMigrationConflict. + if (!error.hasField("errmsg")) { + error.append("errmsg", errorMessage(status.reason())); + } errors.push_back(error.obj()); } |