Skip to content

Commit b8aa7f5

Browse files
snauryblinkov
authored andcommitted
CreateDatabase: support specifying the number of coordinators/mediators (#15415)
1 parent 8a7ce5f commit b8aa7f5

File tree

7 files changed

+59
-2
lines changed

7 files changed

+59
-2
lines changed

ydb/core/cms/console/console__create_tenant.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ class TTenantsManager::TTxCreateTenant : public TTransactionBase<TTenantsManager
138138
Tenant->PlanResolution = rec.options().plan_resolution();
139139
}
140140

141+
if (rec.options().coordinators()) {
142+
Tenant->Coordinators = rec.options().coordinators();
143+
} else if (rec.resources_kind_case() == Ydb::Cms::CreateDatabaseRequest::kServerlessResources) {
144+
Tenant->Coordinators = 1;
145+
}
146+
147+
if (rec.options().mediators()) {
148+
Tenant->Mediators = rec.options().mediators();
149+
}
150+
141151
if (rec.options().disable_tx_service()) {
142152
Tenant->Coordinators = 0;
143153
Tenant->Mediators = 0;
@@ -251,7 +261,6 @@ class TTenantsManager::TTxCreateTenant : public TTransactionBase<TTenantsManager
251261

252262
Tenant->IsExternalHive = false;
253263
Tenant->IsGraphShardEnabled = false;
254-
Tenant->Coordinators = 1;
255264
Tenant->SlotsAllocationConfirmed = true;
256265
} else {
257266
return Error(Ydb::StatusIds::BAD_REQUEST,

ydb/public/api/protos/ydb_cms.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ message DatabaseOptions {
6363
bool disable_external_subdomain = 2;
6464
// Transaction plan resolution in milliseconds
6565
uint32 plan_resolution = 3;
66+
// Number of coordinators (server default is used when zero)
67+
uint32 coordinators = 4;
68+
// Number of mediators (server default is used when zero)
69+
uint32 mediators = 5;
6670
}
6771

6872
// A set of quotas for schema operations

ydb/tests/functional/tenants/test_dynamic_tenants.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,33 @@ def test_check_access(ydb_cluster):
498498
for user in users.values():
499499
ydb_cluster.remove_database(user['path'])
500500
ydb_cluster.unregister_and_stop_slots(database_nodes[user['path']])
501+
502+
503+
def test_custom_coordinator_options(ydb_cluster):
504+
database = '/Root/users/custom_options'
505+
ydb_cluster.create_database(
506+
database,
507+
storage_pool_units_count={
508+
'hdd': 1
509+
},
510+
options={
511+
'coordinators': 4,
512+
'mediators': 5,
513+
'plan_resolution': 100,
514+
},
515+
)
516+
database_nodes = ydb_cluster.register_and_start_slots(database, count=1)
517+
ydb_cluster.wait_tenant_up(database)
518+
519+
description = ydb_cluster.client.describe(database, '')
520+
params = description.PathDescription.DomainDescription.ProcessingParams
521+
assert_that(
522+
[
523+
len(params.Coordinators),
524+
len(params.Mediators),
525+
params.PlanResolution,
526+
],
527+
equal_to([4, 5, 100]))
528+
529+
ydb_cluster.remove_database(database)
530+
ydb_cluster.unregister_and_stop_slots(database_nodes)

ydb/tests/library/common/protobuf_console.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ def set_disk_quotas(self, disk_quotas):
7272
def set_attribute(self, name, value):
7373
self.protobuf.CreateTenantRequest.Request.attributes[name] = value
7474

75+
def set_options(self, **kwargs):
76+
for name, value in kwargs.items():
77+
setattr(self.protobuf.CreateTenantRequest.Request.options, name, value)
78+
7579

7680
class AlterTenantRequest(AbstractProtobufBuilder):
7781
"""

ydb/tests/library/harness/kikimr_cluster_interface.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def create_database(
189189
disable_external_subdomain=False,
190190
timeout_seconds=120,
191191
token=None,
192+
options=None,
192193
):
193194
req = CreateTenantRequest(database_name)
194195
for storage_pool_type_name, units_count in storage_pool_units_count.items():
@@ -203,6 +204,9 @@ def create_database(
203204
if token is not None:
204205
req.set_user_token(token)
205206

207+
if options is not None:
208+
req.set_options(**options)
209+
206210
response = self.client.send_request(req.protobuf, method='ConsoleRequest')
207211
operation = response.CreateTenantResponse.Response.operation
208212
if not operation.ready and response.Status.Code != StatusIds.STATUS_CODE_UNSPECIFIED:

ydb/tools/cfg/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def __init__(self, count, kind, zone):
221221

222222

223223
class Tenant(object):
224-
def __init__(self, name, storage_units, compute_units=None, overridden_configs=None, shared=False, plan_resolution=None):
224+
def __init__(self, name, storage_units, compute_units=None, overridden_configs=None, shared=False, plan_resolution=None, coordinators=None, mediators=None):
225225
self.name = name
226226
self.overridden_configs = overridden_configs
227227
self.storage_units = tuple(StorageUnit(**storage_unit_template) for storage_unit_template in storage_units)
@@ -230,6 +230,8 @@ def __init__(self, name, storage_units, compute_units=None, overridden_configs=N
230230
self.compute_units = tuple(ComputeUnit(**compute_unit_template) for compute_unit_template in compute_units)
231231
self.shared = shared
232232
self.plan_resolution = plan_resolution
233+
self.coordinators = coordinators
234+
self.mediators = mediators
233235

234236

235237
class HostConfig(object):

ydb/tools/cfg/dynamic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ def _construct_create_tenant_request(domain, tenant):
315315

316316
if tenant.plan_resolution is not None:
317317
console_request.CreateTenantRequest.Request.options.plan_resolution = tenant.plan_resolution
318+
if tenant.coordinators is not None:
319+
console_request.CreateTenantRequest.Request.options.coordinators = tenant.coordinators
320+
if tenant.mediators is not None:
321+
console_request.CreateTenantRequest.Request.options.mediators = tenant.mediators
318322

319323
return utils.message_to_string(console_request)
320324

0 commit comments

Comments
 (0)