Skip to content

Commit 7247ac6

Browse files
committed
iops split
1 parent 1d5bc91 commit 7247ac6

3 files changed

Lines changed: 53 additions & 6 deletions

File tree

src/api/organization/project/branch/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from .....deployment import (
2727
AUTOSCALER_PVC_SUFFIX,
2828
STORAGE_PVC_SUFFIX,
29+
WAL_IOPS_FRACTION,
2930
DeploymentParameters,
3031
ResizeParameters,
3132
branch_api_domain,
@@ -869,7 +870,8 @@ async def _clone_branch_environment_task(
869870
storage_class_name: str | None = None
870871
if copy_data:
871872
try:
872-
storage_class_name = await ensure_branch_storage_class(branch_id, iops=parameters.iops)
873+
data_iops = max(1, round(parameters.iops * (1 - WAL_IOPS_FRACTION)))
874+
storage_class_name = await ensure_branch_storage_class(branch_id, iops=data_iops)
873875
await clone_branch_database_volume(
874876
source_branch_id=source_branch_id,
875877
target_branch_id=branch_id,
@@ -942,7 +944,8 @@ async def _restore_branch_environment_task(
942944
await _persist_branch_status(branch_id, BranchServiceStatus.CREATING)
943945
storage_class_name: str | None = None
944946
try:
945-
storage_class_name = await ensure_branch_storage_class(branch_id, iops=parameters.iops)
947+
data_iops = max(1, round(parameters.iops * (1 - WAL_IOPS_FRACTION)))
948+
storage_class_name = await ensure_branch_storage_class(branch_id, iops=data_iops)
946949
await restore_branch_database_volume_from_snapshot(
947950
source_branch_id=source_branch_id,
948951
target_branch_id=branch_id,
@@ -1022,7 +1025,8 @@ async def _restore_branch_environment_in_place_task(
10221025
return
10231026

10241027
try:
1025-
storage_class_name = await ensure_branch_storage_class(branch_id, iops=parameters.iops)
1028+
data_iops = max(1, round(parameters.iops * (1 - WAL_IOPS_FRACTION)))
1029+
storage_class_name = await ensure_branch_storage_class(branch_id, iops=data_iops)
10261030
await restore_branch_database_volume_from_snapshot(
10271031
source_branch_id=source_branch_id,
10281032
target_branch_id=branch_id,

src/deployment/__init__.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
AUTOSCALER_PVC_SUFFIX = "-block-data"
8080
AUTOSCALER_WAL_PVC_SUFFIX = "-pg-wal"
8181
PITR_WAL_PVC_SIZE = "100Gi"
82+
WAL_IOPS_FRACTION = 0.25
8283
_LOAD_BALANCER_TIMEOUT_SECONDS = float(600)
8384
_LOAD_BALANCER_POLL_INTERVAL_SECONDS = float(2)
8485
_OVERLAY_IP_TIMEOUT_SECONDS = float(300)
@@ -355,14 +356,28 @@ async def resolve_branch_database_volume_size(branch_id: Identifier) -> int:
355356
async def update_branch_volume_iops(branch_id: Identifier, iops: int) -> None:
356357
namespace = deployment_namespace(branch_id)
357358

359+
data_iops = max(1, round(iops * (1 - WAL_IOPS_FRACTION)))
360+
wal_iops = max(1, round(iops * WAL_IOPS_FRACTION))
361+
358362
volume, _ = await resolve_autoscaler_volume_identifiers(namespace)
359363
try:
360364
async with create_simplyblock_api() as sb_api:
361-
await sb_api.update_volume(volume=volume, payload={"max_rw_iops": iops})
365+
await sb_api.update_volume(volume=volume, payload={"max_rw_iops": data_iops})
362366
except VelaSimplyblockAPIError as exc:
363367
raise VelaDeploymentError("Failed to update volume") from exc
364368

365-
logger.info("Updated Simplyblock volume %s IOPS to %s", volume, iops)
369+
logger.info("Updated Simplyblock data volume %s IOPS to %s", volume, data_iops)
370+
371+
try:
372+
wal_volume, _ = await resolve_autoscaler_wal_volume_identifiers(namespace)
373+
try:
374+
async with create_simplyblock_api() as sb_api:
375+
await sb_api.update_volume(volume=wal_volume, payload={"max_rw_iops": wal_iops})
376+
except VelaSimplyblockAPIError as exc:
377+
raise VelaDeploymentError("Failed to update WAL volume") from exc
378+
logger.info("Updated Simplyblock WAL volume %s IOPS to %s", wal_volume, wal_iops)
379+
except VelaDeploymentError as exc:
380+
logger.info("WAL volume not found for branch %s; skipping WAL IOPS update: %s", branch_id, exc)
366381

367382

368383
async def ensure_branch_storage_class(branch_id: Identifier, *, iops: int) -> str:
@@ -384,6 +399,23 @@ async def ensure_branch_storage_class(branch_id: Identifier, *, iops: int) -> st
384399
return storage_class_name
385400

386401

402+
def _load_compose_manifest() -> dict[str, Any]:
403+
compose_resource = resources.files(__package__).joinpath("compose.yml")
404+
compose_content = yaml.safe_load(compose_resource.read_text())
405+
if not isinstance(compose_content, dict):
406+
raise VelaDeploymentError("docker-compose manifest must be a mapping")
407+
return compose_content
408+
409+
410+
def _configure_compose_storage(compose: dict[str, Any], *, enable_file_storage: bool) -> dict[str, Any]:
411+
services = compose.get("services")
412+
if not isinstance(services, dict):
413+
raise VelaDeploymentError("docker-compose manifest missing 'services' mapping")
414+
if not enable_file_storage:
415+
services.pop("storage", None)
416+
return compose
417+
418+
387419
def _load_chart_values(chart_root: Any) -> dict[str, Any]:
388420
values_content = yaml.safe_load((chart_root / "values.yaml").read_text())
389421
if not isinstance(values_content, dict):
@@ -399,6 +431,7 @@ def _configure_vela_values(
399431
database_admin_password: str,
400432
pgbouncer_admin_password: str,
401433
storage_class_name: str,
434+
wal_iops: int,
402435
use_existing_db_pvc: bool,
403436
pgbouncer_config: Mapping[str, int] | None,
404437
enable_file_storage: bool,
@@ -454,6 +487,7 @@ def _configure_vela_values(
454487
wal_persistence["create"] = not use_existing_db_pvc
455488
wal_persistence["size"] = PITR_WAL_PVC_SIZE
456489
wal_persistence["storageClassName"] = storage_class_name
490+
wal_persistence["annotations"] = {"simplybk/qos-rw-iops": str(wal_iops)}
457491
wal_persistence["claimName"] = wal_persistence.get("claimName") or (
458492
f"{_autoscaler_vm_name()}{AUTOSCALER_WAL_PVC_SUFFIX}"
459493
)
@@ -521,14 +555,17 @@ async def create_vela_config(
521555
postgresql_resource = resources.files(__package__).joinpath("postgresql.conf")
522556
values_content = _load_chart_values(chart)
523557

524-
storage_class_name = await ensure_branch_storage_class(branch_id, iops=parameters.iops)
558+
data_iops = max(1, round(parameters.iops * (1 - WAL_IOPS_FRACTION)))
559+
wal_iops = max(1, round(parameters.iops * WAL_IOPS_FRACTION))
560+
storage_class_name = await ensure_branch_storage_class(branch_id, iops=data_iops)
525561
values_content = _configure_vela_values(
526562
values_content,
527563
parameters=parameters,
528564
jwt_secret=jwt_secret,
529565
database_admin_password=database_admin_password,
530566
pgbouncer_admin_password=pgbouncer_admin_password,
531567
storage_class_name=storage_class_name,
568+
wal_iops=wal_iops,
532569
use_existing_db_pvc=use_existing_db_pvc,
533570
pgbouncer_config=pgbouncer_config,
534571
enable_file_storage=parameters.enable_file_storage,

src/deployment/charts/vela/templates/autoscaler/wal-pvc.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ metadata:
2222
namespace: {{ .Release.Namespace }}
2323
labels:
2424
{{- include "vela.labels" . | nindent 4 }}
25+
{{- if $pgWalPersistence.annotations }}
26+
annotations:
27+
{{- range $k, $v := $pgWalPersistence.annotations }}
28+
{{ $k }}: {{ $v | quote }}
29+
{{- end }}
30+
{{- end }}
2531
spec:
2632
{{- if $pgWalPersistence.storageClassName }}
2733
storageClassName: {{ $pgWalPersistence.storageClassName }}

0 commit comments

Comments
 (0)