7979AUTOSCALER_PVC_SUFFIX = "-block-data"
8080AUTOSCALER_WAL_PVC_SUFFIX = "-pg-wal"
8181PITR_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 )
@@ -356,13 +357,39 @@ async def update_branch_volume_iops(branch_id: Identifier, iops: int) -> None:
356357 namespace = deployment_namespace (branch_id )
357358
358359 volume , _ = await resolve_autoscaler_volume_identifiers (namespace )
360+
361+ # Detect PITR by checking whether the WAL PVC exists.
362+ wal_pvc_name = f"{ _autoscaler_vm_name ()} { AUTOSCALER_WAL_PVC_SUFFIX } "
363+ try :
364+ await kube_service .get_persistent_volume_claim (namespace , wal_pvc_name )
365+ pitr_active = True
366+ except VelaKubernetesError :
367+ pitr_active = False
368+
369+ if pitr_active :
370+ data_iops = max (1 , round (iops * (1 - WAL_IOPS_FRACTION )))
371+ wal_iops = max (1 , round (iops * WAL_IOPS_FRACTION ))
372+ else :
373+ data_iops = iops
374+
359375 try :
360376 async with create_simplyblock_api () as sb_api :
361- await sb_api .update_volume (volume = volume , payload = {"max_rw_iops" : iops })
377+ await sb_api .update_volume (volume = volume , payload = {"max_rw_iops" : data_iops })
362378 except VelaSimplyblockAPIError as exc :
363379 raise VelaDeploymentError ("Failed to update volume" ) from exc
364380
365- logger .info ("Updated Simplyblock volume %s IOPS to %s" , volume , iops )
381+ logger .info ("Updated Simplyblock data volume %s IOPS to %s" , volume , data_iops )
382+
383+ if pitr_active :
384+ wal_volume , _ = await resolve_autoscaler_wal_volume_identifiers (namespace )
385+ try :
386+ async with create_simplyblock_api () as sb_api :
387+ await sb_api .update_volume (volume = wal_volume , payload = {"max_rw_iops" : wal_iops })
388+ except VelaSimplyblockAPIError as exc :
389+ raise VelaDeploymentError ("Failed to update WAL volume" ) from exc
390+ logger .info ("Updated Simplyblock WAL volume %s IOPS to %s" , wal_volume , wal_iops )
391+ else :
392+ logger .info ("WAL PVC absent for branch %s; full IOPS budget applied to data volume" , branch_id )
366393
367394
368395async def ensure_branch_storage_class (branch_id : Identifier , * , iops : int ) -> str :
@@ -397,15 +424,18 @@ async def _create_fresh_pvcs(
397424 parameters : DeploymentParameters ,
398425 * ,
399426 pitr_enabled : bool ,
427+ wal_iops : int = 0 ,
400428) -> None :
401429 """Create empty block PVCs for a brand-new deployment before helm install."""
402430 from .kubernetes .pvc import create_pvc
403431
404432 access_modes = ["ReadWriteMany" ]
405433
406- def _pvc (name : str , size : str ) -> kubernetes_client .V1PersistentVolumeClaim :
434+ def _pvc (
435+ name : str , size : str , annotations : dict [str , str ] | None = None
436+ ) -> kubernetes_client .V1PersistentVolumeClaim :
407437 return kubernetes_client .V1PersistentVolumeClaim (
408- metadata = kubernetes_client .V1ObjectMeta (name = name ),
438+ metadata = kubernetes_client .V1ObjectMeta (name = name , annotations = annotations ),
409439 spec = kubernetes_client .V1PersistentVolumeClaimSpec (
410440 access_modes = access_modes ,
411441 storage_class_name = storage_class_name ,
@@ -419,7 +449,8 @@ def _pvc(name: str, size: str) -> kubernetes_client.V1PersistentVolumeClaim:
419449
420450 if pitr_enabled :
421451 wal_pvc_name = f"{ _autoscaler_vm_name ()} { AUTOSCALER_WAL_PVC_SUFFIX } "
422- await create_pvc (namespace , _pvc (wal_pvc_name , PITR_WAL_PVC_SIZE ))
452+ wal_annotations = {"simplybk/qos-rw-iops" : str (wal_iops )} if wal_iops > 0 else None
453+ await create_pvc (namespace , _pvc (wal_pvc_name , PITR_WAL_PVC_SIZE , annotations = wal_annotations ))
423454
424455
425456def _configure_vela_values (
@@ -548,10 +579,18 @@ async def create_vela_config(
548579 postgresql_resource = resources .files (__package__ ).joinpath ("postgresql.conf" )
549580 values_content = _load_chart_values (chart )
550581
551- storage_class_name = await ensure_branch_storage_class (branch_id , iops = parameters .iops )
582+ if pitr_enabled :
583+ data_iops = max (1 , round (parameters .iops * (1 - WAL_IOPS_FRACTION )))
584+ wal_iops = max (1 , round (parameters .iops * WAL_IOPS_FRACTION ))
585+ else :
586+ data_iops = parameters .iops
587+ wal_iops = 0
588+ storage_class_name = await ensure_branch_storage_class (branch_id , iops = data_iops )
552589
553590 if not use_existing_db_pvc :
554- await _create_fresh_pvcs (namespace , storage_class_name , parameters , pitr_enabled = pitr_enabled )
591+ await _create_fresh_pvcs (
592+ namespace , storage_class_name , parameters , pitr_enabled = pitr_enabled , wal_iops = wal_iops
593+ )
555594
556595 values_content = _configure_vela_values (
557596 values_content ,
0 commit comments