Skip to content

CreateDatabase: support specifying the number of coordinators/mediators #15415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion ydb/core/cms/console/console__create_tenant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ class TTenantsManager::TTxCreateTenant : public TTransactionBase<TTenantsManager
Tenant->PlanResolution = rec.options().plan_resolution();
}

if (rec.options().coordinators()) {
Tenant->Coordinators = rec.options().coordinators();
} else if (rec.resources_kind_case() == Ydb::Cms::CreateDatabaseRequest::kServerlessResources) {
Tenant->Coordinators = 1;
}

if (rec.options().mediators()) {
Tenant->Mediators = rec.options().mediators();
}

if (rec.options().disable_tx_service()) {
Tenant->Coordinators = 0;
Tenant->Mediators = 0;
Expand Down Expand Up @@ -251,7 +261,6 @@ class TTenantsManager::TTxCreateTenant : public TTransactionBase<TTenantsManager

Tenant->IsExternalHive = false;
Tenant->IsGraphShardEnabled = false;
Tenant->Coordinators = 1;
Tenant->SlotsAllocationConfirmed = true;
} else {
return Error(Ydb::StatusIds::BAD_REQUEST,
Expand Down
4 changes: 4 additions & 0 deletions ydb/public/api/protos/ydb_cms.proto
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ message DatabaseOptions {
bool disable_external_subdomain = 2;
// Transaction plan resolution in milliseconds
uint32 plan_resolution = 3;
// Number of coordinators (server default is used when zero)
uint32 coordinators = 4;
// Number of mediators (server default is used when zero)
uint32 mediators = 5;
}

// A set of quotas for schema operations
Expand Down
30 changes: 30 additions & 0 deletions ydb/tests/functional/tenants/test_dynamic_tenants.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,33 @@ def test_check_access(ydb_cluster):
for user in users.values():
ydb_cluster.remove_database(user['path'])
ydb_cluster.unregister_and_stop_slots(database_nodes[user['path']])


def test_custom_coordinator_options(ydb_cluster):
database = '/Root/users/custom_options'
ydb_cluster.create_database(
database,
storage_pool_units_count={
'hdd': 1
},
options={
'coordinators': 4,
'mediators': 5,
'plan_resolution': 100,
},
)
database_nodes = ydb_cluster.register_and_start_slots(database, count=1)
ydb_cluster.wait_tenant_up(database)

description = ydb_cluster.client.describe(database, '')
params = description.PathDescription.DomainDescription.ProcessingParams
assert_that(
[
len(params.Coordinators),
len(params.Mediators),
params.PlanResolution,
],
equal_to([4, 5, 100]))

ydb_cluster.remove_database(database)
ydb_cluster.unregister_and_stop_slots(database_nodes)
4 changes: 4 additions & 0 deletions ydb/tests/library/common/protobuf_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def set_disk_quotas(self, disk_quotas):
def set_attribute(self, name, value):
self.protobuf.CreateTenantRequest.Request.attributes[name] = value

def set_options(self, **kwargs):
for name, value in kwargs.items():
setattr(self.protobuf.CreateTenantRequest.Request.options, name, value)


class AlterTenantRequest(AbstractProtobufBuilder):
"""
Expand Down
4 changes: 4 additions & 0 deletions ydb/tests/library/harness/kikimr_cluster_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def create_database(
disable_external_subdomain=False,
timeout_seconds=120,
token=None,
options=None,
):
req = CreateTenantRequest(database_name)
for storage_pool_type_name, units_count in storage_pool_units_count.items():
Expand All @@ -203,6 +204,9 @@ def create_database(
if token is not None:
req.set_user_token(token)

if options is not None:
req.set_options(**options)

response = self.client.send_request(req.protobuf, method='ConsoleRequest')
operation = response.CreateTenantResponse.Response.operation
if not operation.ready and response.Status.Code != StatusIds.STATUS_CODE_UNSPECIFIED:
Expand Down
4 changes: 3 additions & 1 deletion ydb/tools/cfg/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def __init__(self, count, kind, zone):


class Tenant(object):
def __init__(self, name, storage_units, compute_units=None, overridden_configs=None, shared=False, plan_resolution=None):
def __init__(self, name, storage_units, compute_units=None, overridden_configs=None, shared=False, plan_resolution=None, coordinators=None, mediators=None):
self.name = name
self.overridden_configs = overridden_configs
self.storage_units = tuple(StorageUnit(**storage_unit_template) for storage_unit_template in storage_units)
Expand All @@ -230,6 +230,8 @@ def __init__(self, name, storage_units, compute_units=None, overridden_configs=N
self.compute_units = tuple(ComputeUnit(**compute_unit_template) for compute_unit_template in compute_units)
self.shared = shared
self.plan_resolution = plan_resolution
self.coordinators = coordinators
self.mediators = mediators


class HostConfig(object):
Expand Down
4 changes: 4 additions & 0 deletions ydb/tools/cfg/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ def _construct_create_tenant_request(domain, tenant):

if tenant.plan_resolution is not None:
console_request.CreateTenantRequest.Request.options.plan_resolution = tenant.plan_resolution
if tenant.coordinators is not None:
console_request.CreateTenantRequest.Request.options.coordinators = tenant.coordinators
if tenant.mediators is not None:
console_request.CreateTenantRequest.Request.options.mediators = tenant.mediators

return utils.message_to_string(console_request)

Expand Down
Loading