diff --git a/fdbcli/TenantCommands.actor.cpp b/fdbcli/TenantCommands.actor.cpp index 24d75b0405..0004fa75c5 100644 --- a/fdbcli/TenantCommands.actor.cpp +++ b/fdbcli/TenantCommands.actor.cpp @@ -350,8 +350,8 @@ ACTOR Future<bool> getTenantCommandActor(Reference<IDatabase> db, std::vector<St int64_t id; std::string prefix; - std::string tenantGroup; std::string tenantState; + std::string tenantGroup; std::string assignedCluster; doc.get("id", id); @@ -363,18 +363,18 @@ ACTOR Future<bool> getTenantCommandActor(Reference<IDatabase> db, std::vector<St } doc.get("tenant_state", tenantState); - bool hasAssignedCluster = doc.tryGet("assigned_cluster", assignedCluster); bool hasTenantGroup = doc.tryGet("tenant_group.printable", tenantGroup); + bool hasAssignedCluster = doc.tryGet("assigned_cluster", assignedCluster); fmt::print(" id: {}\n", id); fmt::print(" prefix: {}\n", printable(prefix).c_str()); fmt::print(" tenant state: {}\n", printable(tenantState).c_str()); - if (hasAssignedCluster) { - fmt::print(" assigned cluster: {}\n", printable(assignedCluster).c_str()); - } if (hasTenantGroup) { fmt::print(" tenant group: {}\n", tenantGroup.c_str()); } + if (hasAssignedCluster) { + fmt::print(" assigned cluster: {}\n", printable(assignedCluster).c_str()); + } } return true; } catch (Error& e) { diff --git a/fdbclient/Tenant.cpp b/fdbclient/Tenant.cpp index 9f3c4bc86a..0461500648 100644 --- a/fdbclient/Tenant.cpp +++ b/fdbclient/Tenant.cpp @@ -74,8 +74,8 @@ TenantMapEntry::TenantMapEntry() {} TenantMapEntry::TenantMapEntry(int64_t id, TenantState tenantState) : tenantState(tenantState) { setId(id); } -TenantMapEntry::TenantMapEntry(int64_t id, Optional<TenantGroupName> tenantGroup, TenantState tenantState) - : tenantGroup(tenantGroup), tenantState(tenantState) { +TenantMapEntry::TenantMapEntry(int64_t id, TenantState tenantState, Optional<TenantGroupName> tenantGroup) + : tenantState(tenantState), tenantGroup(tenantGroup) { setId(id); } @@ -131,6 +131,17 @@ std::string TenantMapEntry::toJson(int apiVersion) const { tenantEntry["tenant_group"] = tenantGroupObject; } + if (tenantGroup.present()) { + json_spirit::mObject tenantGroupObject; + std::string encodedTenantGroup = base64::encoder::from_string(tenantGroup.get().toString()); + // Remove trailing newline + encodedTenantGroup.resize(encodedTenantGroup.size() - 1); + + tenantGroupObject["base64"] = encodedTenantGroup; + tenantGroupObject["printable"] = printable(tenantGroup.get()); + tenantEntry["tenant_group"] = tenantGroupObject; + } + return json_spirit::write_string(json_spirit::mValue(tenantEntry)); } diff --git a/fdbclient/include/fdbclient/Tenant.h b/fdbclient/include/fdbclient/Tenant.h index 16ce0a9fbf..44c47c11db 100644 --- a/fdbclient/include/fdbclient/Tenant.h +++ b/fdbclient/include/fdbclient/Tenant.h @@ -46,8 +46,8 @@ struct TenantMapEntry { int64_t id = -1; Key prefix; - Optional<TenantGroupName> tenantGroup; TenantState tenantState = TenantState::READY; + Optional<TenantGroupName> tenantGroup; Optional<ClusterName> assignedCluster; int64_t configurationSequenceNum = 0; @@ -55,7 +55,7 @@ struct TenantMapEntry { TenantMapEntry(); TenantMapEntry(int64_t id, TenantState tenantState); - TenantMapEntry(int64_t id, Optional<TenantGroupName> tenantGroup, TenantState tenantState); + TenantMapEntry(int64_t id, TenantState tenantState, Optional<TenantGroupName> tenantGroup); void setId(int64_t id); @@ -64,7 +64,7 @@ struct TenantMapEntry { std::string toJson(int apiVersion) const; - Value encode() const { return ObjectWriter::toValue(*this, IncludeVersion(ProtocolVersion::withTenantGroups())); } + Value encode() const { return ObjectWriter::toValue(*this, IncludeVersion(ProtocolVersion::withTenants())); } static TenantMapEntry decode(ValueRef const& value) { TenantMapEntry entry; @@ -75,7 +75,7 @@ struct TenantMapEntry { template <class Ar> void serialize(Ar& ar) { - serializer(ar, id, tenantGroup, tenantState, assignedCluster, configurationSequenceNum); + serializer(ar, id, tenantState, tenantGroup, assignedCluster, configurationSequenceNum); if constexpr (Ar::isDeserializing) { if (id >= 0) { prefix = idToPrefix(id); @@ -93,7 +93,7 @@ struct TenantGroupEntry { TenantGroupEntry() = default; TenantGroupEntry(Optional<ClusterName> assignedCluster) : assignedCluster(assignedCluster) {} - Value encode() { return ObjectWriter::toValue(*this, IncludeVersion(ProtocolVersion::withMetacluster())); } + Value encode() { return ObjectWriter::toValue(*this, IncludeVersion(ProtocolVersion::withTenants())); } static TenantGroupEntry decode(ValueRef const& value) { TenantGroupEntry entry; ObjectReader reader(value.begin(), IncludeVersion()); diff --git a/fdbserver/workloads/TenantManagementWorkload.actor.cpp b/fdbserver/workloads/TenantManagementWorkload.actor.cpp index d9814ad24f..ad4853cfa8 100644 --- a/fdbserver/workloads/TenantManagementWorkload.actor.cpp +++ b/fdbserver/workloads/TenantManagementWorkload.actor.cpp @@ -268,8 +268,8 @@ struct TenantManagementWorkload : TestWorkload { wait(tr->commit()); } else if (operationType == OperationType::MANAGEMENT_DATABASE) { ASSERT(tenantsToCreate.size() == 1); - Optional<TenantMapEntry> result = wait(TenantAPI::createTenant( - self->dataDb.getReference(), tenantsToCreate.begin()->first, tenantsToCreate.begin()->second)); + wait(success(TenantAPI::createTenant( + self->dataDb.getReference(), tenantsToCreate.begin()->first, tenantsToCreate.begin()->second))); } else if (operationType == OperationType::MANAGEMENT_TRANSACTION) { tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS); int64_t _nextId = wait(TenantAPI::getNextTenantId(tr)); @@ -802,9 +802,9 @@ struct TenantManagementWorkload : TestWorkload { std::string base64Prefix; std::string printablePrefix; std::string tenantStateStr; - std::string assignedClusterStr; std::string base64TenantGroup; std::string printableTenantGroup; + std::string assignedClusterStr; jsonDoc.get("id", id); jsonDoc.get("prefix.base64", base64Prefix); @@ -815,11 +815,6 @@ struct TenantManagementWorkload : TestWorkload { jsonDoc.get("tenant_state", tenantStateStr); - Optional<ClusterName> assignedCluster; - if (jsonDoc.tryGet("assigned_cluster", assignedClusterStr)) { - assignedCluster = ClusterNameRef(assignedClusterStr); - } - Optional<TenantGroupName> tenantGroup; if (jsonDoc.tryGet("tenant_group.base64", base64TenantGroup)) { jsonDoc.get("tenant_group.printable", printableTenantGroup); @@ -828,7 +823,12 @@ struct TenantManagementWorkload : TestWorkload { tenantGroup = TenantGroupNameRef(tenantGroupStr); } - TenantMapEntry entry(id, tenantGroup, TenantMapEntry::stringToTenantState(tenantStateStr)); + Optional<ClusterName> assignedCluster; + if (jsonDoc.tryGet("assigned_cluster", assignedClusterStr)) { + assignedCluster = ClusterNameRef(assignedClusterStr); + } + + TenantMapEntry entry(id, TenantMapEntry::stringToTenantState(tenantStateStr), tenantGroup); ASSERT(entry.prefix == prefix); return entry; } @@ -896,6 +896,7 @@ struct TenantManagementWorkload : TestWorkload { try { retry = true; wait(tr->onError(e)); + retry = true; } catch (Error& e) { error = e; retry = false; @@ -1185,8 +1186,8 @@ struct TenantManagementWorkload : TestWorkload { ASSERT(!hasInvalidOption); ASSERT(!hasSystemTenantGroup); ASSERT(!specialKeysUseInvalidTuple); - auto itr = self->createdTenants.find(tenant); + auto itr = self->createdTenants.find(tenant); if (itr->second.tenantGroup.present()) { auto tenantGroupItr = self->createdTenantGroups.find(itr->second.tenantGroup.get()); ASSERT(tenantGroupItr != self->createdTenantGroups.end()); diff --git a/flow/include/flow/error_definitions.h b/flow/include/flow/error_definitions.h index 41422f68ad..75394391b5 100755 --- a/flow/include/flow/error_definitions.h +++ b/flow/include/flow/error_definitions.h @@ -234,8 +234,8 @@ ERROR( tenants_disabled, 2136, "Tenants have been disabled in the cluster" ) ERROR( unknown_tenant, 2137, "Tenant is not available from this server" ) ERROR( illegal_tenant_access, 2138, "Illegal tenant access" ) ERROR( invalid_tenant_group_name, 2139, "Tenant group name cannot begin with \\xff" ) -ERROR( tenant_removed, 2140, "The tenant was removed" ) -ERROR( invalid_tenant_configuration, 2141, "Tenant configuration is invalid" ) +ERROR( invalid_tenant_configuration, 2140, "Tenant configuration is invalid" ) +ERROR( tenant_removed, 2141, "The tenant was removed" ) ERROR( invalid_tenant_state, 2142, "Operation cannot be applied to tenant in its current state" ) ERROR( invalid_cluster_name, 2150, "Data cluster name cannot begin with \\xff" )