diff options
author | mathisbessamdb <mathis.bessa@mongodb.com> | 2022-11-18 23:04:18 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-18 23:58:48 +0000 |
commit | 4fd85ab061c1b31af3d641d743420d66ce25cf5c (patch) | |
tree | ac715e5637d6aee1523be2fdc8bf185058910c60 /src | |
parent | 0d9b3912cee0897af35ec529a687d886f2b5a06d (diff) | |
download | mongo-4fd85ab061c1b31af3d641d743420d66ce25cf5c.tar.gz |
SERVER-71179 Update the ShardSplitCommands to use the TenantId class
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/repl/tenant_migration_util.h | 22 | ||||
-rw-r--r-- | src/mongo/db/serverless/shard_split_commands.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/serverless/shard_split_commands.idl | 2 |
3 files changed, 33 insertions, 2 deletions
diff --git a/src/mongo/db/repl/tenant_migration_util.h b/src/mongo/db/repl/tenant_migration_util.h index e26daf9ad7e..2332693961d 100644 --- a/src/mongo/db/repl/tenant_migration_util.h +++ b/src/mongo/db/repl/tenant_migration_util.h @@ -79,6 +79,28 @@ inline Status validateDatabasePrefix(const std::vector<std::string>& tenantsId) return Status::OK(); } +inline Status validateDatabasePrefix(const TenantId& tenantId) { + auto tId = tenantId.toString(); + const bool isPrefixSupported = kUnsupportedTenantIds.find(tId) == kUnsupportedTenantIds.end() && + tId.find('_') == std::string::npos; + + return isPrefixSupported + ? Status::OK() + : Status(ErrorCodes::BadValue, + str::stream() << "cannot migrate databases for tenant \'" << tId << "'"); +} + +inline Status validateDatabasePrefix(const std::vector<TenantId>& tenantsId) { + for (const auto& tenantId : tenantsId) { + auto status = validateDatabasePrefix(tenantId); + if (!status.isOK()) { + return status; + } + } + + return Status::OK(); +} + inline Status validateProtocolFCVCompatibility( const boost::optional<MigrationProtocolEnum>& protocol) { if (!protocol) diff --git a/src/mongo/db/serverless/shard_split_commands.cpp b/src/mongo/db/serverless/shard_split_commands.cpp index 5ce6c9c0307..3988879730d 100644 --- a/src/mongo/db/serverless/shard_split_commands.cpp +++ b/src/mongo/db/serverless/shard_split_commands.cpp @@ -64,7 +64,16 @@ public: const auto& cmd = request(); auto stateDoc = ShardSplitDonorDocument(cmd.getMigrationId()); - stateDoc.setTenantIds(cmd.getTenantIds()); + std::vector<std::string> tenantIds; + // TODO (SERVER-71184) revert the code to directly assigned getTenantIds to the statedoc + for (auto id : cmd.getTenantIds()) { + tenantIds.push_back(id.toString()); + } + std::vector<StringData> tenantIdsSd; + for (const auto& id : tenantIds) { + tenantIdsSd.push_back(id); + } + stateDoc.setTenantIds(tenantIdsSd); stateDoc.setRecipientTagName(cmd.getRecipientTagName()); stateDoc.setRecipientSetName(cmd.getRecipientSetName()); diff --git a/src/mongo/db/serverless/shard_split_commands.idl b/src/mongo/db/serverless/shard_split_commands.idl index 3856f9a3ddc..95382514160 100644 --- a/src/mongo/db/serverless/shard_split_commands.idl +++ b/src/mongo/db/serverless/shard_split_commands.idl @@ -67,7 +67,7 @@ commands: type: string tenantIds: description: "The identifier for the list of tenants being migrated." - type: array<string> + type: array<tenant_id> validator: callback: "tenant_migration_util::validateDatabasePrefix" |