Skip to content

Commit 58a41e7

Browse files
committed
CreateDatabase: support specifying number of coordinators/mediators
1 parent 77ffed5 commit 58a41e7

File tree

7 files changed

+66
-2
lines changed

7 files changed

+66
-2
lines changed

ydb/core/cms/console/console__create_tenant.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ 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+
151+
if (rec.options().mediator_buckets()) {
152+
Tenant->TimeCastBucketsPerMediator = rec.options().mediator_buckets();
153+
}
154+
141155
if (rec.options().disable_tx_service()) {
142156
Tenant->Coordinators = 0;
143157
Tenant->Mediators = 0;
@@ -251,7 +265,6 @@ class TTenantsManager::TTxCreateTenant : public TTransactionBase<TTenantsManager
251265

252266
Tenant->IsExternalHive = false;
253267
Tenant->IsGraphShardEnabled = false;
254-
Tenant->Coordinators = 1;
255268
Tenant->SlotsAllocationConfirmed = true;
256269
} else {
257270
return Error(Ydb::StatusIds::BAD_REQUEST,

ydb/public/api/protos/ydb_cms.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ 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;
70+
// Number of per-mediator buckets (server default is used when zero)
71+
uint32 mediator_buckets = 6;
6672
}
6773

6874
// A set of quotas for schema operations

ydb/tests/functional/tenants/test_dynamic_tenants.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,32 @@ 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+
'mediator_buckets': 16,
514+
'plan_resolution': 100,
515+
},
516+
)
517+
database_nodes = ydb_cluster.register_and_start_slots(database, count=1)
518+
ydb_cluster.wait_tenant_up(database)
519+
520+
description = ydb_cluster.client.describe(database, '')
521+
params = description.PathDescription.DomainDescription.ProcessingParams
522+
assert_that(
523+
[
524+
len(params.Coordinators),
525+
len(params.Mediators),
526+
params.TimeCastBucketsPerMediator,
527+
params.PlanResolution,
528+
],
529+
equal_to([4, 5, 16, 100]))

ydb/tests/library/common/protobuf_console.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ 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)
7578

7679
class AlterTenantRequest(AbstractProtobufBuilder):
7780
"""

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: 4 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, mediator_buckets=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,9 @@ 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
235+
self.mediator_buckets = mediator_buckets
233236

234237

235238
class HostConfig(object):

ydb/tools/cfg/dynamic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ 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
322+
if tenant.mediator_buckets is not None:
323+
console_request.CreateTenantRequest.Request.options.mediator_buckets = tenant.mediator_buckets
318324

319325
return utils.message_to_string(console_request)
320326

0 commit comments

Comments
 (0)