Skip to content

Commit

Permalink
Adjust default values for ClickHousePlugin parameters
Browse files Browse the repository at this point in the history
Calculate the default value for max_concurrent_ parameters based on the
number of Clickhouse nodes.
  • Loading branch information
meatlink committed Sep 28, 2023
1 parent aad5757 commit e0dbb66
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
16 changes: 16 additions & 0 deletions astacus/coordinator/plugins/clickhouse/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
)
from astacus.coordinator.plugins.zookeeper_config import ZooKeeperConfiguration
from pathlib import Path
from pydantic import root_validator
from typing import List, Sequence


Expand Down Expand Up @@ -83,6 +84,21 @@ class ClickHousePlugin(CoordinatorPlugin):
max_concurrent_sync: int = 100
use_system_unfreeze: bool = True

@root_validator(pre=True)
def _apply_max_concurrent_query_defaults(cls, values):
default_value = 10 * len(values.get("clickhouse", 10).nodes)
properties = [
"max_concurrent_create_databases",
"max_concurrent_drop_databases",
"max_concurrent_restart_replica",
"max_concurrent_restore_replica",
"max_concurrent_attach",
"max_concurrent_sync",
]
for property in properties:
values.setdefault(property, default_value)
return values

def get_backup_steps(self, *, context: OperationContext) -> List[Step]:
zookeeper_client = get_zookeeper_client(self.zookeeper)
clickhouse_clients = get_clickhouse_clients(self.clickhouse)
Expand Down
56 changes: 56 additions & 0 deletions tests/unit/coordinator/plugins/clickhouse/test_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""
from astacus.coordinator.plugins.clickhouse.config import ClickHouseConfiguration, ClickHouseNode
from astacus.coordinator.plugins.clickhouse.plugin import ClickHousePlugin

import pytest


@pytest.mark.parametrize(
"property",
[
"max_concurrent_create_databases",
"max_concurrent_drop_databases",
"max_concurrent_restart_replica",
"max_concurrent_restore_replica",
"max_concurrent_attach",
"max_concurrent_sync",
],
)
def test_max_concurrent_queries_params_have_default_values(property: str) -> None:
plugin = ClickHousePlugin(
clickhouse=ClickHouseConfiguration(
nodes=[
ClickHouseNode(host="host", port=4242),
ClickHouseNode(host="host", port=4242),
ClickHouseNode(host="host", port=4242),
]
)
)
assert getattr(plugin, property) == 30


def test_max_concurrent_queries_params_accept_explicit_values() -> None:
plugin = ClickHousePlugin(
max_concurrent_create_databases=1,
max_concurrent_drop_databases=2,
max_concurrent_restart_replica=3,
max_concurrent_restore_replica=4,
max_concurrent_attach=5,
max_concurrent_sync=6,
clickhouse=ClickHouseConfiguration(
nodes=[
ClickHouseNode(host="host", port=4242),
ClickHouseNode(host="host", port=4242),
ClickHouseNode(host="host", port=4242),
]
),
)
assert plugin.max_concurrent_create_databases == 1
assert plugin.max_concurrent_drop_databases == 2
assert plugin.max_concurrent_restart_replica == 3
assert plugin.max_concurrent_restore_replica == 4
assert plugin.max_concurrent_attach == 5
assert plugin.max_concurrent_sync == 6

0 comments on commit e0dbb66

Please sign in to comment.